Module smoldot_light::network_service

source ·
Expand description

Background network service.

The NetworkService manages background tasks dedicated to connecting to other nodes. Importantly, its design is oriented towards the particular use case of the light client.

The NetworkService spawns one background task (using PlatformRef::spawn_task) for each active connection.

The objective of the NetworkService in general is to try stay connected as much as possible to the nodes of the peer-to-peer network of the chain, and maintain open substreams with them in order to send out requests (e.g. block requests) and notifications (e.g. block announces).

Connectivity to the network is performed in the background as an implementation detail of the service. The public API only allows emitting requests and notifications towards the already-connected nodes.

After a NetworkService is created, one can add chains using NetworkService::add_chain. If all references to a NetworkServiceChain are destroyed, the chain is automatically purged.

An important part of the API is the list of channel receivers of Event returned by NetworkServiceChain::subscribe. These channels inform the foreground about updates to the network connectivity.

Structs§

Enums§