Skip to content
Snippets Groups Projects
Commit 6fed3aab authored by Éloïs's avatar Éloïs
Browse files

[fix] network-docs: parse endpoint v1 with ip

parent 22599cb4
No related branches found
No related tags found
1 merge request!217Elois/fix
...@@ -25,11 +25,12 @@ ed25519_sig = @{ base64{88} | (base64{87} ~ "=") | (base64{86} ~ "==") } ...@@ -25,11 +25,12 @@ ed25519_sig = @{ base64{88} | (base64{87} ~ "=") | (base64{86} ~ "==") }
// Endpoint v1 rules // Endpoint v1 rules
api_name = @{ (ASCII_ALPHA_UPPER | ASCII_DIGIT | "_")+ } api_name = @{ (ASCII_ALPHA_UPPER | ASCII_DIGIT | "_")+ }
node_id = @{ hexa_lower{1,8} } node_id = @{ hexa_lower{1,8} }
host = @{ ASCII_ALPHA_LOWER ~ (alphanum_lower | "-" | "_" | ".")* } host = _{ host_inner ~ " " }
host_inner = @{ ASCII_ALPHA_LOWER ~ (alphanum_lower | "-" | "_" | ".")* }
port = @{ u_int } port = @{ u_int }
path_inner = @{ (ASCII_ALPHANUMERIC | "-" | "_" | ".")+ } path_inner = @{ (ASCII_ALPHANUMERIC | "-" | "_" | ".")+ }
endpoint_v1 = ${ api_name ~ (" " ~ node_id)? ~ " " ~ (ip4 | ip6 | host) ~ " " ~ port ~ (" " ~ "/"? ~ path_inner)? ~ " "? } endpoint_v1 = ${ api_name ~ (" " ~ node_id)? ~ " " ~ (ip4 | ip6 | host) ~ port ~ (" " ~ "/"? ~ path_inner)? ~ " "? }
// IP v6 rules // IP v6 rules
ip6_seg = _{ hexa_lower{1,4} } ip6_seg = _{ hexa_lower{1,4} }
......
...@@ -175,7 +175,9 @@ impl EndpointV1 { ...@@ -175,7 +175,9 @@ impl EndpointV1 {
None => None, None => None,
}; };
} }
Rule::host => host_str = ep_pair.as_str(), Rule::host_inner => host_str = ep_pair.as_str(),
Rule::ip4_inner => host_str = ep_pair.as_str(),
Rule::ip6_inner => host_str = ep_pair.as_str(),
Rule::port => port = ep_pair.as_str().parse().unwrap(), Rule::port => port = ep_pair.as_str().parse().unwrap(),
Rule::path_inner => path = Some(String::from(ep_pair.as_str())), Rule::path_inner => path = Some(String::from(ep_pair.as_str())),
_ => fatal_error!("unexpected rule: {:?}", ep_pair.as_rule()), // Grammar ensures that we never reach this line _ => fatal_error!("unexpected rule: {:?}", ep_pair.as_rule()), // Grammar ensures that we never reach this line
...@@ -561,6 +563,38 @@ mod tests { ...@@ -561,6 +563,38 @@ mod tests {
use super::*; use super::*;
use bincode::{deserialize, serialize}; use bincode::{deserialize, serialize};
use maplit::hashset; use maplit::hashset;
use unwrap::unwrap;
#[test]
fn test_parse_endpoint_v1_with_ip() -> Result<(), TextDocumentParseError> {
let issuer = PubKey::Ed25519(unwrap!(ed25519::PublicKey::from_base58(
"8iVdpXqFLCxGyPqgVx5YbFSkmWKkceXveRd2yvBKeARL",
)));
let parser_ep_v1 =
EndpointV1::parse_from_raw("WS2P e66254bf 91.121.157.13 20901", issuer, 0, 0)?;
assert_eq!(
EndpointV1 {
api: ApiName(String::from("WS2P")),
node_id: Some(NodeId::from("e66254bf")),
issuer,
hash_full_id: Some(
Hash::from_hex(
"B56286E3A423B1BD4A116F0358795870A4136C97CEE955F144C84C6EE27B8BFB"
)
.expect("wrong hard hash")
),
host: String::from("91.121.157.13"),
port: 20901,
path: None,
raw_endpoint: String::from("WS2P e66254bf 91.121.157.13 20901"),
status: 0,
last_check: 0,
},
parser_ep_v1
);
Ok(())
}
#[inline] #[inline]
fn api_part_1() -> ApiPart { fn api_part_1() -> ApiPart {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment