Skip to content

Commit 72aad2c

Browse files
authored
Merge pull request #212 from f3r10/do_not_require_https_in_address
simln-lib/feat: Parse address detecting if starts with https
2 parents aef31ae + 6b3fe6a commit 72aad2c

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ information is required:
6363
```
6464
{
6565
"id": <node_id>,
66-
"address": https://<ip:port or domain:port>,
66+
"address": <ip:port or domain:port>,
6767
"macaroon": <path_to_selected_macaroon>,
6868
"cert": <path_to_tls_cert>
6969
}
@@ -74,14 +74,13 @@ Whereas for CLN nodes, the following information is required:
7474
```
7575
{
7676
"id": <node_id>,
77-
"address": https://<ip:port or domain:port>,
77+
"address": <ip:port or domain:port>,
7878
"ca_cert": <path_to_ca_cert>,
7979
"client_cert": <path_to_client_cert>,
8080
"client_key": <path_to_client_key>
8181
}
8282
```
8383

84-
**Note that node addresses must be declare with HTTPS transport, i.e. <https://ip-or-domain:port>**
8584

8685
Payment activity can be simulated in two different ways:
8786
* Random activity: generate random activity on the `nodes` provided,
@@ -102,13 +101,13 @@ not "drain" from the simulation.
102101
"nodes": [
103102
{
104103
"id": "Alice",
105-
"address": "https://127.0.0.1:10011",
104+
"address": "127.0.0.1:10011",
106105
"macaroon": "/path/admin.macaroon",
107106
"cert": "/path/tls.cert"
108107
},
109108
{
110109
"id": "0230a16a05c5ca120136b3a770a2adfdad88a68d526e63448a9eef88bddd6a30d8",
111-
"address": "https://localhost:10013",
110+
"address": "localhost:10013",
112111
"ca_cert": "/path/ca.pem",
113112
"client_cert": "/path/client.pem",
114113
"client_key": "/path/client-key.pem"
@@ -177,26 +176,26 @@ The example simulation file below sets up the following simulation:
177176
"nodes": [
178177
{
179178
"id": "Alice",
180-
"address": "https://localhost:10011",
179+
"address": "localhost:10011",
181180
"macaroon": "/path/admin.macaroon",
182181
"cert": "/path/tls.cert"
183182
},
184183
{
185184
"id": "0230a16a05c5ca120136b3a770a2adfdad88a68d526e63448a9eef88bddd6a30d8",
186-
"address": "https://127.0.0.1:10013",
185+
"address": "127.0.0.1:10013",
187186
"ca_cert": "/path/ca.pem",
188187
"client_cert": "/path/client.pem",
189188
"client_key": "/path/client-key.pem"
190189
},
191190
{
192191
"id": "Erin",
193-
"address": "https://localhost:10012",
192+
"address": "localhost:10012",
194193
"macaroon": "/path/admin.macaroon",
195194
"cert": "/path/tls.cert"
196195
},
197196
{
198197
"id": "Frank",
199-
"address": "https://localhost:10014",
198+
"address": "localhost:10014",
200199
"macaroon": "/path/admin.macaroon",
201200
"cert": "/path/tls.cert"
202201
}
@@ -232,7 +231,6 @@ The example simulation file below sets up the following simulation:
232231
}
233232
```
234233

235-
**Note that node addresses must be declare with HTTPS transport, i.e <https://ip-or-domain>**
236234

237235
Nodes can be identified by their public key or an id string (as
238236
described above). Activity sources and destinations may reference the

simln-lib/src/cln.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::{
2424
pub struct ClnConnection {
2525
#[serde(with = "serializers::serde_node_id")]
2626
pub id: NodeId,
27+
#[serde(with = "serializers::serde_address")]
2728
pub address: String,
2829
#[serde(deserialize_with = "serializers::deserialize_path")]
2930
pub ca_cert: String,
@@ -57,7 +58,7 @@ impl ClnNode {
5758
));
5859

5960
let mut client = NodeClient::new(
60-
Channel::from_shared(connection.address.to_string())
61+
Channel::from_shared(connection.address)
6162
.map_err(|err| LightningError::ConnectionError(err.to_string()))?
6263
.tls_config(tls)
6364
.map_err(|_| {

simln-lib/src/lnd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const SEND_PAYMENT_TIMEOUT_SECS: i32 = 300;
2626
pub struct LndConnection {
2727
#[serde(with = "serializers::serde_node_id")]
2828
pub id: NodeId,
29+
#[serde(with = "serializers::serde_address")]
2930
pub address: String,
3031
#[serde(deserialize_with = "serializers::deserialize_path")]
3132
pub macaroon: String,

simln-lib/src/serializers.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,29 @@ pub mod serde_node_id {
4545
}
4646
}
4747

48+
pub mod serde_address {
49+
use super::*;
50+
51+
pub fn serialize<S>(address: &str, serializer: S) -> Result<S::Ok, S::Error>
52+
where
53+
S: serde::Serializer,
54+
{
55+
serializer.serialize_str(address)
56+
}
57+
58+
pub fn deserialize<'de, D>(deserializer: D) -> Result<String, D::Error>
59+
where
60+
D: serde::Deserializer<'de>,
61+
{
62+
let s = String::deserialize(deserializer)?;
63+
if s.starts_with("https://") {
64+
Ok(s)
65+
} else {
66+
Ok(format!("https://{}", s))
67+
}
68+
}
69+
}
70+
4871
pub mod serde_value_or_range {
4972
use super::*;
5073
use serde::{de::Error, ser::SerializeTuple};

0 commit comments

Comments
 (0)