@@ -27,11 +27,6 @@ use std::sync::Arc;
27
27
use std:: time:: Duration ;
28
28
use topology:: { gateway, NymTopology } ;
29
29
30
- const GOOD_GATEWAYS : [ & str ; 2 ] = [
31
- "DiYR9o8KgeQ81woKPYVAu4LNaAEg8SWkiufDCahNnPov" ,
32
- "5nrYxPR8gt2Gzo2BbHtsGf66KAEQY91WmM1eW78EphNy" ,
33
- ] ;
34
-
35
30
pub fn command_args < ' a , ' b > ( ) -> clap:: App < ' a , ' b > {
36
31
App :: new ( "init" )
37
32
. about ( "Initialise a Nym client. Do this first!" )
@@ -100,28 +95,30 @@ async fn register_with_gateway(
100
95
. expect ( "failed to register with the gateway!" )
101
96
}
102
97
103
- async fn gateway_details ( validator_server : & str , gateway_id : & str ) -> gateway:: Node {
98
+ async fn gateway_details ( validator_server : & str , chosen_gateway_id : Option < & str > ) -> gateway:: Node {
104
99
let validator_client_config = validator_client:: Config :: new ( validator_server. to_string ( ) ) ;
105
100
let validator_client = validator_client:: Client :: new ( validator_client_config) ;
106
101
let topology = validator_client. get_active_topology ( ) . await . unwrap ( ) ;
107
102
let nym_topology: NymTopology = topology. into ( ) ;
108
103
let version_filtered_topology = nym_topology. filter_system_version ( env ! ( "CARGO_PKG_VERSION" ) ) ;
109
104
110
- version_filtered_topology
111
- . gateways ( )
112
- . iter ( )
113
- . find ( |gateway| gateway . identity_key . to_base58_string ( ) == gateway_id )
114
- . expect ( & * format ! ( "no gateway with id {} exists!" , gateway_id ) )
115
- . clone ( )
116
- }
117
-
118
- fn select_gateway ( arg : Option < & str > ) -> & str {
119
- if let Some ( gateway_id ) = arg {
120
- gateway_id
105
+ // if we have chosen particular gateway - use it, otherwise choose a random one.
106
+ // (remember that in active topology all gateways have at least 100 reputation so should
107
+ // be working correctly )
108
+
109
+ if let Some ( gateway_id ) = chosen_gateway_id {
110
+ version_filtered_topology
111
+ . gateways ( )
112
+ . iter ( )
113
+ . find ( |gateway| gateway . identity_key . to_base58_string ( ) == gateway_id )
114
+ . expect ( & * format ! ( "no gateway with id {} exists!" , gateway_id ) )
115
+ . clone ( )
121
116
} else {
122
- // TODO1: this should only be done on testnet
123
- // TODO2: it should probably check if chosen gateway is actually online
124
- GOOD_GATEWAYS . choose ( & mut rand:: thread_rng ( ) ) . unwrap ( )
117
+ version_filtered_topology
118
+ . gateways ( )
119
+ . choose ( & mut rand:: thread_rng ( ) )
120
+ . expect ( "there are no gateways on the network!" )
121
+ . clone ( )
125
122
}
126
123
}
127
124
@@ -154,12 +151,17 @@ pub fn execute(matches: &ArgMatches) {
154
151
// create identity, encryption and ack keys.
155
152
let mut key_manager = KeyManager :: new ( & mut rng) ;
156
153
157
- let gateway_id = select_gateway ( matches. value_of ( "gateway" ) ) ;
158
- config. get_base_mut ( ) . with_gateway_id ( gateway_id) ;
154
+ let chosen_gateway_id = matches. value_of ( "gateway" ) ;
159
155
160
156
let registration_fut = async {
161
- let gate_details =
162
- gateway_details ( & config. get_base ( ) . get_validator_rest_endpoint ( ) , gateway_id) . await ;
157
+ let gate_details = gateway_details (
158
+ & config. get_base ( ) . get_validator_rest_endpoint ( ) ,
159
+ chosen_gateway_id,
160
+ )
161
+ . await ;
162
+ config
163
+ . get_base_mut ( )
164
+ . with_gateway_id ( gate_details. identity_key . to_base58_string ( ) ) ;
163
165
let shared_keys =
164
166
register_with_gateway ( & gate_details, key_manager. identity_keypair ( ) ) . await ;
165
167
( shared_keys, gate_details. client_listener )
0 commit comments