@@ -41,7 +41,7 @@ use std::thread;
4141use std:: time:: { Duration , Instant } ;
4242use futures:: { future, Future , Stream , IntoFuture } ;
4343use futures:: sync:: { mpsc, oneshot} ;
44- use tokio_core :: reactor :: { Core , Handle } ;
44+ use tokio :: runtime :: current_thread ;
4545use tokio_io:: { AsyncRead , AsyncWrite } ;
4646use tokio_timer:: { Interval , Deadline } ;
4747
@@ -118,7 +118,7 @@ impl NetworkService {
118118 local_peer_id : local_peer_id. clone ( ) ,
119119 kbuckets_timeout : Duration :: from_secs ( 600 ) ,
120120 request_timeout : Duration :: from_secs ( 10 ) ,
121- known_initial_peers : network_state. known_peers ( ) . collect ( ) ,
121+ known_initial_peers : network_state. known_peers ( ) ,
122122 } ) ;
123123
124124 let shared = Arc :: new ( Shared {
@@ -191,16 +191,16 @@ impl NetworkService {
191191
192192 let shared = self . shared . clone ( ) ;
193193 let join_handle = thread:: spawn ( move || {
194- // Tokio core that is going to run everything in this thread.
195- let mut core = match Core :: new ( ) {
194+ // Tokio runtime that is going to run everything in this thread.
195+ let mut runtime = match current_thread :: Runtime :: new ( ) {
196196 Ok ( c) => c,
197197 Err ( err) => {
198198 let _ = init_tx. send ( Err ( err. into ( ) ) ) ;
199199 return
200200 }
201201 } ;
202202
203- let fut = match init_thread ( core . handle ( ) , shared,
203+ let fut = match init_thread ( shared,
204204 timeouts_register_rx, close_rx) {
205205 Ok ( future) => {
206206 debug ! ( target: "sub-libp2p" , "Successfully started networking service" ) ;
@@ -213,7 +213,7 @@ impl NetworkService {
213213 }
214214 } ;
215215
216- match core . run ( fut) {
216+ match runtime . block_on ( fut) {
217217 Ok ( ( ) ) => debug ! ( target: "sub-libp2p" , "libp2p future finished" ) ,
218218 Err ( err) => error ! ( target: "sub-libp2p" , "error while running libp2p: {:?}" , err) ,
219219 }
@@ -395,7 +395,6 @@ impl NetworkContext for NetworkContextImpl {
395395/// - `timeouts_register_rx` should receive newly-registered timeouts.
396396/// - `close_rx` should be triggered when we want to close the network.
397397fn init_thread (
398- core : Handle ,
399398 shared : Arc < Shared > ,
400399 timeouts_register_rx : mpsc:: UnboundedReceiver <
401400 ( Duration , ( Arc < NetworkProtocolHandler + Send + Sync + ' static > , ProtocolId , TimerToken ) )
@@ -405,7 +404,6 @@ fn init_thread(
405404 // Build the transport layer.
406405 let transport = {
407406 let base = transport:: build_transport (
408- core. clone ( ) ,
409407 transport:: UnencryptedAllowed :: Denied ,
410408 shared. network_state . local_private_key ( ) . clone ( )
411409 ) ;
@@ -535,7 +533,7 @@ fn init_thread(
535533
536534 // Build the timeouts system for the `register_timeout` function.
537535 // (note: this has nothing to do with socket timeouts)
538- let timeouts = timeouts:: build_timeouts_stream ( core . clone ( ) , timeouts_register_rx)
536+ let timeouts = timeouts:: build_timeouts_stream ( timeouts_register_rx)
539537 . for_each ( {
540538 let shared = shared. clone ( ) ;
541539 move |( handler, protocol_id, timer_token) | {
@@ -630,7 +628,7 @@ fn listener_handle<'a, C>(
630628 match shared. network_state . ping_connection ( node_id. clone ( ) ) {
631629 Ok ( ( _, ping_connec) ) => {
632630 trace ! ( target: "sub-libp2p" , "Successfully opened ping substream with {:?}" , node_id) ;
633- let fut = ping_connec. set_until ( pinger, future) ;
631+ let fut = ping_connec. tie_or_passthrough ( pinger, future) ;
634632 Box :: new ( fut) as Box < _ >
635633 } ,
636634 Err ( err) => Box :: new ( future:: err ( err) ) as Box < _ >
@@ -687,7 +685,7 @@ fn handle_kademlia_connection(
687685 val
688686 } ) ;
689687
690- Ok ( kad_connec. set_until ( controller, future) )
688+ Ok ( kad_connec. tie_or_passthrough ( controller, future) )
691689}
692690
693691/// When a remote performs a `FIND_NODE` Kademlia request for `searched`,
@@ -823,7 +821,7 @@ fn handle_custom_connection(
823821 } ) ;
824822
825823 let val = ( custom_proto_out. outgoing , custom_proto_out. protocol_version ) ;
826- let final_fut = unique_connec. set_until ( val, fut)
824+ let final_fut = unique_connec. tie_or_stop ( val, fut)
827825 . then ( move |val| {
828826 // Makes sure that `dc_guard` is kept alive until here.
829827 drop ( dc_guard) ;
@@ -950,7 +948,7 @@ fn perform_kademlia_query<T, To, St, C>(
950948 let random_peer_id = random_key. into_peer_id ( ) ;
951949 trace ! ( target: "sub-libp2p" , "Start kademlia discovery for {:?}" , random_peer_id) ;
952950
953- shared. clone ( )
951+ let future = shared. clone ( )
954952 . kad_system
955953 . find_node ( random_peer_id, {
956954 let shared = shared. clone ( ) ;
@@ -974,7 +972,10 @@ fn perform_kademlia_query<T, To, St, C>(
974972 )
975973 . into_future ( )
976974 . map_err ( |( err, _) | err)
977- . map ( |_| ( ) )
975+ . map ( |_| ( ) ) ;
976+
977+ // Note that we use a `Box` in order to speed up compilation.
978+ Box :: new ( future) as Box < Future < Item = _ , Error = _ > >
978979}
979980
980981/// Connects to additional nodes, if necessary.
@@ -1163,8 +1164,7 @@ fn open_peer_custom_proto<T, To, St, C>(
11631164 ) ;
11641165 }
11651166
1166- // TODO: this future should be used
1167- let _ = unique_connec. get_or_dial ( & swarm_controller, & addr, with_err) ;
1167+ unique_connec. dial ( & swarm_controller, & addr, with_err) ;
11681168 } ,
11691169 Err ( err) => {
11701170 trace ! ( target: "sub-libp2p" ,
@@ -1200,11 +1200,14 @@ fn obtain_kad_connection<T, To, St, C>(shared: Arc<Shared>,
12001200 } )
12011201 } ) ;
12021202
1203- shared. network_state
1203+ let future = shared. network_state
12041204 . kad_connection ( who. clone ( ) )
12051205 . into_future ( )
1206- . map ( move |( _, k) | k. get_or_dial ( & swarm_controller, & addr, transport) )
1207- . flatten ( )
1206+ . map ( move |( _, k) | k. dial ( & swarm_controller, & addr, transport) )
1207+ . flatten ( ) ;
1208+
1209+ // Note that we use a Box in order to speed up compilation.
1210+ Box :: new ( future) as Box < Future < Item = _ , Error = _ > >
12081211}
12091212
12101213/// Processes the information about a node.
@@ -1305,7 +1308,7 @@ fn ping_all<T, St, C>(
13051308
13061309 let addr = Multiaddr :: from ( AddrComponent :: P2P ( who. clone ( ) . into_bytes ( ) ) ) ;
13071310 let fut = pinger
1308- . get_or_dial ( & swarm_controller, & addr, transport. clone ( ) )
1311+ . dial ( & swarm_controller, & addr, transport. clone ( ) )
13091312 . and_then ( move |mut p| {
13101313 trace ! ( target: "sub-libp2p" , "Pinging peer #{} aka. {:?}" , peer, who) ;
13111314 p. ping ( )
@@ -1334,7 +1337,7 @@ fn ping_all<T, St, C>(
13341337 ping_futures. push ( fut) ;
13351338 }
13361339
1337- future:: loop_fn ( ping_futures, |ping_futures| {
1340+ let future = future:: loop_fn ( ping_futures, |ping_futures| {
13381341 if ping_futures. is_empty ( ) {
13391342 let fut = future:: ok ( future:: Loop :: Break ( ( ) ) ) ;
13401343 return future:: Either :: A ( fut)
@@ -1344,7 +1347,10 @@ fn ping_all<T, St, C>(
13441347 . map ( |( ( ) , _, rest) | future:: Loop :: Continue ( rest) )
13451348 . map_err ( |( err, _, _) | err) ;
13461349 future:: Either :: B ( fut)
1347- } )
1350+ } ) ;
1351+
1352+ // Note that we use a Box in order to speed up compilation.
1353+ Box :: new ( future) as Box < Future < Item = _ , Error = _ > >
13481354}
13491355
13501356/// Expects a multiaddr of the format `/p2p/<node_id>` and returns the node ID.
0 commit comments