X-Git-Url: https://git.novaco.in/?p=electrum-server.git;a=blobdiff_plain;f=backends%2Firc%2F__init__.py;h=5511d8f2cfac7128aa05d3dd106d432b9d3033c1;hp=cf830b95e5195686ff6b97e3e07258b9c5c25e72;hb=a496f883b9d1ce78c3686097a386520e4364aa01;hpb=1751c457609209877431311c54e48278947b4ad7 diff --git a/backends/irc/__init__.py b/backends/irc/__init__.py index cf830b9..5511d8f 100644 --- a/backends/irc/__init__.py +++ b/backends/irc/__init__.py @@ -72,14 +72,16 @@ class IrcThread(threading.Thread): def run(self): ircname = self.getname() + print_log("joining IRC") while not self.processor.shared.stopped(): try: s = socket.socket() s.connect(('irc.freenode.net', 6667)) - s.settimeout(0.1) + s.settimeout(0.3) except: s.close() + print_log("IRC: reconnect in 10 s") time.sleep(10) continue @@ -114,26 +116,29 @@ class IrcThread(threading.Thread): line = line.strip('\r') if not line: continue + # print_log("<--", line) line = line.split() if line[0] == 'PING': out_msg.append('PONG ' + line[1] + '\n') - elif '353' in line: # answer to /names - k = line.index('353') - for item in line[k+1:]: + elif line[1] == '353': # answer to /names + for item in line[2:]: if item.startswith(self.prepend): out_msg.append('WHO %s\n' % item) - elif '352' in line: # answer to /who - # warning: this is a horrible hack which apparently works - k = line.index('352') + elif line[1] == '352': # answer to /who try: - ip = socket.gethostbyname(line[k+4]) + ip = socket.gethostbyname(line[5]) except: - print_log("gethostbyname error", line[k+4]) + print_log("gethostbyname error", line[5]) continue - name = line[k+6] - host = line[k+9] - ports = line[k+10:] + name = line[7] + host = line[10] + ports = line[11:] self.peers[name] = (ip, host, ports) + elif line[1] == 'KICK': + try: + print_log("KICK", line[3] + line[4]) + except: + print_log("KICK", "error") if time.time() - t > 5*60: #self.processor.push_response({'method': 'server.peers', 'params': [self.get_peers()]}) @@ -155,7 +160,6 @@ class ServerProcessor(Processor): Processor.__init__(self) self.daemon = True self.banner = config.get('server', 'banner') - self.password = config.get('server', 'password') if config.get('server', 'irc') == 'yes': self.irc = IrcThread(self, config) @@ -178,19 +182,6 @@ class ServerProcessor(Processor): params = request['params'] result = None - if method in ['server.stop', 'server.info', 'server.debug']: - try: - password = request['params'][0] - except: - password = None - - if password != self.password: - self.push_response(session, - {'id': request['id'], - 'result': None, - 'error': 'incorrect password'}) - return - if method == 'server.banner': result = self.banner.replace('\\n', '\n') @@ -200,32 +191,6 @@ class ServerProcessor(Processor): elif method == 'server.version': result = VERSION - elif method == 'server.stop': - self.shared.stop() - result = 'stopping, please wait until all threads terminate.' - - elif method == 'server.info': - result = map(lambda s: {"time": s.time, - "name": s.name, - "address": s.address, - "version": s.version, - "subscriptions": len(s.subscriptions)}, - self.dispatcher.request_dispatcher.get_sessions()) - - elif method == 'server.debug': - try: - s = request['params'][1] - except: - s = None - - if s: - from guppy import hpy - h = hpy() - bp = self.dispatcher.request_dispatcher.processors['blockchain'] - try: - result = str(eval(s)) - except: - result = "error" else: print_log("unknown method", method)