MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / getRecentPeers

Method getRecentPeers

src/Site/Site.py:876–902  ·  view source on GitHub ↗
(self, need_num)

Source from the content-addressed store, hash-verified

874
875 # Return: Recently found peers
876 def getRecentPeers(self, need_num):
877 found = list(set(self.peers_recent))
878 self.log.debug("Recent peers %s of %s (need: %s)" % (len(found), len(self.peers_recent), need_num))
879
880 if len(found) >= need_num or len(found) >= len(self.peers):
881 return sorted(
882 found,
883 key=lambda peer: peer.reputation,
884 reverse=True
885 )[0:need_num]
886
887 # Add random peers
888 need_more = need_num - len(found)
889 if not self.connection_server.tor_manager.enabled:
890 peers = [peer for peer in self.peers.values() if not peer.ip.endswith(".onion")]
891 else:
892 peers = list(self.peers.values())
893
894 found_more = sorted(
895 peers[0:need_more * 50],
896 key=lambda peer: peer.reputation,
897 reverse=True
898 )[0:need_more * 2]
899
900 found += found_more
901
902 return found[0:need_num]
903
904 def getConnectedPeers(self):
905 back = []

Callers 5

checkModificationsMethod · 0.95
publishMethod · 0.95
needConnectionsMethod · 0.95
announcePexMethod · 0.80
startWorkersMethod · 0.80

Calls 1

valuesMethod · 0.80

Tested by

no test coverage detected