def _check_update_remote_address(self, msg, peer):
if not msg.sender_address:
return
msghost, msgport = msg.sender_address.split(':')
dbhost, dbport = peer.address.split(':')
if msghost != dbhost and msghost == peer.protocol.address[0]:
# Allow the Peer to update our records of its host if it told us to
# and it matches where its connection is coming from. We only do it
# if it told us to to prevent wierd outgoing only routes or such to
# cause any problems. We also only trust it if those match so it
# can't make us connect to random addresses or cause problems or
# whatever.
if log.isEnabledFor(logging.INFO):
log.info(\
"Remote Peer said address [{}] has changed, updating our"\
" record [{}].".format(msg.sender_address, peer.address))
peer.address = "{}:{}".format(msghost, msgport)
elif msgport != dbport:
if log.isEnabledFor(logging.INFO):
log.info(\
"Remote Peer said port [{}] has changed, updating our"\
" record [{}].".format(msgport, dbport))
peer.address = "{}:{}".format(dbhost, msgport)
else:
return
def dbcall():
with self.node.db.open_session() as sess:
dbp = sess.query(Peer).get(peer.dbid);
dbp.address = peer.address
sess.commit()
yield from self.loop.run_in_executor(None, dbcall)
评论列表
文章目录