@@ -39,34 +39,47 @@ impl SelectedGateway {
3939 pub fn from_topology_node (
4040 node : RoutingNode ,
4141 must_use_tls : bool ,
42+ no_hostname : bool ,
4243 ) -> Result < Self , ClientCoreError > {
4344 // for now, let's use 'old' behaviour, if you want to change it, you can pass it up the enum stack yourself : )
4445 let prefer_ipv6 = false ;
4546
46- let gateway_listener = if must_use_tls {
47- node. ws_entry_address_tls ( )
48- . ok_or ( ClientCoreError :: UnsupportedWssProtocol {
49- gateway : node. identity_key . to_base58_string ( ) ,
50- } ) ?
47+ let ( gateway_listener, fallback_listener) = if must_use_tls {
48+ // WSS main, no fallback
49+ let primary =
50+ node. ws_entry_address_tls ( )
51+ . ok_or ( ClientCoreError :: UnsupportedWssProtocol {
52+ gateway : node. identity_key . to_base58_string ( ) ,
53+ } ) ?;
54+ ( primary, None )
55+ } else if no_hostname {
56+ // First IP address for main, second if it exists for fallback
57+ let primary = node. ws_entry_address_no_hostname ( prefer_ipv6, 0 ) . ok_or (
58+ ClientCoreError :: MissingIpAddress ( node. identity_key . to_base58_string ( ) ) ,
59+ ) ?;
60+ let fallback = node. ws_entry_address_no_hostname ( prefer_ipv6, 1 ) ;
61+ ( primary, fallback)
5162 } else {
52- node. ws_entry_address ( prefer_ipv6)
53- . ok_or ( ClientCoreError :: UnsupportedEntry {
54- id : node. node_id ,
55- identity : node. identity_key . to_base58_string ( ) ,
56- } ) ?
63+ // WS hostname main, IP address fallback
64+ let primary =
65+ node. ws_entry_address ( prefer_ipv6)
66+ . ok_or ( ClientCoreError :: UnsupportedEntry {
67+ id : node. node_id ,
68+ identity : node. identity_key . to_base58_string ( ) ,
69+ } ) ?;
70+ let fallback = node. ws_entry_address_no_hostname ( prefer_ipv6, 0 ) ;
71+ ( primary, fallback)
5772 } ;
5873
59- let fallback_listener =
60- node. ws_entry_address_no_hostname ( prefer_ipv6)
61- . and_then ( |address| {
62- Url :: parse ( & address)
63- . inspect_err ( |err| {
64- tracing:: warn!( "Malformed fallback listener, none will be used : {err}" )
65- } )
66- . ok ( )
67- } ) ;
68-
69- let gateway_listener =
74+ let fallback_listener_url = fallback_listener. and_then ( |address| {
75+ Url :: parse ( & address)
76+ . inspect_err ( |err| {
77+ tracing:: warn!( "Malformed fallback listener, none will be used : {err}" )
78+ } )
79+ . ok ( )
80+ } ) ;
81+
82+ let gateway_listener_url =
7083 Url :: parse ( & gateway_listener) . map_err ( |source| ClientCoreError :: MalformedListener {
7184 gateway_id : node. identity_key . to_base58_string ( ) ,
7285 raw_listener : gateway_listener,
@@ -76,8 +89,8 @@ impl SelectedGateway {
7689 Ok ( SelectedGateway :: Remote {
7790 gateway_id : node. identity_key ,
7891 gateway_listeners : GatewayListeners {
79- primary : gateway_listener ,
80- fallback : fallback_listener ,
92+ primary : gateway_listener_url ,
93+ fallback : fallback_listener_url ,
8194 } ,
8295 } )
8396 }
@@ -168,15 +181,22 @@ impl InitialisationResult {
168181#[ derive( Clone , Debug ) ]
169182pub enum GatewaySelectionSpecification {
170183 /// Uniformly choose a random remote gateway.
171- UniformRemote { must_use_tls : bool } ,
184+ UniformRemote {
185+ must_use_tls : bool ,
186+ no_hostname : bool ,
187+ } ,
172188
173189 /// Should the new, remote, gateway be selected based on latency.
174- RemoteByLatency { must_use_tls : bool } ,
190+ RemoteByLatency {
191+ must_use_tls : bool ,
192+ no_hostname : bool ,
193+ } ,
175194
176195 /// Gateway with this specific identity should be chosen.
177196 // JS: I don't really like the name of this enum variant but couldn't think of anything better at the time
178197 Specified {
179198 must_use_tls : bool ,
199+ no_hostname : bool ,
180200 identity : IdentityKey ,
181201 } ,
182202
@@ -192,6 +212,7 @@ impl Default for GatewaySelectionSpecification {
192212 fn default ( ) -> Self {
193213 GatewaySelectionSpecification :: UniformRemote {
194214 must_use_tls : false ,
215+ no_hostname : false ,
195216 }
196217 }
197218}
@@ -201,16 +222,24 @@ impl GatewaySelectionSpecification {
201222 gateway_identity : Option < String > ,
202223 latency_based_selection : Option < bool > ,
203224 must_use_tls : bool ,
225+ no_hostname : bool ,
204226 ) -> Self {
205227 if let Some ( identity) = gateway_identity {
206228 GatewaySelectionSpecification :: Specified {
207229 identity,
208230 must_use_tls,
231+ no_hostname,
209232 }
210233 } else if let Some ( true ) = latency_based_selection {
211- GatewaySelectionSpecification :: RemoteByLatency { must_use_tls }
234+ GatewaySelectionSpecification :: RemoteByLatency {
235+ must_use_tls,
236+ no_hostname,
237+ }
212238 } else {
213- GatewaySelectionSpecification :: UniformRemote { must_use_tls }
239+ GatewaySelectionSpecification :: UniformRemote {
240+ must_use_tls,
241+ no_hostname,
242+ }
214243 }
215244 }
216245}
0 commit comments