Ejemplo n.º 1
0
def load_required_nodes(owner, host, port, phases, node_id=str(uuid.uuid4())):
    """
    manually insert network node into database
    Args:
        owner: node owner
        host: node host
        port: node port
        phases: node phases provided
        node_id: node uuid pk
    """
    node = Node(node_id, owner, host, port, phases)
    net_dao.insert_node(node)
    print('inserted node into database ' + os.environ.get('BLOCKCHAIN_DB_NAME') + " " + node.node_id)
Ejemplo n.º 2
0
def load_required_nodes(owner, host, port, phases, node_id=str(uuid.uuid4())):
    """
    manually insert network node into database
    Args:
        owner: node owner
        host: node host
        port: node port
        phases: node phases provided
        node_id: node uuid pk
    """
    node = Node(node_id, owner, host, port, phases)
    net_dao.insert_node(node)
    print('inserted node into database ' +
          os.environ.get('BLOCKCHAIN_DB_NAME') + " " + node.node_id)
Ejemplo n.º 3
0
 def connect_subscription_node(self, subscription):
     """ connect to subscription node """
     node = net_dao.get(subscription["subscribed_node_id"])
     # check if node is already in database and just not connected
     if node:
         subscription_node = Node(node["node_id"], node["node_owner"], node["host"], node["port"], node["phases"])
         phase = int(node["phases"], 2)
         if phase not in self.peer_dict:
             self.peer_dict.setdefault(phase, [])
         try:
             self.connect_node(subscription_node, phase)
         except:
             logger().warning("Failed to connect to subscription node %s", node['node_id'])
     else:
         # insert new node into table and recursively call connect_subscription_node
         node = Node(subscription['subscribed_node_id'], subscription['node_owner'], subscription['host'], subscription['port'], "00001")
         net_dao.insert_node(node)
         self.connect_subscription_node(subscription)
Ejemplo n.º 4
0
 def refresh_registered(self):
     """ - gathering latency and health for connected (registered) nodes
         - gathering "peers of peers"
     """
     logger().info('connection refresh')
     if self.peer_dict.values():
         for peer in self.connections:
             if self.calc_latency(peer):
                 net_dao.update_con_activity(peer)  # update node health
                 peers_discovered = peer.client.get_peers()
                 for thrift_node in peers_discovered:  # converting to network node and updating database
                     converted_node = Node(thrift_node.node_id, thrift_node.owner, thrift_node.host,
                                           str(thrift_node.port), bin(thrift_node.phases))
                     try:
                         net_dao.insert_node(converted_node)
                     except Exception as ex:  # likely trying to add a dupe node
                         template = "An exception of type {0} occurred. Arguments:\n{1!r}"
                         message = template.format(type(ex).__name__, ex.args)
                         # logger().warning(message)
                         continue
Ejemplo n.º 5
0
def load_required_nodes():
    node = Node('6625e727-f5b8-45ab-87c7-d113192ce168', 'TWDC', 'localhost',
                '8083', '01000')
    net_dao.insert_node(node)
    print('inserted node into database ' +
          os.environ.get('BLOCKCHAIN_DB_NAME') + " " + node.node_id)
Ejemplo n.º 6
0
def load_required_nodes():
    node = Node(str(uuid.uuid4()), 'TWDC', 'localhost', '8084', '10000')
    net_dao.insert_node(node)
    print('inserted node into database ' +
          os.environ.get('BLOCKCHAIN_DB_NAME') + " " + node.node_id)