summaryrefslogtreecommitdiffstats
path: root/retiolum/scripts/adv_graphgen/tinc_graphs/Graph.py
diff options
context:
space:
mode:
Diffstat (limited to 'retiolum/scripts/adv_graphgen/tinc_graphs/Graph.py')
-rwxr-xr-xretiolum/scripts/adv_graphgen/tinc_graphs/Graph.py56
1 files changed, 33 insertions, 23 deletions
diff --git a/retiolum/scripts/adv_graphgen/tinc_graphs/Graph.py b/retiolum/scripts/adv_graphgen/tinc_graphs/Graph.py
index b001780d..29491997 100755
--- a/retiolum/scripts/adv_graphgen/tinc_graphs/Graph.py
+++ b/retiolum/scripts/adv_graphgen/tinc_graphs/Graph.py
@@ -6,8 +6,11 @@ from .Services import add_services
from .Availability import get_node_availability
import sys,json
from time import time
-DUMP_FILE = os.environment.get("AVAILABILITY_FILE", "tinc-availability.json")
+DUMP_FILE = os.environ.get("AVAILABILITY_FILE", "tinc-availability.json")
+hostpath=os.environ.get("TINC_HOSTPATH", "/etc/tinc/retiolum/hosts")
+# will be filled later
+supernodes= []
def resolve_myself(nodes):
#resolve MYSELF to the real ip
@@ -34,23 +37,24 @@ def generate_availability_stats(nodes):
""" generates stats of from availability
"""
jlines = []
- try:
- f = BackwardsReader(DUMP_FILE)
- lines_to_use = 1000
- while True:
- if lines_to_use == 0: break
- line = f.readline()
- if not line: break
- jline = json.loads(line)
- if not jline['nodes']: continue
-
- jlines.append(jline)
- lines_to_use -=1
- except Exception as e: sys.stderr.write(str(e))
+ # try:
+ # f = BackwardsReader(DUMP_FILE)
+ # lines_to_use = 1000
+ # while True:
+ # if lines_to_use == 0: break
+ # line = f.readline()
+ # if not line: break
+ # jline = json.loads(line)
+ # if not jline['nodes']: continue
+
+ # jlines.append(jline)
+ # lines_to_use -=1
+ # except Exception as e: sys.stderr.write(str(e))
for k,v in nodes.items():
- v['availability'] = get_node_availability(k,jlines)
- sys.stderr.write( "%s -> %f\n" %(k ,v['availability']))
+ # TODO: get this information in a different way
+ v['availability'] = get_node_availability(k,[])
+
def generate_stats(nodes):
""" Generates some statistics of the network and nodes
@@ -211,7 +215,6 @@ def anonymize_nodes(nodes):
return newnodes
def main():
- supernodes= []
if len(sys.argv) != 2 or sys.argv[1] not in ["anonymous","complete"]:
print("usage: %s (anonymous|complete)")
sys.exit(1)
@@ -231,18 +234,25 @@ def main():
print_edge(k,v)
elif sys.argv[1] == "complete":
- for supernode,addr in check_all_the_super():
- supernodes.append(supernode)
+ try:
+ for supernode,addr in check_all_the_super(hostpath):
+ supernodes.append(supernode)
+ except FileNotFoundError as e:
+ print("!! cannot load list of supernodes ({})".format(hostpath))
+ print("!! Use TINC_HOSTPATH env to override")
+ sys.exit(1)
generate_availability_stats(nodes)
add_services(nodes)
for k,v in nodes.items():
print_node(k,v)
print_edge(k,v)
- try:
- dump_graph(nodes)
- except Exception as e:
- sys.stderr.write("Cannot dump graph: %s" % str(e))
+
+ #TODO: get availability somehow else
+ # try:
+ # dump_graph(nodes)
+ # except Exception as e:
+ # sys.stderr.write("Cannot dump graph: %s" % str(e))
else:
pass