void RouterContext::Init () { m_StartupTime = i2p::util::GetSecondsSinceEpoch (); if (!Load ()) CreateNewRouter (); UpdateRouterInfo (); }
void RouterContext::SetLowBandwidth() { if (m_RouterInfo.IsHighBandwidth()) { m_RouterInfo.SetCaps( m_RouterInfo.GetCaps() & ~i2p::data::RouterInfo::eHighBandwidth); UpdateRouterInfo(); } }
void RouterContext::UpdateNTCPV6Address (const boost::asio::ip::address& host) { bool updated = false, found = false; int port = 0; auto& addresses = m_RouterInfo.GetAddresses (); for (auto& addr : addresses) { if (addr.host.is_v6 () && addr.transportStyle == i2p::data::RouterInfo::eTransportNTCP) { if (addr.host != host) { addr.host = host; updated = true; } found = true; } else port = addr.port; } if (!found) { // create new address m_RouterInfo.AddNTCPAddress (host.to_string ().c_str (), port); auto mtu = i2p::util::net::GetMTU (host); if (mtu) { LogPrint ("Our v6 MTU=", mtu); if (mtu > 1472) mtu = 1472; } m_RouterInfo.AddSSUAddress (host.to_string ().c_str (), port, GetIdentHash (), mtu ? mtu : 1472); // TODO updated = true; } if (updated) UpdateRouterInfo (); }
void RouterContext::SetReachable () { // update caps uint8_t caps = m_RouterInfo.GetCaps (); caps &= ~i2p::data::RouterInfo::eUnreachable; caps |= i2p::data::RouterInfo::eReachable; caps |= i2p::data::RouterInfo::eSSUIntroducer; if (m_IsFloodfill) caps |= i2p::data::RouterInfo::eFloodfill; m_RouterInfo.SetCaps (caps); // insert NTCP back auto& addresses = m_RouterInfo.GetAddresses (); for (size_t i = 0; i < addresses.size (); i++) { if (addresses[i].transportStyle == i2p::data::RouterInfo::eTransportSSU) { // insert NTCP address with host/port form SSU m_RouterInfo.AddNTCPAddress (addresses[i].host.to_string ().c_str (), addresses[i].port); break; } } // delete previous introducers for (auto& addr : addresses) addr.introducers.clear (); // update UpdateRouterInfo (); }
void RouterContext::CreateNewRouter () { m_Keys = i2p::data::CreateRandomKeys (); m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag, CryptoPP::Integer (m_Keys.signingPrivateKey, 20)); UpdateRouterInfo (); }
void RouterContext::SetSupportsV6 (bool supportsV6) { if (supportsV6) m_RouterInfo.EnableV6 (); else m_RouterInfo.DisableV6 (); UpdateRouterInfo (); }
void RouterContext::UpdateStats () { if (m_IsFloodfill) { // update routers and leasesets m_RouterInfo.SetProperty (ROUTER_INFO_PROPERTY_LEASESETS, boost::lexical_cast<std::string>(i2p::data::netdb.GetNumLeaseSets ())); m_RouterInfo.SetProperty (ROUTER_INFO_PROPERTY_ROUTERS, boost::lexical_cast<std::string>(i2p::data::netdb.GetNumRouters ())); UpdateRouterInfo (); } }
bool RouterContext::AddIntroducer (const i2p::data::RouterInfo& routerInfo, uint32_t tag) { bool ret = false; auto address = routerInfo.GetSSUAddress (); if (address) { ret = m_RouterInfo.AddIntroducer (address, tag); if (ret) UpdateRouterInfo (); } return ret; }
void RouterContext::Init( const std::string& host, int port, const boost::filesystem::path& dataPath) { m_Host = host; m_Port = port; m_DataPath = dataPath; m_StartupTime = i2p::util::GetSecondsSinceEpoch(); if (!Load()) CreateNewRouter(); UpdateRouterInfo(); }
void RouterContext::UpdatePort( int port) { bool updated = false; for (auto& address : m_RouterInfo.GetAddresses()) { if (address.port != port) { address.port = port; updated = true; } } if (updated) UpdateRouterInfo(); }
void RouterContext::UpdateAddress( const boost::asio::ip::address& host) { bool updated = false; for (auto& address : m_RouterInfo.GetAddresses()) { if (address.host != host && address.IsCompatible(host)) { address.host = host; updated = true; } } auto ts = i2p::util::GetSecondsSinceEpoch(); if (updated || ts > m_LastUpdateTime + ROUTER_INFO_UPDATE_INTERVAL) UpdateRouterInfo(); }
void RouterContext::SetFloodfill (bool floodfill) { m_IsFloodfill = floodfill; if (floodfill) m_RouterInfo.SetCaps (m_RouterInfo.GetCaps () | i2p::data::RouterInfo::eFloodfill); else { m_RouterInfo.SetCaps (m_RouterInfo.GetCaps () & ~i2p::data::RouterInfo::eFloodfill); // we don't publish number of routers and leaseset for non-floodfill m_RouterInfo.DeleteProperty (ROUTER_INFO_PROPERTY_LEASESETS); m_RouterInfo.DeleteProperty (ROUTER_INFO_PROPERTY_ROUTERS); } UpdateRouterInfo (); }
void RouterContext::SetUnreachable() { // set caps m_RouterInfo.SetCaps( // LU, B i2p::data::RouterInfo::eUnreachable | i2p::data::RouterInfo::eSSUTesting); // remove NTCP address auto& addresses = m_RouterInfo.GetAddresses(); for (size_t i = 0; i < addresses.size(); i++) { if (addresses[i].transport_style == i2p::data::RouterInfo::eTransportNTCP) { addresses.erase(addresses.begin() + i); break; } } // delete previous introducers for (auto& addr : addresses) addr.introducers.clear(); // update UpdateRouterInfo(); }
void RouterContext::RemoveIntroducer (const boost::asio::ip::udp::endpoint& e) { if (m_RouterInfo.RemoveIntroducer (e)) UpdateRouterInfo (); }