partial cleanup of Peer.py
This commit is contained in:
parent
05e15e0255
commit
e4ba0fdb53
1 changed files with 11 additions and 8 deletions
|
@ -5,7 +5,8 @@ from Debug import Debug
|
||||||
|
|
||||||
# Communicate remote peers
|
# Communicate remote peers
|
||||||
class Peer(object):
|
class Peer(object):
|
||||||
__slots__ = ("ip", "port", "site", "key", "connection_server", "connection", "last_found", "last_response", "last_ping", "added", "connection_error", "hash_failed", "download_bytes", "download_time")
|
__slots__ = ("ip", "port", "site", "key", "connection_server", "connection", "last_found", "last_response",
|
||||||
|
"last_ping", "added", "connection_error", "hash_failed", "download_bytes", "download_time")
|
||||||
|
|
||||||
def __init__(self, ip, port, site=None):
|
def __init__(self, ip, port, site=None):
|
||||||
self.ip = ip
|
self.ip = ip
|
||||||
|
@ -107,7 +108,9 @@ class Peer(object):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
self.onConnectionError()
|
self.onConnectionError()
|
||||||
self.log("%s (connection_error: %s, hash_failed: %s, retry: %s)" % (Debug.formatException(err), self.connection_error, self.hash_failed, retry))
|
self.log("%s (connection_error: %s, hash_failed: %s, retry: %s)" % (Debug.formatException(err),
|
||||||
|
self.connection_error,
|
||||||
|
self.hash_failed, retry))
|
||||||
time.sleep(1*retry)
|
time.sleep(1*retry)
|
||||||
self.connect()
|
self.connect()
|
||||||
return None # Failed after 4 retry
|
return None # Failed after 4 retry
|
||||||
|
@ -117,7 +120,7 @@ class Peer(object):
|
||||||
location = 0
|
location = 0
|
||||||
buff = StringIO()
|
buff = StringIO()
|
||||||
s = time.time()
|
s = time.time()
|
||||||
while 1: # Read in 512k parts
|
while True: # Read in 512k parts
|
||||||
back = self.request("getFile", {"site": site, "inner_path": inner_path, "location": location}) # Get file content from last location
|
back = self.request("getFile", {"site": site, "inner_path": inner_path, "location": location}) # Get file content from last location
|
||||||
if not back or "body" not in back: # Error
|
if not back or "body" not in back: # Error
|
||||||
return False
|
return False
|
||||||
|
@ -138,7 +141,7 @@ class Peer(object):
|
||||||
response_time = None
|
response_time = None
|
||||||
for retry in range(1, 3): # Retry 3 times
|
for retry in range(1, 3): # Retry 3 times
|
||||||
s = time.time()
|
s = time.time()
|
||||||
with gevent.Timeout(10.0, False): # 10 sec timeout, dont raise exception
|
with gevent.Timeout(10.0, False): # 10 sec timeout, don't raise exception
|
||||||
response = self.request("ping")
|
response = self.request("ping")
|
||||||
|
|
||||||
if response and "body" in response and response["body"] == "Pong!":
|
if response and "body" in response and response["body"] == "Pong!":
|
||||||
|
|
Loading…
Reference in a new issue