async def on_add_peer(self, features, source_info): '''Add a peer (but only if the peer resolves to the source).''' if not source_info: return False source = source_info[0] peers = Peer.peers_from_features(features, source) if not peers: return False # Just look at the first peer, require it peer = peers[0] host = peer.host if peer.is_tor: permit = self.permit_new_onion_peer() reason = 'rate limiting' else: infos = await self.loop.getaddrinfo(host, 80, type=SOCK_STREAM) permit = any(source == info[-1][0] for info in infos) reason = 'source-destination mismatch' if permit: self.log_info('accepted add_peer request from {} for {}'.format( source, host)) self.add_peers([peer], check_ports=True) else: self.log_warning( 'rejected add_peer request from {} for {} ({})'.format( source, host, reason)) return permit
def on_add_peer(self, features, source): '''Add peers from an incoming connection.''' peers = Peer.peers_from_features(features, source) if peers: self.log_info('add_peer request received from {}' .format(peers[0].host)) self.add_peers(peers, check_ports=True) return bool(peers)
def on_add_peer(self, features, source): '''Add peers from an incoming connection.''' peers = Peer.peers_from_features(features, source) if peers: hosts = [peer.host for peer in peers] self.log_info('add_peer request from {} for {}' .format(source, ', '.join(hosts))) self.add_peers(peers, check_ports=True) return bool(peers)