config.set('server', 'host', 'ecdsa.org')
config.set('server', 'port', 50000)
config.set('server', 'password', '')
+config.set('server', 'irc', 'yes')
+config.set('server', 'ircname', 'Electrum server')
config.add_section('database')
config.set('database', 'type', 'psycopg2')
config.set('database', 'database', 'abe')
config.readfp(f)
f.close()
except:
- print "Could not read electrum.conf. I will use the dafault values."
+ print "Could not read electrum.conf. I will use the default values."
stopping = False
block_number = -1
try:
s = socket.socket()
s.connect(('irc.freenode.net', 6667))
- s.send('USER '+config.get('server','host')+' '+NICK+' bla :'+NICK+'\n')
+ s.send('USER electrum 0 * :'+config.get('server','host')+' '+config.get('server','ircname')+'\n')
s.send('NICK '+NICK+'\n')
s.send('JOIN #electrum\n')
+ sf = s.makefile('r', 0)
t = 0
while not stopping:
- line = s.recv(2048)
+ line = sf.readline()
line = line.rstrip('\r\n')
line = line.split()
if line[0]=='PING':
s.send('PONG '+line[1]+'\n')
elif '353' in line: # answer to /names
k = line.index('353')
- try:
- k2 = line.index('366')
- except:
- continue
- for item in line[k+1:k2]:
+ for item in line[k+1:]:
if item[0:2] == 'E_':
- s.send('USERHOST %s\n'%item)
- elif '302' in line: # answer to /userhost
- k = line.index('302')
- m = re.match( "^:(.*?)=\+~(.*?)@(.*?)$", line[k+2] )
- if m:
- name = m.group(1)
- host = m.group(2)
- ip = m.group(3)
- peer_list[name] = (ip,host)
+ s.send('WHO %s\n'%item)
+ elif '352' in line: # answer to /who
+ # warning: this is a horrible hack which apparently works
+ k = line.index('352')
+ ip = line[k+4]
+ ip = socket.gethostbyname(ip)
+ name = line[k+6]
+ host = line[k+9]
+ peer_list[name] = (ip,host)
elif time.time() - t > 5*60:
s.send('NAMES #electrum\n')
t = time.time()
+ peer_list = {}
except:
traceback.print_exc(file=sys.stdout)
finally:
+ sf.close()
s.close()
if args.dbtype == 'sqlite3':
args.connect_args = { 'database' : config.get('database','database') }
elif args.dbtype == 'MySQLdb':
- args.connect_args = { 'db' : config.get('database','database'), 'user' : config.get('database','user'), 'passwd' : config.get('database','pass') }
+ args.connect_args = { 'db' : config.get('database','database'), 'user' : config.get('database','username'), 'passwd' : config.get('database','password') }
elif args.dbtype == 'psycopg2':
args.connect_args = { 'database' : config.get('database','database') }
store = MyStore(args)
thread.start_new_thread(listen_thread, (store,))
thread.start_new_thread(clean_session_thread, ())
- thread.start_new_thread(irc_thread, ())
+ if (config.get('server','irc') == 'yes' ):
+ thread.start_new_thread(irc_thread, ())
while not stopping:
try: