mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 15:14:14 +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;
|
ipv4 = false;
|
||||||
ipv6 = true;
|
ipv6 = true;
|
||||||
#endif
|
#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);
|
uint16_t port; i2p::config::GetOption("port", port);
|
||||||
if (!i2p::config::IsDefault("port"))
|
if (!i2p::config::IsDefault("port"))
|
||||||
{
|
{
|
||||||
LogPrint(eLogInfo, "Daemon: accepting incoming connections at port ", port);
|
LogPrint(eLogInfo, "Daemon: accepting incoming connections at port ", port);
|
||||||
i2p::context.UpdatePort (port);
|
i2p::context.UpdatePort (port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool transit; i2p::config::GetOption("notransit", transit);
|
|
||||||
i2p::context.SetSupportsV6 (ipv6);
|
i2p::context.SetSupportsV6 (ipv6);
|
||||||
i2p::context.SetSupportsV4 (ipv4);
|
i2p::context.SetSupportsV4 (ipv4);
|
||||||
|
|
||||||
|
bool transit; i2p::config::GetOption("notransit", transit);
|
||||||
i2p::context.SetAcceptsTunnels (!transit);
|
i2p::context.SetAcceptsTunnels (!transit);
|
||||||
uint16_t transitTunnels; i2p::config::GetOption("limits.transittunnels", transitTunnels);
|
uint16_t transitTunnels; i2p::config::GetOption("limits.transittunnels", transitTunnels);
|
||||||
SetMaxNumTransitTunnels (transitTunnels);
|
SetMaxNumTransitTunnels (transitTunnels);
|
||||||
@ -252,14 +221,15 @@ namespace i2p
|
|||||||
bool ntcp; i2p::config::GetOption("ntcp", ntcp);
|
bool ntcp; i2p::config::GetOption("ntcp", ntcp);
|
||||||
bool ssu; i2p::config::GetOption("ssu", ssu);
|
bool ssu; i2p::config::GetOption("ssu", ssu);
|
||||||
LogPrint(eLogInfo, "Daemon: starting Transports");
|
LogPrint(eLogInfo, "Daemon: starting Transports");
|
||||||
if(!ssu) LogPrint(eLogDebug, "Daemon: ssu disabled");
|
if(!ssu) LogPrint(eLogInfo, "Daemon: ssu disabled");
|
||||||
if(!ntcp) LogPrint(eLogDebug, "Daemon: ntcp disabled");
|
if(!ntcp) LogPrint(eLogInfo, "Daemon: ntcp disabled");
|
||||||
i2p::transport::transports.Start(ntcp, ssu);
|
i2p::transport::transports.Start(ntcp, ssu);
|
||||||
if (i2p::transport::transports.IsBoundNTCP() || i2p::transport::transports.IsBoundSSU()) {
|
if (i2p::transport::transports.IsBoundNTCP() || i2p::transport::transports.IsBoundSSU()) {
|
||||||
LogPrint(eLogInfo, "Daemon: Transports started");
|
LogPrint(eLogInfo, "Daemon: Transports started");
|
||||||
} else {
|
} else {
|
||||||
LogPrint(eLogError, "Daemon: failed to start Transports");
|
LogPrint(eLogError, "Daemon: failed to start Transports");
|
||||||
/** shut down netdb right away */
|
/** shut down netdb right away */
|
||||||
|
i2p::transport::transports.Stop();
|
||||||
i2p::data::netdb.Stop();
|
i2p::data::netdb.Stop();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -49,9 +49,7 @@ namespace i2p
|
|||||||
uint16_t port; i2p::config::GetOption("port", port);
|
uint16_t port; i2p::config::GetOption("port", port);
|
||||||
if (!port)
|
if (!port)
|
||||||
port = rand () % (30777 - 9111) + 9111; // I2P network ports range
|
port = rand () % (30777 - 9111) + 9111; // I2P network ports range
|
||||||
std::string host; i2p::config::GetOption("host", host);
|
std::string host = i2p::util::config::GetHost();
|
||||||
if (i2p::config::IsDefault("host"))
|
|
||||||
host = "127.0.0.1"; // replace default address with safe value
|
|
||||||
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 |
|
||||||
|
@ -114,7 +114,7 @@ namespace transport
|
|||||||
auto& addresses = context.GetRouterInfo ().GetAddresses ();
|
auto& addresses = context.GetRouterInfo ().GetAddresses ();
|
||||||
for (auto address : addresses)
|
for (auto address : addresses)
|
||||||
{
|
{
|
||||||
if (!m_NTCPServer && enableNTCP)
|
if (m_NTCPServer == nullptr && enableNTCP)
|
||||||
{
|
{
|
||||||
m_NTCPServer = new NTCPServer ();
|
m_NTCPServer = new NTCPServer ();
|
||||||
m_NTCPServer->Start ();
|
m_NTCPServer->Start ();
|
||||||
@ -129,7 +129,7 @@ namespace transport
|
|||||||
|
|
||||||
if (address->transportStyle == RouterInfo::eTransportSSU)
|
if (address->transportStyle == RouterInfo::eTransportSSU)
|
||||||
{
|
{
|
||||||
if (!m_SSUServer && enableSSU)
|
if (m_SSUServer == nullptr && enableSSU)
|
||||||
{
|
{
|
||||||
if (address->host.is_v4())
|
if (address->host.is_v4())
|
||||||
m_SSUServer = new SSUServer (address->port);
|
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
|
} // util
|
||||||
} // i2p
|
} // i2p
|
||||||
|
6
util.h
6
util.h
@ -68,6 +68,12 @@ 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user