make format and introduce new function EnsureRouter on router to check nodedb or do dht lookup

pull/630/head
Jeff Becker 5 years ago
parent 9c15f87da1
commit 2897141036
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -99,25 +99,28 @@ namespace llarp
PathContext::ForwardLRCM(const RouterID& nextHop, PathContext::ForwardLRCM(const RouterID& nextHop,
const std::array< EncryptedFrame, 8 >& frames) const std::array< EncryptedFrame, 8 >& frames)
{ {
auto msg = std::make_shared<const LR_CommitMessage>(frames); auto msg = std::make_shared< const LR_CommitMessage >(frames);
LogDebug("forwarding LRCM to ", nextHop); LogDebug("forwarding LRCM to ", nextHop);
if(m_Router->HasSessionTo(nextHop)) if(m_Router->HasSessionTo(nextHop))
{ {
return m_Router->SendToOrQueue(nextHop, msg.get()); return m_Router->SendToOrQueue(nextHop, msg.get());
} }
const RouterID router = nextHop; const RouterID router = nextHop;
AbstractRouter * const r = m_Router; AbstractRouter* const r = m_Router;
m_Router->LookupRouter(nextHop, [msg, r, router](const std::vector<RouterContact> & found) { m_Router->EnsureRouter(
if(found.size()) nextHop, [msg, r, router](const std::vector< RouterContact >& found) {
{ if(found.size())
r->TryConnectAsync(found[0], 1); {
r->SendToOrQueue(router, msg.get()); r->TryConnectAsync(found[0], 1);
} r->SendToOrQueue(router, msg.get());
else }
LogError("dropped LRCM to ", router, " as we cannot find in via DHT"); else
}); LogError("dropped LRCM to ", router,
LogInfo("we are not directly connected to ", router, " so we need to do a lookup"); " as we cannot find in via DHT");
});
LogInfo("we are not directly connected to ", router,
" so we need to do a lookup");
return true; return true;
} }
template < typename Map_t, typename Key_t, typename CheckValue_t, template < typename Map_t, typename Key_t, typename CheckValue_t,

@ -1,8 +1,19 @@
#include <router/abstractrouter.hpp> #include <router/abstractrouter.hpp>
#include <nodedb.hpp>
namespace llarp namespace llarp
{ {
AbstractRouter::~AbstractRouter() AbstractRouter::~AbstractRouter()
{ {
} }
void
AbstractRouter::EnsureRouter(RouterID router, RouterLookupHandler handler)
{
std::vector< RouterContact > found(1);
if(nodedb()->Get(router, found[0]))
handler(found);
else
LookupRouter(router, handler);
}
} // namespace llarp } // namespace llarp

@ -218,12 +218,16 @@ namespace llarp
virtual bool virtual bool
ConnectionToRouterAllowed(const RouterID &router) const = 0; ConnectionToRouterAllowed(const RouterID &router) const = 0;
/// return true if we have at least 1 session to this router in either direction /// return true if we have at least 1 session to this router in either
/// direction
virtual bool virtual bool
HasSessionTo(const RouterID & router) const = 0; HasSessionTo(const RouterID &router) const = 0;
virtual util::StatusObject virtual util::StatusObject
ExtractStatus() const = 0; ExtractStatus() const = 0;
void
EnsureRouter(RouterID router, RouterLookupHandler handler);
}; };
} // namespace llarp } // namespace llarp

@ -360,8 +360,8 @@ namespace llarp
// we don't have the RC locally so do a dht lookup // we don't have the RC locally so do a dht lookup
_dht->impl->LookupRouter(remote, _dht->impl->LookupRouter(remote,
std::bind(&Router::HandleDHTLookupForSendTo, this, std::bind(&Router::HandleDHTLookupForSendTo, this,
remote, std::placeholders::_1)); remote, std::placeholders::_1));
return true; return true;
} }

@ -535,8 +535,6 @@ namespace llarp
bool bool
HasSessionTo(const RouterID &remote) const override; HasSessionTo(const RouterID &remote) const override;
void void
HandleDHTLookupForTryEstablishTo( HandleDHTLookupForTryEstablishTo(
RouterID remote, const std::vector< RouterContact > &results); RouterID remote, const std::vector< RouterContact > &results);

@ -123,9 +123,9 @@ namespace llarp
} }
} }
// tick active endpoints // tick active endpoints
for(const auto & item : m_Endpoints) for(const auto &item : m_Endpoints)
{ {
item.second->Tick(now); item.second->Tick(now);
} }
/* /*
std::vector< RouterID > expired; std::vector< RouterID > expired;

@ -329,8 +329,7 @@ namespace llarp
LinkLayer::NewOutboundSession(const RouterContact& rc, LinkLayer::NewOutboundSession(const RouterContact& rc,
const AddressInfo& addr) const AddressInfo& addr)
{ {
return std::make_shared< OutboundSession >( return std::make_shared< OutboundSession >(this, NewSocket(), rc, addr);
this, NewSocket(), rc, addr);
} }
uint64 uint64

Loading…
Cancel
Save