Skip to content

feat(SwarmBuilder): make with_bandwidth_logging chainable #4643

Open
@mxinden

Description

Description

SwarmBuilder::with_bandwidth_logging allows adding a bandwidth logging to a tree of transports constructed via SwarmBuilder. It returns both the builder and the BandwidthSinks. That is not ideal as it breaks the builder chain.

This originally came up in #4120 (comment).

Motivation

A single continuous builder chain is more ergonomic.

Current Implementation

The current with_bandwidth_logging requires a two step builder flow:

let (builder, _bandwidth_sinks) = SwarmBuilder::with_new_identity()
.with_tokio()
.with_tcp(
Default::default(),
libp2p_tls::Config::new,
libp2p_yamux::Config::default,
)
.unwrap()
.with_quic()
.with_dns()
.unwrap()
.with_relay_client(libp2p_tls::Config::new, libp2p_yamux::Config::default)
.unwrap()
.with_websocket(libp2p_tls::Config::new, libp2p_yamux::Config::default)
.await
.unwrap()
.with_bandwidth_logging();
let _: Swarm<MyBehaviour> = builder
.with_behaviour(|_key, relay| MyBehaviour { relay })
.unwrap()
.build();
}

See also #4626 (comment).

Are you planning to do it yourself in a pull request ?

No

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions