From a92652f4ad4722fb249bf24c45d70a9a0b391694 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 24 Nov 2016 10:11:46 -0500 Subject: [PATCH] add ifname4 and ifname6 options --- Config.cpp | 6 ++++-- RouterContext.cpp | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Config.cpp b/Config.cpp index d8dd6a27..6f4014ba 100644 --- a/Config.cpp +++ b/Config.cpp @@ -41,6 +41,8 @@ namespace config { ("datadir", value()->default_value(""), "Path to storage of i2pd data (RI, keys, peer profiles, ...)") ("host", value()->default_value("0.0.0.0"), "External IP") ("ifname", value()->default_value(""), "Network interface to bind to") + ("ifname4", value()->default_value(""), "Network interface to bind to for ipv4") + ("ifname6", value()->default_value(""), "Network interface to bind to for ipv6") ("nat", value()->zero_tokens()->default_value(true), "Should we assume we are behind NAT?") ("port", value()->default_value(0), "Port to listen for incoming connections (default: auto)") ("ipv4", value()->zero_tokens()->default_value(true), "Enable communication through ipv4") @@ -59,7 +61,7 @@ namespace config { ("close", value()->default_value("ask"), "Action on close: minimize, exit, ask") // TODO: add custom validator or something #endif ; - + options_description limits("Limits options"); limits.add_options() ("limits.coresize", value()->default_value(0), "Maximum size of corefile in Kb (0 - use system limit)") @@ -192,7 +194,7 @@ namespace config { ("trust.family", value()->default_value(""), "Router Familiy to trust for first hops") ("trust.routers", value()->default_value(""), "Only Connect to these routers") ("trust.hidden", value()->default_value(false), "Should we hide our router from other routers?"); - + options_description websocket("Websocket Options"); websocket.add_options() ("websockets.enabled", value()->default_value(false), "enable websocket server") diff --git a/RouterContext.cpp b/RouterContext.cpp index 7847bef7..c1341a62 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -74,6 +74,22 @@ namespace i2p routerInfo.AddSSUAddress (host.c_str(), port, routerInfo.GetIdentHash ()); routerInfo.AddNTCPAddress (host.c_str(), port); } + + std::string ifname4; i2p::config::GetOption("ifname4", ifname4); + if(ifname4.size()) + { + std::string host = i2p::util::net::GetInterfaceAddress(ifname4, false).to_string(); + routerInfo.AddSSUAddress (host.c_str(), port, routerInfo.GetIdentHash()); + routerInfo.AddNTCPAddress (host.c_str(), port); + } + std::string ifname6; i2p::config::GetOption("ifname6", ifname6); + if (ifname6.size()) + { + std::string host = i2p::util::net::GetInterfaceAddress(ifname6, true).to_string(); + routerInfo.AddSSUAddress (host.c_str(), port, routerInfo.GetIdentHash()); + routerInfo.AddNTCPAddress (host.c_str(), port); + } + routerInfo.SetCaps (i2p::data::RouterInfo::eReachable | i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC routerInfo.SetProperty ("netId", std::to_string (m_NetID));