Merge branch 'master' of ssh://github.com/majestrate/loki-network

pull/453/head
Jeff 5 years ago
commit 6e9fa786af

@ -25,6 +25,8 @@
#include <link/utp_internal.hpp> #include <link/utp_internal.hpp>
#include <util/metrics.hpp>
namespace llarp namespace llarp
{ {
namespace utp namespace utp
@ -85,6 +87,8 @@ namespace llarp
ssize_t s = utp_writev(sock, vecs.data(), vecs.size()); ssize_t s = utp_writev(sock, vecs.data(), vecs.size());
if(s < 0) if(s < 0)
return; return;
METRICS_DYNAMIC_INT_UPDATE(
"utp.session.tx", RouterID(remoteRC.pubkey).ToString().c_str(), s);
m_TXRate += s; m_TXRate += s;
size_t sz = s; size_t sz = s;
while(vecq.size() && sz >= vecq.front().iov_len) while(vecq.size() && sz >= vecq.front().iov_len)
@ -178,6 +182,9 @@ namespace llarp
PruneInboundMessages(now); PruneInboundMessages(now);
m_TXRate = 0; m_TXRate = 0;
m_RXRate = 0; m_RXRate = 0;
METRICS_DYNAMIC_UPDATE("utp.session.sendq",
RouterID(remoteRC.pubkey).ToString().c_str(),
sendq.size());
} }
/// low level read /// low level read
@ -188,6 +195,8 @@ namespace llarp
Alive(); Alive();
m_RXRate += sz; m_RXRate += sz;
size_t s = sz; size_t s = sz;
METRICS_DYNAMIC_INT_UPDATE(
"utp.session.rx", RouterID(remoteRC.pubkey).ToString().c_str(), s);
// process leftovers // process leftovers
if(recvBufOffset) if(recvBufOffset)
{ {

@ -42,7 +42,7 @@ namespace llarp
using FragmentBuffer = llarp::AlignedBuffer< FragmentBufferSize >; using FragmentBuffer = llarp::AlignedBuffer< FragmentBufferSize >;
/// maximum size for send queue for a session before we drop /// maximum size for send queue for a session before we drop
constexpr size_t MaxSendQueueSize = 1024; constexpr size_t MaxSendQueueSize = 64;
/// buffer for a link layer message /// buffer for a link layer message
using MessageBuffer = llarp::AlignedBuffer< MAX_LINK_MSG_SIZE >; using MessageBuffer = llarp::AlignedBuffer< MAX_LINK_MSG_SIZE >;

@ -29,6 +29,12 @@ namespace llarp
void void
Clear() override; Clear() override;
const char*
Name() const override
{
return "DHTImmediate";
}
}; };
} // namespace llarp } // namespace llarp

@ -31,6 +31,12 @@ namespace llarp
{ {
} }
const char*
Name() const override
{
return "Discard";
}
bool bool
DecodeKey(__attribute__((unused)) const llarp_buffer_t& key, DecodeKey(__attribute__((unused)) const llarp_buffer_t& key,
__attribute__((unused)) llarp_buffer_t* buf) override __attribute__((unused)) llarp_buffer_t* buf) override

@ -44,6 +44,12 @@ namespace llarp
void void
Clear() override; Clear() override;
const char*
Name() const override
{
return "LinkIntro";
}
}; };
} // namespace llarp } // namespace llarp

@ -9,6 +9,7 @@
#include <router_contact.hpp> #include <router_contact.hpp>
#include <util/buffer.hpp> #include <util/buffer.hpp>
#include <util/logger.hpp> #include <util/logger.hpp>
#include <util/metrics.hpp>
namespace llarp namespace llarp
{ {
@ -67,10 +68,12 @@ namespace llarp
} }
// create the message to parse based off message type // create the message to parse based off message type
llarp::LogDebug("inbound message ", *strbuf.cur); llarp::LogDebug("inbound message ", *strbuf.cur);
bool isLIM = false;
switch(*strbuf.cur) switch(*strbuf.cur)
{ {
case 'i': case 'i':
handler->msg = &handler->holder->i; handler->msg = &handler->holder->i;
isLIM = true;
break; break;
case 'd': case 'd':
handler->msg = &handler->holder->d; handler->msg = &handler->holder->d;
@ -90,6 +93,14 @@ namespace llarp
default: default:
return false; return false;
} }
if(!isLIM)
{
const std::string host =
"RX_" + RouterID(handler->from->GetPubKey()).ToString();
METRICS_DYNAMIC_INCREMENT(handler->msg->Name(), host.c_str());
}
handler->msg->session = handler->from; handler->msg->session = handler->from;
handler->firstkey = false; handler->firstkey = false;
return true; return true;

@ -30,6 +30,10 @@ namespace llarp
virtual void virtual void
Clear() = 0; Clear() = 0;
// the name of this kind of message
virtual const char*
Name() const = 0;
}; };
} // namespace llarp } // namespace llarp

@ -31,6 +31,12 @@ namespace llarp
void void
Clear() override; Clear() override;
const char*
Name() const override
{
return "RelayUpstream";
}
}; };
struct RelayDownstreamMessage : public ILinkMessage struct RelayDownstreamMessage : public ILinkMessage
@ -53,6 +59,12 @@ namespace llarp
void void
Clear() override; Clear() override;
const char*
Name() const override
{
return "RelayDownstream";
}
}; };
} // namespace llarp } // namespace llarp

