redundancy with outbound contexts

have multiple outbound contexts and send on the one that is alive
pull/18/head
Jeff Becker 6 years ago
parent 2e3601b140
commit 8878e5c4d1
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -29,6 +29,8 @@ namespace llarp
static const llarp_time_t INTROSET_PUBLISH_RETRY_INTERVAL = 5000; static const llarp_time_t INTROSET_PUBLISH_RETRY_INTERVAL = 5000;
static const size_t MAX_OUTBOUND_CONTEXT_COUNT = 4;
Endpoint(const std::string& nickname, llarp_router* r); Endpoint(const std::string& nickname, llarp_router* r);
~Endpoint(); ~Endpoint();
@ -243,6 +245,10 @@ namespace llarp
bool bool
MarkCurrentIntroBad(llarp_time_t now); MarkCurrentIntroBad(llarp_time_t now);
/// return true if we are ready to send
bool
ReadyToSend() const;
bool bool
ShouldBuildMore() const; ShouldBuildMore() const;
@ -405,8 +411,8 @@ namespace llarp
std::unordered_map< Address, PendingBufferQueue, Address::Hash > std::unordered_map< Address, PendingBufferQueue, Address::Hash >
m_PendingTraffic; m_PendingTraffic;
std::unordered_map< Address, std::unique_ptr< OutboundContext >, std::unordered_multimap< Address, std::unique_ptr< OutboundContext >,
Address::Hash > Address::Hash >
m_RemoteSessions; m_RemoteSessions;
std::unordered_multimap< Address, std::unique_ptr< OutboundContext >, std::unordered_multimap< Address, std::unique_ptr< OutboundContext >,

@ -643,22 +643,32 @@ namespace llarp
Address addr; Address addr;
introset.A.CalculateAddress(addr.data()); introset.A.CalculateAddress(addr.data());
// only add new session if it's not there if(m_RemoteSessions.count(addr) >= MAX_OUTBOUND_CONTEXT_COUNT)
if(m_RemoteSessions.find(addr) == m_RemoteSessions.end())
{ {
OutboundContext* ctx = new OutboundContext(introset, this); auto itr = m_RemoteSessions.find(addr);
m_RemoteSessions.insert(
std::make_pair(addr, std::unique_ptr< OutboundContext >(ctx))); auto i = m_PendingServiceLookups.find(addr);
llarp::LogInfo("Created New outbound context for ", addr.ToString()); if(i != m_PendingServiceLookups.end())
{
auto f = i->second;
m_PendingServiceLookups.erase(i);
f(addr, itr->second.get());
}
return;
} }
OutboundContext* ctx = new OutboundContext(introset, this);
m_RemoteSessions.insert(
std::make_pair(addr, std::unique_ptr< OutboundContext >(ctx)));
llarp::LogInfo("Created New outbound context for ", addr.ToString());
// inform pending // inform pending
auto itr = m_PendingServiceLookups.find(addr); auto itr = m_PendingServiceLookups.find(addr);
if(itr != m_PendingServiceLookups.end()) if(itr != m_PendingServiceLookups.end())
{ {
auto f = itr->second; auto f = itr->second;
m_PendingServiceLookups.erase(itr); m_PendingServiceLookups.erase(itr);
f(itr->first, m_RemoteSessions.at(addr).get()); f(addr, ctx);
} }
} }
@ -917,10 +927,17 @@ namespace llarp
return true; return true;
} }
bool
Endpoint::OutboundContext::ReadyToSend() const
{
return GetPathByRouter(remoteIntro.router) != nullptr;
}
bool bool
Endpoint::SendToOrQueue(const Address& remote, llarp_buffer_t data, Endpoint::SendToOrQueue(const Address& remote, llarp_buffer_t data,
ProtocolType t) ProtocolType t)
{ {
// inbound converstation
{ {
auto itr = m_AddressToService.find(remote); auto itr = m_AddressToService.find(remote);
if(itr != m_AddressToService.end()) if(itr != m_AddressToService.end())
@ -974,20 +991,31 @@ namespace llarp
llarp::LogError("failed to encrypt and sign"); llarp::LogError("failed to encrypt and sign");
return false; return false;
} }
llarp::LogDebug(Name(), " send ", data.sz, " via ", remoteIntro); llarp::LogDebug(Name(), " send ", data.sz, " via ",
remoteIntro.router);
return p->SendRoutingMessage(&transfer, Router()); return p->SendRoutingMessage(&transfer, Router());
} }
} }
} }
// outbound converstation
if(HasPathToService(remote)) if(HasPathToService(remote))
{ {
llarp::LogDebug(Name(), " has session to ", remote, " sending ", auto range = m_RemoteSessions.equal_range(remote);
data.sz, " bytes"); auto itr = range.first;
auto itr = m_RemoteSessions.find(remote); while(itr != range.second)
itr->second->AsyncEncryptAndSendTo(data, t); {
return true; if(itr->second->ReadyToSend())
{
itr->second->AsyncEncryptAndSendTo(data, t);
return true;
}
++itr;
}
// all paths are not ready?
return false;
} }
// no converstation
auto itr = m_PendingTraffic.find(remote); auto itr = m_PendingTraffic.find(remote);
if(itr == m_PendingTraffic.end()) if(itr == m_PendingTraffic.end())
{ {
@ -1227,8 +1255,8 @@ namespace llarp
routing::PathTransferMessage transfer(msg, remoteIntro.pathID); routing::PathTransferMessage transfer(msg, remoteIntro.pathID);
if(path->SendRoutingMessage(&transfer, m_Endpoint->Router())) if(path->SendRoutingMessage(&transfer, m_Endpoint->Router()))
{ {
llarp::LogInfo("sent data to ", remoteIntro.pathID, " on ", llarp::LogDebug("sent data to ", remoteIntro.pathID, " on ",
remoteIntro.router); remoteIntro.router);
lastGoodSend = now; lastGoodSend = now;
} }
else else

Loading…
Cancel
Save