today's work

pull/384/head
Jeff Becker 5 years ago
parent eceb55623c
commit 6a09348c47
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -342,8 +342,9 @@ add_log_tag(${ABYSS_EXE})
add_log_tag(${ABYSS_LIB}) add_log_tag(${ABYSS_LIB})
if(SHADOW) 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}) add_shadow_plugin(shadow-plugin-${SHARED_LIB} ${EXE_SRC})
target_link_libraries(shadow-plugin-${SHARED_LIB} ${LIBS}) 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) install(TARGETS shadow-plugin-${SHARED_LIB} DESTINATION plugins)
else() else()
if(NOT WIN32) if(NOT WIN32)

@ -16,12 +16,12 @@ SETCAP ?= which setcap && setcap cap_net_admin,cap_net_bind_service=+eip
SHADOW_ROOT ?= $(HOME)/.shadow SHADOW_ROOT ?= $(HOME)/.shadow
SHADOW_BIN=$(SHADOW_ROOT)/bin/shadow SHADOW_BIN=$(SHADOW_ROOT)/bin/shadow
SHADOW_CONFIG=$(REPO)/shadow.config.xml 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_LOG=$(REPO)/shadow.log.txt
SHADOW_SRC ?= $(HOME)/local/shadow SHADOW_SRC ?= $(HOME)/local/shadow
SHADOW_PARSE ?= python $(SHADOW_SRC)/src/tools/parse-shadow.py - -m 0 --packet-data 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_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_ROOT=/tmp/lokinet_testnet_tmp
TESTNET_CONF=$(TESTNET_ROOT)/supervisor.conf 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) $(CONFIG_CMD) -DCMAKE_BUILD_TYPE=Debug -DSHADOW=ON -DCMAKE_C_COMPILER=$(CC) -DCMAKE_CXX_COMPILER=$(CXX)
shadow-build: shadow-configure shadow-build: shadow-configure
$(MAKE) -C $(BUILD_ROOT) clean
$(MAKE) -C $(BUILD_ROOT) $(MAKE) -C $(BUILD_ROOT)
shadow-run: shadow-build shadow-run: shadow-build
$(PYTHON) $(REPO)/contrib/shadow/genconf.py $(SHADOW_CONFIG) $(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)" bash -c "$(SHADOW_BIN) -w $$(cat /proc/cpuinfo | grep processor | wc -l) $(SHADOW_CONFIG) | $(SHADOW_PARSE)"
shadow-plot: shadow-run 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", shadowRoot = getSetting(os.environ, "SHADOW_ROOT",
os.path.join(os.environ['HOME'], '.shadow')) 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): def nodeconf(conf, baseDir, name, ifname=None, port=None):
@ -59,11 +59,11 @@ def makeClient(settings, name, id):
basedir = getSetting(settings, 'baseDir', 'tmp') basedir = getSetting(settings, 'baseDir', 'tmp')
nodeconf(peer['config'], basedir, name) nodeconf(peer['config'], basedir, name)
fname = os.path.join(basedir, "test-service.ini") fname = os.path.join(basedir, "test-service.ini")
peer['config']['services'] = { peer['config']['network'] = {
'test-service': fname 'type': 'null',
'tag':'test',
'prefetch-tag':'test'
} }
with open(fname, 'w') as f:
f.write("[test-service]")
return peer return peer
@ -71,6 +71,9 @@ def makeSVCNode(settings, name, id, port):
peer = makeBase(settings, name, id) peer = makeBase(settings, name, id)
nodeconf(peer['config'], getSetting( nodeconf(peer['config'], getSetting(
settings, 'baseDir', 'tmp'), name, 'eth0', port) settings, 'baseDir', 'tmp'), name, 'eth0', port)
peer['config']['network'] = {
'type': 'null'
}
return peer return peer
@ -81,7 +84,7 @@ def genconf(settings, outf):
topology.attrib['path'] = getSetting(settings, 'topology', os.path.join( topology.attrib['path'] = getSetting(settings, 'topology', os.path.join(
shadowRoot, 'share', 'topology.graphml.xml')) shadowRoot, 'share', 'topology.graphml.xml'))
pluginName = getSetting(settings, 'name', 'llarpd') pluginName = getSetting(settings, 'name', 'lokinet-shared')
kill = etree.SubElement(root, 'kill') kill = etree.SubElement(root, 'kill')
kill.attrib['time'] = getSetting(settings, 'runFor', '600') kill.attrib['time'] = getSetting(settings, 'runFor', '600')
@ -96,7 +99,7 @@ def genconf(settings, outf):
plugin.attrib['id'] = pluginName plugin.attrib['id'] = pluginName
plugin.attrib['path'] = libpath plugin.attrib['path'] = libpath
basePort = getSetting(settings, 'svc-base-port', 19000) basePort = getSetting(settings, 'svc-base-port', 19000)
svcNodeCount = getSetting(settings, 'service-nodes', 20) svcNodeCount = getSetting(settings, 'service-nodes', 80)
peers = list() peers = list()
for nodeid in range(svcNodeCount): for nodeid in range(svcNodeCount):
peers.append(makeSVCNode( 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); llarp::ev_io* ev = static_cast< llarp::ev_io* >(events[idx].udata);
if(ev) if(ev)
{ {
if(events[idx].filter & EV_ERROR) if(events[idx.filter] & EV_EOF == 0)
{
ev->error();
}
else if(events[idx.filter] & EV_EOF == 0)
{ {
if(events[idx].filter & EVFILT_WRITE) if(events[idx].filter & EVFILT_WRITE)
{ {

@ -236,7 +236,7 @@ namespace llarp
auto dlt = now - lastActive; auto dlt = now - lastActive;
if(dlt >= sessionTimeout) if(dlt >= sessionTimeout)
{ {
LogDebug("session timeout reached for ", remoteAddr); LogInfo("session timeout reached for ", remoteAddr);
return true; return true;
} }
return false; return false;
@ -254,6 +254,17 @@ namespace llarp
return remoteAddr; 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 uint64
LinkLayer::SendTo(utp_callback_arguments* arg) LinkLayer::SendTo(utp_callback_arguments* arg)
{ {
@ -374,6 +385,7 @@ namespace llarp
utp_context_set_userdata(_utp_ctx, this); utp_context_set_userdata(_utp_ctx, this);
utp_set_callback(_utp_ctx, UTP_SENDTO, &LinkLayer::SendTo); 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_ACCEPT, &LinkLayer::OnAccept);
utp_set_callback(_utp_ctx, UTP_ON_CONNECT, &LinkLayer::OnConnect);
utp_set_callback(_utp_ctx, UTP_ON_STATE_CHANGE, utp_set_callback(_utp_ctx, UTP_ON_STATE_CHANGE,
&LinkLayer::OnStateChange); &LinkLayer::OnStateChange);
utp_set_callback(_utp_ctx, UTP_ON_READ, &LinkLayer::OnRead); utp_set_callback(_utp_ctx, UTP_ON_READ, &LinkLayer::OnRead);
@ -404,9 +416,11 @@ namespace llarp
} }
#ifdef __linux__ #ifdef __linux__
void void
LinkLayer::ProcessICMP() LinkLayer::ProcessICMP()
{ {
#ifndef TESTNET
do do
{ {
byte_t vec_buf[4096], ancillary_buf[4096]; byte_t vec_buf[4096], ancillary_buf[4096];
@ -475,13 +489,13 @@ namespace llarp
} }
} }
} while(true); } while(true);
#endif
} }
#endif #endif
void void
LinkLayer::Pump() LinkLayer::Pump()
{ {
utp_issue_deferred_acks(_utp_ctx);
#ifdef __linux__ #ifdef __linux__
ProcessICMP(); ProcessICMP();
#endif #endif
@ -507,6 +521,7 @@ namespace llarp
} }
} }
} }
utp_issue_deferred_acks(_utp_ctx);
} }
void void
@ -577,9 +592,7 @@ namespace llarp
SendQueueBacklog = [&]() -> size_t { return sendq.size(); }; SendQueueBacklog = [&]() -> size_t { return sendq.size(); };
SendKeepAlive = [&]() -> bool { SendKeepAlive = [&]() -> bool {
auto now = parent->Now(); if(state == eSessionReady)
if(sendq.size() == 0 && state == eSessionReady && now > lastActive
&& now - lastActive > 5000)
{ {
DiscardMessage msg; DiscardMessage msg;
std::array< byte_t, 128 > tmp; std::array< byte_t, 128 > tmp;
@ -590,6 +603,7 @@ namespace llarp
buf.cur = buf.base; buf.cur = buf.base;
if(!this->QueueWriteBuffers(buf)) if(!this->QueueWriteBuffers(buf))
return false; return false;
PumpWrite();
} }
return true; return true;
}; };
@ -840,6 +854,7 @@ namespace llarp
if(sock) if(sock)
{ {
utp_set_userdata(sock, nullptr); utp_set_userdata(sock, nullptr);
sock = nullptr;
} }
} }
@ -872,7 +887,6 @@ namespace llarp
else else
{ {
LogWarn("utp_socket got data with no underlying session"); LogWarn("utp_socket got data with no underlying session");
utp_shutdown(arg->socket, SHUT_RDWR);
utp_close(arg->socket); utp_close(arg->socket);
} }
return 0; return 0;
@ -881,20 +895,10 @@ namespace llarp
uint64 uint64
LinkLayer::OnStateChange(utp_callback_arguments* arg) 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)); Session* session = static_cast< Session* >(utp_get_userdata(arg->socket));
if(session) if(session)
{ {
if(arg->state == UTP_STATE_CONNECT) if(arg->state == UTP_STATE_WRITABLE)
{
if(session->state == Session::eClose)
{
return 0;
}
session->OutboundLinkEstablished(l);
}
else if(arg->state == UTP_STATE_WRITABLE)
{ {
session->PumpWrite(); session->PumpWrite();
} }
@ -1155,11 +1159,9 @@ namespace llarp
utp_close(sock); utp_close(sock);
} }
LogDebug("utp_close ", remoteAddr); LogDebug("utp_close ", remoteAddr);
utp_set_userdata(sock, nullptr);
} }
} }
EnterState(eClose); EnterState(eClose);
sock = nullptr;
} }
void void

