make hop count and length configurable

pull/720/head
Jeff Becker 5 years ago
parent cdf02eae6e
commit f48754c45d
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -367,6 +367,7 @@ namespace libuv
{
if(m_UDP && m_UDP->tick)
m_UDP->tick(m_UDP);
gotpkts = false;
}
static int

@ -54,7 +54,7 @@ namespace llarp
bool
BaseSession::ShouldBuildMore(llarp_time_t now) const
{
const size_t expect = (1 + (m_NumPaths / 2));
const size_t expect = (1 + (numPaths / 2));
// check 30 seconds into the future and see if we need more paths
const llarp_time_t future = now + (30 * 1000) + buildIntervalLimit;
return NumPathsExistingAt(future) < expect && !BuildCooldownHit(now);
@ -248,7 +248,7 @@ namespace llarp
bool
BaseSession::IsReady() const
{
const size_t expect = (1 + (m_NumPaths / 2));
const size_t expect = (1 + (numPaths / 2));
return AvailablePaths(llarp::path::ePathRoleExit) >= expect;
}
@ -262,7 +262,7 @@ namespace llarp
BaseSession::UrgentBuild(llarp_time_t now) const
{
if(!IsReady())
return NumInStatus(path::ePathBuilding) < m_NumPaths;
return NumInStatus(path::ePathBuilding) < numPaths;
return path::Builder::UrgentBuild(now);
}

@ -153,7 +153,7 @@ namespace llarp
m_Exit = std::make_shared< llarp::exit::ExitSession >(
exitRouter,
util::memFn(&TunEndpoint::QueueInboundPacketForExit, this), router,
m_NumPaths, numHops, ShouldBundleRC());
numPaths, numHops, ShouldBundleRC());
llarp::LogInfo(Name(), " using exit at ", exitRouter);
}
if(k == "local-dns")

@ -183,7 +183,7 @@ namespace llarp
{
util::StatusObject obj{{"buildStats", m_BuildStats.ExtractStatus()},
{"numHops", uint64_t(numHops)},
{"numPaths", uint64_t(m_NumPaths)}};
{"numPaths", uint64_t(numPaths)}};
std::vector< util::StatusObject > pathObjs;
std::transform(m_Paths.begin(), m_Paths.end(),
std::back_inserter(pathObjs),

@ -8,7 +8,7 @@ namespace llarp
{
namespace path
{
PathSet::PathSet(size_t num) : m_NumPaths(num)
PathSet::PathSet(size_t num) : numPaths(num)
{
}
@ -17,10 +17,10 @@ namespace llarp
{
(void)now;
const auto building = NumInStatus(ePathBuilding);
if(building > m_NumPaths)
if(building > numPaths)
return false;
const auto established = NumInStatus(ePathEstablished);
return established <= m_NumPaths;
return established <= numPaths;
}
bool

@ -269,9 +269,9 @@ namespace llarp
}
}
protected:
size_t m_NumPaths;
size_t numPaths;
protected:
BuildStats m_BuildStats;
void

@ -38,7 +38,7 @@ namespace llarp
bool
Endpoint::SetOption(const std::string& k, const std::string& v)
{
return m_state->SetOption(k, v, Name());
return m_state->SetOption(k, v, *this);
}
llarp_ev_loop_ptr
@ -984,7 +984,7 @@ namespace llarp
/// TODO: V6
return HandleInboundPacket(tag, pkt, eProtocolTrafficV4);
},
Router(), m_NumPaths, numHops, false, ShouldBundleRC());
Router(), numPaths, numHops, false, ShouldBundleRC());
m_state->m_SNodeSessions.emplace(snode, std::make_pair(session, tag));
}
@ -1031,7 +1031,7 @@ namespace llarp
while(queue.size())
{
const auto& msg = queue.top();
llarp_buffer_t buf(msg->payload);
const llarp_buffer_t buf(msg->payload);
HandleInboundPacket(msg->tag, buf, msg->proto);
queue.pop();
}
@ -1069,7 +1069,7 @@ namespace llarp
const llarp_buffer_t& data, ProtocolType t)
{
// inbound converstation
auto now = Now();
const auto now = Now();
if(HasInboundConvo(remote))
{
@ -1209,7 +1209,7 @@ namespace llarp
return should
|| ( // try spacing tunnel builds out evenly in time
(dlt <= (path::default_lifetime / 4))
&& (NumInStatus(path::ePathBuilding) < m_NumPaths));
&& (NumInStatus(path::ePathBuilding) < numPaths));
}
std::shared_ptr< Logic >

@ -2,6 +2,7 @@
#include <exit/session.hpp>
#include <hook/shell.hpp>
#include <service/endpoint.hpp>
#include <service/outbound_context.hpp>
#include <util/str.hpp>
@ -11,8 +12,9 @@ namespace llarp
{
bool
EndpointState::SetOption(const std::string& k, const std::string& v,
const std::string& name)
Endpoint& ep)
{
const auto name = ep.Name();
if(k == "keyfile")
{
m_Keyfile = v;
@ -34,10 +36,36 @@ namespace llarp
}
if(k == "min-latency")
{
auto val = atoi(v.c_str());
const auto val = atoi(v.c_str());
if(val > 0)
m_MinPathLatency = val;
}
if(k == "paths")
{
const auto val = atoi(v.c_str());
if(val >= 1)
{
ep.numPaths = val;
LogInfo(name, " set number of hops to ", ep.numHops);
}
else
{
LogWarn(name, " invalid number of hops: ", v);
}
}
if(k == "hops")
{
const auto val = atoi(v.c_str());
if(val >= 1)
{
ep.numHops = val;
LogInfo(name, " set number of hops to ", ep.numHops);
}
else
{
LogWarn(name, " invalid number of hops: ", v);
}
}
if(k == "bundle-rc")
{
m_BundleRC = IsTrueValue(v.c_str());

@ -32,6 +32,7 @@ namespace llarp
{
struct IServiceLookup;
struct OutboundContext;
struct Endpoint;
struct EndpointState
{
@ -97,8 +98,7 @@ namespace llarp
std::unordered_map< Tag, CachedTagResult, Tag::Hash > m_PrefetchedTags;
bool
SetOption(const std::string& k, const std::string& v,
const std::string& name);
SetOption(const std::string& k, const std::string& v, Endpoint& ep);
util::StatusObject
ExtractStatus(util::StatusObject& obj) const;

@ -323,7 +323,7 @@ namespace llarp
return false;
const bool should =
(!(path::Builder::BuildCooldownHit(now)
|| path::Builder::NumInStatus(path::ePathBuilding) >= m_NumPaths))
|| path::Builder::NumInStatus(path::ePathBuilding) >= numPaths))
&& path::Builder::ShouldBuildMore(now);
if(!ReadyToSend())

@ -156,7 +156,8 @@ namespace llarp
T.Zero();
N.Zero();
Z.Zero();
R = 0;
R = 0;
version = LLARP_PROTO_VERSION;
}
bool

@ -25,12 +25,11 @@ namespace llarp
bool
SendContext::Send(const ProtocolFrame& msg, path::Path_ptr path)
{
auto transfer = std::make_shared< const routing::PathTransferMessage >(
msg, remoteIntro.pathID);
{
util::Lock lock(&m_SendQueueMutex);
m_SendQueue.emplace_back(transfer, path);
}
util::Lock lock(&m_SendQueueMutex);
m_SendQueue.emplace_back(
std::make_shared< const routing::PathTransferMessage >(
msg, remoteIntro.pathID),
path);
return true;
}
@ -46,7 +45,7 @@ namespace llarp
lastGoodSend = r->Now();
}
else
LogError("Failed to send frame on path");
LogError(m_Endpoint->Name(), " failed to send frame on path");
}
m_SendQueue.clear();
}
@ -57,30 +56,22 @@ namespace llarp
{
SharedSecret shared;
ProtocolFrame f;
f.C.Zero();
f.N.Randomize();
f.T = currentConvoTag;
f.S = ++sequenceNo;
auto now = m_Endpoint->Now();
if(remoteIntro.ExpiresSoon(now))
{
// shift intro
if(MarkCurrentIntroBad(now))
{
LogInfo("intro shifted");
}
}
auto path = m_PathSet->GetNewestPathByRouter(remoteIntro.router);
if(!path)
{
LogError("cannot encrypt and send: no path for intro ", remoteIntro);
LogError(m_Endpoint->Name(),
" cannot encrypt and send: no path for intro ", remoteIntro);
return;
}
if(!m_DataHandler->GetCachedSessionKeyFor(f.T, shared))
{
LogError("No cached session key");
LogError(m_Endpoint->Name(),
" has no cached session key on session T=", f.T);
return;
}
@ -96,7 +87,7 @@ namespace llarp
m.PutBuffer(payload);
if(!f.EncryptAndSign(m, shared, m_Endpoint->GetIdentity()))
{
LogError("failed to sign");
LogError(m_Endpoint->Name(), " failed to sign message");
return;
}
Send(f, path);
@ -106,14 +97,6 @@ namespace llarp
SendContext::AsyncEncryptAndSendTo(const llarp_buffer_t& data,
ProtocolType protocol)
{
auto now = m_Endpoint->Now();
if(remoteIntro.ExpiresSoon(now))
{
if(!ShiftIntroduction())
{
LogWarn("no good path yet, your message may drop");
}
}
if(lastGoodSend)
{
EncryptAndSendTo(data, protocol);

Loading…
Cancel
Save