Add receiver ID handling
This commit is contained in:
parent
ebda40e034
commit
db8eae74e5
@ -6,6 +6,7 @@ from libp2p.peer.peerinfo import info_from_p2p_addr
|
|||||||
from libp2p.pubsub.pubsub import Pubsub
|
from libp2p.pubsub.pubsub import Pubsub
|
||||||
from libp2p.pubsub.floodsub import FloodSub
|
from libp2p.pubsub.floodsub import FloodSub
|
||||||
from tests.pubsub.utils import message_id_generator
|
from tests.pubsub.utils import message_id_generator
|
||||||
|
from libp2p.peer.id import ID
|
||||||
|
|
||||||
TOPIC = "eth"
|
TOPIC = "eth"
|
||||||
SUPPORTED_PUBSUB_PROTOCOLS = ["/floodsub/1.0.0"]
|
SUPPORTED_PUBSUB_PROTOCOLS = ["/floodsub/1.0.0"]
|
||||||
@ -21,7 +22,7 @@ class ReceiverNode():
|
|||||||
self.next_msg_id_func = message_id_generator(0)
|
self.next_msg_id_func = message_id_generator(0)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def create(cls, ack_protocol, topic):
|
async def create(cls, node_id, transport_opt_str, ack_protocol, topic):
|
||||||
"""
|
"""
|
||||||
Create a new ReceiverNode and attach a libp2p node, a floodsub, and a pubsub
|
Create a new ReceiverNode and attach a libp2p node, a floodsub, and a pubsub
|
||||||
instance to this new node
|
instance to this new node
|
||||||
@ -31,8 +32,10 @@ class ReceiverNode():
|
|||||||
"""
|
"""
|
||||||
self = ReceiverNode()
|
self = ReceiverNode()
|
||||||
|
|
||||||
libp2p_node = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/0"])
|
id_opt = ID("peer-" + node_id)
|
||||||
await libp2p_node.get_network().listen(multiaddr.Multiaddr("/ip4/127.0.0.1/tcp/0"))
|
|
||||||
|
libp2p_node = await new_node(id_opt=id_opt, transport_opt=[transport_opt_str])
|
||||||
|
await libp2p_node.get_network().listen(multiaddr.Multiaddr(transport_opt_str))
|
||||||
|
|
||||||
self.libp2p_node = libp2p_node
|
self.libp2p_node = libp2p_node
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import asyncio
|
|||||||
import json
|
import json
|
||||||
import multiaddr
|
import multiaddr
|
||||||
import sys
|
import sys
|
||||||
|
from libp2p.peer.id import ID
|
||||||
from sender import SenderNode
|
from sender import SenderNode
|
||||||
from receiver import ReceiverNode
|
from receiver import ReceiverNode
|
||||||
from libp2p.peer.peerinfo import info_from_p2p_addr
|
from libp2p.peer.peerinfo import info_from_p2p_addr
|
||||||
@ -16,7 +17,6 @@ python receiver_driver.py topology_config.json "my_node_id"
|
|||||||
|
|
||||||
async def connect(node1, node2_addr):
|
async def connect(node1, node2_addr):
|
||||||
# node1 connects to node2
|
# node1 connects to node2
|
||||||
print(node2_addr)
|
|
||||||
info = info_from_p2p_addr(node2_addr)
|
info = info_from_p2p_addr(node2_addr)
|
||||||
await node1.connect(info)
|
await node1.connect(info)
|
||||||
|
|
||||||
@ -79,16 +79,21 @@ async def main():
|
|||||||
|
|
||||||
# Create Receiver Node
|
# Create Receiver Node
|
||||||
print("Creating receiver")
|
print("Creating receiver")
|
||||||
receiver_node = await ReceiverNode.create(ACK_PROTOCOL, my_topic)
|
my_transport_opt_str = topology_config_dict["node_id_map"][my_node_id]
|
||||||
|
receiver_node = await ReceiverNode.create(my_node_id, my_transport_opt_str, ACK_PROTOCOL, my_topic)
|
||||||
print("Receiver created")
|
print("Receiver created")
|
||||||
|
# TODO: sleep for like 15 seconds to let other nodes start up
|
||||||
|
|
||||||
# Connect receiver node to all other relevant receiver nodes
|
# Connect receiver node to all other relevant receiver nodes
|
||||||
for neighbor in topology_config_dict["topology"][my_node_id]:
|
for neighbor in topology_config_dict["topology"][my_node_id]:
|
||||||
neighbor_addr_str = topology_config_dict["node_id_map"][neighbor]
|
neighbor_addr_str = topology_config_dict["node_id_map"][neighbor]
|
||||||
|
|
||||||
|
# Add p2p part
|
||||||
|
neighbor_addr_str += "/p2p/" + ID("peer-" + neighbor).pretty()
|
||||||
|
|
||||||
# Convert neighbor_addr_str to multiaddr
|
# Convert neighbor_addr_str to multiaddr
|
||||||
neighbor_addr = multiaddr.Multiaddr(neighbor_addr_str)
|
neighbor_addr = multiaddr.Multiaddr(neighbor_addr_str)
|
||||||
await connect(receiver_node, neighbor_addr)
|
await connect(receiver_node.libp2p_node, neighbor_addr)
|
||||||
|
|
||||||
# Get sender info as multiaddr
|
# Get sender info as multiaddr
|
||||||
sender_addr_str = topology_config_dict["node_id_map"]["sender"]
|
sender_addr_str = topology_config_dict["node_id_map"]["sender"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user