Browse Source

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
pull/574/head
Jeff Becker 8 years ago
parent
commit
3ad196c4c7
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
  1. 44
      Daemon.cpp
  2. 4
      RouterContext.cpp
  3. 4
      Transports.cpp
  4. 25
      util.cpp
  5. 6
      util.h

44
Daemon.cpp

@ -124,47 +124,16 @@ namespace i2p @@ -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 @@ -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;
}

4
RouterContext.cpp

@ -49,9 +49,7 @@ namespace i2p @@ -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 |

4
Transports.cpp

@ -114,7 +114,7 @@ namespace transport @@ -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 @@ -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

@ -461,5 +461,30 @@ namespace net @@ -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

@ -68,6 +68,12 @@ namespace util @@ -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…
Cancel
Save