From f66e907758fbe58b93776f8b9d1779cf725d5c75 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Sat, 23 Mar 2024 17:04:16 +0200 Subject: [PATCH] added private_core option on listener --- ng-sdk-js/src/lib.rs | 20 ++++++++++---------- ngd/src/main.rs | 1 + p2p-net/src/types.rs | 9 ++++++++- p2p-net/src/utils.rs | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/ng-sdk-js/src/lib.rs b/ng-sdk-js/src/lib.rs index 249a805..7d15a29 100644 --- a/ng-sdk-js/src/lib.rs +++ b/ng-sdk-js/src/lib.rs @@ -57,8 +57,8 @@ pub async fn get_local_bootstrap(location: String, invite: JsValue) -> JsValue { #[cfg(target_arch = "wasm32")] #[wasm_bindgen] -pub async fn decode_invitation(invite: String) -> JsValue { - let res = decode_invitation_string(invite); +pub async fn get_local_bootstrap_with_public(location: String, invite: JsValue) -> JsValue { + let res = retrieve_local_bootstrap(location, invite.as_string(), true).await; if res.is_some() { serde_wasm_bindgen::to_value(&res.unwrap()).unwrap() } else { @@ -68,8 +68,8 @@ pub async fn decode_invitation(invite: String) -> JsValue { #[cfg(target_arch = "wasm32")] #[wasm_bindgen] -pub async fn get_local_url(location: String) -> JsValue { - let res = retrieve_local_url(location).await; +pub async fn decode_invitation(invite: String) -> JsValue { + let res = decode_invitation_string(invite); if res.is_some() { serde_wasm_bindgen::to_value(&res.unwrap()).unwrap() } else { @@ -79,10 +79,10 @@ pub async fn get_local_url(location: String) -> JsValue { #[cfg(target_arch = "wasm32")] #[wasm_bindgen] -pub async fn get_ngone_url_of_invitation(invitation_string: String) -> JsValue { - let res = decode_invitation_string(invitation_string); +pub async fn get_local_url(location: String) -> JsValue { + let res = retrieve_local_url(location).await; if res.is_some() { - serde_wasm_bindgen::to_value(&res.unwrap().get_urls()[0]).unwrap() + serde_wasm_bindgen::to_value(&res.unwrap()).unwrap() } else { JsValue::FALSE } @@ -90,10 +90,10 @@ pub async fn get_ngone_url_of_invitation(invitation_string: String) -> JsValue { #[cfg(target_arch = "wasm32")] #[wasm_bindgen] -pub async fn get_local_bootstrap_with_public(location: String, invite: JsValue) -> JsValue { - let res = retrieve_local_bootstrap(location, invite.as_string(), true).await; +pub async fn get_ngone_url_of_invitation(invitation_string: String) -> JsValue { + let res = decode_invitation_string(invitation_string); if res.is_some() { - serde_wasm_bindgen::to_value(&res.unwrap()).unwrap() + serde_wasm_bindgen::to_value(&res.unwrap().get_urls()[0]).unwrap() } else { JsValue::FALSE } diff --git a/ngd/src/main.rs b/ngd/src/main.rs index 9f85472..9cc4340 100644 --- a/ngd/src/main.rs +++ b/ngd/src/main.rs @@ -688,6 +688,7 @@ async fn main_inner() -> Result<(), ()> { ipv6: public_part.0.is_some(), interface_refresh: 0, port: private_part.1, + private_core: false, discoverable: false, refuse_clients: args.public_without_clients, serve_app: false, diff --git a/p2p-net/src/types.rs b/p2p-net/src/types.rs index 1acf676..704fc31 100644 --- a/p2p-net/src/types.rs +++ b/p2p-net/src/types.rs @@ -951,6 +951,9 @@ pub struct ListenerV0 { /// local port to listen on pub port: u16, + /// force a private or localhost interface to be accepted as a core interface + pub private_core: bool, + /// should the server serve the app files in HTTP mode (not WS). this setting will be discarded and app will not be served anyway if remote IP is public or listener is public pub serve_app: bool, @@ -998,6 +1001,7 @@ impl ListenerV0 { interface_refresh: 0, ipv6, port, + private_core: false, discoverable: false, accept_direct: true, refuse_clients: false, @@ -1013,7 +1017,10 @@ impl ListenerV0 { AcceptForwardForV0::PublicDyn(_) => true, AcceptForwardForV0::PublicDomain(_) | AcceptForwardForV0::PublicDomainPeer(_) => false, AcceptForwardForV0::PrivateDomain(_) => false, - AcceptForwardForV0::No => self.if_type == InterfaceType::Public, + AcceptForwardForV0::No => { + self.if_type == InterfaceType::Public + || (self.private_core && self.if_type != InterfaceType::Invalid) + } } } diff --git a/p2p-net/src/utils.rs b/p2p-net/src/utils.rs index b328b40..be37499 100644 --- a/p2p-net/src/utils.rs +++ b/p2p-net/src/utils.rs @@ -276,7 +276,7 @@ pub fn get_domain_without_port_443(domain: &str) -> &str { } pub fn is_public_ipv4(ip: &Ipv4Addr) -> bool { - // TODO, use core::net::Ipv6Addr.is_global when it will be stable + // TODO, use core::net::Ipv4Addr.is_global when it will be stable return is_ipv4_global(ip); }