MCPcopy Index your code
hub / github.com/HelloZeroNet/ZeroNet / loadPeers

Method loadPeers

plugins/PeerDb/PeerDbPlugin.py:37–58  ·  view source on GitHub ↗
(self, site)

Source from the content-addressed store, hash-verified

35 return schema
36
37 def loadPeers(self, site):
38 s = time.time()
39 site_id = self.site_ids.get(site.address)
40 res = self.execute("SELECT * FROM peer WHERE site_id = :site_id", {"site_id": site_id})
41 num = 0
42 num_hashfield = 0
43 for row in res:
44 peer = site.addPeer(str(row["address"]), row["port"])
45 if not peer: # Already exist
46 continue
47 if row["hashfield"]:
48 peer.hashfield.replaceFromBytes(row["hashfield"])
49 num_hashfield += 1
50 peer.time_added = row["time_added"]
51 peer.time_found = row["time_found"]
52 peer.reputation = row["reputation"]
53 if row["address"].endswith(".onion"):
54 peer.reputation = peer.reputation / 2 - 1 # Onion peers less likely working
55 num += 1
56 if num_hashfield:
57 site.content_manager.has_optional_files = True
58 site.log.debug("%s peers (%s with hashfield) loaded in %.3fs" % (num, num_hashfield, time.time() - s))
59
60 def iteratePeers(self, site):
61 site_id = self.site_ids.get(site.address)

Callers

nothing calls this directly

Calls 4

addPeerMethod · 0.80
replaceFromBytesMethod · 0.80
getMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected