Esempio n. 1
0
def render(network_map, path=None):
    """ Render a network map.

    Args:
        network_map: The generated network map to render.
        path: The path to save the rendered output at.
              Saves to '~/.storj/graphs/network map TIMESTAMP.png' by default.
    """

    name = "network map %s" % str(datetime.datetime.now())
    path = path or os.path.join(STORJ_HOME, "graphs", "%s.png" % name)
    util.ensure_path_exists(os.path.dirname(path))

    graph = pygraphviz.AGraph()  # (strict=False,directed=True)

    # add nodes
    for nodeid, results in network_map.items():
        nodehexid = binascii.hexlify(nodeid)
        ip, port = results["addr"]
        # label = "%s\n%s:%i" % (nodehexid, ip, port)
        has_peers = len(results["peers"]) > 0
        graph.add_node(nodehexid, color='green' if has_peers else "blue")

    # add connections
    for nodeid, results in network_map.items():
        nodehexid = binascii.hexlify(nodeid)
        for peerid, ip, port in results["peers"]:
            peerhexid = binascii.hexlify(peerid)
            graph.add_edge(nodehexid, peerhexid)

    # render graph
    graph.layout(prog='dot')
    graph.draw(path, prog='circo')
    return path
Esempio n. 2
0
def render(network_map, path=None):
    """ Render a network map.

    Args:
        network_map: The generated network map to render.
        path: The path to save the rendered output at.
              Saves to '~/.storj/graphs/network map TIMESTAMP.png' by default.
    """

    name = "network map %s" % str(datetime.datetime.now())
    path = path or os.path.join(STORJ_HOME, "graphs", "%s.png" % name)
    util.ensure_path_exists(os.path.dirname(path))

    graph = pygraphviz.AGraph()  # (strict=False,directed=True)

    # add nodes
    for nodeid, results in network_map.items():
        nodehexid = binascii.hexlify(nodeid)
        ip, port = results["addr"]
        # label = "%s\n%s:%i" % (nodehexid, ip, port)
        has_peers = len(results["peers"]) > 0
        graph.add_node(nodehexid, color='green' if has_peers else "blue")

    # add connections
    for nodeid, results in network_map.items():
        nodehexid = binascii.hexlify(nodeid)
        for peerid, ip, port in results["peers"]:
            peerhexid = binascii.hexlify(peerid)
            graph.add_edge(nodehexid, peerhexid)

    # render graph
    graph.layout(prog='dot')
    graph.draw(path, prog='circo')
    return path
Esempio n. 3
0
def render(network_map, path=None):
    """ Render a network map.

    Args:
        network_map: The generated network map to render.
        path: The path to save the rendered output at.
              Saves to '~/.storj/graphs/network map TIMESTAMP.png' by default.
    """

    now = datetime.datetime.now()
    name = "network_map_%s" % now.strftime('%Y-%m-%d_%H:%M:%S')
    path = path or os.path.join(storjnode.common.STORJ_HOME,
                                "graphs", "%s.png" % name)
    path = util.full_path(path)
    util.ensure_path_exists(os.path.dirname(path))

    graph = pygraphviz.AGraph()  # (strict=False,directed=True)

    # add nodes
    for nodeid, results in network_map.items():
        node_address = storjnode.util.node_id_to_address(nodeid)
        ip, port = results["addr"]
        has_peers = len(results["peers"]) > 0
        graph.add_node(node_address, color='green' if has_peers else "blue")

    # add connections
    for nodeid, results in network_map.items():
        node_address = storjnode.util.node_id_to_address(nodeid)
        for peerid, ip, port in results["peers"]:
            peer_address = storjnode.util.node_id_to_address(peerid)
            graph.add_edge(node_address, peer_address)

    # render graph
    graph.layout(prog='dot')
    graph.draw(path, prog='circo')
    return path