mirror of https://github.com/oxen-io/lokinet
today's work
This commit is contained in:
parent
eceb55623c
commit
6a09348c47
|
@ -342,8 +342,9 @@ add_log_tag(${ABYSS_EXE})
|
|||
add_log_tag(${ABYSS_LIB})
|
||||
|
||||
if(SHADOW)
|
||||
add_shadow_plugin(shadow-plugin-${SHARED_LIB} ${EXE_SRC} ${LIB_SRC} ${UTP_SRC} ${LIB_PLATFORM_SRC} ${CPP_BACKPORT_SRC} ${ABYSS_SRC} ${CRYPTOGRAPHY_SRC})
|
||||
target_link_libraries(shadow-plugin-${SHARED_LIB} ${LIBS})
|
||||
add_shadow_plugin(shadow-plugin-${SHARED_LIB} ${EXE_SRC})
|
||||
target_include_directories(shadow-plugin-${SHARED_LIB} PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/llarp ${PROJECT_SOURCE_DIR}/crypto/include ${PROJECT_SOURCE_DIR}/vendor/cppbackport-master/lib)
|
||||
target_link_libraries(shadow-plugin-${SHARED_LIB} ${STATIC_LIB} ${LIBS})
|
||||
install(TARGETS shadow-plugin-${SHARED_LIB} DESTINATION plugins)
|
||||
else()
|
||||
if(NOT WIN32)
|
||||
|
|
8
Makefile
8
Makefile
|
@ -16,12 +16,12 @@ SETCAP ?= which setcap && setcap cap_net_admin,cap_net_bind_service=+eip
|
|||
SHADOW_ROOT ?= $(HOME)/.shadow
|
||||
SHADOW_BIN=$(SHADOW_ROOT)/bin/shadow
|
||||
SHADOW_CONFIG=$(REPO)/shadow.config.xml
|
||||
SHADOW_PLUGIN=$(REPO)/libshadow-plugin-llarp.so
|
||||
SHADOW_PLUGIN=$(BUILD_ROOT)/libshadow-plugin-lokinet-shared.so
|
||||
SHADOW_LOG=$(REPO)/shadow.log.txt
|
||||
|
||||
SHADOW_SRC ?= $(HOME)/local/shadow
|
||||
SHADOW_PARSE ?= python $(SHADOW_SRC)/src/tools/parse-shadow.py - -m 0 --packet-data
|
||||
SHADOW_PLOT ?= python $(SHADOW_SRC)/src/tools/plot-shadow.py -d $(REPO) LokiNET -c $(SHADOW_CONFIG) -r 10000 -e '.*'
|
||||
SHADOW_PARSE ?= $(PYTHON) $(SHADOW_SRC)/src/tools/parse-shadow.py - -m 0 --packet-data
|
||||
SHADOW_PLOT ?= $(PYTHON) $(SHADOW_SRC)/src/tools/plot-shadow.py -d $(REPO) LokiNET -c $(SHADOW_CONFIG) -r 10000 -e '.*'
|
||||
|
||||
TESTNET_ROOT=/tmp/lokinet_testnet_tmp
|
||||
TESTNET_CONF=$(TESTNET_ROOT)/supervisor.conf
|
||||
|
@ -135,11 +135,11 @@ shadow-configure: clean
|
|||
$(CONFIG_CMD) -DCMAKE_BUILD_TYPE=Debug -DSHADOW=ON -DCMAKE_C_COMPILER=$(CC) -DCMAKE_CXX_COMPILER=$(CXX)
|
||||
|
||||
shadow-build: shadow-configure
|
||||
$(MAKE) -C $(BUILD_ROOT) clean
|
||||
$(MAKE) -C $(BUILD_ROOT)
|
||||
|
||||
shadow-run: shadow-build
|
||||
$(PYTHON) $(REPO)/contrib/shadow/genconf.py $(SHADOW_CONFIG)
|
||||
cp $(SHADOW_PLUGIN) $(REPO)
|
||||
bash -c "$(SHADOW_BIN) -w $$(cat /proc/cpuinfo | grep processor | wc -l) $(SHADOW_CONFIG) | $(SHADOW_PARSE)"
|
||||
|
||||
shadow-plot: shadow-run
|
||||
|
|
|
@ -13,7 +13,7 @@ def getSetting(s, name, fallback): return name in s and s[name] or fallback
|
|||
shadowRoot = getSetting(os.environ, "SHADOW_ROOT",
|
||||
os.path.join(os.environ['HOME'], '.shadow'))
|
||||
|
||||
libpath = 'libshadow-plugin-lokinet.so'
|
||||
libpath = 'libshadow-plugin-lokinet-shared.so'
|
||||
|
||||
|
||||
def nodeconf(conf, baseDir, name, ifname=None, port=None):
|
||||
|
@ -59,11 +59,11 @@ def makeClient(settings, name, id):
|
|||
basedir = getSetting(settings, 'baseDir', 'tmp')
|
||||
nodeconf(peer['config'], basedir, name)
|
||||
fname = os.path.join(basedir, "test-service.ini")
|
||||
peer['config']['services'] = {
|
||||
'test-service': fname
|
||||
peer['config']['network'] = {
|
||||
'type': 'null',
|
||||
'tag':'test',
|
||||
'prefetch-tag':'test'
|
||||
}
|
||||
with open(fname, 'w') as f:
|
||||
f.write("[test-service]")
|
||||
return peer
|
||||
|
||||
|
||||
|
@ -71,6 +71,9 @@ def makeSVCNode(settings, name, id, port):
|
|||
peer = makeBase(settings, name, id)
|
||||
nodeconf(peer['config'], getSetting(
|
||||
settings, 'baseDir', 'tmp'), name, 'eth0', port)
|
||||
peer['config']['network'] = {
|
||||
'type': 'null'
|
||||
}
|
||||
return peer
|
||||
|
||||
|
||||
|
@ -81,7 +84,7 @@ def genconf(settings, outf):
|
|||
topology.attrib['path'] = getSetting(settings, 'topology', os.path.join(
|
||||
shadowRoot, 'share', 'topology.graphml.xml'))
|
||||
|
||||
pluginName = getSetting(settings, 'name', 'llarpd')
|
||||
pluginName = getSetting(settings, 'name', 'lokinet-shared')
|
||||
|
||||
kill = etree.SubElement(root, 'kill')
|
||||
kill.attrib['time'] = getSetting(settings, 'runFor', '600')
|
||||
|
@ -96,7 +99,7 @@ def genconf(settings, outf):
|
|||
plugin.attrib['id'] = pluginName
|
||||
plugin.attrib['path'] = libpath
|
||||
basePort = getSetting(settings, 'svc-base-port', 19000)
|
||||
svcNodeCount = getSetting(settings, 'service-nodes', 20)
|
||||
svcNodeCount = getSetting(settings, 'service-nodes', 80)
|
||||
peers = list()
|
||||
for nodeid in range(svcNodeCount):
|
||||
peers.append(makeSVCNode(
|
||||
|
|
|
@ -374,11 +374,7 @@ llarp_kqueue_loop::tick(int ms)
|
|||
llarp::ev_io* ev = static_cast< llarp::ev_io* >(events[idx].udata);
|
||||
if(ev)
|
||||
{
|
||||
if(events[idx].filter & EV_ERROR)
|
||||
{
|
||||
ev->error();
|
||||
}
|
||||
else if(events[idx.filter] & EV_EOF == 0)
|
||||
if(events[idx.filter] & EV_EOF == 0)
|
||||
{
|
||||
if(events[idx].filter & EVFILT_WRITE)
|
||||
{
|
||||
|
|
|
@ -236,7 +236,7 @@ namespace llarp
|
|||
auto dlt = now - lastActive;
|
||||
if(dlt >= sessionTimeout)
|
||||
{
|
||||
LogDebug("session timeout reached for ", remoteAddr);
|
||||
LogInfo("session timeout reached for ", remoteAddr);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -254,6 +254,17 @@ namespace llarp
|
|||
return remoteAddr;
|
||||
}
|
||||
|
||||
uint64
|
||||
LinkLayer::OnConnect(utp_callback_arguments* arg)
|
||||
{
|
||||
LinkLayer* l =
|
||||
static_cast< LinkLayer* >(utp_context_get_userdata(arg->context));
|
||||
Session* session = static_cast< Session* >(utp_get_userdata(arg->socket));
|
||||
if(session && l)
|
||||
session->OutboundLinkEstablished(l);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64
|
||||
LinkLayer::SendTo(utp_callback_arguments* arg)
|
||||
{
|
||||
|
@ -374,6 +385,7 @@ namespace llarp
|
|||
utp_context_set_userdata(_utp_ctx, this);
|
||||
utp_set_callback(_utp_ctx, UTP_SENDTO, &LinkLayer::SendTo);
|
||||
utp_set_callback(_utp_ctx, UTP_ON_ACCEPT, &LinkLayer::OnAccept);
|
||||
utp_set_callback(_utp_ctx, UTP_ON_CONNECT, &LinkLayer::OnConnect);
|
||||
utp_set_callback(_utp_ctx, UTP_ON_STATE_CHANGE,
|
||||
&LinkLayer::OnStateChange);
|
||||
utp_set_callback(_utp_ctx, UTP_ON_READ, &LinkLayer::OnRead);
|
||||
|
@ -404,9 +416,11 @@ namespace llarp
|
|||
}
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
void
|
||||
LinkLayer::ProcessICMP()
|
||||
{
|
||||
#ifndef TESTNET
|
||||
do
|
||||
{
|
||||
byte_t vec_buf[4096], ancillary_buf[4096];
|
||||
|
@ -475,13 +489,13 @@ namespace llarp
|
|||
}
|
||||
}
|
||||
} while(true);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
LinkLayer::Pump()
|
||||
{
|
||||
utp_issue_deferred_acks(_utp_ctx);
|
||||
#ifdef __linux__
|
||||
ProcessICMP();
|
||||
#endif
|
||||
|
@ -507,6 +521,7 @@ namespace llarp
|
|||
}
|
||||
}
|
||||
}
|
||||
utp_issue_deferred_acks(_utp_ctx);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -577,9 +592,7 @@ namespace llarp
|
|||
SendQueueBacklog = [&]() -> size_t { return sendq.size(); };
|
||||
|
||||
SendKeepAlive = [&]() -> bool {
|
||||
auto now = parent->Now();
|
||||
if(sendq.size() == 0 && state == eSessionReady && now > lastActive
|
||||
&& now - lastActive > 5000)
|
||||
if(state == eSessionReady)
|
||||
{
|
||||
DiscardMessage msg;
|
||||
std::array< byte_t, 128 > tmp;
|
||||
|
@ -590,6 +603,7 @@ namespace llarp
|
|||
buf.cur = buf.base;
|
||||
if(!this->QueueWriteBuffers(buf))
|
||||
return false;
|
||||
PumpWrite();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
@ -840,6 +854,7 @@ namespace llarp
|
|||
if(sock)
|
||||
{
|
||||
utp_set_userdata(sock, nullptr);
|
||||
sock = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -872,7 +887,6 @@ namespace llarp
|
|||
else
|
||||
{
|
||||
LogWarn("utp_socket got data with no underlying session");
|
||||
utp_shutdown(arg->socket, SHUT_RDWR);
|
||||
utp_close(arg->socket);
|
||||
}
|
||||
return 0;
|
||||
|
@ -881,20 +895,10 @@ namespace llarp
|
|||
uint64
|
||||
LinkLayer::OnStateChange(utp_callback_arguments* arg)
|
||||
{
|
||||
LinkLayer* l =
|
||||
static_cast< LinkLayer* >(utp_context_get_userdata(arg->context));
|
||||
Session* session = static_cast< Session* >(utp_get_userdata(arg->socket));
|
||||
if(session)
|
||||
{
|
||||
if(arg->state == UTP_STATE_CONNECT)
|
||||
{
|
||||
if(session->state == Session::eClose)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
session->OutboundLinkEstablished(l);
|
||||
}
|
||||
else if(arg->state == UTP_STATE_WRITABLE)
|
||||
if(arg->state == UTP_STATE_WRITABLE)
|
||||
{
|
||||
session->PumpWrite();
|
||||
}
|
||||
|
@ -1155,11 +1159,9 @@ namespace llarp
|
|||
utp_close(sock);
|
||||
}
|
||||
LogDebug("utp_close ", remoteAddr);
|
||||
utp_set_userdata(sock, nullptr);
|
||||
}
|
||||
}
|
||||
EnterState(eClose);
|
||||
sock = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -109,8 +109,8 @@ namespace llarp
|
|||
SharedSecret txKey;
|
||||
/// timestamp last active
|
||||
llarp_time_t lastActive;
|
||||
/// session timeout (30s)
|
||||
const static llarp_time_t sessionTimeout = 30 * 1000;
|
||||
/// session timeout (60s)
|
||||
const static llarp_time_t sessionTimeout = DefaultLinkSessionLifetime;
|
||||
|
||||
/// send queue for utp
|
||||
std::deque< utp_iovec > vecq;
|
||||
|
@ -298,6 +298,9 @@ namespace llarp
|
|||
static uint64
|
||||
OnStateChange(utp_callback_arguments*);
|
||||
|
||||
static uint64
|
||||
OnConnect(utp_callback_arguments*);
|
||||
|
||||
/// accept callback
|
||||
static uint64
|
||||
OnAccept(utp_callback_arguments*);
|
||||
|
|
|
@ -764,7 +764,7 @@ namespace llarp
|
|||
if(m_BuiltHook)
|
||||
m_BuiltHook(this);
|
||||
m_BuiltHook = nullptr;
|
||||
|
||||
LogDebug("path latency is now ", intro.latency, " for ", Name());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -256,7 +256,9 @@ namespace llarp
|
|||
bool
|
||||
Builder::ShouldBuildMore(llarp_time_t now) const
|
||||
{
|
||||
return PathSet::ShouldBuildMore(now) && !BuildCooldownHit(now);
|
||||
if(llarp::randint() % 3 >= 1)
|
||||
return PathSet::ShouldBuildMore(now) && !BuildCooldownHit(now);
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -52,6 +52,13 @@ namespace llarp
|
|||
bool
|
||||
BuildCooldownHit(llarp_time_t now) const;
|
||||
|
||||
/// get roles for this path builder
|
||||
virtual PathRole
|
||||
GetRoles() const
|
||||
{
|
||||
return ePathRoleAny;
|
||||
}
|
||||
|
||||
virtual bool
|
||||
Stop() override;
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ namespace llarp
|
|||
if(strbuf.sz != 1)
|
||||
return false;
|
||||
self->key = *strbuf.cur;
|
||||
LogDebug("routing message '", self->key, "'");
|
||||
switch(self->key)
|
||||
{
|
||||
case 'D':
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace llarp
|
|||
{
|
||||
Endpoint::Endpoint(const std::string& name, AbstractRouter* r,
|
||||
Context* parent)
|
||||
: path::Builder(r, r->dht(), 6, DEFAULT_HOP_LENGTH)
|
||||
: path::Builder(r, r->dht(), 3, DEFAULT_HOP_LENGTH)
|
||||
, context(parent)
|
||||
, m_Router(r)
|
||||
, m_Name(name)
|
||||
|
@ -1272,53 +1272,51 @@ namespace llarp
|
|||
ProtocolFrame& f = transfer.T;
|
||||
path::Path* p = nullptr;
|
||||
std::set< ConvoTag > tags;
|
||||
if(!GetConvoTagsForService(itr->second, tags))
|
||||
if(GetConvoTagsForService(itr->second, tags))
|
||||
{
|
||||
llarp::LogError("no convo tag");
|
||||
return false;
|
||||
}
|
||||
Introduction remoteIntro;
|
||||
SharedSecret K;
|
||||
// pick tag
|
||||
for(const auto& tag : tags)
|
||||
{
|
||||
if(tag.IsZero())
|
||||
continue;
|
||||
if(!GetCachedSessionKeyFor(tag, K))
|
||||
continue;
|
||||
if(p == nullptr && GetIntroFor(tag, remoteIntro))
|
||||
Introduction remoteIntro;
|
||||
SharedSecret K;
|
||||
// pick tag
|
||||
for(const auto& tag : tags)
|
||||
{
|
||||
if(!remoteIntro.ExpiresSoon(now))
|
||||
p = GetNewestPathByRouter(remoteIntro.router);
|
||||
if(p)
|
||||
if(tag.IsZero())
|
||||
continue;
|
||||
if(!GetCachedSessionKeyFor(tag, K))
|
||||
continue;
|
||||
if(p == nullptr && GetIntroFor(tag, remoteIntro))
|
||||
{
|
||||
f.T = tag;
|
||||
break;
|
||||
if(!remoteIntro.ExpiresSoon(now))
|
||||
p = GetNewestPathByRouter(remoteIntro.router);
|
||||
if(p)
|
||||
{
|
||||
f.T = tag;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(p)
|
||||
{
|
||||
// TODO: check expiration of our end
|
||||
ProtocolMessage m(f.T);
|
||||
m.proto = t;
|
||||
m.introReply = p->intro;
|
||||
PutReplyIntroFor(f.T, m.introReply);
|
||||
m.sender = m_Identity.pub;
|
||||
m.PutBuffer(data);
|
||||
f.N.Randomize();
|
||||
f.S = GetSeqNoForConvo(f.T);
|
||||
f.C.Zero();
|
||||
transfer.Y.Randomize();
|
||||
transfer.P = remoteIntro.pathID;
|
||||
if(!f.EncryptAndSign(Router()->crypto(), m, K, m_Identity))
|
||||
if(p)
|
||||
{
|
||||
llarp::LogError("failed to encrypt and sign");
|
||||
return false;
|
||||
// TODO: check expiration of our end
|
||||
ProtocolMessage m(f.T);
|
||||
m.proto = t;
|
||||
m.introReply = p->intro;
|
||||
PutReplyIntroFor(f.T, m.introReply);
|
||||
m.sender = m_Identity.pub;
|
||||
m.PutBuffer(data);
|
||||
f.N.Randomize();
|
||||
f.S = GetSeqNoForConvo(f.T);
|
||||
f.C.Zero();
|
||||
transfer.Y.Randomize();
|
||||
transfer.P = remoteIntro.pathID;
|
||||
if(!f.EncryptAndSign(Router()->crypto(), m, K, m_Identity))
|
||||
{
|
||||
llarp::LogError("failed to encrypt and sign");
|
||||
return false;
|
||||
}
|
||||
llarp::LogDebug(Name(), " send ", data.sz, " via ",
|
||||
remoteIntro.router);
|
||||
return p->SendRoutingMessage(&transfer, Router());
|
||||
}
|
||||
llarp::LogDebug(Name(), " send ", data.sz, " via ",
|
||||
remoteIntro.router);
|
||||
return p->SendRoutingMessage(&transfer, Router());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,8 +40,6 @@ namespace llarp
|
|||
std::ostream& out;
|
||||
|
||||
std::function< void(const std::string&) > customLog;
|
||||
|
||||
llarp::util::Mutex access;
|
||||
#ifdef _WIN32
|
||||
bool isConsoleModern =
|
||||
true; // qol fix so oldfag clients don't see ugly escapes
|
||||
|
@ -240,6 +238,9 @@ namespace llarp
|
|||
#endif
|
||||
ss << (char)27 << "[0;0m";
|
||||
_glog.out << ss.str() << std::endl;
|
||||
#ifdef TESTNET
|
||||
_glog.out << std::flush;
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue