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> 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) 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 Standards-Version: 3.9.6
Homepage: http://loki.network/ Homepage: https://loki.network/
Vcs-Git: git://github.com/loki-project/lokinet-builder.git Vcs-Git: git://github.com/loki-project/lokinet-builder.git
Vcs-Browser: https://github.com/loki-project/lokinet-builder Vcs-Browser: https://github.com/loki-project/lokinet-builder

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

2
debian/postinst vendored

@ -1,3 +1,3 @@
#!/bin/sh -e #!/bin/sh -e
setcap cap_net_admin,cap_net_bind_service=+eip /usr/bin/lokinet || echo "failed to setcap lokinet" 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 bool
LR_CommitMessage::HandleMessage(AbstractRouter* router) const 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(), llarp::LogError("LRCM invalid number of records, ", frames.size(),
"!=", MAXHOPS); "!=", path::max_len);
return false; return false;
} }
if(!router->pathContext().AllowingTransit()) if(!router->pathContext().AllowingTransit())

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

@ -21,15 +21,6 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #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 namespace llarp
{ {
class Logic; class Logic;
@ -40,6 +31,23 @@ namespace llarp
namespace path 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 struct TransitHopInfo
{ {
TransitHopInfo() = default; TransitHopInfo() = default;
@ -153,7 +161,7 @@ namespace llarp
ShortHash nonceXOR; ShortHash nonceXOR;
llarp_time_t started = 0; llarp_time_t started = 0;
// 10 minutes default // 10 minutes default
llarp_time_t lifetime = DEFAULT_PATH_LIFETIME; llarp_time_t lifetime = default_lifetime;
llarp_proto_version_t version; llarp_proto_version_t version;
llarp_time_t m_LastActivity = 0; llarp_time_t m_LastActivity = 0;
@ -288,7 +296,7 @@ namespace llarp
/// nonce for key exchange /// nonce for key exchange
TunnelNonce nonce; TunnelNonce nonce;
// lifetime // lifetime
llarp_time_t lifetime = DEFAULT_PATH_LIFETIME; llarp_time_t lifetime = default_lifetime;
~PathHopConfig(); ~PathHopConfig();
PathHopConfig(); PathHopConfig();

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

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

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

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

@ -152,9 +152,10 @@ namespace llarp
for(const auto& intro : I) for(const auto& intro : I)
{ {
if(intro.expiresAt > now 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; return false;
else if(W == nullptr) else if(W == nullptr)
{ {

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

@ -31,7 +31,7 @@ namespace llarp
{ {
/// minimum interval for publishing introsets /// minimum interval for publishing introsets
static const llarp_time_t INTROSET_PUBLISH_INTERVAL = 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; static const llarp_time_t INTROSET_PUBLISH_RETRY_INTERVAL = 5000;
@ -586,7 +586,7 @@ namespace llarp
bool bool
IsExpired(llarp_time_t now, 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) if(now <= lastUsed)
return false; return false;

@ -42,10 +42,10 @@ TEST_F(HiddenServiceTest, TestGenerateIntroSet)
while(I.I.size() < 10) while(I.I.size() < 10)
{ {
llarp::service::Introduction intro; llarp::service::Introduction intro;
intro.expiresAt = now + (DEFAULT_PATH_LIFETIME / 2); intro.expiresAt = now + (llarp::path::default_lifetime / 2);
intro.router.Randomize(); intro.router.Randomize();
intro.pathID.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(ident.SignIntroSet(I, Crypto(), now));
ASSERT_TRUE(I.Verify(Crypto(), now)); ASSERT_TRUE(I.Verify(Crypto(), now));

Loading…
Cancel
Save