@ -109,8 +109,8 @@ namespace llarp
SharedSecret txKey; SharedSecret txKey;
/// timestamp last active /// timestamp last active
llarp_time_t lastActive; llarp_time_t lastActive;
/// session timeout (30s) /// session timeout (60s)
const static llarp_time_t sessionTimeout = 30 * 1000; const static llarp_time_t sessionTimeout = DefaultLinkSessionLifetime;
/// send queue for utp /// send queue for utp
std::deque< utp_iovec > vecq; std::deque< utp_iovec > vecq;
@ -298,6 +298,9 @@ namespace llarp
static uint64 static uint64
OnStateChange(utp_callback_arguments*); OnStateChange(utp_callback_arguments*);
static uint64
OnConnect(utp_callback_arguments*);
/// accept callback /// accept callback
static uint64 static uint64
OnAccept(utp_callback_arguments*); OnAccept(utp_callback_arguments*);

@ -764,7 +764,7 @@ namespace llarp
if(m_BuiltHook) if(m_BuiltHook)
m_BuiltHook(this); m_BuiltHook(this);
m_BuiltHook = nullptr; m_BuiltHook = nullptr;
LogDebug("path latency is now ", intro.latency, " for ", Name());
return true; return true;
} }
else else

@ -256,7 +256,9 @@ namespace llarp
bool bool
Builder::ShouldBuildMore(llarp_time_t now) const 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 void

