@@ -472,7 +472,7 @@ impl RelaySelector {
472
472
let near_location = match specialized_config {
473
473
SpecializedSelectorConfig :: Normal ( config) => {
474
474
let user_preferences = RelayQuery :: from ( config. clone ( ) ) ;
475
- Self :: get_relay_midpoint ( & user_preferences, parsed_relays, & config)
475
+ Self :: get_relay_midpoint ( & user_preferences, parsed_relays, config. custom_lists )
476
476
}
477
477
SpecializedSelectorConfig :: Custom ( _) => None ,
478
478
} ;
@@ -508,9 +508,9 @@ impl RelaySelector {
508
508
SpecializedSelectorConfig :: Custom ( custom_config) => {
509
509
Ok ( GetRelay :: Custom ( custom_config. clone ( ) ) )
510
510
}
511
- SpecializedSelectorConfig :: Normal ( pure_config ) => {
511
+ SpecializedSelectorConfig :: Normal ( normal_config ) => {
512
512
let parsed_relays = & self . parsed_relays . lock ( ) . unwrap ( ) ;
513
- Self :: get_relay_inner ( & query, parsed_relays, & pure_config )
513
+ Self :: get_relay_inner ( & query, parsed_relays, normal_config . custom_lists )
514
514
}
515
515
}
516
516
}
@@ -555,7 +555,7 @@ impl RelaySelector {
555
555
parsed_relays,
556
556
)
557
557
. ok_or ( Error :: NoRelay ) ?;
558
- Self :: get_relay_inner ( & query, parsed_relays, & normal_config)
558
+ Self :: get_relay_inner ( & query, parsed_relays, normal_config. custom_lists )
559
559
}
560
560
}
561
561
}
@@ -585,7 +585,7 @@ impl RelaySelector {
585
585
// settings
586
586
. filter ( |query| runtime_params. compatible ( query) )
587
587
. filter_map ( |query| query. clone ( ) . intersection ( user_query. clone ( ) ) )
588
- . filter ( |query| Self :: get_relay_inner ( query, parsed_relays, user_config) . is_ok ( ) )
588
+ . filter ( |query| Self :: get_relay_inner ( query, parsed_relays, user_config. custom_lists ) . is_ok ( ) )
589
589
. cycle ( ) // If the above filters remove all relays, cycle will also return an empty iterator
590
590
. nth ( retry_attempt)
591
591
}
@@ -610,22 +610,24 @@ impl RelaySelector {
610
610
fn get_relay_inner (
611
611
query : & RelayQuery ,
612
612
parsed_relays : & ParsedRelays ,
613
- config : & NormalSelectorConfig < ' _ > ,
613
+ custom_lists : & CustomListsSettings ,
614
614
) -> Result < GetRelay , Error > {
615
615
match query. tunnel_protocol {
616
616
Constraint :: Only ( TunnelType :: Wireguard ) => {
617
- Self :: get_wireguard_relay ( query, config , parsed_relays)
617
+ Self :: get_wireguard_relay ( query, custom_lists , parsed_relays)
618
618
}
619
619
Constraint :: Only ( TunnelType :: OpenVpn ) => {
620
- Self :: get_openvpn_relay ( query, config , parsed_relays)
620
+ Self :: get_openvpn_relay ( query, custom_lists , parsed_relays)
621
621
}
622
622
Constraint :: Any => {
623
623
// Try Wireguard, then OpenVPN, then fail
624
624
for tunnel_type in [ TunnelType :: Wireguard , TunnelType :: OpenVpn ] {
625
625
let mut new_query = query. clone ( ) ;
626
626
new_query. tunnel_protocol = Constraint :: Only ( tunnel_type) ;
627
627
// If a suitable relay is found, short-circuit and return it
628
- if let Ok ( relay) = Self :: get_relay_inner ( & new_query, parsed_relays, config) {
628
+ if let Ok ( relay) =
629
+ Self :: get_relay_inner ( & new_query, parsed_relays, custom_lists)
630
+ {
629
631
return Ok ( relay) ;
630
632
}
631
633
}
@@ -638,14 +640,14 @@ impl RelaySelector {
638
640
fn get_relay_inner (
639
641
mut query : RelayQuery ,
640
642
parsed_relays : & ParsedRelays ,
641
- config : & NormalSelectorConfig < ' _ > ,
643
+ custom_lists : & CustomListsSettings ,
642
644
) -> Result < GetRelay , Error > {
643
645
// FIXME: A bit of defensive programming - calling `get_wiregurad_relay` with a query that
644
646
// doesn't specify Wireguard as the desired tunnel type is not valid and will lead
645
647
// to unwanted behavior. This should be seen as a workaround, and it would be nicer
646
648
// to lift this invariant to be checked by the type system instead.
647
649
query. tunnel_protocol = Constraint :: Only ( TunnelType :: Wireguard ) ;
648
- Self :: get_wireguard_relay ( query, config , parsed_relays)
650
+ Self :: get_wireguard_relay ( query, custom_lists , parsed_relays)
649
651
}
650
652
651
653
/// Derive a valid Wireguard relay configuration from `query`.
@@ -663,17 +665,17 @@ impl RelaySelector {
663
665
/// [`MullvadEndpoint`]: mullvad_types::endpoint::MullvadEndpoint
664
666
fn get_wireguard_relay (
665
667
query : & RelayQuery ,
666
- config : & NormalSelectorConfig < ' _ > ,
668
+ custom_lists : & CustomListsSettings ,
667
669
parsed_relays : & ParsedRelays ,
668
670
) -> Result < GetRelay , Error > {
669
671
assert_eq ! (
670
672
query. tunnel_protocol,
671
673
Constraint :: Only ( TunnelType :: Wireguard )
672
674
) ;
673
675
let inner = if !query. wireguard_constraints . multihop ( ) {
674
- Self :: get_wireguard_singlehop_config ( query, config , parsed_relays) ?
676
+ Self :: get_wireguard_singlehop_config ( query, custom_lists , parsed_relays) ?
675
677
} else {
676
- Self :: get_wireguard_multihop_config ( query, config , parsed_relays) ?
678
+ Self :: get_wireguard_multihop_config ( query, custom_lists , parsed_relays) ?
677
679
} ;
678
680
let endpoint = Self :: get_wireguard_endpoint ( query, parsed_relays, & inner) ?;
679
681
let obfuscator =
@@ -693,11 +695,10 @@ impl RelaySelector {
693
695
/// * `Ok(WireguardInner::Singlehop)` otherwise
694
696
fn get_wireguard_singlehop_config (
695
697
query : & RelayQuery ,
696
- config : & NormalSelectorConfig < ' _ > ,
698
+ custom_lists : & CustomListsSettings ,
697
699
parsed_relays : & ParsedRelays ,
698
700
) -> Result < WireguardConfig , Error > {
699
- let candidates =
700
- filter_matching_relay_list ( query, parsed_relays. relays ( ) , config. custom_lists ) ;
701
+ let candidates = filter_matching_relay_list ( query, parsed_relays. relays ( ) , custom_lists) ;
701
702
helpers:: pick_random_relay ( & candidates)
702
703
. cloned ( )
703
704
. map ( WireguardConfig :: singlehop)
@@ -713,7 +714,7 @@ impl RelaySelector {
713
714
/// * `Ok(WireguardInner::Multihop)` otherwise
714
715
fn get_wireguard_multihop_config (
715
716
query : & RelayQuery ,
716
- config : & NormalSelectorConfig < ' _ > ,
717
+ custom_lists : & CustomListsSettings ,
717
718
parsed_relays : & ParsedRelays ,
718
719
) -> Result < WireguardConfig , Error > {
719
720
// Here, we modify the original query just a bit.
@@ -728,16 +729,10 @@ impl RelaySelector {
728
729
let mut exit_relay_query = query. clone ( ) ;
729
730
// DAITA should only be enabled for the entry relay
730
731
exit_relay_query. wireguard_constraints . daita = Constraint :: Only ( false ) ;
731
- let exit_candidates = filter_matching_relay_list (
732
- & exit_relay_query,
733
- parsed_relays. relays ( ) ,
734
- config. custom_lists ,
735
- ) ;
736
- let entry_candidates = filter_matching_relay_list (
737
- & entry_relay_query,
738
- parsed_relays. relays ( ) ,
739
- config. custom_lists ,
740
- ) ;
732
+ let exit_candidates =
733
+ filter_matching_relay_list ( & exit_relay_query, parsed_relays. relays ( ) , custom_lists) ;
734
+ let entry_candidates =
735
+ filter_matching_relay_list ( & entry_relay_query, parsed_relays. relays ( ) , custom_lists) ;
741
736
742
737
fn pick_random_excluding < ' a > ( list : & ' a [ Relay ] , exclude : & ' a Relay ) -> Option < & ' a Relay > {
743
738
list. iter ( )
@@ -826,15 +821,20 @@ impl RelaySelector {
826
821
#[ cfg( not( target_os = "android" ) ) ]
827
822
fn get_openvpn_relay (
828
823
query : & RelayQuery ,
829
- config : & NormalSelectorConfig < ' _ > ,
824
+ custom_lists : & CustomListsSettings ,
830
825
parsed_relays : & ParsedRelays ,
831
826
) -> Result < GetRelay , Error > {
832
827
assert_eq ! ( query. tunnel_protocol, Constraint :: Only ( TunnelType :: OpenVpn ) ) ;
833
828
let exit =
834
- Self :: choose_openvpn_relay ( query, config , parsed_relays) . ok_or ( Error :: NoRelay ) ?;
829
+ Self :: choose_openvpn_relay ( query, custom_lists , parsed_relays) . ok_or ( Error :: NoRelay ) ?;
835
830
let endpoint = Self :: get_openvpn_endpoint ( query, & exit, parsed_relays) ?;
836
- let bridge =
837
- Self :: get_openvpn_bridge ( query, & exit, & endpoint. protocol , parsed_relays, config) ?;
831
+ let bridge = Self :: get_openvpn_bridge (
832
+ query,
833
+ & exit,
834
+ & endpoint. protocol ,
835
+ parsed_relays,
836
+ custom_lists,
837
+ ) ?;
838
838
839
839
// FIXME: This assert would be better to encode at the type level.
840
840
assert ! ( matches!( exit. endpoint_data, RelayEndpointData :: Openvpn ) ) ;
@@ -887,13 +887,13 @@ impl RelaySelector {
887
887
relay : & Relay ,
888
888
protocol : & TransportProtocol ,
889
889
parsed_relays : & ParsedRelays ,
890
- config : & NormalSelectorConfig < ' _ > ,
890
+ custom_lists : & CustomListsSettings ,
891
891
) -> Result < Option < SelectedBridge > , Error > {
892
892
if !BridgeQuery :: should_use_bridge ( & query. openvpn_constraints . bridge_settings ) {
893
893
Ok ( None )
894
894
} else {
895
895
let bridge_query = & query. openvpn_constraints . bridge_settings . clone ( ) . unwrap ( ) ;
896
- let custom_lists = & config . custom_lists ;
896
+ let custom_lists = & custom_lists;
897
897
match protocol {
898
898
TransportProtocol :: Udp => {
899
899
log:: error!( "Can not use OpenVPN bridges over UDP" ) ;
@@ -1011,15 +1011,15 @@ impl RelaySelector {
1011
1011
fn get_relay_midpoint (
1012
1012
query : & RelayQuery ,
1013
1013
parsed_relays : & ParsedRelays ,
1014
- config : & NormalSelectorConfig < ' _ > ,
1014
+ custom_lists : & CustomListsSettings ,
1015
1015
) -> Option < Coordinates > {
1016
1016
use std:: ops:: Not ;
1017
1017
if query. location . is_any ( ) {
1018
1018
return None ;
1019
1019
}
1020
1020
1021
1021
let matching_locations: Vec < Location > =
1022
- filter_matching_relay_list ( query, parsed_relays. relays ( ) , config . custom_lists )
1022
+ filter_matching_relay_list ( query, parsed_relays. relays ( ) , custom_lists)
1023
1023
. into_iter ( )
1024
1024
. filter_map ( |relay| relay. location )
1025
1025
. unique_by ( |location| location. city . clone ( ) )
@@ -1037,12 +1037,12 @@ impl RelaySelector {
1037
1037
#[ cfg( not( target_os = "android" ) ) ]
1038
1038
fn choose_openvpn_relay (
1039
1039
query : & RelayQuery ,
1040
- config : & NormalSelectorConfig < ' _ > ,
1040
+ custom_lists : & CustomListsSettings ,
1041
1041
parsed_relays : & ParsedRelays ,
1042
1042
) -> Option < Relay > {
1043
1043
// Filter among all valid relays
1044
1044
let relays = parsed_relays. relays ( ) ;
1045
- let candidates = filter_matching_relay_list ( query, relays, config . custom_lists ) ;
1045
+ let candidates = filter_matching_relay_list ( query, relays, custom_lists) ;
1046
1046
// Pick one of the valid relays.
1047
1047
helpers:: pick_random_relay ( & candidates) . cloned ( )
1048
1048
}
0 commit comments