Skip to content
Snippets Groups Projects
Commit 80084744 authored by Moul's avatar Moul
Browse files

[mod] give best_node() boolean values.

- Fix boolean values sent to 'info' and 'argos' cmds.
parent 7816a0c3
No related branches found
No related tags found
1 merge request!85#42: Retrieve informations once and use them in the whole program
...@@ -9,5 +9,5 @@ if __name__ == '__main__': ...@@ -9,5 +9,5 @@ if __name__ == '__main__':
ep, cli_args = cli() ep, cli_args = cli()
if not check_port(ep["port"]): if not check_port(ep["port"]):
exit(1) exit(1)
best_node(ep, 1) best_node(ep, True)
manage_cmd(ep, cli_args) manage_cmd(ep, cli_args)
...@@ -110,7 +110,7 @@ def network_info(ep, discover): ...@@ -110,7 +110,7 @@ def network_info(ep, discover):
print("Getting informations about nodes:") print("Getting informations about nodes:")
while (i < len(endpoints)): while (i < len(endpoints)):
print("{0:.0f}%".format(i/len(endpoints) * 100, 1), end=" ") print("{0:.0f}%".format(i/len(endpoints) * 100, 1), end=" ")
best_ep = best_node(endpoints[i], 0) best_ep = best_node(endpoints[i], False)
print(best_ep if best_ep is None else endpoints[i][best_ep], end=" ") print(best_ep if best_ep is None else endpoints[i][best_ep], end=" ")
print(endpoints[i]["port"]) print(endpoints[i]["port"])
try: try:
......
...@@ -19,7 +19,7 @@ def discover_peers(ep, discover): ...@@ -19,7 +19,7 @@ def discover_peers(ep, discover):
for i, ep in enumerate(endpoints): for i, ep in enumerate(endpoints):
if discover: if discover:
print("{0:.0f}%".format(i / len(endpoints) * 100)) print("{0:.0f}%".format(i / len(endpoints) * 100))
if best_node(ep, 0) is None: if best_node(ep, False) is None:
endpoints.remove(ep) endpoints.remove(ep)
elif discover: elif discover:
endpoints = recursive_discovering(endpoints, ep) endpoints = recursive_discovering(endpoints, ep)
...@@ -33,7 +33,7 @@ def recursive_discovering(endpoints, ep): ...@@ -33,7 +33,7 @@ def recursive_discovering(endpoints, ep):
""" """
news = parse_endpoints(get_request(ep, "network/peers")["peers"]) news = parse_endpoints(get_request(ep, "network/peers")["peers"])
for new in news: for new in news:
if best_node(new, 0) is not None and new not in endpoints: if best_node(new, False) is not None and new not in endpoints:
endpoints.append(new) endpoints.append(new)
recursive_discovering(endpoints, new) recursive_discovering(endpoints, new)
return endpoints return endpoints
...@@ -100,7 +100,7 @@ def check_ip(address): ...@@ -100,7 +100,7 @@ def check_ip(address):
def get_request(ep, path): def get_request(ep, path):
address = best_node(ep, 0) address = best_node(ep, False)
if address is None: if address is None:
return address return address
url = "http://" + ep[address] + ":" + ep["port"] + "/" + path url = "http://" + ep[address] + ":" + ep["port"] + "/" + path
...@@ -113,7 +113,7 @@ def get_request(ep, path): ...@@ -113,7 +113,7 @@ def get_request(ep, path):
def post_request(ep, path, postdata): def post_request(ep, path, postdata):
address = best_node(ep, 0) address = best_node(ep, False)
if address is None: if address is None:
return address return address
url = "http://" + ep[address] + ":" + ep["port"] + "/" + path url = "http://" + ep[address] + ":" + ep["port"] + "/" + path
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment