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

[fix] gva: listen on specified ipv4 & ipv6

parent 77ded9e8
No related branches found
No related tags found
1 merge request!1335Gva proto 2
...@@ -182,7 +182,8 @@ export class ConfDTO ...@@ -182,7 +182,8 @@ export class ConfDTO
public proxiesConf: ProxiesConf | undefined, public proxiesConf: ProxiesConf | undefined,
public gva?: { public gva?: {
enabled: boolean; enabled: boolean;
host?: string; ip4?: string;
ip6?: string;
port?: number; port?: number;
path?: string; path?: string;
subscriptionsPath?: string; subscriptionsPath?: string;
......
...@@ -11,7 +11,8 @@ export class RustServerConf { ...@@ -11,7 +11,8 @@ export class RustServerConf {
} }
export class GvaConf { export class GvaConf {
host?: string ip4?: string
ip6?: string
port?: number port?: number
path?: string; path?: string;
subscriptionsPath?: string; subscriptionsPath?: string;
......
...@@ -13,12 +13,15 @@ ...@@ -13,12 +13,15 @@
// You should have received a copy of the GNU Affero General Public License // 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/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use std::net::{Ipv4Addr, Ipv6Addr};
use crate::*; use crate::*;
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct GvaConf { pub struct GvaConf {
host: Option<String>, ip4: Option<Ipv4Addr>,
ip6: Option<Ipv6Addr>,
port: Option<u16>, port: Option<u16>,
path: Option<String>, path: Option<String>,
subscriptions_path: Option<String>, subscriptions_path: Option<String>,
...@@ -30,10 +33,11 @@ pub struct GvaConf { ...@@ -30,10 +33,11 @@ pub struct GvaConf {
} }
impl GvaConf { impl GvaConf {
pub fn get_host(&self) -> String { pub fn get_ip4(&self) -> Ipv4Addr {
self.host self.ip4.unwrap_or(Ipv4Addr::LOCALHOST)
.to_owned() }
.unwrap_or_else(|| "localhost".to_owned()) pub fn get_ip6(&self) -> Option<Ipv6Addr> {
self.ip6
} }
pub fn get_port(&self) -> u16 { pub fn get_port(&self) -> u16 {
self.port.unwrap_or(30901) self.port.unwrap_or(30901)
...@@ -65,8 +69,10 @@ impl GvaConf { ...@@ -65,8 +69,10 @@ impl GvaConf {
pub fn get_remote_host(&self) -> String { pub fn get_remote_host(&self) -> String {
if let Some(ref remote_host) = self.remote_host { if let Some(ref remote_host) = self.remote_host {
remote_host.to_owned() remote_host.to_owned()
} else if let Some(ip6) = self.ip6 {
format!("{} [{}]", self.get_ip4(), ip6)
} else { } else {
self.get_host() self.get_ip4().to_string()
} }
} }
pub fn get_remote_port(&self) -> u16 { pub fn get_remote_port(&self) -> u16 {
......
...@@ -212,13 +212,27 @@ impl GvaModule { ...@@ -212,13 +212,27 @@ impl GvaModule {
log::info!( log::info!(
"GVA server listen on http://{}:{}/{}", "GVA server listen on http://{}:{}/{}",
&conf.get_host(), conf.get_ip4(),
conf.get_port(), conf.get_port(),
&conf.get_path() &conf.get_path()
); );
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) warp::serve(routes)
.run(([0, 0, 0, 0], conf.get_port())) .run((conf.get_ip4(), conf.get_port()))
.await; .await;
}
log::warn!("GVA server stopped"); log::warn!("GVA server stopped");
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment