@@ -163,6 +163,8 @@ impl Builder {
163
163
1 => Some ( discovery. into_iter ( ) . next ( ) . expect ( "checked length" ) ) ,
164
164
_ => Some ( Box :: new ( ConcurrentDiscovery :: from_services ( discovery) ) ) ,
165
165
} ;
166
+ let server_config = static_config. create_server_config ( self . alpn_protocols ) ?;
167
+
166
168
let msock_opts = magicsock:: Options {
167
169
addr_v4 : self . addr_v4 ,
168
170
addr_v6 : self . addr_v6 ,
@@ -172,12 +174,13 @@ impl Builder {
172
174
discovery,
173
175
proxy_url : self . proxy_url ,
174
176
dns_resolver,
177
+ server_config,
175
178
#[ cfg( any( test, feature = "test-utils" ) ) ]
176
179
insecure_skip_relay_cert_verify : self . insecure_skip_relay_cert_verify ,
177
180
#[ cfg( any( test, feature = "test-utils" ) ) ]
178
181
path_selection : self . path_selection ,
179
182
} ;
180
- Endpoint :: bind ( static_config, msock_opts, self . alpn_protocols ) . await
183
+ Endpoint :: bind ( static_config, msock_opts) . await
181
184
}
182
185
183
186
// # The very common methods everyone basically needs.
@@ -442,7 +445,6 @@ impl Builder {
442
445
self
443
446
}
444
447
}
445
-
446
448
/// Configuration for a [`quinn::Endpoint`] that cannot be changed at runtime.
447
449
#[ derive( Debug ) ]
448
450
struct StaticConfig {
@@ -453,7 +455,7 @@ struct StaticConfig {
453
455
454
456
impl StaticConfig {
455
457
/// Create a [`quinn::ServerConfig`] with the specified ALPN protocols.
456
- fn create_server_config ( & self , alpn_protocols : Vec < Vec < u8 > > ) -> Result < ServerConfig > {
458
+ fn create_server_config ( & self , alpn_protocols : Vec < Vec < u8 > > ) -> Result < quinn :: ServerConfig > {
457
459
let server_config = make_server_config (
458
460
& self . secret_key ,
459
461
alpn_protocols,
@@ -506,7 +508,6 @@ pub fn make_server_config(
506
508
#[ derive( Clone , Debug ) ]
507
509
pub struct Endpoint {
508
510
msock : Handle ,
509
- endpoint : quinn:: Endpoint ,
510
511
rtt_actor : Arc < rtt_actor:: RttHandle > ,
511
512
static_config : Arc < StaticConfig > ,
512
513
}
@@ -528,39 +529,16 @@ impl Endpoint {
528
529
/// This is for internal use, the public interface is the [`Builder`] obtained from
529
530
/// [Self::builder]. See the methods on the builder for documentation of the parameters.
530
531
#[ instrument( "ep" , skip_all, fields( me = %static_config. secret_key. public( ) . fmt_short( ) ) ) ]
531
- async fn bind (
532
- static_config : StaticConfig ,
533
- msock_opts : magicsock:: Options ,
534
- initial_alpns : Vec < Vec < u8 > > ,
535
- ) -> Result < Self > {
532
+ async fn bind ( static_config : StaticConfig , msock_opts : magicsock:: Options ) -> Result < Self > {
536
533
let msock = magicsock:: MagicSock :: spawn ( msock_opts) . await ?;
537
534
trace ! ( "created magicsock" ) ;
538
-
539
- let server_config = static_config. create_server_config ( initial_alpns) ?;
540
-
541
- let mut endpoint_config = quinn:: EndpointConfig :: default ( ) ;
542
- // Setting this to false means that quinn will ignore packets that have the QUIC fixed bit
543
- // set to 0. The fixed bit is the 3rd bit of the first byte of a packet.
544
- // For performance reasons and to not rewrite buffers we pass non-QUIC UDP packets straight
545
- // through to quinn. We set the first byte of the packet to zero, which makes quinn ignore
546
- // the packet if grease_quic_bit is set to false.
547
- endpoint_config. grease_quic_bit ( false ) ;
548
-
549
- let endpoint = quinn:: Endpoint :: new_with_abstract_socket (
550
- endpoint_config,
551
- Some ( server_config) ,
552
- Arc :: new ( msock. clone ( ) ) ,
553
- Arc :: new ( quinn:: TokioRuntime ) ,
554
- ) ?;
555
535
trace ! ( "created quinn endpoint" ) ;
556
536
debug ! ( version = env!( "CARGO_PKG_VERSION" ) , "iroh Endpoint created" ) ;
557
537
let ep = Self {
558
538
msock : msock. clone ( ) ,
559
- endpoint : endpoint. clone ( ) ,
560
539
rtt_actor : Arc :: new ( rtt_actor:: RttHandle :: new ( ) ) ,
561
540
static_config : Arc :: new ( static_config) ,
562
541
} ;
563
- msock. set_quic_endpoint ( Some ( endpoint) ) ;
564
542
Ok ( ep)
565
543
}
566
544
@@ -570,7 +548,7 @@ impl Endpoint {
570
548
/// Note that this *overrides* the current list of ALPNs.
571
549
pub fn set_alpns ( & self , alpns : Vec < Vec < u8 > > ) -> Result < ( ) > {
572
550
let server_config = self . static_config . create_server_config ( alpns) ?;
573
- self . endpoint . set_server_config ( Some ( server_config) ) ;
551
+ self . msock . endpoint ( ) . set_server_config ( Some ( server_config) ) ;
574
552
Ok ( ( ) )
575
553
}
576
554
@@ -668,7 +646,8 @@ impl Endpoint {
668
646
669
647
// TODO: We'd eventually want to replace "localhost" with something that makes more sense.
670
648
let connect = self
671
- . endpoint
649
+ . msock
650
+ . endpoint ( )
672
651
. connect_with ( client_config, addr. 0 , "localhost" ) ?;
673
652
674
653
let connection = connect
@@ -698,7 +677,7 @@ impl Endpoint {
698
677
/// [`Endpoint::close`].
699
678
pub fn accept ( & self ) -> Accept < ' _ > {
700
679
Accept {
701
- inner : self . endpoint . accept ( ) ,
680
+ inner : self . msock . endpoint ( ) . accept ( ) ,
702
681
ep : self . clone ( ) ,
703
682
}
704
683
}
@@ -1066,7 +1045,7 @@ impl Endpoint {
1066
1045
}
1067
1046
#[ cfg( test) ]
1068
1047
pub ( crate ) fn endpoint ( & self ) -> & quinn:: Endpoint {
1069
- & self . endpoint
1048
+ self . msock . endpoint ( )
1070
1049
}
1071
1050
}
1072
1051
0 commit comments