Skip to content

Commit 3b481ee

Browse files
authored
Merge pull request #325 from nymtech/jon/import-credential-file
Import credential file in vpnd
2 parents d663d6e + 599d440 commit 3b481ee

File tree

3 files changed

+69
-69
lines changed

3 files changed

+69
-69
lines changed

nym-vpnc/src/main.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,13 @@ async fn import_credential(
148148
import_args: &ImportCredentialArgs,
149149
) -> anyhow::Result<()> {
150150
let import_type: ImportCredentialTypeEnum = import_args.credential_type.clone().into();
151-
let request = match import_type {
152-
ImportCredentialTypeEnum::Path(_path) => todo!(),
153-
ImportCredentialTypeEnum::Data(data) => {
154-
let bin = parse_encoded_credential_data(&data)?;
155-
tonic::Request::new(ImportUserCredentialRequest { credential: bin })
156-
}
151+
let raw_credential = match import_type {
152+
ImportCredentialTypeEnum::Path(path) => std::fs::read(path)?,
153+
ImportCredentialTypeEnum::Data(data) => parse_encoded_credential_data(&data)?,
157154
};
158-
155+
let request = tonic::Request::new(ImportUserCredentialRequest {
156+
credential: raw_credential,
157+
});
159158
let mut client = get_client(args).await?;
160159
let response = client.import_user_credential(request).await?.into_inner();
161160
println!("{:?}", response);

nym-vpnd/src/service/vpn_service.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,26 @@ impl NymVpnService {
187187
*self.shared_vpn_state.lock().unwrap() = state;
188188
}
189189

190-
async fn handle_disconnect(&mut self) -> VpnServiceDisconnectResult {
191-
// To handle the mutable borrow we set the state separate from the sending the stop
192-
// message, including the logical check for the ctrl sender twice.
193-
let is_running = self.vpn_ctrl_sender.is_some();
190+
fn is_running(&self) -> bool {
191+
self.vpn_ctrl_sender
192+
.as_ref()
193+
.map(|s| !s.is_closed())
194+
.unwrap_or(false)
195+
}
194196

195-
if is_running {
197+
async fn handle_disconnect(&mut self) -> VpnServiceDisconnectResult {
198+
// To handle the mutable borrow we set the state separate from the sending the stop message
199+
if self.is_running() {
196200
self.set_shared_state(VpnState::Disconnecting);
201+
} else {
202+
return VpnServiceDisconnectResult::NotRunning;
197203
}
198204

199205
if let Some(ref mut vpn_ctrl_sender) = self.vpn_ctrl_sender {
200-
let _ = vpn_ctrl_sender
206+
vpn_ctrl_sender
201207
.send(nym_vpn_lib::NymVpnCtrlMessage::Stop)
202-
.await;
208+
.await
209+
.ok();
203210
VpnServiceDisconnectResult::Success
204211
} else {
205212
VpnServiceDisconnectResult::NotRunning
@@ -220,9 +227,7 @@ impl NymVpnService {
220227
&mut self,
221228
credential: Vec<u8>,
222229
) -> VpnServiceImportUserCredentialResult {
223-
// BUG: this is not correct after a connect/disconnect cycle
224-
let is_running = self.vpn_ctrl_sender.is_some();
225-
if is_running {
230+
if self.is_running() {
226231
return VpnServiceImportUserCredentialResult::Fail(
227232
"Can't import credential while VPN is running".to_string(),
228233
);

proto/nym/vpn.proto

Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ syntax = "proto3";
22

33
package nym.vpn;
44

5-
message Empty {}
6-
7-
message Gateway {
8-
string id = 1;
9-
Location location = 2;
10-
}
11-
12-
message Location {
13-
string two_letter_country_code = 1;
14-
}
15-
16-
message Node {
17-
oneof node {
18-
Location location = 1;
19-
Gateway gateway = 2;
20-
Empty fastest = 3;
21-
}
22-
}
5+
// message Empty {}
6+
7+
// message Gateway {
8+
// string id = 1;
9+
// Location location = 2;
10+
// }
11+
//
12+
// message Location {
13+
// string two_letter_country_code = 1;
14+
// }
15+
//
16+
// message Node {
17+
// oneof node {
18+
// Location location = 1;
19+
// Gateway gateway = 2;
20+
// Empty fastest = 3;
21+
// }
22+
// }
2323

2424
message ConnectRequest {
2525
// Node entry = 1;
@@ -36,12 +36,12 @@ message DisconnectResponse {
3636
bool success = 1;
3737
}
3838

39-
enum VpnMode {
40-
MODE_UNSPECIFIED = 0;
41-
MIXNET_FIVE_HOP = 1;
42-
MIXNET_TWO_HOP = 2;
43-
WIREGUARD_TWO_HOP = 3;
44-
}
39+
// enum VpnMode {
40+
// MODE_UNSPECIFIED = 0;
41+
// MIXNET_FIVE_HOP = 1;
42+
// MIXNET_TWO_HOP = 2;
43+
// WIREGUARD_TWO_HOP = 3;
44+
// }
4545

4646
enum ConnectionStatus {
4747
STATUS_UNSPECIFIED = 0;
@@ -53,48 +53,44 @@ enum ConnectionStatus {
5353
CONNECTION_FAILED = 6;
5454
}
5555

56-
message LocationListResponse {
57-
repeated Location location = 1;
58-
}
59-
60-
message SetVpnModeRequest {
61-
VpnMode mode = 1;
62-
}
63-
64-
message GetVpnModeResponse {
65-
VpnMode mode = 1;
66-
}
67-
68-
message GatewayResponse {
69-
Gateway gateways = 1;
70-
}
56+
// message LocationListResponse {
57+
// repeated Location location = 1;
58+
// }
59+
//
60+
// message SetVpnModeRequest {
61+
// VpnMode mode = 1;
62+
// }
63+
//
64+
// message GetVpnModeResponse {
65+
// VpnMode mode = 1;
66+
// }
67+
//
68+
// message GatewayResponse {
69+
// Gateway gateways = 1;
70+
// }
7171

7272
message StatusRequest {}
7373
message StatusResponse {
7474
ConnectionStatus status = 1;
7575
Error error = 2;
7676
}
7777

78-
message ConnectionStatusUpdate {
79-
ConnectionStatus status = 1;
80-
repeated ConnectionProgress connection_progress = 2;
81-
// optional Error error = 3;
82-
}
83-
84-
message ConnectionProgress {
85-
string message = 1;
86-
}
78+
// message ConnectionStatusUpdate {
79+
// ConnectionStatus status = 1;
80+
// repeated ConnectionProgress connection_progress = 2;
81+
// // optional Error error = 3;
82+
// }
83+
//
84+
// message ConnectionProgress {
85+
// string message = 1;
86+
// }
8787

8888
message Error {
8989
string message = 1;
9090
// ErrorType type = 2; // TOBE implemented
9191
// optional string source = 3;
9292
}
9393

94-
message SetUserCredentialsRequest {
95-
string key = 1;
96-
}
97-
9894
message ImportUserCredentialRequest {
9995
bytes credential = 1;
10096
}

0 commit comments

Comments
 (0)