@@ -39,7 +39,7 @@ use mullvad_types::{
39
39
OpenVpnConstraints , RelayConstraints , RelayOverride , RelaySettings , ResolvedBridgeSettings ,
40
40
WireguardConstraints ,
41
41
} ,
42
- relay_list:: { Relay , RelayEndpointData , RelayList } ,
42
+ relay_list:: { Relay , RelayEndpointData , RelayList , ShadowsocksBridgeProvider } ,
43
43
settings:: Settings ,
44
44
wireguard:: QuantumResistantState ,
45
45
CustomTunnelEndpoint , Intersection ,
@@ -53,9 +53,10 @@ use talpid_types::{
53
53
ErrorExt ,
54
54
} ;
55
55
56
- /// [`WIREGUARD_RETRY_ORDER`] defines an ordered set of relay parameters which the relay selector should
57
- /// prioritize on successive connection attempts. Note that these will *never* override user
58
- /// preferences. See [the documentation on `RelayQuery`][RelayQuery] for further details.
56
+ /// [`WIREGUARD_RETRY_ORDER`] defines an ordered set of relay parameters which the relay selector
57
+ /// should should prioritize on successive connection attempts. Note that these will *never*
58
+ /// override user preferences. See [the documentation on `RelayQuery`][RelayQuery] for further
59
+ /// details.
59
60
///
60
61
/// This list should be kept in sync with the expected behavior defined in `docs/relay-selector.md`
61
62
pub static WIREGUARD_RETRY_ORDER : LazyLock < Vec < RelayQuery > > = LazyLock :: new ( || {
@@ -83,8 +84,8 @@ pub static WIREGUARD_RETRY_ORDER: LazyLock<Vec<RelayQuery>> = LazyLock::new(|| {
83
84
]
84
85
} ) ;
85
86
86
- /// [`OPENVPN_RETRY_ORDER`] defines an ordered set of relay parameters which the relay selector should
87
- /// prioritize on successive connection attempts. Note that these will *never* override user
87
+ /// [`OPENVPN_RETRY_ORDER`] defines an ordered set of relay parameters which the relay selector
88
+ /// should prioritize on successive connection attempts. Note that these will *never* override user
88
89
/// preferences. See [the documentation on `RelayQuery`][RelayQuery] for further details.
89
90
///
90
91
/// This list should be kept in sync with the expected behavior defined in `docs/relay-selector.md`
@@ -435,6 +436,47 @@ impl<'a> TryFrom<NormalSelectorConfig<'a>> for RelayQuery {
435
436
}
436
437
}
437
438
439
+ impl ShadowsocksBridgeProvider for RelaySelector {
440
+ /// Returns a non-custom bridge based on the relay and bridge constraints, ignoring the bridge
441
+ /// state.
442
+ fn get_bridge_forced ( & self ) -> Option < Shadowsocks > {
443
+ let parsed_relays = & self . parsed_relays . lock ( ) . unwrap ( ) . parsed_list ( ) . clone ( ) ;
444
+ let config = self . config . lock ( ) . unwrap ( ) ;
445
+ let specialized_config = SpecializedSelectorConfig :: from ( & * config) ;
446
+
447
+ let near_location = match specialized_config {
448
+ SpecializedSelectorConfig :: Normal ( config) => RelayQuery :: try_from ( config. clone ( ) )
449
+ . ok ( )
450
+ . and_then ( |user_preferences| {
451
+ Self :: get_relay_midpoint ( & user_preferences, parsed_relays, config. custom_lists )
452
+ } ) ,
453
+ SpecializedSelectorConfig :: Custom ( _) => None ,
454
+ } ;
455
+
456
+ let bridge_settings = & config. bridge_settings ;
457
+ let constraints = match bridge_settings. resolve ( ) {
458
+ Ok ( ResolvedBridgeSettings :: Normal ( settings) ) => InternalBridgeConstraints {
459
+ location : settings. location . clone ( ) ,
460
+ providers : settings. providers . clone ( ) ,
461
+ ownership : settings. ownership ,
462
+ transport_protocol : Constraint :: Only ( TransportProtocol :: Tcp ) ,
463
+ } ,
464
+ _ => InternalBridgeConstraints {
465
+ location : Constraint :: Any ,
466
+ providers : Constraint :: Any ,
467
+ ownership : Constraint :: Any ,
468
+ transport_protocol : Constraint :: Only ( TransportProtocol :: Tcp ) ,
469
+ } ,
470
+ } ;
471
+
472
+ let custom_lists = & config. custom_lists ;
473
+ Self :: get_proxy_settings ( parsed_relays, & constraints, near_location, custom_lists)
474
+ . map ( |( settings, _relay) | settings)
475
+ . inspect_err ( |error| log:: error!( "Failed to get bridge: {error}" ) )
476
+ . ok ( )
477
+ }
478
+ }
479
+
438
480
impl RelaySelector {
439
481
/// Returns a new `RelaySelector` backed by relays cached on disk.
440
482
pub fn new (
@@ -507,45 +549,6 @@ impl RelaySelector {
507
549
self . parsed_relays . lock ( ) . unwrap ( ) . last_updated ( )
508
550
}
509
551
510
- /// Returns a non-custom bridge based on the relay and bridge constraints, ignoring the bridge
511
- /// state.
512
- pub fn get_bridge_forced ( & self ) -> Option < Shadowsocks > {
513
- let parsed_relays = & self . parsed_relays . lock ( ) . unwrap ( ) . parsed_list ( ) . clone ( ) ;
514
- let config = self . config . lock ( ) . unwrap ( ) ;
515
- let specialized_config = SpecializedSelectorConfig :: from ( & * config) ;
516
-
517
- let near_location = match specialized_config {
518
- SpecializedSelectorConfig :: Normal ( config) => RelayQuery :: try_from ( config. clone ( ) )
519
- . ok ( )
520
- . and_then ( |user_preferences| {
521
- Self :: get_relay_midpoint ( & user_preferences, parsed_relays, config. custom_lists )
522
- } ) ,
523
- SpecializedSelectorConfig :: Custom ( _) => None ,
524
- } ;
525
-
526
- let bridge_settings = & config. bridge_settings ;
527
- let constraints = match bridge_settings. resolve ( ) {
528
- Ok ( ResolvedBridgeSettings :: Normal ( settings) ) => InternalBridgeConstraints {
529
- location : settings. location . clone ( ) ,
530
- providers : settings. providers . clone ( ) ,
531
- ownership : settings. ownership ,
532
- transport_protocol : Constraint :: Only ( TransportProtocol :: Tcp ) ,
533
- } ,
534
- _ => InternalBridgeConstraints {
535
- location : Constraint :: Any ,
536
- providers : Constraint :: Any ,
537
- ownership : Constraint :: Any ,
538
- transport_protocol : Constraint :: Only ( TransportProtocol :: Tcp ) ,
539
- } ,
540
- } ;
541
-
542
- let custom_lists = & config. custom_lists ;
543
- Self :: get_proxy_settings ( parsed_relays, & constraints, near_location, custom_lists)
544
- . map ( |( settings, _relay) | settings)
545
- . inspect_err ( |error| log:: error!( "Failed to get bridge: {error}" ) )
546
- . ok ( )
547
- }
548
-
549
552
/// Returns random relay and relay endpoint matching `query`.
550
553
pub fn get_relay_by_query ( & self , query : RelayQuery ) -> Result < GetRelay , Error > {
551
554
let config_guard = self . config . lock ( ) . unwrap ( ) ;
@@ -697,10 +700,10 @@ impl RelaySelector {
697
700
parsed_relays : & RelayList ,
698
701
custom_lists : & CustomListsSettings ,
699
702
) -> Result < GetRelay , Error > {
700
- // FIXME: A bit of defensive programming - calling `get_wireguard_relay_inner` with a query that
701
- // doesn't specify Wireguard as the desired tunnel type is not valid and will lead
702
- // to unwanted behavior. This should be seen as a workaround, and it would be nicer
703
- // to lift this invariant to be checked by the type system instead.
703
+ // FIXME: A bit of defensive programming - calling `get_wireguard_relay_inner` with a query
704
+ // that doesn't specify Wireguard as the desired tunnel type is not valid and will
705
+ // lead to unwanted behavior. This should be seen as a workaround, and it would be
706
+ // nicer to lift this invariant to be checked by the type system instead.
704
707
let mut query = query. clone ( ) ;
705
708
query. set_tunnel_protocol ( TunnelType :: Wireguard ) ?;
706
709
Self :: get_wireguard_relay_inner ( & query, custom_lists, parsed_relays)
0 commit comments