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:
parent
30281c8fb5
commit
6e081d95f5
7 changed files with 45 additions and 20 deletions
|
@ -107,9 +107,9 @@ class UiRequestPlugin(object):
|
|||
("%s/%s", ( len([peer for peer in site.peers.values() if peer.connection and peer.connection.connected]), len(site.peers) ) ),
|
||||
("%s", len(site.content_manager.contents)),
|
||||
])
|
||||
yield "<tr><td id='peers_%s' style='display: none'>" % site.address
|
||||
yield "<tr><td id='peers_%s' style='display: none; white-space: pre'>" % site.address
|
||||
for key, peer in site.peers.items():
|
||||
yield "(%s) %s -<br>" % (peer.connection, key)
|
||||
yield "(%s, err: %s) %22s -<br>" % (peer.connection, peer.connection_error, key)
|
||||
yield "<br></td></tr>"
|
||||
yield "</table>"
|
||||
|
||||
|
|
|
@ -632,7 +632,7 @@ class NotificationIcon(object):
|
|||
Shell_NotifyIcon(NIM_ADD, ctypes.pointer(iconinfo))
|
||||
|
||||
iconinfo.union.uVersion = NOTIFYICON_VERSION
|
||||
self.iconinfo = iconinfo
|
||||
self.iconinfo = ctypes.pointer(iconinfo)
|
||||
|
||||
Shell_NotifyIcon(NIM_SETVERSION, ctypes.pointer(iconinfo))
|
||||
|
||||
|
@ -643,10 +643,15 @@ class NotificationIcon(object):
|
|||
last_time = -1
|
||||
ret = None
|
||||
while not self._die:
|
||||
ret = GetMessage(ctypes.pointer(message), 0, 0, 0)
|
||||
TranslateMessage(ctypes.pointer(message))
|
||||
DispatchMessage(ctypes.pointer(message))
|
||||
try:
|
||||
ret = GetMessage(ctypes.pointer(message), 0, 0, 0)
|
||||
TranslateMessage(ctypes.pointer(message))
|
||||
DispatchMessage(ctypes.pointer(message))
|
||||
except Exception, err:
|
||||
# print "NotificationIcon error", err, message
|
||||
message = MSG()
|
||||
time.sleep(0.125)
|
||||
print "Icon thread stopped, removing icon..."
|
||||
#KillTimer(self._hwnd, self._timerid)
|
||||
|
||||
Shell_NotifyIcon(NIM_DELETE, ctypes.pointer(iconinfo))
|
||||
|
@ -734,13 +739,15 @@ class NotificationIcon(object):
|
|||
|
||||
|
||||
def die(self):
|
||||
self._die = True
|
||||
PostMessage(self._hwnd, WM_NULL, 0, 0)
|
||||
time.sleep(0.2)
|
||||
try:
|
||||
Shell_NotifyIcon(NIM_DELETE, ctypes.pointer(self.iconinfo))
|
||||
except:
|
||||
pass
|
||||
Shell_NotifyIcon(NIM_DELETE, self.iconinfo)
|
||||
except Exception, err:
|
||||
print "Icon remove error", err
|
||||
ctypes.windll.user32.DestroyWindow(self._hwnd)
|
||||
ctypes.windll.user32.DestroyIcon(self._hicon)
|
||||
self._die = True
|
||||
|
||||
|
||||
def pump(self):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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})
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
def main():
|
||||
print " - Starging ZeroNet..."
|
||||
print " - Starting ZeroNet..."
|
||||
import sys, os
|
||||
try:
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) # Imports relative to src
|
||||
|
|
Loading…
Reference in a new issue