p2p_chat/network/behaviour.rs
1//! This module defines the composite `NetworkBehaviour` for the application.
2use libp2p::{ping, swarm::NetworkBehaviour};
3
4use crate::net::{ChatBehaviour, DiscoveryBehaviour, MailboxBehaviour};
5
6/// The composite `NetworkBehaviour` for the application.
7///
8/// This struct combines all the individual network behaviours into a single
9/// behaviour that can be used by the `libp2p` `Swarm`.
10#[derive(NetworkBehaviour)]
11pub struct P2PBehaviour {
12 /// The behaviour for sending and receiving chat messages.
13 pub chat: ChatBehaviour,
14 /// The behaviour for interacting with mailbox nodes.
15 pub mailbox: MailboxBehaviour,
16 /// The behaviour for peer discovery.
17 pub discovery: DiscoveryBehaviour,
18 /// The behaviour for pinging other peers to keep connections alive.
19 pub ping: ping::Behaviour,
20}