start seperating tun and endpoint

pull/686/head
Jeff Becker 5 years ago
parent ef50c726b1
commit 64e9622270
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -18,8 +18,8 @@ namespace llarp
}
bool
HandleWriteIPPacket(const llarp_buffer_t &,
std::function< huint128_t(void) >) override
HandleIPPacket(const AlignedBuffer< 32 >, const llarp_buffer_t &,
bool) override
{
return true;
}
@ -35,18 +35,6 @@ namespace llarp
{
return false;
}
huint128_t
ObtainIPForAddr(const AlignedBuffer< 32 > &, bool) override
{
return {0};
}
bool
HasAddress(const AlignedBuffer< 32 > &) const override
{
return false;
}
};
} // namespace handlers
} // namespace llarp

@ -385,6 +385,8 @@ namespace llarp
context->ForEachService(
[&](const std::string &,
const std::shared_ptr< service::Endpoint > &service) -> bool {
if(!service->HasIfAddr())
return true;
huint128_t ip = service->GetIfAddr();
if(ip.h)
{

@ -81,25 +81,27 @@ namespace llarp
SetupNetworking() override;
/// overrides Endpoint
bool
HandleIPPacket(const AlignedBuffer< 32 > addr, const llarp_buffer_t& buf,
bool serviceNode) override
{
return HandleWriteIPPacket(buf, [=]() -> huint128_t {
return ObtainIPForAddr(addr, serviceNode);
});
}
/// handle inbound traffic
bool
HandleWriteIPPacket(const llarp_buffer_t& buf,
std::function< huint128_t(void) > getFromIP) override;
std::function< huint128_t(void) > getFromIP);
/// queue outbound packet to the world
bool
QueueOutboundTraffic(llarp::net::IPPacket&& pkt);
/// we have a resolvable ip address
bool
HasIfAddr() const override
{
return true;
}
/// get the local interface's address
huint128_t
GetIfAddr() const override;
GetIfAddr() const;
bool
HasLocalIP(const huint128_t& ip) const;
@ -142,15 +144,14 @@ namespace llarp
}
bool
HasAddress(const AlignedBuffer< 32 >& addr) const override
HasAddress(const AlignedBuffer< 32 >& addr) const
{
return m_AddrToIP.find(addr) != m_AddrToIP.end();
}
/// get ip address for key unconditionally
huint128_t
ObtainIPForAddr(const AlignedBuffer< 32 >& addr,
bool serviceNode) override;
ObtainIPForAddr(const AlignedBuffer< 32 >& addr, bool serviceNode);
/// flush network traffic
void

@ -161,7 +161,6 @@ struct llarp_nodedb
void
SaveAll() LOCKS_EXCLUDED(access);
};
/// struct for async rc verification

@ -138,6 +138,7 @@ namespace llarp
ctx.router->PersistSessionUntil(remote, ctx.path->ExpireTime());
// add own path
ctx.router->pathContext().AddOwnPath(ctx.pathset, ctx.path);
ctx.pathset->PathBuildStarted(ctx.path);
}
else
LogError(ctx.pathset->Name(), " failed to send LRCM to ", remote);
@ -166,12 +167,17 @@ namespace llarp
if(ShouldBuildMore(now))
BuildOne();
TickPaths(now, router);
if(m_BuildStats.SuccsessRatio() <= BuildStats::MinGoodRatio)
{
LogWarn(Name(), " has a low path build success. ", m_BuildStats);
}
}
util::StatusObject
Builder::ExtractStatus() const
{
util::StatusObject obj{{"numHops", uint64_t(numHops)},
util::StatusObject obj{{"buildStats", m_BuildStats.ExtractStatus()},
{"numHops", uint64_t(numHops)},
{"numPaths", uint64_t(m_NumPaths)}};
std::vector< util::StatusObject > pathObjs;
std::transform(m_Paths.begin(), m_Paths.end(),
@ -425,6 +431,7 @@ namespace llarp
buildIntervalLimit = MIN_PATH_BUILD_INTERVAL;
router->routerProfiling().MarkPathSuccess(p.get());
LogInfo(p->Name(), " built latency=", p->intro.latency);
m_BuildStats.success++;
}
void

@ -288,6 +288,43 @@ namespace llarp
PathSet::HandlePathBuildTimeout(Path_ptr p)
{
LogWarn(Name(), " path build ", p->HopsString(), " timed out");
m_BuildStats.timeouts++;
}
void
PathSet::PathBuildStarted(Path_ptr p)
{
LogInfo(Name(), " path build ", p->HopsString(), " started");
m_BuildStats.attempts++;
}
util::StatusObject
BuildStats::ExtractStatus() const
{
return util::StatusObject{{"success", success},
{"attempts", attempts},
{"timeouts", timeouts},
{"fails", fails}};
}
std::string
BuildStats::ToString() const
{
std::stringstream ss;
ss << SuccsessRatio() << " percent success ";
ss << "(success=" << success << " ";
ss << "attempts=" << attempts << " ";
ss << "timeouts=" << timeouts << " ";
ss << "fails=" << fails << ")";
return ss.str();
}
double
BuildStats::SuccsessRatio() const
{
if(attempts)
return success / attempts;
return 0;
}
bool

@ -38,6 +38,32 @@ namespace llarp
ePathExpired
};
/// Stats about all our path builds
struct BuildStats
{
static constexpr double MinGoodRatio = 0.25;
uint64_t attempts = 0;
uint64_t success = 0;
uint64_t fails = 0;
uint64_t timeouts = 0;
util::StatusObject
ExtractStatus() const;
double
SuccsessRatio() const;
std::string
ToString() const;
friend std::ostream&
operator<<(std::ostream& o, const BuildStats& st)
{
return o << st.ToString();
}
};
/// the role of this path can fulfill
using PathRole = int;
@ -99,6 +125,9 @@ namespace llarp
virtual void
HandlePathBuildTimeout(Path_ptr path);
virtual void
PathBuildStarted(Path_ptr path);
/// a path died now what?
virtual void
HandlePathDied(Path_ptr path) = 0;
@ -243,6 +272,8 @@ namespace llarp
protected:
size_t m_NumPaths;
BuildStats m_BuildStats;
void
TickPaths(llarp_time_t now, AbstractRouter* r);

@ -152,29 +152,6 @@ namespace llarp
return m_Endpoints.size() ? true : false;
}
bool
Context::FindBestAddressFor(const AlignedBuffer< 32 > &addr, bool isSNode,
huint128_t &ip)
{
auto itr = m_Endpoints.begin();
while(itr != m_Endpoints.end())
{
if(itr->second->HasAddress(addr))
{
ip = itr->second->ObtainIPForAddr(addr, isSNode);
return true;
}
++itr;
}
itr = m_Endpoints.find("default");
if(itr != m_Endpoints.end())
{
ip = itr->second->ObtainIPForAddr(addr, isSNode);
return true;
}
return false;
}
bool
Context::AddDefaultEndpoint(
const std::unordered_multimap< std::string, std::string > &opts)

