added RoutedHost and updated new_node to support it

This commit is contained in:
Alex Haynes
2019-04-20 17:35:05 -04:00
parent 367a939087
commit e7424d3673
6 changed files with 85 additions and 15 deletions

View File

@ -15,8 +15,7 @@ class KadPeerInfo(PeerInfo):
def __init__(self, peer_id, peer_data=None):
super(KadPeerInfo, self).__init__(peer_id, peer_data)
# pylint: disable=protected-access
self.peer_id = peer_id._id_str
self.peer_id = peer_id.get_raw_id()
self.long_id = int(digest(peer_id._id_str).hex(), 16)
self.addrs = peer_data.get_addrs() if peer_data else None

View File

@ -16,7 +16,7 @@ log = logging.getLogger(__name__) # pylint: disable=invalid-name
# pylint: disable=too-many-instance-attributes
class Server:
class KademliaServer:
"""
High level view of a node instance. This is the object that should be
created to start listening as an active node on the network.

View File

@ -0,0 +1,35 @@
from libp2p.host.basic_host import BasicHost
class RoutedHost(BasicHost):
def __init__(self, _network, _kad_network):
super(RoutedHost, self).__init__(_network)
self.kad_network = _kad_network
def get_kad_network(self):
return self.kad_network
def kad_listen(self, port, interface='0.0.0.0'):
return self.kad_network.listen(port, interface)
def kad_get(self, key):
return self.kad_network.get(key)
def kad_set(self, key, value):
return self.kad_network.set(key, value)
def kad_set_digest(self, dkey, value):
return self.kad_network.set_digest(dkey, value)
def check_dht_value_type(value):
"""
Checks to see if the type of the value is a valid type for
placing in the dht.
"""
typeset = [
int,
float,
bool,
str,
bytes
]
return type(value) in typeset # pylint: disable=unidiomatic-typecheck