Libp2p Swarm with Quic Transport

I am having trouble creating a libp2p swarm with a quic transport. The issue stems from Swarm needing to know that my Transport and StreamMuxer are separate entities. The issue is that Quic has multiplexing out of the box so my code below doesn't work.

pub async fn new_udp_swarm(key_pair: KeyPair) -> Result<Swarm<UdpBehaviour>, Box<dyn Error>> {
    let peer_id: PeerID = key_pair.public().to_peer_id();
    let transport: GenTransport<Provider> = new_udp_transport(key_pair.clone()).await?;
    let behaviour: UdpBehaviour = new_udp_behaviour(key_pair.clone()),await?;
    Ok(libp2p::Swarm::with_tokio_executor(transport, behaviour, peer_id))
}
pub async fn new_udp_transport(key_pair: KeyPair) -> std::io::Result<GenTransport<Provider>> {
    let config: Config = libp2p::quic::Config::new(&key_pair);
    let transport: GenTransport<Provider> = libp2p::quic::Transport::new(config);
    Ok(transport)
}
pub async fn new_udp_behaviour(key_pair: KeyPair) -> Result<UdpBehaviour, Box<dyn Error>> {
    // code //
}

I assume I need to change my return for

pub async fn new_udp_transport(key_pair: KeyPair)

from

std::io::Result<GenTransport<Provider>>

to

std::io::Result<transport::Boxed<(PeerId, StreamMuxerBox)>>

but am not sure how I would do this, or if it is even possible at the moment?
If not possible, then I may need to clarify my need through another discussion. Here is the best link I could find on this issue:

hey hey, this is what I've found so far to be possible to do, with the latest libp2p version, you use the map function that Transport type implements.

fn build_transport(id_keys: Keypair) -> Boxed<(PeerId, StreamMuxerBox)> {
    let mut quic_config = QuicConfig::new(&id_keys);
    quic_config.support_draft_29 = true;
    QuicTransport::new(quic_config)
        .map(|(peer_id, muxer), _| (peer_id, StreamMuxerBox::new(muxer)))
        .boxed()
}

I hope that this helps you out, but I've found that it's not suited for situations where you need to have relay behavior because this approach doesn't play well with the Relay Client Transport, which doesn't return that tuple of (Peer_Id, Connection), it only returns Connection which doesn't implement the StreamMuxer trait.

That's where I'm stuck, but I hope mapping solves your issues.
Cheers

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.