With the following code block from the Rust chat example, can someone explain to me (or point me to docs that explain) what the NetworkBehaviourEventProcess
abstraction is exactly. And what the generic-like traits it requires (FloodsubEvent
, and MdnsEvent
in this particular example). Again, I feel like this is already explained somewhere, so any links are helpful.
I’ve also ready the Introduction :: libp2p Documentation docs (just FYI)
impl NetworkBehaviourEventProcess<FloodsubEvent> for ChatBehavior {
fn inject_event(&mut self, message: FloodsubEvent) {
if let FloodsubEvent::Message(message) = message {
info!("Received: '{:?}' from {:?}", String::from_utf8_lossy(&message.data), message.source);
}
}
}
impl NetworkBehaviourEventProcess<MdnsEvent> for ChatBehavior {
fn inject_event(&mut self, event: MdnsEvent) {
match event {
MdnsEvent::Discovered(list) =>
for (peer, _) in list {
self.floodsub.add_node_to_partial_view(peer);
}
MdnsEvent::Expired(list) =>
for (peer, _) in list {
if !self.mdns.has_node(&peer) {
self.floodsub.remove_node_from_partial_view(&peer);
}
}
}
}
}