diff --git a/plugins/Stats/StatsPlugin.py b/plugins/Stats/StatsPlugin.py
index b6aa2336..77f4a20b 100644
--- a/plugins/Stats/StatsPlugin.py
+++ b/plugins/Stats/StatsPlugin.py
@@ -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 "
" % site.address
+ yield " |
" % site.address
for key, peer in site.peers.items():
- yield "(%s) %s - " % (peer.connection, key)
+ yield "(%s, err: %s) %22s - " % (peer.connection, peer.connection_error, key)
yield "
|
"
yield ""
diff --git a/plugins/Trayicon/lib/notificationicon.py b/plugins/Trayicon/lib/notificationicon.py
index 73e1c83c..19b26af5 100644
--- a/plugins/Trayicon/lib/notificationicon.py
+++ b/plugins/Trayicon/lib/notificationicon.py
@@ -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):
diff --git a/src/Config.py b/src/Config.py
index c625700c..413e965f 100644
--- a/src/Config.py
+++ b/src/Config.py
@@ -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
diff --git a/src/File/FileRequest.py b/src/File/FileRequest.py
index efc7e82a..484a4ba7 100644
--- a/src/File/FileRequest.py
+++ b/src/File/FileRequest.py
@@ -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})
diff --git a/src/Peer/Peer.py b/src/Peer/Peer.py
index 09b2ced1..49146904 100644
--- a/src/Peer/Peer.py
+++ b/src/Peer/Peer.py
@@ -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
diff --git a/src/Site/Site.py b/src/Site/Site.py
index 4666d021..cbf652b2 100644
--- a/src/Site/Site.py
+++ b/src/Site/Site.py
@@ -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
diff --git a/zeronet.py b/zeronet.py
index a610424c..5fce3ec1 100644
--- a/zeronet.py
+++ b/zeronet.py
@@ -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