Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
Improved peer connection and updating
Browse files Browse the repository at this point in the history
  • Loading branch information
rtrevinnoc committed Mar 9, 2021
1 parent 7f2c854 commit fec2754
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion future.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def sendRegisterRequestToPeer(url):
"".encode('utf-8'),
overwrite=False)
peerRegistryTransaction.commit()
listOfPeers.append(peer)
listOfPeers = list(set(listOfPeers))
print("Registered with http")
return "Registered with http"
except:
Expand All @@ -119,6 +121,8 @@ def sendRegisterRequestToPeer(url):
"".encode('utf-8'),
overwrite=False)
peerRegistryTransaction.commit()
listOfPeers.append(peer)
listOfPeers = list(set(listOfPeers))
print("Registered with https")
return "Registered with https"
except:
Expand Down Expand Up @@ -150,6 +154,8 @@ def sendAnswerRequestToPeer(url, query, queryVector, queryLanguage,
},
timeout=10)
result = r.json()["result"]
listOfPeers.append(peer)
listOfPeers = list(set(listOfPeers))
print("Obtained with http")
return {"urls": list(zip(result["urls"], result["url_scores"]))}
except:
Expand All @@ -165,11 +171,17 @@ def sendAnswerRequestToPeer(url, query, queryVector, queryLanguage,
},
timeout=10)
result = r.json()["result"]
listOfPeers.append(peer)
listOfPeers = list(set(listOfPeers))
print("Obtained with https")
return {
"urls": list(zip(result["urls"], result["url_scores"]))
}
except:
try:
listOfPeers.remove(peer)
except:
pass
print("Could not connect with peer")
return {"urls": []}

Expand Down Expand Up @@ -198,6 +210,8 @@ def sendImagesAnswerRequestToPeer(url, query, queryVector, queryLanguage,
},
timeout=10)
result = r.json()["result"]
listOfPeers.append(peer)
listOfPeers = list(set(listOfPeers))
print("Obtained with http")
return {
"images": list(zip(result["images"], result["images_scores"]))
Expand All @@ -215,12 +229,18 @@ def sendImagesAnswerRequestToPeer(url, query, queryVector, queryLanguage,
},
timeout=10)
result = r.json()["result"]
listOfPeers.append(peer)
listOfPeers = list(set(listOfPeers))
print("Obtained with https")
return {
"images":
list(zip(result["images"], result["images_scores"]))
}
except:
try:
listOfPeers.remove(peer)
except:
pass
print("Could not connect with peer")
return {"images": []}

Expand All @@ -229,7 +249,6 @@ def sendImagesAnswerRequestToPeer(url, query, queryVector, queryLanguage,
with peerRegistry.begin() as peerRegistryDBTransaction:
peerRegistryDBSelector = peerRegistryDBTransaction.cursor()
for key, value in peerRegistryDBSelector:
listOfPeers.append(key.decode("utf-8"))
sendRegisterRequestToPeer(key)
numberOfPeers = len(listOfPeers)

Expand Down Expand Up @@ -590,6 +609,7 @@ def _registerPeer():

if hostname != "private":
listOfPeers.append(peerIP)
listOfPeers = list(set(listOfPeers))
numberOfPeers += 1

return jsonify(result={"listOfPeers": listOfPeers})
Expand Down

0 comments on commit fec2754

Please sign in to comment.