make it work

pull/389/head
Jeff Becker 5 years ago
parent 8a4c0ce841
commit 6489ea2152
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -172,26 +172,24 @@ namespace llarp
IHopHandler* IHopHandler*
PathContext::GetByUpstream(const RouterID& remote, const PathID_t& id) PathContext::GetByUpstream(const RouterID& remote, const PathID_t& id)
{ {
auto own = MapGet( auto own = MapGet(m_OurPaths, id,
m_OurPaths, id, [](__attribute__((unused)) const PathSet* s) -> bool {
[](__attribute__((unused)) const PathSet* s) -> bool { // TODO: is this right?
// TODO: is this right? return true;
return true; },
}, [remote, id](PathSet* p) -> IHopHandler* {
[remote, id](PathSet* p) -> IHopHandler* { return p->GetByUpstream(remote, id);
return p->GetByUpstream(remote, id); });
});
if(own) if(own)
return own; return own;
return MapGet( return MapGet(m_TransitPaths, id,
m_TransitPaths, id, [remote](const std::shared_ptr< TransitHop >& hop) -> bool {
[remote](const std::shared_ptr< TransitHop >& hop) -> bool { return hop->info.upstream == remote;
return hop->info.upstream == remote; },
}, [](const std::shared_ptr< TransitHop >& h) -> IHopHandler* {
[](const std::shared_ptr< TransitHop >& h) -> IHopHandler* { return h.get();
return h.get(); });
});
} }
bool bool
@ -208,14 +206,13 @@ namespace llarp
IHopHandler* IHopHandler*
PathContext::GetByDownstream(const RouterID& remote, const PathID_t& id) PathContext::GetByDownstream(const RouterID& remote, const PathID_t& id)
{ {
return MapGet( return MapGet(m_TransitPaths, id,
m_TransitPaths, id, [remote](const std::shared_ptr< TransitHop >& hop) -> bool {
[remote](const std::shared_ptr< TransitHop >& hop) -> bool { return hop->info.downstream == remote;
return hop->info.downstream == remote; },
}, [](const std::shared_ptr< TransitHop >& h) -> IHopHandler* {
[](const std::shared_ptr< TransitHop >& h) -> IHopHandler* { return h.get();
return h.get(); });
});
} }
PathSet* PathSet*
@ -440,6 +437,13 @@ namespace llarp
return intro.latency > 0 && _status == ePathEstablished; return intro.latency > 0 && _status == ePathEstablished;
} }
bool
Path::IsEndpoint(const RouterID& r, const PathID_t& id) const
{
return hops[hops.size() - 1].rc.pubkey == r
&& hops[hops.size() - 1].txID == id;
}
RouterID RouterID
Path::Upstream() const Path::Upstream() const
{ {

@ -156,6 +156,22 @@ namespace llarp
return chosen; return chosen;
} }
Path*
PathSet::GetByEndpointWithID(RouterID ep, PathID_t id) const
{
Lock_t l(&m_PathsMutex);
auto itr = m_Paths.begin();
while(itr != m_Paths.end())
{
if(itr->second->IsEndpoint(ep, id))
{
return itr->second;
}
++itr;
}
return nullptr;
}
Path* Path*
PathSet::GetPathByID(PathID_t id) const PathSet::GetPathByID(PathID_t id) const
{ {

@ -176,6 +176,9 @@ namespace llarp
Path* Path*
GetPathByID(PathID_t id) const; GetPathByID(PathID_t id) const;
Path*
GetByEndpointWithID(RouterID router, PathID_t id) const;
bool bool
GetCurrentIntroductionsWithFilter( GetCurrentIntroductionsWithFilter(
std::set< service::Introduction >& intros, std::set< service::Introduction >& intros,

@ -1585,6 +1585,7 @@ namespace llarp
self->handler->PutCachedSessionKeyFor(self->msg.tag, self->sharedKey); self->handler->PutCachedSessionKeyFor(self->msg.tag, self->sharedKey);
self->handler->PutIntroFor(self->msg.tag, self->remoteIntro); self->handler->PutIntroFor(self->msg.tag, self->remoteIntro);
self->handler->PutSenderFor(self->msg.tag, self->remote); self->handler->PutSenderFor(self->msg.tag, self->remote);
self->handler->PutReplyIntroFor(self->msg.tag, self->msg.introReply);
self->hook(self->frame); self->hook(self->frame);
delete self; delete self;
} }
@ -1671,24 +1672,22 @@ namespace llarp
ex->msg.PutBuffer(payload); ex->msg.PutBuffer(payload);
ex->msg.introReply = path->intro; ex->msg.introReply = path->intro;
m_DataHandler->PutReplyIntroFor(currentConvoTag, path->intro); ex->frame.F = ex->msg.introReply.pathID;
llarp_threadpool_queue_job(m_Endpoint->Worker(), llarp_threadpool_queue_job(m_Endpoint->Worker(),
{ex, &AsyncKeyExchange::Encrypt}); {ex, &AsyncKeyExchange::Encrypt});
} }
bool bool
Endpoint::SendContext::Send(ProtocolFrame& msg) Endpoint::SendContext::Send(const ProtocolFrame& msg)
{ {
auto path = m_PathSet->GetPathByRouter(remoteIntro.router); auto path = m_PathSet->GetByEndpointWithID(remoteIntro.router, msg.F);
if(path == nullptr)
path = m_Endpoint->GetPathByRouter(remoteIntro.router);
if(path) if(path)
{ {
const routing::PathTransferMessage transfer(msg, remoteIntro.pathID); const routing::PathTransferMessage transfer(msg, remoteIntro.pathID);
if(path->SendRoutingMessage(&transfer, m_Endpoint->Router())) if(path->SendRoutingMessage(&transfer, m_Endpoint->Router()))
{ {
llarp::LogDebug("sent data to ", remoteIntro.pathID, " on ", llarp::LogInfo("sent intro to ", remoteIntro.pathID, " on ",
remoteIntro.router, " seqno=", sequenceNo); remoteIntro.router, " seqno=", sequenceNo);
lastGoodSend = m_Endpoint->Now(); lastGoodSend = m_Endpoint->Now();
++sequenceNo; ++sequenceNo;
return true; return true;

@ -222,7 +222,7 @@ namespace llarp
/// send a fully encrypted hidden service frame /// send a fully encrypted hidden service frame
/// via a path on our pathset with path id p /// via a path on our pathset with path id p
bool bool
Send(ProtocolFrame& f); Send(const ProtocolFrame& f);
llarp::SharedSecret sharedKey; llarp::SharedSecret sharedKey;
ServiceInfo remoteIdent; ServiceInfo remoteIdent;

Loading…
Cancel
Save