report error when peer rejects our update
also improve code and comment
This commit is contained in:
parent
03a9f2c490
commit
fa1c25326a
1 changed files with 4 additions and 4 deletions
|
@ -154,7 +154,7 @@ class Peer(object):
|
||||||
|
|
||||||
self.log("Send request: %s %s %s %s" % (params.get("site", ""), cmd, params.get("inner_path", ""), params.get("location", "")))
|
self.log("Send request: %s %s %s %s" % (params.get("site", ""), cmd, params.get("inner_path", ""), params.get("location", "")))
|
||||||
|
|
||||||
for retry in range(1, 4): # Retry 3 times
|
for retry in range(3):
|
||||||
try:
|
try:
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
# this is redundant, already established that self.connection is present
|
# this is redundant, already established that self.connection is present
|
||||||
|
@ -165,7 +165,7 @@ class Peer(object):
|
||||||
if "error" in res:
|
if "error" in res:
|
||||||
self.log("%s error: %s" % (cmd, res["error"]))
|
self.log("%s error: %s" % (cmd, res["error"]))
|
||||||
self.onConnectionError("Response error")
|
self.onConnectionError("Response error")
|
||||||
break
|
return res
|
||||||
else: # Successful request, reset connection error num
|
else: # Successful request, reset connection error num
|
||||||
self.connection_error = 0
|
self.connection_error = 0
|
||||||
self.time_response = time.time()
|
self.time_response = time.time()
|
||||||
|
@ -183,9 +183,9 @@ class Peer(object):
|
||||||
"%s (connection_error: %s, hash_failed: %s, retry: %s)" %
|
"%s (connection_error: %s, hash_failed: %s, retry: %s)" %
|
||||||
(Debug.formatException(err), self.connection_error, self.hash_failed, retry)
|
(Debug.formatException(err), self.connection_error, self.hash_failed, retry)
|
||||||
)
|
)
|
||||||
time.sleep(1 * retry)
|
time.sleep(retry+1)
|
||||||
self.connect()
|
self.connect()
|
||||||
return None # Failed after 4 retry
|
return None # Failed after 3 attempts
|
||||||
|
|
||||||
# Get a file content from peer
|
# Get a file content from peer
|
||||||
def getFile(self, site, inner_path, file_size=None, pos_from=0, pos_to=None, streaming=False):
|
def getFile(self, site, inner_path, file_size=None, pos_from=0, pos_to=None, streaming=False):
|
||||||
|
|
Loading…
Reference in a new issue