mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-10-31 09:20:38 +00:00
fix meshnet mode:
* don't default to ipv4 when creating router.info * add i2p::util::config::GetHost for getting host to use from config * proper check for no transports in Transports.cpp on startup
This commit is contained in:
parent
562f320198
commit
3ad196c4c7
44
Daemon.cpp
44
Daemon.cpp
@ -124,47 +124,16 @@ namespace i2p
|
||||
ipv4 = false;
|
||||
ipv6 = true;
|
||||
#endif
|
||||
|
||||
i2p::context.SetSupportsV6 (ipv6);
|
||||
i2p::context.SetSupportsV4 (ipv4);
|
||||
|
||||
bool nat; i2p::config::GetOption("nat", nat);
|
||||
if (nat)
|
||||
{
|
||||
LogPrint(eLogInfo, "Daemon: assuming be are behind NAT");
|
||||
// we are behind nat, try setting via host
|
||||
std::string host; i2p::config::GetOption("host", host);
|
||||
if (!i2p::config::IsDefault("host"))
|
||||
{
|
||||
LogPrint(eLogInfo, "Daemon: setting address for incoming connections to ", host);
|
||||
i2p::context.UpdateAddress (boost::asio::ip::address::from_string (host));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// we are not behind nat
|
||||
std::string ifname; i2p::config::GetOption("ifname", ifname);
|
||||
if (ifname.size())
|
||||
{
|
||||
// bind to interface, we have no NAT so set external address too
|
||||
auto addr = i2p::util::net::GetInterfaceAddress(ifname, ipv6);
|
||||
LogPrint(eLogInfo, "Daemon: bind to network interface ", ifname, " with public address ", addr);
|
||||
i2p::context.UpdateAddress(addr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint16_t port; i2p::config::GetOption("port", port);
|
||||
if (!i2p::config::IsDefault("port"))
|
||||
{
|
||||
{
|
||||
LogPrint(eLogInfo, "Daemon: accepting incoming connections at port ", port);
|
||||
i2p::context.UpdatePort (port);
|
||||
}
|
||||
|
||||
|
||||
bool transit; i2p::config::GetOption("notransit", transit);
|
||||
}
|
||||
i2p::context.SetSupportsV6 (ipv6);
|
||||
i2p::context.SetSupportsV4 (ipv4);
|
||||
|
||||
bool transit; i2p::config::GetOption("notransit", transit);
|
||||
i2p::context.SetAcceptsTunnels (!transit);
|
||||
uint16_t transitTunnels; i2p::config::GetOption("limits.transittunnels", transitTunnels);
|
||||
SetMaxNumTransitTunnels (transitTunnels);
|
||||
@ -252,14 +221,15 @@ namespace i2p
|
||||
bool ntcp; i2p::config::GetOption("ntcp", ntcp);
|
||||
bool ssu; i2p::config::GetOption("ssu", ssu);
|
||||
LogPrint(eLogInfo, "Daemon: starting Transports");
|
||||
if(!ssu) LogPrint(eLogDebug, "Daemon: ssu disabled");
|
||||
if(!ntcp) LogPrint(eLogDebug, "Daemon: ntcp disabled");
|
||||
if(!ssu) LogPrint(eLogInfo, "Daemon: ssu disabled");
|
||||
if(!ntcp) LogPrint(eLogInfo, "Daemon: ntcp disabled");
|
||||
i2p::transport::transports.Start(ntcp, ssu);
|
||||
if (i2p::transport::transports.IsBoundNTCP() || i2p::transport::transports.IsBoundSSU()) {
|
||||
LogPrint(eLogInfo, "Daemon: Transports started");
|
||||
} else {
|
||||
LogPrint(eLogError, "Daemon: failed to start Transports");
|
||||
/** shut down netdb right away */
|
||||
i2p::transport::transports.Stop();
|
||||
i2p::data::netdb.Stop();
|
||||
return false;
|
||||
}
|
||||
|
@ -49,9 +49,7 @@ namespace i2p
|
||||
uint16_t port; i2p::config::GetOption("port", port);
|
||||
if (!port)
|
||||
port = rand () % (30777 - 9111) + 9111; // I2P network ports range
|
||||
std::string host; i2p::config::GetOption("host", host);
|
||||
if (i2p::config::IsDefault("host"))
|
||||
host = "127.0.0.1"; // replace default address with safe value
|
||||
std::string host = i2p::util::config::GetHost();
|
||||
routerInfo.AddSSUAddress (host.c_str(), port, routerInfo.GetIdentHash ());
|
||||
routerInfo.AddNTCPAddress (host.c_str(), port);
|
||||
routerInfo.SetCaps (i2p::data::RouterInfo::eReachable |
|
||||
|
@ -114,7 +114,7 @@ namespace transport
|
||||
auto& addresses = context.GetRouterInfo ().GetAddresses ();
|
||||
for (auto address : addresses)
|
||||
{
|
||||
if (!m_NTCPServer && enableNTCP)
|
||||
if (m_NTCPServer == nullptr && enableNTCP)
|
||||
{
|
||||
m_NTCPServer = new NTCPServer ();
|
||||
m_NTCPServer->Start ();
|
||||
@ -129,7 +129,7 @@ namespace transport
|
||||
|
||||
if (address->transportStyle == RouterInfo::eTransportSSU)
|
||||
{
|
||||
if (!m_SSUServer && enableSSU)
|
||||
if (m_SSUServer == nullptr && enableSSU)
|
||||
{
|
||||
if (address->host.is_v4())
|
||||
m_SSUServer = new SSUServer (address->port);
|
||||
|
25
util.cpp
25
util.cpp
@ -461,5 +461,30 @@ namespace net
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
6
util.h
6
util.h
@ -68,6 +68,12 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user