@@ -6,7 +6,7 @@ use futures_lite::{stream::Stream, StreamExt};
6
6
use futures_util:: future:: FutureExt ;
7
7
use genawaiter:: sync:: { Co , Gen } ;
8
8
use iroh_net:: {
9
- dialer:: { ConnDirection , ConnManager , NewConnection } ,
9
+ dialer:: { ConnDirection , ConnInfo , ConnManager } ,
10
10
endpoint:: Connection ,
11
11
key:: PublicKey ,
12
12
AddrInfo , Endpoint , NodeAddr ,
@@ -382,9 +382,14 @@ impl Actor {
382
382
}
383
383
}
384
384
}
385
- Some ( new_conn ) = self . conn_manager. next( ) => {
385
+ Some ( res ) = self . conn_manager. next( ) => {
386
386
trace!( ?i, "tick: conn_manager" ) ;
387
- self . handle_new_connection( new_conn) . await ;
387
+ match res {
388
+ Ok ( conn) => self . handle_new_connection( conn) . await ,
389
+ Err ( err) => {
390
+ self . handle_in_event( InEvent :: PeerDisconnected ( err. node_id) , Instant :: now( ) ) . await ?;
391
+ }
392
+ }
388
393
}
389
394
Some ( res) = self . conn_tasks. join_next( ) , if !self . conn_tasks. is_empty( ) => {
390
395
match res {
@@ -393,7 +398,7 @@ impl Actor {
393
398
Ok ( ( node_id, result) ) => {
394
399
self . conn_manager. remove( & node_id) ;
395
400
self . conn_send_tx. remove( & node_id) ;
396
- self . handle_in_event( InEvent :: PeerDisconnected ( node_id) , Instant :: now( ) ) . await ?;
401
+ self . handle_in_event( InEvent :: PeerDisconnected ( node_id) , Instant :: now( ) ) . await ?;
397
402
match result {
398
403
Ok ( ( ) ) => {
399
404
debug!( peer=%node_id. fmt_short( ) , "connection closed without error" ) ;
@@ -430,11 +435,11 @@ impl Actor {
430
435
async fn handle_to_actor_msg ( & mut self , msg : ToActor , now : Instant ) -> anyhow:: Result < ( ) > {
431
436
trace ! ( "handle to_actor {msg:?}" ) ;
432
437
match msg {
433
- ToActor :: AcceptConn ( conn) => match self . conn_manager . accept ( conn ) {
434
- Err ( err) => warn ! ( ?err , "failed to accept connection" ) ,
435
- Ok ( None ) => { }
436
- Ok ( Some ( conn ) ) => self . handle_new_connection ( conn ) . await ,
437
- } ,
438
+ ToActor :: AcceptConn ( conn) => {
439
+ if let Err ( err) = self . conn_manager . accept ( conn ) {
440
+ warn ! ( ?err , "failed to accept connection" ) ;
441
+ }
442
+ }
438
443
ToActor :: Join ( topic_id, peers, reply) => {
439
444
self . handle_in_event ( InEvent :: Command ( topic_id, Command :: Join ( peers) ) , now)
440
445
. await ?;
@@ -498,7 +503,7 @@ impl Actor {
498
503
self . conn_manager . remove ( & peer_id) ;
499
504
}
500
505
} else {
501
- if !self . conn_manager . is_dialing ( & peer_id) {
506
+ if !self . conn_manager . is_pending ( & peer_id) {
502
507
debug ! ( peer = ?peer_id, "dial" ) ;
503
508
self . conn_manager . dial ( peer_id) ;
504
509
}
@@ -545,38 +550,31 @@ impl Actor {
545
550
Ok ( ( ) )
546
551
}
547
552
548
- async fn handle_new_connection ( & mut self , new_conn : NewConnection ) {
549
- let NewConnection {
553
+ async fn handle_new_connection ( & mut self , new_conn : ConnInfo ) {
554
+ let ConnInfo {
550
555
conn,
551
- node_id : peer_id ,
556
+ node_id,
552
557
direction,
553
558
} = new_conn;
554
- match conn {
555
- Ok ( conn) => {
556
- let ( send_tx, send_rx) = mpsc:: channel ( SEND_QUEUE_CAP ) ;
557
- self . conn_send_tx . insert ( peer_id, send_tx. clone ( ) ) ;
558
-
559
- // Spawn a task for this connection
560
- let pending_sends = self . pending_sends . remove ( & peer_id) ;
561
- let in_event_tx = self . in_event_tx . clone ( ) ;
562
- debug ! ( peer=%peer_id. fmt_short( ) , ?direction, "connection established" ) ;
563
- self . conn_tasks . spawn (
564
- connection_loop (
565
- peer_id,
566
- conn,
567
- direction,
568
- send_rx,
569
- in_event_tx,
570
- pending_sends,
571
- )
572
- . map ( move |r| ( peer_id, r) )
573
- . instrument ( error_span ! ( "gossip_conn" , peer = %peer_id. fmt_short( ) ) ) ,
574
- ) ;
575
- }
576
- Err ( err) => {
577
- warn ! ( peer=%peer_id. fmt_short( ) , "connecting to node failed: {err:?}" ) ;
578
- }
579
- }
559
+ let ( send_tx, send_rx) = mpsc:: channel ( SEND_QUEUE_CAP ) ;
560
+ self . conn_send_tx . insert ( node_id, send_tx. clone ( ) ) ;
561
+
562
+ // Spawn a task for this connection
563
+ let pending_sends = self . pending_sends . remove ( & node_id) ;
564
+ let in_event_tx = self . in_event_tx . clone ( ) ;
565
+ debug ! ( peer=%node_id. fmt_short( ) , ?direction, "connection established" ) ;
566
+ self . conn_tasks . spawn (
567
+ connection_loop (
568
+ node_id,
569
+ conn,
570
+ direction,
571
+ send_rx,
572
+ in_event_tx,
573
+ pending_sends,
574
+ )
575
+ . map ( move |r| ( node_id, r) )
576
+ . instrument ( error_span ! ( "gossip_conn" , peer = %node_id. fmt_short( ) ) ) ,
577
+ ) ;
580
578
}
581
579
582
580
fn subscribe_all ( & mut self ) -> broadcast:: Receiver < ( TopicId , Event ) > {
0 commit comments