working on adding tests
This commit is contained in:
parent
98f8df25ab
commit
fdaa4f56b9
|
@ -15,6 +15,7 @@ class KadPeerInfo(PeerInfo):
|
||||||
def __init__(self, peer_id, peer_data=None):
|
def __init__(self, peer_id, peer_data=None):
|
||||||
super(KadPeerInfo, self).__init__(peer_id, peer_data)
|
super(KadPeerInfo, self).__init__(peer_id, peer_data)
|
||||||
|
|
||||||
|
self.peer_id_obj = peer_id
|
||||||
self.peer_id = peer_id.get_raw_id()
|
self.peer_id = peer_id.get_raw_id()
|
||||||
self.xor_id = peer_id.get_xor_id()
|
self.xor_id = peer_id.get_xor_id()
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ class KadmeliaPeerRouter(IPeerRouting):
|
||||||
def __init__(self, dht_server):
|
def __init__(self, dht_server):
|
||||||
self.server = dht_server
|
self.server = dht_server
|
||||||
|
|
||||||
def find_peer(self, peer_id):
|
async def find_peer(self, peer_id):
|
||||||
"""
|
"""
|
||||||
Find specific Peer
|
Find specific Peer
|
||||||
FindPeer searches for a peer with given peer_id, returns a peer.PeerInfo
|
FindPeer searches for a peer with given peer_id, returns a peer.PeerInfo
|
||||||
|
@ -18,7 +18,7 @@ class KadmeliaPeerRouter(IPeerRouting):
|
||||||
"""
|
"""
|
||||||
# switching peer_id to xor_id used by kademlia as node_id
|
# switching peer_id to xor_id used by kademlia as node_id
|
||||||
xor_id = peer_id.get_xor_id()
|
xor_id = peer_id.get_xor_id()
|
||||||
value = self.server.get(xor_id)
|
value = await self.server.get(xor_id)
|
||||||
return decode_peerinfo(value)
|
return decode_peerinfo(value)
|
||||||
|
|
||||||
|
|
||||||
|
|
0
tests/routing/__init__.py
Normal file
0
tests/routing/__init__.py
Normal file
25
tests/routing/test_kad_peer_router.py
Normal file
25
tests/routing/test_kad_peer_router.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import asyncio
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from libp2p.kademlia.network import KademliaServer
|
||||||
|
from libp2p.routing.kademlia.kademlia_peer_router import KadmeliaPeerRouter
|
||||||
|
from libp2p.peer.id import id_b58_encode
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_example():
|
||||||
|
node_a = KademliaServer()
|
||||||
|
await node_a.listen(5678)
|
||||||
|
|
||||||
|
node_b = KademliaServer()
|
||||||
|
await node_b.listen(5679)
|
||||||
|
|
||||||
|
value = await node_b.bootstrap([("127.0.0.1", 5678)])
|
||||||
|
peer_info = value[0]
|
||||||
|
peer_id = peer_info.peer_id_obj
|
||||||
|
print(id_b58_encode(peer_id))
|
||||||
|
# await node_a.set(peer_info.xor_id, str(peer_info.ip) + "/" + str(peer_info.port))
|
||||||
|
# router = KadmeliaPeerRouter(node_b)
|
||||||
|
# value = await router.find_peer(peer_id)
|
||||||
|
# print("value vvvv")
|
||||||
|
# print(value.xor_)
|
||||||
|
# assert value == str(peer_info.ip) + "/" + str(peer_info.port)
|
Loading…
Reference in New Issue
Block a user