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
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)
{
// try parent as fallback
@ -199,9 +199,11 @@ namespace llarp
m_Endpoint->GetIdentity(), currentIntroSet.K, remoteIntro,
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.proto = t;
ex->msg.introReply = path->intro;
ex->frame.F = ex->msg.introReply.pathID;
llarp_threadpool_queue_job(m_Endpoint->CryptoWorker(),

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

@ -24,17 +24,17 @@ namespace llarp
AsyncEncryptAndSendTo(const llarp_buffer_t& payload, ProtocolType t);
/// send a fully encrypted hidden service frame
/// via a path on our pathset with path id p
/// via a path
bool
Send(const ProtocolFrame& f);
Send(const ProtocolFrame& f, path::Path_ptr path);
SharedSecret sharedKey;
ServiceInfo remoteIdent;
Introduction remoteIntro;
ConvoTag currentConvoTag;
path::PathSet* m_PathSet;
IDataHandler* m_DataHandler;
Endpoint* m_Endpoint;
path::PathSet* const m_PathSet;
IDataHandler* const m_DataHandler;
Endpoint* const m_Endpoint;
uint64_t sequenceNo = 0;
llarp_time_t lastGoodSend = 0;
llarp_time_t createdAt;

Loading…
Cancel
Save