defaultMuxers top-level property
Default configuration options for libp2p Default muxer configuration for Yamux.
This factory now matches the Multiplexer Function(Conn secureConn, bool isClient)
signature. It assumes secureConn
can be cast to TransportConn
as required
by YamuxSession
. The actual connection upgrade logic (security + muxer negotiation)
will be handled by the Swarm/Upgrader, which will then call this factory.
Implementation
/// Default muxer configuration for Yamux.
///
/// This factory now matches the `Multiplexer Function(Conn secureConn, bool isClient)`
/// signature. It assumes `secureConn` can be cast to `TransportConn` as required
/// by `YamuxSession`. The actual connection upgrade logic (security + muxer negotiation)
/// will be handled by the Swarm/Upgrader, which will then call this factory.
Option defaultMuxers = Libp2p.muxer(
'/yamux/1.0.0',
(secureConn, isClient) {
// YamuxSession expects a TransportConn.
// The `secureConn` provided by the (future) Upgrader should be compatible.
if (secureConn is! TransportConn) {
// This might happen if the security layer doesn't output a TransportConn.
// Or if an insecure connection (which might be a raw TransportConn) is used directly.
// For now, we'll throw if it's not directly a TransportConn.
// A more robust solution might involve an adapter or ensuring the security
// layer preserves or wraps TransportConn capabilities.
throw ArgumentError(
'YamuxSession factory requires a TransportConn, but received ${secureConn.runtimeType}. '
'The Upgrader needs to ensure the connection passed to the muxer factory is suitable.');
}
return YamuxSession(
secureConn, // Already checked to be a TransportConn
const MultiplexerConfig(), // Use default Yamux config
isClient,
);
},
);