Version 0.2.9, Only send peers over pex that worked within 2 hours, Mark peer as bad on publish 5sec timeout, Starting typo fix, Only ask peers from 2 sources every 20 min, Maybe fixed notification icon crashing

This commit is contained in:
HelloZeroNet 2015-04-15 23:33:21 +02:00
parent 30281c8fb5
commit 6e081d95f5
7 changed files with 45 additions and 20 deletions

View file

@ -3,7 +3,7 @@ import ConfigParser
class Config(object):
def __init__(self):
self.version = "0.2.8"
self.version = "0.2.9"
self.parser = self.createArguments()
argv = sys.argv[:] # Copy command line arguments
argv = self.parseConfig(argv) # Add arguments from config file

View file

@ -132,9 +132,7 @@ class FileRequest:
got_peer_keys.append("%s:%s" % address)
if (site.addPeer(*address)): added += 1
# Send back peers that is not in the sent list and connectable (not port 0)
peers = site.peers.values()
random.shuffle(peers)
packed_peers = [peer.packAddress() for peer in peers if not peer.key.endswith(":0") and peer.key not in got_peer_keys][0:params["need"]]
packed_peers = [peer.packAddress() for peer in site.getConnectablePeers(params["need"], got_peer_keys)]
if added:
self.log.debug("Added %s peers to %s using pex, sending back %s" % (added, site, len(packed_peers)))
self.response({"peers": packed_peers})

View file

@ -148,9 +148,7 @@ class Peer:
# Request peer exchange from peer
def pex(self, site=None, need_num=5):
if not site: site = self.site # If no site definied request peers for this site
peers = self.site.peers.values()
random.shuffle(peers)
packed_peers = [peer.packAddress() for peer in peers if not peer.key.endswith(":0")][0:need_num]
packed_peers = [peer.packAddress() for peer in self.site.getConnectablePeers(5)] # give him/her 5 connectable peers
response = self.request("pex", {"site": site.address, "peers": packed_peers, "need": need_num})
if not response or "error" in response:
return False

View file

@ -212,6 +212,7 @@ class Site:
published.append(peer)
self.log.info("[OK] %s: %s" % (peer.key, result["ok"]))
else:
if result == {"exception": "Timeout"}: peer.onConnectionError()
self.log.info("[FAILED] %s: %s" % (peer.key, result))
@ -285,7 +286,7 @@ class Site:
# Gather peer from connected peers
@util.Noparallel(blocking=False)
def announcePex(self, query_num=3, need_num=5):
def announcePex(self, query_num=2, need_num=5):
peers = [peer for peer in self.peers.values() if peer.connection and peer.connection.connected] # Connected peers
if len(peers) == 0: # Small number of connected peers for this site, connect to any
peers = self.peers.values()
@ -420,6 +421,27 @@ class Site:
return connected
# Return: Probably working, connectable Peers
def getConnectablePeers(self, need_num=5, ignore=[]):
peers = self.peers.values()
random.shuffle(peers)
found = []
for peer in peers:
if peer.key.endswith(":0"): continue # Not connectable
if not peer.connection: continue # No connection
if peer.key in ignore: continue # The requester has this peer
if time.time() - peer.connection.last_recv_time > 60*60*2: # Last message more than 2 hours ago
peer.connection = None # Cleanup: Dead connection
continue
found.append(peer)
if len(found) >= need_num: break # Found requested number of peers
if not found and not ignore: # Not found any peer and the requester dont have any, return not that good peers
found = [peer for peer in peers if not peer.key.endswith(":0") and peer.key not in ignore][0:need_num]
return found
# - Events -
@ -470,7 +492,7 @@ class Site:
def fileFailed(self, inner_path):
if inner_path == "content.json":
self.content_updated = False
self.log.error("Can't update content.json")
self.log.debug("Can't update content.json")
if inner_path in self.bad_files:
self.bad_files[inner_path] = self.bad_files.get(inner_path, 0)+1