MCPcopy Create free account
hub / github.com/HelloZeroNet/ZeroNet / getConnectedPeers

Method getConnectedPeers

src/Site/Site.py:904–923  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

902 return found[0:need_num]
903
904 def getConnectedPeers(self):
905 back = []
906 if not self.connection_server:
907 return []
908
909 tor_manager = self.connection_server.tor_manager
910 for connection in self.connection_server.connections:
911 if not connection.connected and time.time() - connection.start_time > 20: # Still not connected after 20s
912 continue
913 peer = self.peers.get("%s:%s" % (connection.ip, connection.port))
914 if peer:
915 if connection.ip.endswith(".onion") and connection.target_onion and tor_manager.start_onions:
916 # Check if the connection is made with the onion address created for the site
917 valid_target_onions = (tor_manager.getOnion(self.address), tor_manager.getOnion("global"))
918 if connection.target_onion not in valid_target_onions:
919 continue
920 if not peer.connection:
921 peer.connect(connection)
922 back.append(peer)
923 return back
924
925 # Cleanup probably dead peers and close connection if too much
926 def cleanupPeers(self, peers_protected=[]):

Callers 11

checkModificationsMethod · 0.95
publishMethod · 0.95
needConnectionsMethod · 0.95
cleanupPeersMethod · 0.95
sendMyHashfieldMethod · 0.95
updateHashfieldMethod · 0.95
announcePexMethod · 0.80
startWorkersMethod · 0.80
startFindOptionalMethod · 0.80
cleanupSitesMethod · 0.80
getTrackersMethod · 0.80

Calls 3

getOnionMethod · 0.80
getMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected