try unscrewing things up

pull/15/head
Jeff Becker 6 years ago
parent 6f1c60d56e
commit ebe30e81c9
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -43,10 +43,10 @@ namespace llarp
bool
SetupNetworking();
/// extends Endpoint
/// overrides Endpoint
/// handle inbound traffic
bool
HandleDataMessage(const PathID_t& src, service::ProtocolMessage* msg);
ProcessDataMessage(service::ProtocolMessage* msg);
#ifndef _MINGW32_NO_THREADS
/// overrides Endpount

@ -7,6 +7,11 @@
#include <llarp/service/protocol.hpp>
#include <llarp/path.hpp>
// minimum time between interoset shifts
#ifndef MIN_SHIFT_INTERVAL
#define MIN_SHIFT_INTERVAL (5 * 1000)
#endif
namespace llarp
{
namespace service
@ -108,9 +113,15 @@ namespace llarp
bool
ForgetPathToService(const Address& remote);
virtual bool
bool
HandleDataMessage(const PathID_t&, ProtocolMessage* msg);
virtual bool
ProcessDataMessage(ProtocolMessage* msg)
{
return true;
}
/// ensure that we know a router, looks up if it doesn't
void
EnsureRouterIsKnown(const RouterID& router);
@ -163,13 +174,12 @@ namespace llarp
PathSet* send, Endpoint* ep);
void
AsyncEncryptAndSendTo(PathID_t pid, llarp_buffer_t payload,
ProtocolType t);
AsyncEncryptAndSendTo(llarp_buffer_t payload, ProtocolType t);
/// send a fully encrypted hidden service frame
/// via a path on our pathset with path id p
void
Send(PathID_t p, ProtocolFrame& f);
Send(ProtocolFrame& f);
llarp::SharedSecret sharedKey;
ServiceInfo remoteIdent;
@ -186,11 +196,10 @@ namespace llarp
private:
void
EncryptAndSendTo(const PathID_t& p, llarp_buffer_t payload,
ProtocolType t);
EncryptAndSendTo(llarp_buffer_t payload, ProtocolType t);
virtual void
AsyncGenIntro(PathID_t p, llarp_buffer_t payload, ProtocolType t)
AsyncGenIntro(llarp_buffer_t payload, ProtocolType t)
{
}
};
@ -223,16 +232,8 @@ namespace llarp
bool
Tick(llarp_time_t now);
/// encrypt asynchronously and send to remote endpoint from us
void
AsyncEncryptAndSendTo(llarp_buffer_t D, ProtocolType protocol)
{
auto path = m_PathSet->GetPathByRouter(remoteIntro.router);
if(path)
SendContext::AsyncEncryptAndSendTo(path->RXID(), D, protocol);
}
void
AsyncGenIntro(PathID_t p, llarp_buffer_t payload, ProtocolType t);
AsyncGenIntro(llarp_buffer_t payload, ProtocolType t);
/// issues a lookup to find the current intro set of the remote service
void
@ -261,6 +262,7 @@ namespace llarp
uint64_t m_UpdateIntrosetTX = 0;
IntroSet currentIntroSet;
std::set< Introduction > m_BadIntros;
llarp_time_t lastShift = 0;
};
// passed a sendto context when we have a path established otherwise

@ -197,11 +197,8 @@ namespace llarp
}
bool
TunEndpoint::HandleDataMessage(const PathID_t &src,
service::ProtocolMessage *msg)
TunEndpoint::ProcessDataMessage(service::ProtocolMessage *msg)
{
if(!Endpoint::HandleDataMessage(src, msg))
return false;
uint32_t themIP = ObtainIPForAddr(msg->sender.Addr());
uint32_t usIP = m_OurIP;
auto buf = llarp::Buffer(msg->payload);

@ -135,9 +135,6 @@ namespace llarp
void
Endpoint::Tick(llarp_time_t now)
{
/// reset tx id for publish
if(now - m_LastPublishAttempt >= INTROSET_PUBLISH_RETRY_INTERVAL)
m_CurrentPublishTX = 0;
// publish descriptors
if(ShouldPublishDescriptors(now))
{
@ -543,8 +540,7 @@ namespace llarp
void
Endpoint::IntroSetPublished()
{
m_CurrentPublishTX = 0;
m_LastPublish = llarp_time_now_ms();
m_LastPublish = llarp_time_now_ms();
llarp::LogInfo(Name(), " IntroSet publish confirmed");
}
@ -712,7 +708,7 @@ namespace llarp
// pick another intro
MarkCurrentIntroBad();
ShiftIntroduction();
UpdateIntroSet();
// UpdateIntroSet();
return true;
}
@ -725,7 +721,7 @@ namespace llarp
return false;
PutIntroFor(msg->tag, path->intro);
EnsureReplyPath(msg->sender);
return true;
return ProcessDataMessage(msg);
}
bool
@ -890,13 +886,13 @@ namespace llarp
llarp::LogError("no convo tag");
return false;
}
Introduction intro;
Introduction remoteIntro;
const byte_t* K = nullptr;
for(const auto& tag : tags)
{
if(p == nullptr && GetIntroFor(tag, intro))
if(p == nullptr && GetIntroFor(tag, remoteIntro))
{
p = GetPathByRouter(intro.router);
p = GetPathByRouter(remoteIntro.router);
if(p)
{
f.T = tag;
@ -922,13 +918,13 @@ namespace llarp
f.S = GetSeqNoForConvo(f.T);
f.C.Zero();
transfer.Y.Randomize();
transfer.P = intro.pathID;
transfer.P = remoteIntro.pathID;
if(!f.EncryptAndSign(&Router()->crypto, m, K, m_Identity))
{
llarp::LogError("failed to encrypt and sign");
return false;
}
llarp::LogInfo(Name(), " send ", data.sz, " via ", intro);
llarp::LogInfo(Name(), " send ", data.sz, " via ", remoteIntro);
return p->SendRoutingMessage(&transfer, Router());
}
}
@ -980,11 +976,13 @@ namespace llarp
void
Endpoint::OutboundContext::ShiftIntroduction()
{
auto now = llarp_time_now_ms();
if(now - lastShift < MIN_SHIFT_INTERVAL)
return;
bool shifted = false;
for(const auto& intro : currentIntroSet.I)
{
if(!intro.router.IsZero())
m_Endpoint->EnsureRouterIsKnown(intro.router);
m_Endpoint->EnsureRouterIsKnown(intro.router);
if(m_BadIntros.count(intro) == 0 && remoteIntro != intro)
{
shifted = intro.router != remoteIntro.router;
@ -993,21 +991,23 @@ namespace llarp
}
}
if(shifted)
{
lastShift = now;
ManualRebuild(1);
}
}
void
Endpoint::SendContext::AsyncEncryptAndSendTo(PathID_t path,
llarp_buffer_t data,
Endpoint::SendContext::AsyncEncryptAndSendTo(llarp_buffer_t data,
ProtocolType protocol)
{
if(sequenceNo)
{
EncryptAndSendTo(path, data, protocol);
EncryptAndSendTo(data, protocol);
}
else
{
AsyncGenIntro(path, data, protocol);
AsyncGenIntro(data, protocol);
}
}
@ -1105,10 +1105,10 @@ namespace llarp
}
void
Endpoint::OutboundContext::AsyncGenIntro(PathID_t p, llarp_buffer_t payload,
Endpoint::OutboundContext::AsyncGenIntro(llarp_buffer_t payload,
ProtocolType t)
{
auto path = m_PathSet->GetPathByID(p);
auto path = m_PathSet->GetPathByRouter(remoteIntro.router);
if(path == nullptr)
return;
@ -1116,7 +1116,7 @@ namespace llarp
m_Endpoint->RouterLogic(), m_Endpoint->Crypto(), remoteIdent,
m_Endpoint->GetIdentity(), currentIntroSet.K, path->intro,
remoteIntro, m_DataHandler);
ex->hook = std::bind(&Endpoint::OutboundContext::Send, this, p,
ex->hook = std::bind(&Endpoint::OutboundContext::Send, this,
std::placeholders::_1);
ex->msg.PutBuffer(payload);
ex->msg.introReply = path->intro;
@ -1125,18 +1125,18 @@ namespace llarp
}
void
Endpoint::SendContext::Send(PathID_t p, ProtocolFrame& msg)
Endpoint::SendContext::Send(ProtocolFrame& msg)
{
auto path = m_PathSet->GetPathByID(p);
auto path = m_PathSet->GetPathByRouter(remoteIntro.router);
if(path)
{
llarp::LogInfo(m_Endpoint->Name(), " send via ", p);
routing::PathTransferMessage transfer(msg, remoteIntro.pathID);
if(!path->SendRoutingMessage(&transfer, m_Endpoint->Router()))
llarp::LogError("Failed to send frame on path");
}
else
llarp::LogError("cannot send becuase we have no path ", p);
llarp::LogError("cannot send becuase we have no path to ",
remoteIntro.router);
}
std::string
@ -1223,8 +1223,7 @@ namespace llarp
}
void
Endpoint::SendContext::EncryptAndSendTo(const PathID_t& p,
llarp_buffer_t payload,
Endpoint::SendContext::EncryptAndSendTo(llarp_buffer_t payload,
ProtocolType t)
{
std::set< ConvoTag > tags;
@ -1241,10 +1240,11 @@ namespace llarp
f.T = *tags.begin();
f.S = m_Endpoint->GetSeqNoForConvo(f.T);
auto path = m_PathSet->GetPathByID(p);
auto path = m_PathSet->GetPathByRouter(remoteIntro.router);
if(!path)
{
llarp::LogError("cannot encrypt and send: no path with rxid=", p);
llarp::LogError("cannot encrypt and send: no path for intro ",
remoteIntro);
return;
}

Loading…
Cancel
Save