parent
23a408c572
commit
8e00affc1a
@ -97,12 +97,14 @@ class PeerSession(JSONSession):
|
|||||||
self.failed = True
|
self.failed = True
|
||||||
self.log_error('server.peers.subscribe: {}'.format(error))
|
self.log_error('server.peers.subscribe: {}'.format(error))
|
||||||
else:
|
else:
|
||||||
|
# Save for later analysis
|
||||||
self.remote_peers = result
|
self.remote_peers = result
|
||||||
self.close_if_done()
|
self.close_if_done()
|
||||||
|
|
||||||
def on_add_peer(self, result, error):
|
def on_add_peer(self, result, error):
|
||||||
'''Handle the response to the add_peer message.'''
|
'''We got a response the add_peer message.'''
|
||||||
self.close_if_done()
|
# This is the last thing we were waiting for; shutdown the connection
|
||||||
|
self.shutdown_connection()
|
||||||
|
|
||||||
def on_features(self, features, error):
|
def on_features(self, features, error):
|
||||||
# Several peers don't implement this. If they do, check they are
|
# Several peers don't implement this. If they do, check they are
|
||||||
@ -147,10 +149,12 @@ class PeerSession(JSONSession):
|
|||||||
self.close_if_done()
|
self.close_if_done()
|
||||||
|
|
||||||
def check_remote_peers(self):
|
def check_remote_peers(self):
|
||||||
'''When a peer gives us a peer update.
|
'''Check the peers list we got from a remote peer.
|
||||||
|
|
||||||
Each update is expected to be of the form:
|
Each update is expected to be of the form:
|
||||||
[ip_addr, hostname, ['v1.0', 't51001', 's51002']]
|
[ip_addr, hostname, ['v1.0', 't51001', 's51002']]
|
||||||
|
|
||||||
|
Call add_peer if the remote doesn't appear to know about us.
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
real_names = [' '.join([u[1]] + u[2]) for u in self.remote_peers]
|
real_names = [' '.join([u[1]] + u[2]) for u in self.remote_peers]
|
||||||
@ -184,6 +188,11 @@ class PeerSession(JSONSession):
|
|||||||
self.peer.mark_bad()
|
self.peer.mark_bad()
|
||||||
elif self.remote_peers:
|
elif self.remote_peers:
|
||||||
self.check_remote_peers()
|
self.check_remote_peers()
|
||||||
|
# We might now be waiting for an add_peer response
|
||||||
|
if not self.has_pending_requests():
|
||||||
|
self.shutdown_connection()
|
||||||
|
|
||||||
|
def shutdown_connection(self):
|
||||||
self.peer.last_connect = time.time()
|
self.peer.last_connect = time.time()
|
||||||
is_good = not (self.failed or self.bad)
|
is_good = not (self.failed or self.bad)
|
||||||
self.peer_mgr.set_connection_status(self.peer, is_good)
|
self.peer_mgr.set_connection_status(self.peer, is_good)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user