mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
* move i2p::util::config::GetHost to RouterContext.cpp
This commit is contained in:
parent
b7c5e3b5d5
commit
26be0c7c82
|
@ -51,7 +51,16 @@ namespace i2p
|
|||
port = rand () % (30777 - 9111) + 9111; // I2P network ports range
|
||||
bool ipv4; i2p::config::GetOption("ipv4", ipv4);
|
||||
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.AddNTCPAddress (host.c_str(), port);
|
||||
routerInfo.SetCaps (i2p::data::RouterInfo::eReachable |
|
||||
|
|
27
util.cpp
27
util.cpp
|
@ -7,7 +7,6 @@
|
|||
#include <set>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include "Config.h"
|
||||
#include "util.h"
|
||||
#include "Log.h"
|
||||
|
||||
|
@ -460,31 +459,5 @@ namespace net
|
|||
#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
|
||||
} // i2p
|
||||
|
|
7
util.h
7
util.h
|
@ -68,14 +68,7 @@ namespace util
|
|||
int GetMTU (const boost::asio::ip::address& localAddress);
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue