|
|
@ -231,8 +231,7 @@ namespace transport |
|
|
|
|
|
|
|
|
|
|
|
void Transports::SendMessages (const i2p::data::IdentHash& ident, const std::vector<std::shared_ptr<i2p::I2NPMessage> >& msgs) |
|
|
|
void Transports::SendMessages (const i2p::data::IdentHash& ident, const std::vector<std::shared_ptr<i2p::I2NPMessage> >& msgs) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
EmitEvent({{"type" , "transport.sendmsg"}, {"ident", ident.ToBase64()}, {"number", std::to_string(msgs.size())}}); |
|
|
|
EmitEvent({{"type" , "transport.sendmsg"}, {"ident", ident.ToBase64()}, {"number", std::to_string(msgs.size())}}); |
|
|
|
|
|
|
|
m_Service.post (std::bind (&Transports::PostMessages, this, ident, msgs)); |
|
|
|
m_Service.post (std::bind (&Transports::PostMessages, this, ident, msgs)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -507,10 +506,9 @@ namespace transport |
|
|
|
} |
|
|
|
} |
|
|
|
if (m_SSUServer) |
|
|
|
if (m_SSUServer) |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool nat; i2p::config::GetOption("nat", nat); |
|
|
|
bool nat; i2p::config::GetOption("nat", nat); |
|
|
|
if (nat) |
|
|
|
if (nat) |
|
|
|
i2p::context.SetStatus (eRouterStatusTesting); |
|
|
|
i2p::context.SetStatus (eRouterStatusTesting); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; i++) |
|
|
|
for (int i = 0; i < 5; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto router = i2p::data::netdb.GetRandomPeerTestRouter (); |
|
|
|
auto router = i2p::data::netdb.GetRandomPeerTestRouter (); |
|
|
@ -569,11 +567,10 @@ namespace transport |
|
|
|
auto remoteIdentity = session->GetRemoteIdentity (); |
|
|
|
auto remoteIdentity = session->GetRemoteIdentity (); |
|
|
|
if (!remoteIdentity) return; |
|
|
|
if (!remoteIdentity) return; |
|
|
|
auto ident = remoteIdentity->GetIdentHash (); |
|
|
|
auto ident = remoteIdentity->GetIdentHash (); |
|
|
|
auto it = m_Peers.find (ident); |
|
|
|
auto it = m_Peers.find (ident); |
|
|
|
if (it != m_Peers.end ()) |
|
|
|
if (it != m_Peers.end ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
EmitEvent({{"type" , "transport.connected"}, {"ident", ident.ToBase64()}, {"inbound", "false"}}); |
|
|
|
EmitEvent({{"type" , "transport.connected"}, {"ident", ident.ToBase64()}, {"inbound", "false"}}); |
|
|
|
|
|
|
|
|
|
|
|
bool sendDatabaseStore = true; |
|
|
|
bool sendDatabaseStore = true; |
|
|
|
if (it->second.delayedMessages.size () > 0) |
|
|
|
if (it->second.delayedMessages.size () > 0) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -599,7 +596,7 @@ namespace transport |
|
|
|
session->Done(); |
|
|
|
session->Done(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
EmitEvent({{"type" , "transport.connected"}, {"ident", ident.ToBase64()}, {"inbound", "true"}}); |
|
|
|
EmitEvent({{"type" , "transport.connected"}, {"ident", ident.ToBase64()}, {"inbound", "true"}}); |
|
|
|
session->SendI2NPMessages ({ CreateDatabaseStoreMsg () }); // send DatabaseStore
|
|
|
|
session->SendI2NPMessages ({ CreateDatabaseStoreMsg () }); // send DatabaseStore
|
|
|
|
std::unique_lock<std::mutex> l(m_PeersMutex); |
|
|
|
std::unique_lock<std::mutex> l(m_PeersMutex); |
|
|
|
m_Peers.insert (std::make_pair (ident, Peer{ 0, nullptr, { session }, i2p::util::GetSecondsSinceEpoch (), {} })); |
|
|
|
m_Peers.insert (std::make_pair (ident, Peer{ 0, nullptr, { session }, i2p::util::GetSecondsSinceEpoch (), {} })); |
|
|
@ -614,7 +611,7 @@ namespace transport |
|
|
|
auto remoteIdentity = session->GetRemoteIdentity (); |
|
|
|
auto remoteIdentity = session->GetRemoteIdentity (); |
|
|
|
if (!remoteIdentity) return; |
|
|
|
if (!remoteIdentity) return; |
|
|
|
auto ident = remoteIdentity->GetIdentHash (); |
|
|
|
auto ident = remoteIdentity->GetIdentHash (); |
|
|
|
EmitEvent({{"type" , "transport.disconnected"}, {"ident", ident.ToBase64()}}); |
|
|
|
EmitEvent({{"type" , "transport.disconnected"}, {"ident", ident.ToBase64()}}); |
|
|
|
auto it = m_Peers.find (ident); |
|
|
|
auto it = m_Peers.find (ident); |
|
|
|
if (it != m_Peers.end ()) |
|
|
|
if (it != m_Peers.end ()) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -678,13 +675,13 @@ 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::RestrictRoutesToFamilies(std::set<std::string> families) |
|
|
|
void Transports::RestrictRoutesToFamilies(std::set<std::string> families) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::lock_guard<std::mutex> lock(m_FamilyMutex); |
|
|
|
std::lock_guard<std::mutex> lock(m_FamilyMutex); |
|
|
|
m_TrustedFamilies.clear(); |
|
|
|
m_TrustedFamilies.clear(); |
|
|
|
for ( const auto& fam : families ) |
|
|
|
for ( const auto& fam : families ) |
|
|
|
m_TrustedFamilies.push_back(fam); |
|
|
|
m_TrustedFamilies.push_back(fam); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Transports::RestrictRoutesToRouters(std::set<i2p::data::IdentHash> routers) |
|
|
|
void Transports::RestrictRoutesToRouters(std::set<i2p::data::IdentHash> routers) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -694,14 +691,14 @@ namespace transport |
|
|
|
m_TrustedRouters.push_back(ri); |
|
|
|
m_TrustedRouters.push_back(ri); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Transports::RoutesRestricted() const { |
|
|
|
bool Transports::RoutesRestricted() const { |
|
|
|
std::unique_lock<std::mutex> famlock(m_FamilyMutex); |
|
|
|
std::unique_lock<std::mutex> famlock(m_FamilyMutex); |
|
|
|
std::unique_lock<std::mutex> routerslock(m_TrustedRoutersMutex); |
|
|
|
std::unique_lock<std::mutex> routerslock(m_TrustedRoutersMutex); |
|
|
|
return m_TrustedFamilies.size() > 0 || m_TrustedRouters.size() > 0; |
|
|
|
return m_TrustedFamilies.size() > 0 || m_TrustedRouters.size() > 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** XXX: if routes are not restricted this dies */ |
|
|
|
/** XXX: if routes are not restricted this dies */ |
|
|
|
std::shared_ptr<const i2p::data::RouterInfo> Transports::GetRestrictedPeer() const |
|
|
|
std::shared_ptr<const i2p::data::RouterInfo> Transports::GetRestrictedPeer() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::lock_guard<std::mutex> l(m_FamilyMutex); |
|
|
|
std::lock_guard<std::mutex> l(m_FamilyMutex); |
|
|
@ -734,7 +731,7 @@ namespace transport |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Transports::IsRestrictedPeer(const i2p::data::IdentHash & ih) const |
|
|
|
bool Transports::IsRestrictedPeer(const i2p::data::IdentHash & ih) const |
|
|
|
{ |
|
|
|
{ |
|
|
|