Example #1
0
 def discover_node(self, node_to_discover):
     """ discover node, get_verifications node info from unregistered nodes (updating unregistered nodes) """
     if self.connect_thrift_node(node_to_discover):
         logger().info('successfully connected to unregistered node port: %s', node_to_discover.port)
         try:  # if able to connect to unregistered node
             if self.calc_latency(node_to_discover):
                 net_dao.update_con_activity(node_to_discover)
         finally:  # disconnect node
             logger().info('disconnecting unregistered node port: %s', node_to_discover.port)
             self.disconnect_node(node_to_discover)
     else:  # failed to ping node (not connected)
         net_dao.update_failed_ping(node_to_discover)
         logger().warning('unsuccessful connection attempt to unregistered node port: %s', node_to_discover.port)
Example #2
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