pull/489/head
Jeff Becker 5 years ago
parent 4764e42669
commit c910a2a2fb
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

2
debian/control vendored

@ -4,7 +4,7 @@ Priority: optional
Maintainer: Jeff Becker (probably not evil) <jeff@i2p.rocks>
Build-Depends: debhelper (>= 9), dpkg-dev (>= 1.17.2~), gcc (>= 4.7) | clang (>= 3.3), cmake (>= 3.0), libcap-dev (>= 2.25)
Standards-Version: 3.9.6
Homepage: http://loki.network/
Homepage: https://loki.network/
Vcs-Git: git://github.com/loki-project/lokinet-builder.git
Vcs-Browser: https://github.com/loki-project/lokinet-builder

@ -1,7 +1,7 @@
[Unit]
Description=LokiNET: Anonymous Network layer thingydoo.
Wants=network.target
After=network.target
Wants=network-online.target
After=network-online.target
[Service]
User=debian-lokinet

2
debian/postinst vendored

@ -1,3 +1,3 @@
#!/bin/sh -e
setcap cap_net_admin,cap_net_bind_service=+eip /usr/bin/lokinet || echo "failed to setcap lokinet"
adduser --quiet --system --home /var/lib/lokinet debian-lokinet
adduser --quiet --system --home /var/lib/lokinet debian-lokinet || echo "debian-lokinet user not added"

@ -63,10 +63,10 @@ namespace llarp
bool
LR_CommitMessage::HandleMessage(AbstractRouter* router) const
{
if(frames.size() != MAXHOPS)
if(frames.size() != path::max_len)
{
llarp::LogError("LRCM invalid number of records, ", frames.size(),
"!=", MAXHOPS);
"!=", path::max_len);
return false;
}
if(!router->pathContext().AllowingTransit())