@ -68,6 +68,12 @@ namespace llarp
bool bool
AsyncDecrypt(llarp::path::PathContext *context) const; AsyncDecrypt(llarp::path::PathContext *context) const;
const char *
Name() const override
{
return "RelayCommit";
}
}; };
} // namespace llarp } // namespace llarp

@ -166,6 +166,8 @@ namespace llarp
const RouterID us = pubkey(); const RouterID us = pubkey();
if(remote.pubkey == us) if(remote.pubkey == us)
return false; return false;
if(!ConnectionToRouterAllowed(remote.pubkey))
return false;
// do we already have a pending job for this remote? // do we already have a pending job for this remote?
if(HasPendingConnectJob(remote.pubkey)) if(HasPendingConnectJob(remote.pubkey))
{ {
@ -628,6 +630,7 @@ namespace llarp
const RouterID us = pubkey(); const RouterID us = pubkey();
if(us == remote) if(us == remote)
return; return;
if(!ConnectionToRouterAllowed(remote)) if(!ConnectionToRouterAllowed(remote))
{ {
LogWarn("not connecting to ", remote, " as it's not permitted by config"); LogWarn("not connecting to ", remote, " as it's not permitted by config");
@ -1145,7 +1148,8 @@ namespace llarp
void void
Router::SendTo(RouterID remote, const ILinkMessage *msg, ILinkLayer *selected) Router::SendTo(RouterID remote, const ILinkMessage *msg, ILinkLayer *selected)
{ {
METRICS_TIME_BLOCK("RouterSendTo", remote.ToString().c_str()); const std::string remoteName = "TX_" + remote.ToString();
METRICS_DYNAMIC_INCREMENT(msg->Name(), remoteName.c_str());
llarp_buffer_t buf(linkmsg_buffer); llarp_buffer_t buf(linkmsg_buffer);
if(!msg->BEncode(&buf)) if(!msg->BEncode(&buf))
@ -1264,6 +1268,11 @@ namespace llarp
{ {
if(rc.IsPublicRouter() && whitelistRouters && IsServiceNode()) if(rc.IsPublicRouter() && whitelistRouters && IsServiceNode())
{ {
if(lokinetRouters.size() == 0)
{
LogError("we have no service nodes in whitelist");
return false;
}
if(lokinetRouters.find(rc.pubkey) == lokinetRouters.end()) if(lokinetRouters.find(rc.pubkey) == lokinetRouters.end())
{ {
RouterID sn(rc.pubkey); RouterID sn(rc.pubkey);

@ -1175,12 +1175,10 @@ namespace llarp
, currentIntroSet(introset) , currentIntroSet(introset)
{ {
auto& profiling = parent->m_Router->routerProfiling();
updatingIntroSet = false; updatingIntroSet = false;
for(const auto intro : introset.I) for(const auto intro : introset.I)
{ {
if(intro.expiresAt > m_NextIntro.expiresAt if(intro.expiresAt > m_NextIntro.expiresAt)
&& !profiling.IsBad(intro.router))
{ {
m_NextIntro = intro; m_NextIntro = intro;
remoteIntro = intro; remoteIntro = intro;
@ -1489,7 +1487,7 @@ namespace llarp
} }
bool bool
Endpoint::OutboundContext::ShiftIntroduction() Endpoint::OutboundContext::ShiftIntroduction(bool rebuild)
{ {
bool success = false; bool success = false;
auto now = Now(); auto now = Now();
@ -1524,7 +1522,7 @@ namespace llarp
break; break;
} }
} }
if(shifted) if(shifted && rebuild)
{ {
lastShift = now; lastShift = now;
BuildOneAlignedTo(m_NextIntro.router); BuildOneAlignedTo(m_NextIntro.router);
@ -1848,13 +1846,25 @@ namespace llarp
llarp::path::PathRole roles) llarp::path::PathRole roles)
{ {
if(m_NextIntro.router.IsZero()) if(m_NextIntro.router.IsZero())
{
llarp::LogError("intro is not set, cannot select hops");
return false; return false;
}
if(hop == numHops - 1) if(hop == numHops - 1)
{ {
if(db->Get(m_NextIntro.router, cur)) if(db->Get(m_NextIntro.router, cur))
{ {
return true; return true;
} }
else if(router->routerProfiling().IsBad(m_NextIntro.router))
{
if(!ShiftIntroduction(false))
{
llarp::LogError("bad intro chosen, not selecting hop");
return false;
}
return db->Get(m_NextIntro.router, cur);
}
else else
{ {
// we don't have it? // we don't have it?

@ -239,8 +239,9 @@ namespace llarp
bool markedBad = false; bool markedBad = false;
virtual bool virtual bool
ShiftIntroduction() ShiftIntroduction(bool rebuild = true)
{ {
(void)rebuild;
return true; return true;
}; };
@ -288,7 +289,7 @@ namespace llarp
/// update the current selected intro to be a new best introduction /// update the current selected intro to be a new best introduction
/// return true if we have changed intros /// return true if we have changed intros
bool bool
ShiftIntroduction() override; ShiftIntroduction(bool rebuild = true) override;
/// mark the current remote intro as bad /// mark the current remote intro as bad
bool bool

Loading…
Cancel
Save