@@ -23,11 +23,9 @@ use std::{
23
23
} ;
24
24
25
25
use anyhow:: { bail, Context , Result } ;
26
- use derive_more:: Debug ;
27
26
use iroh_base:: { NodeAddr , NodeId , PublicKey , RelayUrl , SecretKey } ;
28
27
use iroh_relay:: RelayMap ;
29
28
use pin_project:: pin_project;
30
- use tokio_util:: sync:: CancellationToken ;
31
29
use tracing:: { debug, instrument, trace, warn} ;
32
30
use url:: Url ;
33
31
@@ -92,7 +90,7 @@ pub enum PathSelection {
92
90
/// new [`NodeId`].
93
91
///
94
92
/// To create the [`Endpoint`] call [`Builder::bind`].
95
- #[ derive( Debug ) ]
93
+ #[ derive( derive_more :: Debug ) ]
96
94
pub struct Builder {
97
95
secret_key : Option < SecretKey > ,
98
96
relay_mode : RelayMode ,
@@ -510,7 +508,6 @@ pub struct Endpoint {
510
508
msock : Handle ,
511
509
endpoint : quinn:: Endpoint ,
512
510
rtt_actor : Arc < rtt_actor:: RttHandle > ,
513
- cancel_token : CancellationToken ,
514
511
static_config : Arc < StaticConfig > ,
515
512
}
516
513
@@ -561,7 +558,6 @@ impl Endpoint {
561
558
msock,
562
559
endpoint,
563
560
rtt_actor : Arc :: new ( rtt_actor:: RttHandle :: new ( ) ) ,
564
- cancel_token : CancellationToken :: new ( ) ,
565
561
static_config : Arc :: new ( static_config) ,
566
562
} )
567
563
}
@@ -618,10 +614,11 @@ impl Endpoint {
618
614
let node_id = node_addr. node_id ;
619
615
let direct_addresses = node_addr. direct_addresses . clone ( ) ;
620
616
621
- // Get the mapped IPv6 address from the magic socket. Quinn will connect to this address.
622
- // Start discovery for this node if it's enabled and we have no valid or verified
623
- // address information for this node.
624
- let ( addr, discovery) = self
617
+ // Get the mapped IPv6 address from the magic socket. Quinn will connect to this
618
+ // address. Start discovery for this node if it's enabled and we have no valid or
619
+ // verified address information for this node. Dropping the discovery cancels any
620
+ // still running task.
621
+ let ( addr, _discovery_drop_guard) = self
625
622
. get_mapping_addr_and_maybe_start_discovery ( node_addr)
626
623
. await
627
624
. with_context ( || {
@@ -636,16 +633,9 @@ impl Endpoint {
636
633
node_id, addr, direct_addresses
637
634
) ;
638
635
639
- // Start connecting via quinn. This will time out after 10 seconds if no reachable address
640
- // is available.
641
- let conn = self . connect_quinn ( node_id, alpn, addr) . await ;
642
-
643
- // Cancel the node discovery task (if still running).
644
- if let Some ( discovery) = discovery {
645
- discovery. cancel ( ) ;
646
- }
647
-
648
- conn
636
+ // Start connecting via quinn. This will time out after 10 seconds if no reachable
637
+ // address is available.
638
+ self . connect_quinn ( node_id, alpn, addr) . await
649
639
}
650
640
651
641
#[ instrument(
@@ -990,7 +980,6 @@ impl Endpoint {
990
980
return Ok ( ( ) ) ;
991
981
}
992
982
993
- self . cancel_token . cancel ( ) ;
994
983
tracing:: debug!( "Closing connections" ) ;
995
984
self . endpoint . close ( 0u16 . into ( ) , b"" ) ;
996
985
self . endpoint . wait_idle ( ) . await ;
@@ -1002,16 +991,11 @@ impl Endpoint {
1002
991
1003
992
/// Check if this endpoint is still alive, or already closed.
1004
993
pub fn is_closed ( & self ) -> bool {
1005
- self . cancel_token . is_cancelled ( ) && self . msock . is_closed ( )
994
+ self . msock . is_closed ( )
1006
995
}
1007
996
1008
997
// # Remaining private methods
1009
998
1010
- /// Expose the internal [`CancellationToken`] to link shutdowns.
1011
- pub ( crate ) fn cancel_token ( & self ) -> & CancellationToken {
1012
- & self . cancel_token
1013
- }
1014
-
1015
999
/// Return the quic mapped address for this `node_id` and possibly start discovery
1016
1000
/// services if discovery is enabled on this magic endpoint.
1017
1001
///
@@ -1085,7 +1069,7 @@ impl Endpoint {
1085
1069
}
1086
1070
1087
1071
/// Future produced by [`Endpoint::accept`].
1088
- #[ derive( Debug ) ]
1072
+ #[ derive( derive_more :: Debug ) ]
1089
1073
#[ pin_project]
1090
1074
pub struct Accept < ' a > {
1091
1075
#[ pin]
0 commit comments