@ -31,10 +31,6 @@ namespace llarp
bool
hasEndpoints();
bool
FindBestAddressFor(const AlignedBuffer< 32 > &addr, bool isSNode,
huint128_t &);
/// function visitor returns false to prematurely break iteration
void
ForEachService(
@ -59,7 +55,7 @@ namespace llarp
StartAll();
private:
AbstractRouter *m_Router;
AbstractRouter *const m_Router;
std::unordered_map< std::string, std::shared_ptr< Endpoint > >
m_Endpoints;
std::list< std::shared_ptr< Endpoint > > m_Stopped;

@ -402,9 +402,9 @@ namespace llarp
auto itr = m_Sessions.find(tag);
if(itr == m_Sessions.end())
{
itr = m_Sessions.emplace(tag, Session{}).first;
itr->second.inbound = inbound;
itr->second.remote = info;
itr = m_Sessions.emplace(tag, Session{}).first;
itr->second.inbound = inbound;
itr->second.remote = info;
}
itr->second.lastUsed = Now();
}
@ -797,12 +797,9 @@ namespace llarp
if(path && path->SendRoutingMessage(msg, m_Router))
{
LogInfo(Name(), " looking up ", router);
m_PendingRouters.emplace(router, RouterLookupJob(this, handler));
return true;
}
else
LogError("failed to send request for router lookup");
}
return false;
}
@ -839,15 +836,15 @@ namespace llarp
PutSenderFor(msg->tag, msg->sender, true);
PutReplyIntroFor(msg->tag, path->intro);
Introduction intro;
intro.pathID = from;
intro.router = PubKey(path->Endpoint());
intro.pathID = from;
intro.router = PubKey(path->Endpoint());
intro.expiresAt = std::min(path->ExpireTime(), msg->introReply.expiresAt);
PutIntroFor(msg->tag, intro);
return ProcessDataMessage(msg);
}
bool
Endpoint::HasPathToSNode(const RouterID& ident) const
Endpoint::HasPathToSNode(const RouterID ident) const
{
auto range = m_SNodeSessions.equal_range(ident);
auto itr = range.first;
@ -963,7 +960,7 @@ namespace llarp
}
bool
Endpoint::EnsurePathToService(const Address& remote, PathEnsureHook hook,
Endpoint::EnsurePathToService(const Address remote, PathEnsureHook hook,
ABSL_ATTRIBUTE_UNUSED llarp_time_t timeoutMS,
bool randomPath)
{
@ -1009,16 +1006,16 @@ namespace llarp
}
void
Endpoint::EnsurePathToSNode(const RouterID& snode, SNodeEnsureHook h)
Endpoint::EnsurePathToSNode(const RouterID snode, SNodeEnsureHook h)
{
using namespace std::placeholders;
if(m_SNodeSessions.count(snode) == 0)
{
auto themIP = ObtainIPForAddr(snode, true);
auto session = std::make_shared< exit::SNodeSession >(
snode,
std::bind(&Endpoint::HandleWriteIPPacket, this, _1,
[themIP]() -> huint128_t { return themIP; }),
[=](const llarp_buffer_t& pkt) -> bool {
return HandleIPPacket(snode, pkt, true);
},
m_Router, m_NumPaths, numHops, false, ShouldBundleRC());
m_SNodeSessions.emplace(snode, session);
}
@ -1064,9 +1061,7 @@ namespace llarp
{
const auto& msg = m_InboundTrafficQueue.top();
llarp_buffer_t buf(msg->payload);
HandleWriteIPPacket(buf, [&]() -> huint128_t {
return ObtainIPForAddr(msg->sender.Addr(), false);
});
HandleIPPacket(msg->sender.Addr(), buf, false);
m_InboundTrafficQueue.pop();
}
});

