run_network_loop

Function run_network_loop 

Source
pub async fn run_network_loop(
    swarm: Swarm<BillPouchBehaviour>,
    cmd_rx: Receiver<NetworkCommand>,
    state: Arc<RwLock<NetworkState>>,
    listen_addr: Multiaddr,
    storage_managers: StorageManagerMap,
    outgoing_assignments: OutgoingAssignments,
    remote_fragment_index: Arc<RwLock<RemoteFragmentIndex>>,
) -> BpResult<()>
Expand description

Drive the P2P event loop until shutdown.

Spawned as a background task by run_daemon. Runs a tokio::select! loop that concurrently:

  • polls the libp2p swarm for events (gossip, mDNS, Identify, Kademlia),
  • reads NetworkCommands from cmd_rx and mutates swarm state.

The loop exits when the command channel is closed or a Shutdown command is received.

§Arguments

  • swarm — the libp2p swarm built by build_swarm.
  • cmd_rx — receiving end of the daemon → network command channel.
  • state — shared NetworkState updated from gossip messages.
  • listen_addr — multiaddr to bind the TCP listener on.