Connection logic tweaks

This commit is contained in:
TheKysek 2016-07-19 14:09:42 +02:00
parent 89baf6258b
commit eae426a413
2 changed files with 8 additions and 4 deletions

View File

@ -116,7 +116,7 @@ class Connection(threading.Thread):
else: else:
break break
except Exception as e: except Exception as e:
print(e) logging.error(e)
break break
self.s.settimeout(0.5) self.s.settimeout(0.5)
self.tls = True self.tls = True
@ -132,15 +132,17 @@ class Connection(threading.Thread):
self.s.settimeout(0.5) self.s.settimeout(0.5)
def _on_connection_fully_established(self): def _on_connection_fully_established(self):
self.status = 'fully_established'
logging.info('Established Bitmessage protocol connection to {}:{}'.format(self.host, self.port)) logging.info('Established Bitmessage protocol connection to {}:{}'.format(self.host, self.port))
if self.remote_version.services & 2: # NODE_SSL if self.remote_version.services & 2: # NODE_SSL
self._do_tls_handshake() self._do_tls_handshake()
time.sleep(5)
with shared.objects_lock: with shared.objects_lock:
if len(shared.objects) > 0:
self.send_queue.put(message.Inv({vector for vector in shared.objects.keys() if shared.objects[vector].expires_time > time.time()})) self.send_queue.put(message.Inv({vector for vector in shared.objects.keys() if shared.objects[vector].expires_time > time.time()}))
addr = {structure.NetAddr(1, c.host, c.port) for c in shared.connections.copy() if not c.server and c.status == 'fully_established'} addr = {structure.NetAddr(c.remote_version.services, c.host, c.port) for c in shared.connections.copy() if not c.server and c.status == 'fully_established'}
if len(addr) != 0: if len(addr) != 0:
self.send_queue.put(message.Addr(addr)) self.send_queue.put(message.Addr(addr))
self.status = 'fully_established'
def _process_queue(self): def _process_queue(self):
while not self.send_queue.empty(): while not self.send_queue.empty():

View File

@ -158,6 +158,8 @@ class Inv(object):
vectors.add(payload[:32]) vectors.add(payload[:32])
payload = payload[32:] payload = payload[32:]
assert vector_count == len(vectors)
return cls(vectors) return cls(vectors)