Browse Source

* move i2p::util::config::GetHost to RouterContext.cpp

pull/578/head
hagen 8 years ago
parent
commit
26be0c7c82
  1. 11
      RouterContext.cpp
  2. 27
      util.cpp
  3. 7
      util.h

11
RouterContext.cpp

@ -51,7 +51,16 @@ namespace i2p
port = rand () % (30777 - 9111) + 9111; // I2P network ports range port = rand () % (30777 - 9111) + 9111; // I2P network ports range
bool ipv4; i2p::config::GetOption("ipv4", ipv4); bool ipv4; i2p::config::GetOption("ipv4", ipv4);
bool ipv6; i2p::config::GetOption("ipv6", ipv6); bool ipv6; i2p::config::GetOption("ipv6", ipv6);
std::string host = i2p::util::config::GetHost(ipv4, ipv6); bool nat; i2p::config::GetOption("nat", nat);
std::string ifname; i2p::config::GetOption("ifname", ifname);
std::string host = ipv6 ? "::" : "127.0.0.1";
if (nat) {
if (!i2p::config::IsDefault("host"))
i2p::config::GetOption("host", host);
} else if (!ifname.empty()) {
/* bind to interface, we have no NAT so set external address too */
host = i2p::util::net::GetInterfaceAddress(ifname, ipv6).to_string();
}
routerInfo.AddSSUAddress (host.c_str(), port, routerInfo.GetIdentHash ()); routerInfo.AddSSUAddress (host.c_str(), port, routerInfo.GetIdentHash ());
routerInfo.AddNTCPAddress (host.c_str(), port); routerInfo.AddNTCPAddress (host.c_str(), port);
routerInfo.SetCaps (i2p::data::RouterInfo::eReachable | routerInfo.SetCaps (i2p::data::RouterInfo::eReachable |

27
util.cpp

@ -7,7 +7,6 @@
#include <set> #include <set>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include "Config.h"
#include "util.h" #include "util.h"
#include "Log.h" #include "Log.h"
@ -460,31 +459,5 @@ namespace net
#endif #endif
} }
} }
namespace config
{
std::string GetHost(bool ipv4, bool ipv6)
{
std::string host;
if(ipv6)
host = "::";
else if(ipv4)
host = "127.0.0.1";
bool nat; i2p::config::GetOption("nat", nat);
if (nat)
{
if (!i2p::config::IsDefault("host"))
i2p::config::GetOption("host", host);
}
else
{
// we are not behind nat
std::string ifname; i2p::config::GetOption("ifname", ifname);
if (ifname.size())
host = i2p::util::net::GetInterfaceAddress(ifname, ipv6).to_string(); // bind to interface, we have no NAT so set external address too
}
return host;
}
} // config
} // util } // util
} // i2p } // i2p

7
util.h

@ -68,14 +68,7 @@ namespace util
int GetMTU (const boost::asio::ip::address& localAddress); int GetMTU (const boost::asio::ip::address& localAddress);
const boost::asio::ip::address GetInterfaceAddress(const std::string & ifname, bool ipv6=false); const boost::asio::ip::address GetInterfaceAddress(const std::string & ifname, bool ipv6=false);
} }
namespace config
{
/** get the host to use from out config, for use in RouterContext.cpp */
std::string GetHost(bool ipv4=true, bool ipv6=true);
}
} }
} }
#endif #endif

Loading…
Cancel
Save