From 28ebfe9fe3c3272adbd0ea9249889b3642869bcc Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Thu, 26 Nov 2020 01:02:36 +0100 Subject: [PATCH] [fix] gva: listen on specified ipv4 & ipv6 --- app/lib/dto/ConfDTO.ts | 3 ++- neon/native/server.d.ts | 3 ++- rust-libs/duniter-conf/src/gva_conf.rs | 18 ++++++++++++------ rust-libs/modules/duniter-gva/src/lib.rs | 20 +++++++++++++++++--- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/app/lib/dto/ConfDTO.ts b/app/lib/dto/ConfDTO.ts index 69325df7b..85743afa9 100644 --- a/app/lib/dto/ConfDTO.ts +++ b/app/lib/dto/ConfDTO.ts @@ -182,7 +182,8 @@ export class ConfDTO public proxiesConf: ProxiesConf | undefined, public gva?: { enabled: boolean; - host?: string; + ip4?: string; + ip6?: string; port?: number; path?: string; subscriptionsPath?: string; diff --git a/neon/native/server.d.ts b/neon/native/server.d.ts index 4f001ec48..d7d5c1ac8 100644 --- a/neon/native/server.d.ts +++ b/neon/native/server.d.ts @@ -11,7 +11,8 @@ export class RustServerConf { } export class GvaConf { - host?: string + ip4?: string + ip6?: string port?: number path?: string; subscriptionsPath?: string; diff --git a/rust-libs/duniter-conf/src/gva_conf.rs b/rust-libs/duniter-conf/src/gva_conf.rs index 4d83d3119..bad62480b 100644 --- a/rust-libs/duniter-conf/src/gva_conf.rs +++ b/rust-libs/duniter-conf/src/gva_conf.rs @@ -13,12 +13,15 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. +use std::net::{Ipv4Addr, Ipv6Addr}; + use crate::*; #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct GvaConf { - host: Option<String>, + ip4: Option<Ipv4Addr>, + ip6: Option<Ipv6Addr>, port: Option<u16>, path: Option<String>, subscriptions_path: Option<String>, @@ -30,10 +33,11 @@ pub struct GvaConf { } impl GvaConf { - pub fn get_host(&self) -> String { - self.host - .to_owned() - .unwrap_or_else(|| "localhost".to_owned()) + pub fn get_ip4(&self) -> Ipv4Addr { + self.ip4.unwrap_or(Ipv4Addr::LOCALHOST) + } + pub fn get_ip6(&self) -> Option<Ipv6Addr> { + self.ip6 } pub fn get_port(&self) -> u16 { self.port.unwrap_or(30901) @@ -65,8 +69,10 @@ impl GvaConf { pub fn get_remote_host(&self) -> String { if let Some(ref remote_host) = self.remote_host { remote_host.to_owned() + } else if let Some(ip6) = self.ip6 { + format!("{} [{}]", self.get_ip4(), ip6) } else { - self.get_host() + self.get_ip4().to_string() } } pub fn get_remote_port(&self) -> u16 { diff --git a/rust-libs/modules/duniter-gva/src/lib.rs b/rust-libs/modules/duniter-gva/src/lib.rs index 461057bdd..51ddaae30 100644 --- a/rust-libs/modules/duniter-gva/src/lib.rs +++ b/rust-libs/modules/duniter-gva/src/lib.rs @@ -212,13 +212,27 @@ impl GvaModule { log::info!( "GVA server listen on http://{}:{}/{}", - &conf.get_host(), + conf.get_ip4(), conf.get_port(), &conf.get_path() ); - warp::serve(routes) - .run(([0, 0, 0, 0], conf.get_port())) + if let Some(ip6) = conf.get_ip6() { + log::info!( + "GVA server listen on http://{}:{}/{}", + ip6, + conf.get_port(), + &conf.get_path() + ); + futures::future::join( + warp::serve(routes.clone()).run((conf.get_ip4(), conf.get_port())), + warp::serve(routes).run((ip6, conf.get_port())), + ) .await; + } else { + warp::serve(routes) + .run((conf.get_ip4(), conf.get_port())) + .await; + } log::warn!("GVA server stopped"); } } -- GitLab