Replies: 4 comments
-
When creating a swarm you have to provide a structure implementing the |
Beta Was this translation helpful? Give feedback.
-
@mxinden Imagine I have a Behaviour like this: #[derive(NetworkBehaviour)]
#[behaviour(out_event = "BehaviourEventOut", poll_method = "poll")]
pub struct Behaviour {
gossipsub: Gossipsub,
mdns: Toggle<Mdns>,
ping: Ping,
identify: Identify,
// kademlia: ...,
// bitswap: Bitswap,
} As you can see I have used NetworkBehaviour drive macro . However the inject_connected is inside the NetworkBehaviour trait. Shall I re-implement all the NetworkBehaviour methods and not use the derived macro? |
Beta Was this translation helpful? Give feedback.
-
@b00f your setup looks quite bit similar to what we have in rust-ipfs. I'd recommend you to add a new component to your Behaviour which would implement the NetworkBehaviour trait. If you are after accounting (which peers are connected etc) on demand, the |
Beta Was this translation helpful? Give feedback.
-
@koivunej Thanks for the explanation. Not an easy way as I expected before but it works as you said. I have created a boilerplate for libp2p here First of all, I really don't like my implementation for events. As you can see I have duplicated codes, here, here and here . Any suggestion to make it better? I also noticed that sometimes some events are missed. If you run the boilerplate you can see that Another problem is that broadcasting immediately after PeerConnected event doesn't work properly. Any idea? |
Beta Was this translation helpful? Give feedback.
-
Is there any way to know if a peer or node is connected (or disconnected) from the network?
I checked the swarm code but I couldn't find a general way.
Beta Was this translation helpful? Give feedback.
All reactions