common codepath for sending protocol frames

pull/576/head
Jeff Becker 5 years ago
parent 6711296b26
commit 5921086391
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -178,9 +178,9 @@ namespace llarp
void void
OutboundContext::AsyncGenIntro(const llarp_buffer_t& payload, OutboundContext::AsyncGenIntro(const llarp_buffer_t& payload,
__attribute__((unused)) ProtocolType t) ProtocolType t)
{ {
auto path = m_PathSet->GetPathByRouter(remoteIntro.router); auto path = m_PathSet->GetNewestPathByRouter(remoteIntro.router);
if(path == nullptr) if(path == nullptr)
{ {
// try parent as fallback // try parent as fallback
@ -199,9 +199,11 @@ namespace llarp
m_Endpoint->GetIdentity(), currentIntroSet.K, remoteIntro, m_Endpoint->GetIdentity(), currentIntroSet.K, remoteIntro,
m_DataHandler, currentConvoTag); m_DataHandler, currentConvoTag);
ex->hook = std::bind(&OutboundContext::Send, this, std::placeholders::_1); ex->hook =
std::bind(&OutboundContext::Send, this, std::placeholders::_1, path);
ex->msg.PutBuffer(payload); ex->msg.PutBuffer(payload);
ex->msg.proto = t;
ex->msg.introReply = path->intro; ex->msg.introReply = path->intro;
ex->frame.F = ex->msg.introReply.pathID; ex->frame.F = ex->msg.introReply.pathID;
llarp_threadpool_queue_job(m_Endpoint->CryptoWorker(), llarp_threadpool_queue_job(m_Endpoint->CryptoWorker(),

@ -3,6 +3,7 @@
#include <messages/path_transfer.hpp> #include <messages/path_transfer.hpp>
#include <service/endpoint.hpp> #include <service/endpoint.hpp>
#include <router/abstractrouter.hpp> #include <router/abstractrouter.hpp>
#include <util/logic.hpp>
namespace llarp namespace llarp
{ {
@ -22,26 +23,20 @@ namespace llarp
} }
bool bool
SendContext::Send(const ProtocolFrame& msg) SendContext::Send(const ProtocolFrame& msg, path::Path_ptr path)
{ {
auto path = m_PathSet->GetByEndpointWithID(remoteIntro.router, msg.F); auto transfer = std::make_shared< const routing::PathTransferMessage >(
if(path) msg, remoteIntro.pathID);
{ m_Endpoint->RouterLogic()->queue_func([=]() {
const routing::PathTransferMessage transfer(msg, remoteIntro.pathID); if(path->SendRoutingMessage(*transfer, m_Endpoint->Router()))
if(path->SendRoutingMessage(transfer, m_Endpoint->Router()))
{ {
LogInfo("sent intro to ", remoteIntro.pathID, " on ",
remoteIntro.router, " seqno=", sequenceNo);
lastGoodSend = m_Endpoint->Now(); lastGoodSend = m_Endpoint->Now();
++sequenceNo; ++sequenceNo;
return true;
} }
else else
LogError("Failed to send frame on path"); LogError("Failed to send frame on path");
} });
else return true;
LogError("cannot send because we have no path to ", remoteIntro.router);
return false;
} }
/// send on an established convo tag /// send on an established convo tag
@ -50,8 +45,7 @@ namespace llarp
{ {
auto crypto = m_Endpoint->Router()->crypto(); auto crypto = m_Endpoint->Router()->crypto();
SharedSecret shared; SharedSecret shared;
routing::PathTransferMessage msg; ProtocolFrame f;
ProtocolFrame& f = msg.T;
f.N.Randomize(); f.N.Randomize();
f.T = currentConvoTag; f.T = currentConvoTag;
f.S = m_Endpoint->GetSeqNoForConvo(f.T); f.S = m_Endpoint->GetSeqNoForConvo(f.T);
@ -94,20 +88,8 @@ namespace llarp
LogError("No cached session key"); LogError("No cached session key");
return; return;
} }
++sequenceNo;
msg.P = remoteIntro.pathID; Send(f, path);
msg.Y.Randomize();
if(path->SendRoutingMessage(msg, m_Endpoint->Router()))
{
LogDebug("sent message via ", remoteIntro.pathID, " on ",
remoteIntro.router);
++sequenceNo;
lastGoodSend = now;
}
else
{
LogWarn("Failed to send routing message for data");
}
} }
void void

@ -24,17 +24,17 @@ namespace llarp
AsyncEncryptAndSendTo(const llarp_buffer_t& payload, ProtocolType t); AsyncEncryptAndSendTo(const llarp_buffer_t& payload, ProtocolType t);
/// 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
bool bool
Send(const ProtocolFrame& f); Send(const ProtocolFrame& f, path::Path_ptr path);
SharedSecret sharedKey; SharedSecret sharedKey;
ServiceInfo remoteIdent; ServiceInfo remoteIdent;
Introduction remoteIntro; Introduction remoteIntro;
ConvoTag currentConvoTag; ConvoTag currentConvoTag;
path::PathSet* m_PathSet; path::PathSet* const m_PathSet;
IDataHandler* m_DataHandler; IDataHandler* const m_DataHandler;
Endpoint* m_Endpoint; Endpoint* const m_Endpoint;
uint64_t sequenceNo = 0; uint64_t sequenceNo = 0;
llarp_time_t lastGoodSend = 0; llarp_time_t lastGoodSend = 0;
llarp_time_t createdAt; llarp_time_t createdAt;

Loading…
Cancel
Save