@ -84,7 +84,7 @@ namespace llarp
virtual huint128_t
GetIfAddr() const
{
return huint128_t{0};
return {0};
}
virtual void
@ -148,11 +148,11 @@ namespace llarp
HandleHiddenServiceFrame(path::Path_ptr p,
const service::ProtocolFrame& msg);
virtual huint128_t
ObtainIPForAddr(const AlignedBuffer< 32 >& addr, bool serviceNode) = 0;
// virtual huint128_t
// ObtainIPForAddr(const AlignedBuffer< 32 >& addr, bool serviceNode) = 0;
virtual bool
HasAddress(const AlignedBuffer< 32 >& addr) const = 0;
// virtual bool
// HasServiceAddress(const AlignedBuffer< 32 >& addr) const = 0;
/// return true if we have a pending job to build to a hidden service but
/// it's not done yet
@ -169,8 +169,12 @@ namespace llarp
std::shared_ptr< ProtocolMessage > msg) override;
virtual bool
HandleWriteIPPacket(const llarp_buffer_t& pkt,
std::function< huint128_t(void) > getFromIP) = 0;
HandleIPPacket(const AlignedBuffer< 32 > addr, const llarp_buffer_t& pkt,
bool serviceNode) = 0;
// virtual bool
// HandleWriteIPPacket(const llarp_buffer_t& pkt,
// std::function< huint128_t(void) > getFromIP) = 0;
bool
ProcessDataMessage(std::shared_ptr< ProtocolMessage > msg);
@ -237,22 +241,22 @@ namespace llarp
/// return false if we have already called this function before for this
/// address
bool
EnsurePathToService(const Address& remote, PathEnsureHook h,
EnsurePathToService(const Address remote, PathEnsureHook h,
uint64_t timeoutMS, bool lookupOnRandomPath = false);
using SNodeEnsureHook =
std::function< void(RouterID, exit::BaseSession_ptr) >;
std::function< void(const RouterID, exit::BaseSession_ptr) >;
/// ensure a path to a service node by public key
void
EnsurePathToSNode(const RouterID& remote, SNodeEnsureHook h);
EnsurePathToSNode(const RouterID remote, SNodeEnsureHook h);
/// return true if this endpoint is trying to lookup this router right now
bool
HasPendingRouterLookup(const RouterID remote) const;
bool
HasPathToSNode(const RouterID& remote) const;
HasPathToSNode(const RouterID remote) const;
void
PutSenderFor(const ConvoTag& tag, const ServiceInfo& info,
@ -292,9 +296,6 @@ namespace llarp
GetConvoTagsForService(const Address& si,
std::set< ConvoTag >& tag) const override;
void
PutNewOutboundContext(const IntroSet& introset);

@ -321,15 +321,17 @@ namespace llarp
{
if(markedBad)
return false;
const bool should = (!(path::Builder::BuildCooldownHit(now) ||path::Builder::NumInStatus(path::ePathBuilding) >= m_NumPaths)) && path::Builder::ShouldBuildMore(now);
const bool should =
(!(path::Builder::BuildCooldownHit(now)
|| path::Builder::NumInStatus(path::ePathBuilding) >= m_NumPaths))
&& path::Builder::ShouldBuildMore(now);
if(!ReadyToSend())
{
return should;
}
llarp_time_t t = 0;
ForEachPath([&t](path::Path_ptr path)
{
ForEachPath([&t](path::Path_ptr path) {
if(path->IsReady())
t = std::max(path->ExpireTime(), t);
});

@ -345,7 +345,7 @@ namespace llarp
self->msg->handler = self->handler;
std::shared_ptr< ProtocolMessage > msg = std::move(self->msg);
path::Path_ptr path = std::move(self->path);
const PathID_t from = self->frame.F;
const PathID_t from = self->frame.F;
self->logic->queue_func(
[=]() { ProtocolMessage::ProcessAsync(path, from, msg); });
delete self;
@ -407,7 +407,7 @@ namespace llarp
LogError("failed to decrypt message");
return false;
}
msg->handler = handler;
msg->handler = handler;
const PathID_t from = F;
logic->queue_func(
[=]() { ProtocolMessage::ProcessAsync(recvPath, from, msg); });

@ -63,7 +63,8 @@ namespace llarp
PutBuffer(const llarp_buffer_t& payload);
static void
ProcessAsync(path::Path_ptr p, PathID_t from, std::shared_ptr< ProtocolMessage > self);
ProcessAsync(path::Path_ptr p, PathID_t from,
std::shared_ptr< ProtocolMessage > self);
bool
operator<(const ProtocolMessage& other) const

@ -21,7 +21,7 @@ namespace llarp
EnsurePrivateFile(fs::path pathname)
{
const auto str = pathname.string();
errno = 0;
errno = 0;
error_code_t ec = errno_error();
if(fs::exists(pathname, ec)) // file exists
{
@ -31,13 +31,13 @@ namespace llarp
auto perms = st.permissions();
if((perms & fs::perms::others_exec) != fs::perms::none)
perms ^= fs::perms::others_exec;
if((perms & fs::perms::others_write) != fs::perms::none)
if((perms & fs::perms::others_write) != fs::perms::none)
perms ^= fs::perms::others_write;
if((perms & fs::perms::others_write) != fs::perms::none)
if((perms & fs::perms::others_write) != fs::perms::none)
perms ^= fs::perms::others_write;
if((perms & fs::perms::group_read) != fs::perms::none)
if((perms & fs::perms::group_read) != fs::perms::none)
perms ^= fs::perms::group_read;
if((perms & fs::perms::others_read) != fs::perms::none)
if((perms & fs::perms::others_read) != fs::perms::none)
perms ^= fs::perms::others_read;
if((perms & fs::perms::owner_exec) != fs::perms::none)
perms ^= fs::perms::owner_exec;

@ -82,7 +82,7 @@ namespace llarp
{
OnLinkEstablished(p);
metrics::integerTick("utp.session.open", "to", 1, "id",
RouterID(remoteRC.pubkey).ToString());
RouterID(remoteRC.pubkey).ToString());
OutboundHandshake();
}
@ -592,7 +592,7 @@ namespace llarp
if(remoteRC.IsPublicRouter())
{
metrics::integerTick("utp.session.close", "to", 1, "id",
RouterID(remoteRC.pubkey).ToString());
RouterID(remoteRC.pubkey).ToString());
}
}
}

Loading…
Cancel
Save