@ -548,7 +548,7 @@ namespace llarp
if(now >= buildStarted)
{
auto dlt = now - buildStarted;
if(dlt >= PATH_BUILD_TIMEOUT)
if(dlt >= path::build_timeout)
{
r->routerProfiling().MarkPathFail(this);
EnterState(ePathTimeout, now);
@ -561,7 +561,7 @@ namespace llarp
if(_status == ePathEstablished)
{
auto dlt = now - m_LastLatencyTestTime;
if(dlt > 5000 && m_LastLatencyTestID == 0)
if(dlt > path::latency_interval && m_LastLatencyTestID == 0)
{
routing::PathLatencyMessage latency;
latency.T = randint();
@ -573,7 +573,7 @@ namespace llarp
if(SupportsAnyRoles(ePathRoleExit | ePathRoleSVC))
{
if(m_LastRecvMessage && now > m_LastRecvMessage
&& now - m_LastRecvMessage > PATH_ALIVE_TIMEOUT)
&& now - m_LastRecvMessage > path::alive_timeout)
{
// TODO: send close exit message
// r->routerProfiling().MarkPathFail(this);
@ -590,7 +590,7 @@ namespace llarp
EnterState(ePathTimeout, now);
}
}
else if(dlt >= PATH_ALIVE_TIMEOUT && m_LastRecvMessage == 0)
else if(dlt >= path::alive_timeout && m_LastRecvMessage == 0)
{
r->routerProfiling().MarkPathFail(this);
EnterState(ePathTimeout, now);
@ -704,11 +704,11 @@ namespace llarp
N.Randomize();
buf.sz = buf.cur - buf.base;
// pad smaller messages
if(buf.sz < MESSAGE_PAD_SIZE)
if(buf.sz < pad_size)
{
// randomize padding
r->crypto()->randbytes(buf.cur, MESSAGE_PAD_SIZE - buf.sz);
buf.sz = MESSAGE_PAD_SIZE;
r->crypto()->randbytes(buf.cur, pad_size - buf.sz);
buf.sz = pad_size;
}
buf.cur = buf.base;
return HandleUpstream(buf, N, r);

@ -21,15 +21,6 @@
#include <unordered_map>
#include <vector>
#define MAXHOPS (8)
#ifndef DEFAULT_HOP_LENGTH
#define DEFAULT_HOP_LENGTH (4)
#endif
#define DEFAULT_PATH_LIFETIME (10 * 60 * 1000)
#define PATH_BUILD_TIMEOUT (15 * 1000)
#define MESSAGE_PAD_SIZE (128)
#define PATH_ALIVE_TIMEOUT (60 * 1000)
namespace llarp
{
class Logic;
@ -40,6 +31,23 @@ namespace llarp
namespace path
{
/// maximum path length
constexpr size_t max_len = 8;
/// default path length
constexpr size_t default_len = 4;
/// pad messages to the nearest this many bytes
constexpr size_t pad_size = 128;
/// default path lifetime in ms
constexpr llarp_time_t default_lifetime = 10 * 60 * 1000;
/// after this many ms a path build times out
constexpr llarp_time_t build_timeout = 15000;
/// measure latency every this interval ms
constexpr llarp_time_t latency_interval = 5000;
/// if a path is inactive for this amount of time it's dead
constexpr llarp_time_t alive_timeout = 60000;
struct TransitHopInfo
{
TransitHopInfo() = default;
@ -153,7 +161,7 @@ namespace llarp
ShortHash nonceXOR;
llarp_time_t started = 0;
// 10 minutes default
llarp_time_t lifetime = DEFAULT_PATH_LIFETIME;
llarp_time_t lifetime = default_lifetime;
llarp_proto_version_t version;
llarp_time_t m_LastActivity = 0;
@ -288,7 +296,7 @@ namespace llarp
/// nonce for key exchange
TunnelNonce nonce;
// lifetime
llarp_time_t lifetime = DEFAULT_PATH_LIFETIME;
llarp_time_t lifetime = default_lifetime;
~PathHopConfig();
PathHopConfig();

@ -139,7 +139,7 @@ namespace llarp
result = func;
worker = pool;
for(size_t idx = 0; idx < MAXHOPS; ++idx)
for(size_t idx = 0; idx < path::max_len; ++idx)
{
LRCM.frames[idx].Randomize();
}
@ -207,18 +207,20 @@ namespace llarp
RouterContact& cur, size_t hop, PathRole roles)
{
(void)roles;
size_t tries = 10;
size_t tries = 10;
if(hop == 0)
{
if(router->NumberOfConnectedRouters() == 0)
return false;
bool got = false;
router->ForEachPeer([&](const ILinkSession * s, bool ) {
if(got || router->IsBootstrapNode(s->GetPubKey()))
return;
cur = s->GetRemoteRC();
got = true;
}, true);
router->ForEachPeer(
[&](const ILinkSession* s, bool) {
if(got || router->IsBootstrapNode(s->GetPubKey()))
return;
cur = s->GetRemoteRC();
got = true;
},
true);
return got;
}
std::set< RouterID > exclude = {prev.pubkey};

@ -76,10 +76,10 @@ namespace llarp
N.Randomize();
buf.sz = buf.cur - buf.base;
// pad to nearest MESSAGE_PAD_SIZE bytes
auto dlt = buf.sz % MESSAGE_PAD_SIZE;
auto dlt = buf.sz % pad_size;
if(dlt)
{
dlt = MESSAGE_PAD_SIZE - dlt;
dlt = pad_size - dlt;
// randomize padding
r->crypto()->randbytes(buf.cur, dlt);
buf.sz += dlt;

@ -59,7 +59,7 @@ namespace llarp
RouterProfile::Tick()
{
// 5 minutes
static constexpr llarp_time_t updateInterval = DEFAULT_PATH_LIFETIME / 2;
static constexpr llarp_time_t updateInterval = path::default_lifetime / 2;
auto now = llarp::time_now_ms();
if(lastUpdated < now && now - lastUpdated > updateInterval)
{
@ -71,10 +71,10 @@ namespace llarp
RouterProfile::IsGood(uint64_t chances) const
{
if(connectTimeoutCount > chances)
return connectTimeoutCount <= connectGoodCount
&& (pathSuccessCount * chances) >= pathFailCount;
else
return (pathSuccessCount * chances) >= pathFailCount;
return connectTimeoutCount < connectGoodCount
&& (pathSuccessCount * chances) > pathFailCount;
chances /= 2;
return (pathSuccessCount * chances) > pathFailCount;
}
bool

@ -374,18 +374,18 @@ namespace llarp
}
void
Router::ForEachPeer(
std::function< void(const ILinkSession *, bool) > visit, bool randomize) const
Router::ForEachPeer(std::function< void(const ILinkSession *, bool) > visit,
bool randomize) const
{
for(const auto &link : outboundLinks)
{
link->ForEachSession(
[visit](const ILinkSession *peer) { visit(peer, true); }, randomize);
[visit](const ILinkSession *peer) { visit(peer, true); }, randomize);
}
for(const auto &link : inboundLinks)
{
link->ForEachSession(
[visit](const ILinkSession *peer) { visit(peer, false); }, randomize);
[visit](const ILinkSession *peer) { visit(peer, false); }, randomize);
}
}
@ -1047,14 +1047,14 @@ namespace llarp
bool
Router::IsBootstrapNode(RouterID r) const
{
for(const auto & rc : bootstrapRCList)
for(const auto &rc : bootstrapRCList)
{
if(rc.pubkey == r)
return true;
}
return false;
}
void
Router::Tick()
{
@ -1082,19 +1082,13 @@ namespace llarp
});
}
// kill dead nodes
std::set< RouterID > removed;
nodedb()->RemoveIf([&](const RouterContact &rc) -> bool {
if(!routerProfiling().IsBad(rc.pubkey))
return false;
routerProfiling().ClearProfile(rc.pubkey);
removed.insert(rc.pubkey);
return true;
});
// request killed nodes 1 time
for(const auto &pk : removed)
LookupRouter(pk);
paths.TickPaths(now);
paths.ExpirePaths(now);
@ -1492,7 +1486,6 @@ namespace llarp
LogInfo("initalized service node: ", us);
if(minConnectedRouters < 6)
minConnectedRouters = 6;
}
else
{
@ -1676,7 +1669,7 @@ namespace llarp
&& !(self->HasSessionTo(other.pubkey)
|| self->HasPendingConnectJob(other.pubkey)))
{
for(const auto & rc : self->bootstrapRCList)
for(const auto &rc : self->bootstrapRCList)
{
if(rc.pubkey == other.pubkey)
return want > 0;

@ -152,9 +152,10 @@ namespace llarp
for(const auto& intro : I)
{
if(intro.expiresAt > now
&& intro.expiresAt - now > DEFAULT_PATH_LIFETIME)
&& intro.expiresAt - now > path::default_lifetime)
{
if(W && intro.expiresAt - W->extendedLifetime > DEFAULT_PATH_LIFETIME)
if(W
&& intro.expiresAt - W->extendedLifetime > path::default_lifetime)
return false;
else if(W == nullptr)
{

@ -21,7 +21,7 @@ namespace llarp
{
Endpoint::Endpoint(const std::string& name, AbstractRouter* r,
Context* parent)
: path::Builder(r, r->dht(), 3, DEFAULT_HOP_LENGTH)
: path::Builder(r, r->dht(), 3, path::default_len)
, context(parent)
, m_Router(r)
, m_Name(name)
@ -729,16 +729,16 @@ namespace llarp
// make sure we have all paths that are established
// in our introset
bool should = false;
ForEachPath([&](const path::Path *p) {
if(!p->IsReady())
return;
for(const auto & i : m_IntroSet.I)
{
if(i == p->intro)
return;
}
should = true;
});
ForEachPath([&](const path::Path* p) {
if(!p->IsReady())
return;
for(const auto& i : m_IntroSet.I)
{
if(i == p->intro)
return;
}
should = true;
});
if(m_IntroSet.HasExpiredIntros(now) || should)
return now - m_LastPublishAttempt >= INTROSET_PUBLISH_RETRY_INTERVAL;
return now - m_LastPublishAttempt >= INTROSET_PUBLISH_INTERVAL;
@ -866,7 +866,8 @@ namespace llarp
job->hook = nullptr;
job->rc = msg->R[0];
llarp_nodedb_async_verify(job);
router->routerProfiling().MarkSuccess(msg->R[0].pubkey);
const RouterID k(msg->R[0].pubkey);
m_Router->routerProfiling().MarkSuccess(k);
m_PendingRouters.erase(itr);
return true;
}
@ -1137,7 +1138,7 @@ namespace llarp
bool
Endpoint::CheckPathIsDead(path::Path*, llarp_time_t dlt)
{
return dlt > 20000;
return dlt > path::alive_timeout;
}
bool
@ -1242,7 +1243,7 @@ namespace llarp
Endpoint::OutboundContext::OutboundContext(const IntroSet& introset,
Endpoint* parent)
: path::Builder(parent->m_Router, parent->m_Router->dht(), 3,
DEFAULT_HOP_LENGTH)
path::default_len)
, SendContext(introset.A, {}, this, parent)
, currentIntroSet(introset)
@ -1251,10 +1252,7 @@ namespace llarp
for(const auto intro : introset.I)
{
if(intro.expiresAt > m_NextIntro.expiresAt)
{
m_NextIntro = intro;
remoteIntro = intro;
}
}
}
@ -1875,7 +1873,7 @@ namespace llarp
auto itr = m_BadIntros.begin();
while(itr != m_BadIntros.end())
{
if(now - itr->second > DEFAULT_PATH_LIFETIME)
if(now - itr->second > path::default_lifetime)
itr = m_BadIntros.erase(itr);
else
++itr;
@ -1917,15 +1915,14 @@ namespace llarp
RouterContact& cur, size_t hop,
llarp::path::PathRole roles)
{
if(m_NextIntro.router.IsZero())
if(remoteIntro.router.IsZero())
{
llarp::LogError("intro is not set, cannot select hops");
return false;
SwapIntros();
}
if(hop == numHops - 1)
{
m_Endpoint->EnsureRouterIsKnown(m_NextIntro.router);
if(db->Get(m_NextIntro.router, cur))
m_Endpoint->EnsureRouterIsKnown(remoteIntro.router);
if(db->Get(remoteIntro.router, cur))
return true;
++m_BuildFails;
return false;
@ -1933,7 +1930,7 @@ namespace llarp
else if(hop == numHops - 2)
{
return db->select_random_hop_excluding(
cur, {prev.pubkey, m_NextIntro.router});
cur, {prev.pubkey, remoteIntro.router});
}
return path::Builder::SelectHop(db, prev, cur, hop, roles);
}
@ -1971,7 +1968,7 @@ namespace llarp
auto dlt = now - intro.expiresAt;
return should
|| ( // try spacing tunnel builds out evenly in time
(dlt < (DEFAULT_PATH_LIFETIME / 2))
(dlt < (path::default_lifetime / 2))
&& (NumInStatus(path::ePathBuilding) < m_NumPaths)
&& (dlt > buildIntervalLimit));
}

@ -31,7 +31,7 @@ namespace llarp
{
/// minimum interval for publishing introsets
static const llarp_time_t INTROSET_PUBLISH_INTERVAL =
DEFAULT_PATH_LIFETIME / 8;
path::default_lifetime / 8;
static const llarp_time_t INTROSET_PUBLISH_RETRY_INTERVAL = 5000;
@ -586,7 +586,7 @@ namespace llarp
bool
IsExpired(llarp_time_t now,
llarp_time_t lifetime = (DEFAULT_PATH_LIFETIME * 2)) const
llarp_time_t lifetime = (path::default_lifetime * 2)) const
{
if(now <= lastUsed)
return false;

@ -42,10 +42,10 @@ TEST_F(HiddenServiceTest, TestGenerateIntroSet)
while(I.I.size() < 10)
{
llarp::service::Introduction intro;
intro.expiresAt = now + (DEFAULT_PATH_LIFETIME / 2);
intro.expiresAt = now + (llarp::path::default_lifetime / 2);
intro.router.Randomize();
intro.pathID.Randomize();
I.I.push_back(intro);
I.I.emplace_back(std::move(intro));
}
ASSERT_TRUE(ident.SignIntroSet(I, Crypto(), now));
ASSERT_TRUE(I.Verify(Crypto(), now));

Loading…
Cancel
Save