|
|
@ -105,7 +105,7 @@ namespace transport |
|
|
|
Stop (); |
|
|
|
Stop (); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Transports::Start () |
|
|
|
void Transports::Start (bool enableNTCP, bool enableSSU) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_DHKeysPairSupplier.Start (); |
|
|
|
m_DHKeysPairSupplier.Start (); |
|
|
|
m_IsRunning = true; |
|
|
|
m_IsRunning = true; |
|
|
@ -114,22 +114,36 @@ namespace transport |
|
|
|
auto& addresses = context.GetRouterInfo ().GetAddresses (); |
|
|
|
auto& addresses = context.GetRouterInfo ().GetAddresses (); |
|
|
|
for (auto address : addresses) |
|
|
|
for (auto address : addresses) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!m_NTCPServer) |
|
|
|
if (!m_NTCPServer && enableNTCP) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_NTCPServer = new NTCPServer (); |
|
|
|
m_NTCPServer = new NTCPServer (); |
|
|
|
m_NTCPServer->Start (); |
|
|
|
m_NTCPServer->Start (); |
|
|
|
|
|
|
|
if (!(m_NTCPServer->IsBoundV6() || m_NTCPServer->IsBoundV4())) { |
|
|
|
|
|
|
|
/** failed to bind to NTCP */ |
|
|
|
|
|
|
|
LogPrint(eLogError, "Transports: failed to bind to TCP"); |
|
|
|
|
|
|
|
m_NTCPServer->Stop(); |
|
|
|
|
|
|
|
delete m_NTCPServer; |
|
|
|
|
|
|
|
m_NTCPServer = nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (address->transportStyle == RouterInfo::eTransportSSU) |
|
|
|
if (address->transportStyle == RouterInfo::eTransportSSU) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!m_SSUServer) |
|
|
|
if (!m_SSUServer && enableSSU) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (address->host.is_v4()) |
|
|
|
if (address->host.is_v4()) |
|
|
|
m_SSUServer = new SSUServer (address->port); |
|
|
|
m_SSUServer = new SSUServer (address->port); |
|
|
|
else |
|
|
|
else |
|
|
|
m_SSUServer = new SSUServer (address->host, address->port); |
|
|
|
m_SSUServer = new SSUServer (address->host, address->port); |
|
|
|
LogPrint (eLogInfo, "Transports: Start listening UDP port ", address->port); |
|
|
|
LogPrint (eLogInfo, "Transports: Start listening UDP port ", address->port); |
|
|
|
|
|
|
|
try { |
|
|
|
m_SSUServer->Start (); |
|
|
|
m_SSUServer->Start (); |
|
|
|
|
|
|
|
} catch ( std::exception & ex ) { |
|
|
|
|
|
|
|
LogPrint(eLogError, "Transports: Failed to bind to UDP port", address->port); |
|
|
|
|
|
|
|
delete m_SSUServer; |
|
|
|
|
|
|
|
m_SSUServer = nullptr; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
DetectExternalIP (); |
|
|
|
DetectExternalIP (); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
@ -291,7 +305,7 @@ namespace transport |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint (eLogWarning, "Transports: NTCP address is not present for ", i2p::data::GetIdentHashAbbreviation (ident), ", trying SSU"); |
|
|
|
LogPrint (eLogDebug, "Transports: NTCP address is not present for ", i2p::data::GetIdentHashAbbreviation (ident), ", trying SSU"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (peer.numAttempts == 1)// SSU
|
|
|
|
if (peer.numAttempts == 1)// SSU
|
|
|
|
{ |
|
|
|
{ |
|
|
@ -623,6 +637,30 @@ namespace transport |
|
|
|
std::advance (it, rand () % m_Peers.size ()); |
|
|
|
std::advance (it, rand () % m_Peers.size ()); |
|
|
|
return it != m_Peers.end () ? it->second.router : nullptr; |
|
|
|
return it != m_Peers.end () ? it->second.router : nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void Transports::RestrictRoutes(std::vector<std::string> families) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_FamilyMutex); |
|
|
|
|
|
|
|
m_TrustedFamilies.clear(); |
|
|
|
|
|
|
|
for ( auto fam : families ) |
|
|
|
|
|
|
|
m_TrustedFamilies.push_back(fam); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Transports::RoutesRestricted() const { |
|
|
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_FamilyMutex); |
|
|
|
|
|
|
|
return m_TrustedFamilies.size() > 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** XXX: if routes are not restricted this dies */ |
|
|
|
|
|
|
|
std::shared_ptr<const i2p::data::RouterInfo> Transports::GetRestrictedPeer() const { |
|
|
|
|
|
|
|
std::string fam; |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_FamilyMutex); |
|
|
|
|
|
|
|
// TODO: random family (?)
|
|
|
|
|
|
|
|
fam = m_TrustedFamilies[0]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
boost::to_lower(fam); |
|
|
|
|
|
|
|
return i2p::data::netdb.GetRandomRouterInFamily(fam); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|