@@ -6,11 +6,12 @@ use libp2p::{
66 transport:: Transport ,
77 upgrade,
88 } ,
9- futures:: future:: Either ,
10- futures:: StreamExt ,
11- identify, identity, noise, ping, quic, relay,
12- swarm:: { NetworkBehaviour , SwarmBuilder , SwarmEvent } ,
13- tcp, yamux, PeerId , Swarm ,
9+ futures:: { future:: Either , StreamExt } ,
10+ identify,
11+ identity:: { self , Keypair } ,
12+ noise, ping, quic, relay,
13+ swarm:: { NetworkBehaviour , SwarmEvent } ,
14+ tcp, yamux, PeerId , Swarm , SwarmBuilder ,
1415} ;
1516use redis:: AsyncCommands ;
1617use std:: net:: { IpAddr , Ipv4Addr } ;
@@ -90,34 +91,26 @@ fn quic_addr(addr: IpAddr) -> Multiaddr {
9091}
9192
9293fn make_swarm ( ) -> Result < Swarm < Behaviour > > {
93- let local_key = identity:: Keypair :: generate_ed25519 ( ) ;
94- let local_peer_id = PeerId :: from ( local_key. public ( ) ) ;
95- log:: info!( "Local peer id: {local_peer_id}" ) ;
96-
97- let transport = tcp:: tokio:: Transport :: new ( tcp:: Config :: default ( ) . nodelay ( true ) )
98- . upgrade ( upgrade:: Version :: V1Lazy )
99- . authenticate ( noise:: Config :: new ( & local_key) ?)
100- . multiplex ( yamux:: Config :: default ( ) )
101- . or_transport ( quic:: tokio:: Transport :: new ( quic:: Config :: new ( & local_key) ) )
102- . map ( |either_output, _| match either_output {
103- Either :: Left ( ( peer_id, muxer) ) => ( peer_id, StreamMuxerBox :: new ( muxer) ) ,
104- Either :: Right ( ( peer_id, muxer) ) => ( peer_id, StreamMuxerBox :: new ( muxer) ) ,
105- } )
106- . boxed ( ) ;
107- let behaviour = Behaviour {
108- relay : relay:: Behaviour :: new ( local_peer_id, relay:: Config :: default ( ) ) ,
109- identify : identify:: Behaviour :: new ( identify:: Config :: new (
110- "/hole-punch-tests/1" . to_owned ( ) ,
111- local_key. public ( ) ,
112- ) ) ,
113- ping : ping:: Behaviour :: default ( ) ,
114- } ;
115-
116- Ok (
117- SwarmBuilder :: with_tokio_executor ( transport, behaviour, local_peer_id)
118- . substream_upgrade_protocol_override ( upgrade:: Version :: V1Lazy )
119- . build ( ) ,
120- )
94+ Ok ( SwarmBuilder :: with_new_identity ( )
95+ . with_tokio ( )
96+ . with_tcp (
97+ tcp:: Config :: default ( ) . nodelay ( true ) ,
98+ |k : & Keypair | noise:: Config :: new ( k) ,
99+ || yamux:: Config :: default ( ) ,
100+ ) ?
101+ . with_quic ( )
102+ . with_behaviour ( |local_key| {
103+ let local_peer_id = PeerId :: from ( local_key. public ( ) ) ;
104+ Behaviour {
105+ relay : relay:: Behaviour :: new ( local_peer_id, relay:: Config :: default ( ) ) ,
106+ identify : identify:: Behaviour :: new ( identify:: Config :: new (
107+ "/hole-punch-tests/1" . to_owned ( ) ,
108+ local_key. public ( ) ,
109+ ) ) ,
110+ ping : ping:: Behaviour :: default ( ) ,
111+ }
112+ } ) ?
113+ . build ( ) )
121114}
122115
123116struct RedisClient {
0 commit comments