Skip to content

Commit 5f1831a

Browse files
committed
Accept a full secret address for advanced connection
This should make it a bit easier to test, because you don't need to copy the individual parts of the secret address.
1 parent 7a5f448 commit 5f1831a

2 files changed

Lines changed: 16 additions & 40 deletions

File tree

src/services/node_service.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,14 @@ pub struct SecretAddress {
6262
}
6363

6464
impl SecretAddress {
65-
pub fn from_string(peer_node_id: String, peer_passphrase: String) -> Result<Self> {
66-
if peer_node_id.is_empty() {
67-
bail!("peer_node_id is empty!")
65+
pub fn from_string(peer_secret_address: String) -> Result<Self> {
66+
let parts: Vec<&str> = peer_secret_address.split('#').collect();
67+
if parts.len() != 2 {
68+
bail!("peer_secret_address does not have the format <node_id>#<passphrase>")
6869
}
6970

70-
if peer_passphrase.is_empty() {
71-
bail!("peer_passphrase is empty!")
72-
}
73-
74-
let peer_node_id = NodeId::from_str(&peer_node_id)?;
75-
let peer_passphrase = SecretKey::from_str(&peer_passphrase)?;
71+
let peer_node_id = NodeId::from_str(&parts[0])?;
72+
let peer_passphrase = SecretKey::from_str(&parts[1])?;
7673

7774
Ok(Self {
7875
peer_node_id,
@@ -173,14 +170,8 @@ pub async fn get_secret_address_from_wormhole(code: &str) -> Result<SecretAddres
173170
MailboxConnection::connect(config, Code::from_str(code)?, false).await?;
174171
let mut wormhole = Wormhole::connect(mailbox_connection).await?;
175172
let bytes = wormhole.receive().await?;
176-
let fragments: Vec<String> = String::from_utf8(bytes)?
177-
.clone()
178-
.split("#")
179-
.map(|value| value.to_string())
180-
.collect();
181-
let peer_node_id = fragments[0].to_string();
182-
let peer_passphrase = fragments[1].to_string();
183-
SecretAddress::from_string(peer_node_id, peer_passphrase)
173+
let secret_address = String::from_utf8(bytes)?;
174+
SecretAddress::from_string(secret_address)
184175
}
185176

186177
async fn handle_node_command(

src/ui/connection_form.rs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,14 @@ fn AdvancedForm() -> Element {
2525
rsx! {
2626
fieldset {
2727
label {
28-
for: "peer_node_id",
29-
"peer node id:"
30-
}
31-
32-
input {
33-
id: "peer_node_id",
34-
name: "peer_node_id",
35-
style: "min-width: 40em;"
36-
}
37-
}
38-
39-
fieldset {
40-
label {
41-
for: "peer_passphrase",
42-
"peer passphrase:"
28+
for: "peer_secret_address",
29+
"peer's secret address:"
4330
}
4431

4532
// TODO: should this be type: password?
4633
input {
47-
id: "peer_passphrase",
48-
name: "peer_passphrase",
34+
id: "peer_secret_address",
35+
name: "peer_secret_address",
4936
style: "min-width: 40em;"
5037
}
5138
}
@@ -54,13 +41,12 @@ fn AdvancedForm() -> Element {
5441

5542
#[derive(Default)]
5643
struct SimpleFormData {
57-
join_code: String
44+
join_code: String,
5845
}
5946

6047
#[derive(Default)]
6148
struct AdvancedFormData {
62-
peer_node_id: String,
63-
peer_passphrase: String
49+
peer_secret_address: String,
6450
}
6551

6652
#[component]
@@ -83,9 +69,8 @@ pub fn ConnectionForm() -> Element {
8369
node_service.send(NodeCommand::ConnectByJoinCode { join_code });
8470
}
8571
"advanced" => {
86-
let peer_node_id = advanced_form_data.read().peer_node_id.clone();
87-
let peer_passphrase = advanced_form_data.read().peer_passphrase.clone();
88-
match SecretAddress::from_string(peer_node_id, peer_passphrase) {
72+
let peer_secret_address = advanced_form_data.read().peer_secret_address.clone();
73+
match SecretAddress::from_string(peer_secret_address) {
8974
Ok(secret_address) => node_service.send(NodeCommand::ConnectByAddress {
9075
secret_address: Box::new(secret_address),
9176
}),

0 commit comments

Comments
 (0)