@ -52,6 +52,13 @@ namespace llarp
bool bool
BuildCooldownHit(llarp_time_t now) const; BuildCooldownHit(llarp_time_t now) const;
/// get roles for this path builder
virtual PathRole
GetRoles() const
{
return ePathRoleAny;
}
virtual bool virtual bool
Stop() override; Stop() override;

@ -67,6 +67,7 @@ namespace llarp
if(strbuf.sz != 1) if(strbuf.sz != 1)
return false; return false;
self->key = *strbuf.cur; self->key = *strbuf.cur;
LogDebug("routing message '", self->key, "'");
switch(self->key) switch(self->key)
{ {
case 'D': case 'D':

@ -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(), 6, DEFAULT_HOP_LENGTH) : path::Builder(r, r->dht(), 3, DEFAULT_HOP_LENGTH)
, context(parent) , context(parent)
, m_Router(r) , m_Router(r)
, m_Name(name) , m_Name(name)
@ -1272,53 +1272,51 @@ namespace llarp
ProtocolFrame& f = transfer.T; ProtocolFrame& f = transfer.T;
path::Path* p = nullptr; path::Path* p = nullptr;
std::set< ConvoTag > tags; std::set< ConvoTag > tags;
if(!GetConvoTagsForService(itr->second, tags)) if(GetConvoTagsForService(itr->second, tags))
{ {
llarp::LogError("no convo tag"); Introduction remoteIntro;
return false; SharedSecret K;
} // pick tag
Introduction remoteIntro; for(const auto& tag : tags)
SharedSecret K;
// pick tag
for(const auto& tag : tags)
{
if(tag.IsZero())
continue;
if(!GetCachedSessionKeyFor(tag, K))
continue;
if(p == nullptr && GetIntroFor(tag, remoteIntro))
{ {
if(!remoteIntro.ExpiresSoon(now)) if(tag.IsZero())
p = GetNewestPathByRouter(remoteIntro.router); continue;
if(p) if(!GetCachedSessionKeyFor(tag, K))
continue;
if(p == nullptr && GetIntroFor(tag, remoteIntro))
{ {
f.T = tag; if(!remoteIntro.ExpiresSoon(now))
break; p = GetNewestPathByRouter(remoteIntro.router);
if(p)
{
f.T = tag;
break;
}
} }
} }
} if(p)
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))
{ {
llarp::LogError("failed to encrypt and sign"); // TODO: check expiration of our end
return false; 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::ostream& out;
std::function< void(const std::string&) > customLog; std::function< void(const std::string&) > customLog;
llarp::util::Mutex access;
#ifdef _WIN32 #ifdef _WIN32
bool isConsoleModern = bool isConsoleModern =
true; // qol fix so oldfag clients don't see ugly escapes true; // qol fix so oldfag clients don't see ugly escapes
@ -240,6 +238,9 @@ namespace llarp
#endif #endif
ss << (char)27 << "[0;0m"; ss << (char)27 << "[0;0m";
_glog.out << ss.str() << std::endl; _glog.out << ss.str() << std::endl;
#ifdef TESTNET
_glog.out << std::flush;
#endif
#ifdef _WIN32 #ifdef _WIN32
} }
else else

Loading…
Cancel
Save