Browse Source

Merge commit 'refs/merge-requests/6' of git://gitorious.org/electrum/electrum into merge-requests/6

283
ThomasV 14 years ago
parent
commit
55d9502184
  1. 18
      server/README-IRC.txt
  2. 1
      server/electrum.conf.sample
  3. 31
      server/server.py

18
server/README-IRC.txt

@ -0,0 +1,18 @@
IRC is used by Electrum server to find 'peers' - other Electrum servers. The current list can be seen by running:
./server.py peers
The following config file options are used by the IRC part of Electrum server:
[server]
irc = yes
host = fqdn.host.name.tld
ircname = some short description
'irc' is used to determine whether the IRC thread will be started or the Electrum server will run in private mode. In private mode, ./server.py peers will always return an empty list.
'host' is a fqdn of your Electrum server. It is used both when binding the listener for incoming clien conections, and also as part of the realname field in IRC (see below).
'ircname' is a short text that will be appended to 'host' when composing the IRC realname field:
realname = 'host' + ' ' + 'ircname', for example 'fqdn.host.name.tld some short description'

1
server/electrum.conf.sample

@ -4,6 +4,7 @@ port = 50000
password = secret password = secret
banner = Welcome to Electrum! banner = Welcome to Electrum!
irc = yes irc = yes
ircname = public Electrum server
[database] [database]
type = sqlite3 type = sqlite3

31
server/server.py

@ -40,6 +40,7 @@ config.set('server', 'host', 'ecdsa.org')
config.set('server', 'port', 50000) config.set('server', 'port', 50000)
config.set('server', 'password', '') config.set('server', 'password', '')
config.set('server', 'irc', 'yes') config.set('server', 'irc', 'yes')
config.set('server', 'ircname', 'Electrum server')
config.add_section('database') config.add_section('database')
config.set('database', 'type', 'psycopg2') config.set('database', 'type', 'psycopg2')
config.set('database', 'database', 'abe') config.set('database', 'database', 'abe')
@ -443,39 +444,37 @@ def irc_thread():
try: try:
s = socket.socket() s = socket.socket()
s.connect(('irc.freenode.net', 6667)) 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('NICK '+NICK+'\n')
s.send('JOIN #electrum\n') s.send('JOIN #electrum\n')
sf = s.makefile('r', 0)
t = 0 t = 0
while not stopping: while not stopping:
line = s.recv(2048) line = sf.readline()
line = line.rstrip('\r\n') line = line.rstrip('\r\n')
line = line.split() line = line.split()
if line[0]=='PING': if line[0]=='PING':
s.send('PONG '+line[1]+'\n') s.send('PONG '+line[1]+'\n')
elif '353' in line: # answer to /names elif '353' in line: # answer to /names
k = line.index('353') k = line.index('353')
try: for item in line[k+1:]:
k2 = line.index('366')
except:
continue
for item in line[k+1:k2]:
if item[0:2] == 'E_': if item[0:2] == 'E_':
s.send('USERHOST %s\n'%item) s.send('WHO %s\n'%item)
elif '302' in line: # answer to /userhost elif '352' in line: # answer to /who
k = line.index('302') # warning: this is a horrible hack which apparently works
m = re.match( "^:(.*?)=\+~(.*?)@(.*?)$", line[k+2] ) k = line.index('352')
if m: ip = line[k+4]
name = m.group(1) ip = socket.gethostbyname(ip)
host = m.group(2) name = line[k+6]
ip = m.group(3) host = line[k+9]
peer_list[name] = (ip,host) peer_list[name] = (ip,host)
elif time.time() - t > 5*60: elif time.time() - t > 5*60:
s.send('NAMES #electrum\n') s.send('NAMES #electrum\n')
t = time.time() t = time.time()
except: except:
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)
finally: finally:
sf.close()
s.close() s.close()

Loading…
Cancel
Save