2 # Copyright(C) 2012 thomasv@gitorious
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as
6 # published by the Free Software Foundation, either version 3 of the
7 # License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public
15 # License along with this program. If not, see
16 # <http://www.gnu.org/licenses/agpl.html>.
18 import time, json, socket, operator, thread, ast, sys, re, traceback
20 from json import dumps, loads
24 config = ConfigParser.ConfigParser()
25 # set some defaults, which will be overwritten by the config file
26 config.add_section('server')
27 config.set('server','banner', 'Welcome to Electrum!')
28 config.set('server', 'host', 'localhost')
29 config.set('server', 'port', '50000')
30 config.set('server', 'password', '')
31 config.set('server', 'irc', 'yes')
32 config.set('server', 'ircname', 'Electrum server')
33 config.add_section('database')
34 config.set('database', 'type', 'psycopg2')
35 config.set('database', 'database', 'abe')
38 f = open('/etc/electrum.conf','r')
42 print "Could not read electrum.conf. I will use the default values."
45 f = open('/etc/electrum.banner','r')
46 config.set('server','banner', f.read())
52 password = config.get('server','password')
55 from processor import Shared, Processor, Dispatcher
58 from transports.stratum_http import HttpServer
59 from transports.stratum_tcp import TcpServer
60 from transports.native import NativeServer
65 from processor import Processor
72 if __name__ == '__main__':
76 server = jsonrpclib.Server('http://%s:8081'%config.get('server','host'))
79 out = server.stop(password)
81 out = "Unknown command: '%s'" % cmd
85 processor = Processor()
87 # Bind shared to processor since constructor is user defined
88 processor.shared = shared
91 abe = abe_backend.AbeBackend(config, processor)
92 processor.register('blockchain', abe.process)
94 sb = irc.ServerBackend(config, processor)
95 processor.register('server', sb.process)
98 dispatcher = Dispatcher(shared, processor)
101 # Create various transports we need
102 host = config.get('server','host')
103 transports = [ NativeServer(shared, abe.store, sb.irc, config.get('server','banner'), host, 50000),
104 TcpServer(shared, processor, host, 50001),
105 HttpServer(shared, processor, host, 8081),
107 for server in transports:
110 print "starting Electrum server on", host
111 while not shared.stopped():
113 print "server stopped"