From 72dbbd53d6afee615fa6ff982ead2b6b79d7b726 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 24 May 2019 11:06:07 -0400 Subject: [PATCH 01/23] update docs and discard pending traffic on connect timeout to prevent memleak --- docs/dht_v0.txt | 21 +++++++++++++++++++++ llarp/router/router.cpp | 22 ++++------------------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/docs/dht_v0.txt b/docs/dht_v0.txt index b47c8e44b..868ea3d57 100644 --- a/docs/dht_v0.txt +++ b/docs/dht_v0.txt @@ -85,6 +85,19 @@ decrement S by 1 and forward to dht peer who is next closest to the SA of the IS. If S is greater than 3, don't store the IS and discard this message. +acknoledge introduction message (AIM) + +acknoledge the publishing of an introduction + +{ + A: "A", + P: published_to_counter, + T: transaction_id_uint64, + V: 0 +} + +increment P by 1 and forward to requester + find router contact message (FRCM) @@ -130,3 +143,11 @@ in response to an exploritory router lookup, where FRCM.E is provided and non ze T: transaction_id_uint64, V: 0 } + +sent in reply to a dht request to indicate transaction timeout + +{ + A: "T", + T: transaction_id_uint64, + V: 0 +} \ No newline at end of file diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 89e19e778..ad5f506b6 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -61,16 +61,6 @@ struct TryConnectJob return now > lastAttempt && now - lastAttempt > 5000; } - void - Failed() - { - llarp::LogInfo("session to ", llarp::RouterID(rc.pubkey), " closed"); - if(link) - link->CloseSessionTo(rc.pubkey); - // delete this - router->pendingEstablishJobs.erase(rc.pubkey); - } - void Success() { @@ -86,6 +76,8 @@ struct TryConnectJob { return Attempt(); } + // discard pending traffic on timeout + router->DiscardOutboundFor(rc.pubkey); router->routerProfiling().MarkConnectTimeout(rc.pubkey); if(router->routerProfiling().IsBad(rc.pubkey)) { @@ -537,7 +529,7 @@ namespace llarp async_verify_context *ctx = static_cast< async_verify_context * >(job->user); auto router = ctx->router; - PubKey pk(job->rc.pubkey); + const PubKey pk(job->rc.pubkey); router->m_Clients.insert(pk); router->FlushOutboundFor(pk, router->GetLinkWithSessionByPubkey(pk)); delete ctx; @@ -551,18 +543,12 @@ namespace llarp async_verify_context *ctx = static_cast< async_verify_context * >(job->user); auto router = ctx->router; - PubKey pk(job->rc.pubkey); + const PubKey pk(job->rc.pubkey); if(!job->valid) { - if(ctx->establish_job) - { - // was an outbound attempt - ctx->establish_job->Failed(); - } delete ctx; router->DiscardOutboundFor(pk); router->pendingVerifyRC.erase(pk); - return; } // we're valid, which means it's already been committed to the nodedb From 5f55e53331dd8a96125f459d554e9f404f8d4daa Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 24 May 2019 11:28:39 -0400 Subject: [PATCH 02/23] prefer inbound links over outbound links --- llarp/router/router.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index ad5f506b6..b0d16dd14 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -1350,12 +1350,12 @@ namespace llarp if(selected->SendTo(remote, buf)) return; } - for(const auto &link : outboundLinks) + for(const auto &link : inboundLinks) { if(link->SendTo(remote, buf)) return; } - for(const auto &link : inboundLinks) + for(const auto &link : outboundLinks) { if(link->SendTo(remote, buf)) return; @@ -1407,22 +1407,37 @@ namespace llarp pendingEstablishJobs.erase(remote); return; } + // if for some reason we don't provide a link layer pick one that has it if(!chosen) { - DiscardOutboundFor(remote); - pendingEstablishJobs.erase(remote); - return; + for(const auto & link : inboundLinks) + { + if(link->HasSessionTo(remote)) + { + chosen = link.get(); + break; + } + } + for(const auto & link : outboundLinks) + { + if(link->HasSessionTo(remote)) + { + chosen = link.get(); + break; + } + } } while(itr->second.size()) { llarp_buffer_t buf(itr->second.front()); if(!chosen->SendTo(remote, buf)) - LogWarn("failed to send outbound message to ", remote, " via ", + LogWarn("failed to send queued outbound message to ", remote, " via ", chosen->Name()); itr->second.pop(); } pendingEstablishJobs.erase(remote); + outboundMessageQueue.erase(itr); } void From fbf9b06685d5c69fe7f95464aa5e36e594e00f37 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 24 May 2019 15:57:40 -0400 Subject: [PATCH 03/23] * don't lookup routers in sendtoorqueue * don't lookup routers that are not public when committing --- llarp/router/router.cpp | 27 +++++++++++++++++---------- llarp/router/router.hpp | 3 --- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index b0d16dd14..38868435d 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -359,9 +359,11 @@ namespace llarp } // we don't have the RC locally so do a dht lookup + /* _dht->impl->LookupRouter(remote, - std::bind(&Router::HandleDHTLookupForSendTo, this, - remote, std::placeholders::_1)); + std::bind(&Router::HandleDHTLookupForSendTo, this, + remote, std::placeholders::_1)); + */ return true; } @@ -530,7 +532,6 @@ namespace llarp static_cast< async_verify_context * >(job->user); auto router = ctx->router; const PubKey pk(job->rc.pubkey); - router->m_Clients.insert(pk); router->FlushOutboundFor(pk, router->GetLinkWithSessionByPubkey(pk)); delete ctx; router->pendingVerifyRC.erase(pk); @@ -560,7 +561,7 @@ namespace llarp router->validRouters.erase(pk); } - RouterContact rc = job->rc; + const RouterContact rc = job->rc; router->validRouters.emplace(pk, rc); @@ -1265,10 +1266,17 @@ namespace llarp LogDebug("keepalive to ", itr->first); link->KeepAliveSessionTo(itr->first); } - else if(m_Clients.count(itr->first) == 0) + else { - LogDebug("establish to ", itr->first); - TryEstablishTo(itr->first); + RouterContact rc; + if(nodedb()->Get(itr->first, rc)) + { + if(rc.IsPublicRouter()) + { + LogDebug("establish to ", itr->first); + TryConnectAsync(rc, 5); + } + } } ++itr; } @@ -1376,7 +1384,6 @@ namespace llarp dht()->impl->Nodes()->DelNode(k); // remove from valid routers if it's a valid router validRouters.erase(remote); - m_Clients.erase(remote); LogInfo("Session to ", remote, " fully closed"); } @@ -1410,7 +1417,7 @@ namespace llarp // if for some reason we don't provide a link layer pick one that has it if(!chosen) { - for(const auto & link : inboundLinks) + for(const auto &link : inboundLinks) { if(link->HasSessionTo(remote)) { @@ -1418,7 +1425,7 @@ namespace llarp break; } } - for(const auto & link : outboundLinks) + for(const auto &link : outboundLinks) { if(link->HasSessionTo(remote)) { diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index 60df1b479..12edd841d 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -310,9 +310,6 @@ namespace llarp std::unordered_map< RouterID, llarp_time_t, RouterID::Hash > m_PersistingSessions; - // RCs of connected clients - std::set< RouterID > m_Clients; - // lokinet routers from lokid, maps pubkey to when we think it will expire, // set to max value right now std::unordered_map< RouterID, llarp_time_t, PubKey::Hash > lokinetRouters; From d113f06ebd28e12e7a1a376c683d950ac2a03213 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 25 May 2019 10:11:40 -0400 Subject: [PATCH 04/23] use for each loop don't lookup expired routers we don't need that right now --- llarp/service/context.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/llarp/service/context.cpp b/llarp/service/context.cpp index ec14a5449..9a29cd86a 100644 --- a/llarp/service/context.cpp +++ b/llarp/service/context.cpp @@ -123,14 +123,11 @@ namespace llarp } } // tick active endpoints + for(const auto & item : m_Endpoints) { - auto itr = m_Endpoints.begin(); - while(itr != m_Endpoints.end()) - { - itr->second->Tick(now); - ++itr; - } + item.second->Tick(now); } + /* std::vector< RouterID > expired; m_Router->nodedb()->visit([&](const RouterContact &rc) -> bool { if(rc.IsExpired(now)) @@ -146,6 +143,7 @@ namespace llarp return false; return true; }); + */ } bool From 56e8147861685761119dd614ebf89f85b2cff0ae Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 25 May 2019 10:46:22 -0400 Subject: [PATCH 05/23] delete inbound messages right after being handled be more virgous with utp acks --- llarp/utp/linklayer.cpp | 6 ++---- llarp/utp/session.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/llarp/utp/linklayer.cpp b/llarp/utp/linklayer.cpp index 267b3c5eb..61ee366aa 100644 --- a/llarp/utp/linklayer.cpp +++ b/llarp/utp/linklayer.cpp @@ -125,10 +125,8 @@ namespace llarp if(arg->error_code == UTP_ETIMEDOUT) { link->HandleTimeout(session); - utp_close(arg->socket); } - else - session->Close(); + session->Close(); } return 0; } @@ -353,6 +351,7 @@ namespace llarp return 0; } utp_read_drained(arg->socket); + utp_issue_deferred_acks(arg->context); } else { @@ -398,7 +397,6 @@ namespace llarp { session->OnLinkEstablished(self); } - return 0; } diff --git a/llarp/utp/session.cpp b/llarp/utp/session.cpp index c9939e9dc..4d79414d8 100644 --- a/llarp/utp/session.cpp +++ b/llarp/utp/session.cpp @@ -554,6 +554,7 @@ namespace llarp if(!itr->second.AppendData(out.cur, length)) { LogError("inbound buffer is full"); + m_RecvMsgs.erase(itr); return false; // not enough room } // mutate key @@ -565,8 +566,6 @@ namespace llarp if(remaining == 0) { - // we done with this guy, prune next tick - itr->second.lastActive = 0; ManagedBuffer buf{itr->second.buffer}; // resize buf.underlying.sz = buf.underlying.cur - buf.underlying.base; @@ -575,6 +574,7 @@ namespace llarp // process buffer LogDebug("got message ", msgid, " from ", remoteAddr); parent->HandleMessage(this, buf.underlying); + m_RecvMsgs.erase(itr); } return true; } @@ -588,10 +588,12 @@ namespace llarp { if(state == eLinkEstablished || state == eSessionReady) { - // only call shutdown and close when we are actually connected + // only call shutdown when we are actually connected utp_shutdown(sock, SHUT_RDWR); - utp_close(sock); } + utp_close(sock); + utp_set_userdata(sock, nullptr); + sock = nullptr; LogDebug("utp_close ", remoteAddr); } } From 27c101cc3296c6ca888a48a497b133c72d4278c8 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 25 May 2019 10:54:30 -0400 Subject: [PATCH 06/23] close timed out sessions --- llarp/iwp/linklayer.cpp | 1 - llarp/link/server.cpp | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/llarp/iwp/linklayer.cpp b/llarp/iwp/linklayer.cpp index 45dbbadd6..17714ce19 100644 --- a/llarp/iwp/linklayer.cpp +++ b/llarp/iwp/linklayer.cpp @@ -48,7 +48,6 @@ namespace llarp { if(!ILinkLayer::Start(l)) return false; - /// TODO: change me to true when done return false; } diff --git a/llarp/link/server.cpp b/llarp/link/server.cpp index 6938a1db1..676eb8988 100644 --- a/llarp/link/server.cpp +++ b/llarp/link/server.cpp @@ -127,6 +127,7 @@ namespace llarp { llarp::LogInfo("session to ", RouterID(itr->second->GetPubKey()), " timed out"); + itr->second->Close(); itr = m_AuthedLinks.erase(itr); } } @@ -145,6 +146,7 @@ namespace llarp else { LogInfo("pending session at ", itr->first, " timed out"); + itr->second->Close(); itr = m_Pending.erase(itr); } } From fa25bfc7974fdb780f485b4da0e3e5c52142d630 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 25 May 2019 12:27:42 -0400 Subject: [PATCH 07/23] more strict connection timeouts --- llarp/utp/linklayer.cpp | 2 +- llarp/utp/session.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/llarp/utp/linklayer.cpp b/llarp/utp/linklayer.cpp index 61ee366aa..e27b0a98f 100644 --- a/llarp/utp/linklayer.cpp +++ b/llarp/utp/linklayer.cpp @@ -330,7 +330,7 @@ namespace llarp const AddressInfo& addr) { return std::make_shared< OutboundSession >( - this, utp_create_socket(_utp_ctx), rc, addr); + this, NewSocket(), rc, addr); } uint64 diff --git a/llarp/utp/session.cpp b/llarp/utp/session.cpp index 4d79414d8..a75cc8de8 100644 --- a/llarp/utp/session.cpp +++ b/llarp/utp/session.cpp @@ -194,10 +194,12 @@ namespace llarp bool Session::TimedOut(llarp_time_t now) const { - if(state == eInitial || state == eLinkEstablished) - return false; + if(state == eConnecting) + return now - lastActive > 5000; if(sendq.size() >= MaxSendQueueSize) { + if(now <= lastSend) + return false; return now - lastSend > 5000; } // let utp manage this From c77e0aff8ab496f1de795f08b12553ed880cbb46 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 25 May 2019 12:27:54 -0400 Subject: [PATCH 08/23] only check for ready paths when counting in future --- llarp/path/pathset.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llarp/path/pathset.cpp b/llarp/path/pathset.cpp index d928e2fe3..305f6a092 100644 --- a/llarp/path/pathset.cpp +++ b/llarp/path/pathset.cpp @@ -54,7 +54,7 @@ namespace llarp Lock_t l(&m_PathsMutex); for(const auto& item : m_Paths) { - if(!item.second->Expired(futureTime)) + if(item.second->IsReady() && !item.second->Expired(futureTime)) ++num; } return num; From 02e8e055edcbbd0b3f2703bc4f1cf96155a3acf2 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 27 May 2019 07:08:59 -0400 Subject: [PATCH 09/23] update munin script --- contrib/munin/lokinet-munin.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/contrib/munin/lokinet-munin.py b/contrib/munin/lokinet-munin.py index 40d8d2b56..ed72f0279 100644 --- a/contrib/munin/lokinet-munin.py +++ b/contrib/munin/lokinet-munin.py @@ -6,12 +6,14 @@ import requests import json import sys +from collections import defaultdict as Dict + from requests.exceptions import RequestException def jsonrpc(method, **args): return requests.post('http://127.0.0.1:1190/', data=json.dumps( - {'method': method, 'params': args, 'id': 0}), headers={'content-type': 'application/json'}).json() + {'method': method, 'params': args, 'id': 'munin'}), headers={'content-type': 'application/json'}).json() def exit_sessions_main(): @@ -43,20 +45,20 @@ def peers_main(): print("lokinet.peers.outbound.label outbound peers") print("lokinet.peers.inbound.label inbound peers") else: - inbound = 0 - outbound = 0 + inbound = Dict(int) + outbound = Dict(int) try: j = jsonrpc("llarp.admin.link.neighboors") for peer in j['result']: if peer["outbound"]: - outbound += 1 + outbound[peer['ident']] += 1 else: - inbound += 1 + inbound[peer['ident']] += 1 except RequestException: pass - print("lokinet.peers.outbound {}".format(outbound)) - print("lokinet.peers.inbound {}".format(inbound)) + print("lokinet.peers.outbound {}".format(len(outbound))) + print("lokinet.peers.inbound {}".format(len(inbound))) if __name__ == '__main__': From fcd9b23a807017fefc91a14646f0b680a40679a9 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 27 May 2019 07:22:48 -0400 Subject: [PATCH 10/23] fix --- contrib/munin/lokinet-munin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contrib/munin/lokinet-munin.py b/contrib/munin/lokinet-munin.py index ed72f0279..abb02c81d 100644 --- a/contrib/munin/lokinet-munin.py +++ b/contrib/munin/lokinet-munin.py @@ -4,6 +4,7 @@ # import requests import json +import os import sys from collections import defaultdict as Dict @@ -62,9 +63,10 @@ def peers_main(): if __name__ == '__main__': - if sys.argv[0] == 'lokinet-peers': + exe = os.path.basename(sys.argv[0]).lower() + if exe == 'lokinet-peers': peers_main() - elif sys.argv[0] == 'lokinet-exit': + elif exe == 'lokinet-exit': exit_sessions_main() else: print( From 5df825f873ead1cb7c108ce8a462b3511eaa5374 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 27 May 2019 07:29:13 -0400 Subject: [PATCH 11/23] more --- contrib/munin/lokinet-munin.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/contrib/munin/lokinet-munin.py b/contrib/munin/lokinet-munin.py index abb02c81d..ad565359f 100644 --- a/contrib/munin/lokinet-munin.py +++ b/contrib/munin/lokinet-munin.py @@ -17,14 +17,14 @@ def jsonrpc(method, **args): {'method': method, 'params': args, 'id': 'munin'}), headers={'content-type': 'application/json'}).json() -def exit_sessions_main(): +def exit_sessions_main(exe): if len(sys.argv) == 2 and sys.argv[1] == 'config': print("graph_title lokinet exit sessions") print("graph_vlabel sessions") print("graph_category network") print("graph_info This graph shows the number of exit sessions on a lokinet exit") - print("lokinet.exit.sessions.info Number of exit sessions") - print("lokinet.exit.sessions.label sessions") + print("{}.sessions.info Number of exit sessions".format(exe)) + print("{}.sessions.label sessions".format(exe)) else: count = 0 try: @@ -32,19 +32,19 @@ def exit_sessions_main(): count = len(j['result']) except RequestException: pass - print("lokinet.exit.sessions {}".format(count)) + print("{}.sessions {}".format(exe, count)) -def peers_main(): +def peers_main(exe): if len(sys.argv) == 2 and sys.argv[1] == 'config': print("graph_title lokinet peers") print("graph_vlabel peers") print("graph_category network") print("graph_info This graph shows the number of node to node sessions of this lokinet router") - print("lokinet.peers.outbound.info Number of outbound lokinet peers") - print("lokinet.peers.inbound.info Number of inbound lokinet peers") - print("lokinet.peers.outbound.label outbound peers") - print("lokinet.peers.inbound.label inbound peers") + print("{}.outbound.info Number of outbound lokinet peers".format(exe)) + print("{}.inbound.info Number of inbound lokinet peers".format(exe)) + print("{}.outbound.label outbound peers".format(exe)) + print("{}.inbound.label inbound peers".format(exe)) else: inbound = Dict(int) outbound = Dict(int) @@ -58,16 +58,16 @@ def peers_main(): except RequestException: pass - print("lokinet.peers.outbound {}".format(len(outbound))) - print("lokinet.peers.inbound {}".format(len(inbound))) + print("{}.outbound {}".format(exe, len(outbound))) + print("{}.inbound {}".format(exe, len(inbound))) if __name__ == '__main__': exe = os.path.basename(sys.argv[0]).lower() if exe == 'lokinet-peers': - peers_main() + peers_main(exe) elif exe == 'lokinet-exit': - exit_sessions_main() + exit_sessions_main(exe) else: print( 'please symlink this as `lokinet-peers` or `lokinet-exit` in munin plugins dir') From 110268dadf9d046eef2a3339a85c17d0688d12ac Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 27 May 2019 07:34:28 -0400 Subject: [PATCH 12/23] more --- contrib/munin/lokinet-munin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/munin/lokinet-munin.py b/contrib/munin/lokinet-munin.py index ad565359f..1eec88d03 100644 --- a/contrib/munin/lokinet-munin.py +++ b/contrib/munin/lokinet-munin.py @@ -64,10 +64,10 @@ def peers_main(exe): if __name__ == '__main__': exe = os.path.basename(sys.argv[0]).lower() - if exe == 'lokinet-peers': + if exe == 'lokinet_peers': peers_main(exe) - elif exe == 'lokinet-exit': + elif exe == 'lokinet_exit': exit_sessions_main(exe) else: print( - 'please symlink this as `lokinet-peers` or `lokinet-exit` in munin plugins dir') + 'please symlink this as `lokinet_peers` or `lokinet_exit` in munin plugins dir') From 6f3465f54684a9d162509e73877cea583fbf862e Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 27 May 2019 07:48:44 -0400 Subject: [PATCH 13/23] add missing lines --- contrib/munin/lokinet-munin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/munin/lokinet-munin.py b/contrib/munin/lokinet-munin.py index 1eec88d03..9fa6fbdf9 100644 --- a/contrib/munin/lokinet-munin.py +++ b/contrib/munin/lokinet-munin.py @@ -23,6 +23,7 @@ def exit_sessions_main(exe): print("graph_vlabel sessions") print("graph_category network") print("graph_info This graph shows the number of exit sessions on a lokinet exit") + print("{}.label lokinet exit".format(exe)) print("{}.sessions.info Number of exit sessions".format(exe)) print("{}.sessions.label sessions".format(exe)) else: @@ -41,6 +42,7 @@ def peers_main(exe): print("graph_vlabel peers") print("graph_category network") print("graph_info This graph shows the number of node to node sessions of this lokinet router") + print("{}.label lokinet peers".format(exe)) print("{}.outbound.info Number of outbound lokinet peers".format(exe)) print("{}.inbound.info Number of inbound lokinet peers".format(exe)) print("{}.outbound.label outbound peers".format(exe)) From ae74dedf29a22b996e37f9469b922004a2ecf960 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 27 May 2019 07:52:04 -0400 Subject: [PATCH 14/23] gfdi --- contrib/munin/lokinet-munin.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/contrib/munin/lokinet-munin.py b/contrib/munin/lokinet-munin.py index 9fa6fbdf9..bdcae3c9a 100644 --- a/contrib/munin/lokinet-munin.py +++ b/contrib/munin/lokinet-munin.py @@ -23,7 +23,6 @@ def exit_sessions_main(exe): print("graph_vlabel sessions") print("graph_category network") print("graph_info This graph shows the number of exit sessions on a lokinet exit") - print("{}.label lokinet exit".format(exe)) print("{}.sessions.info Number of exit sessions".format(exe)) print("{}.sessions.label sessions".format(exe)) else: @@ -33,7 +32,7 @@ def exit_sessions_main(exe): count = len(j['result']) except RequestException: pass - print("{}.sessions {}".format(exe, count)) + print("{}.sessions.value {}".format(exe, count)) def peers_main(exe): @@ -42,7 +41,6 @@ def peers_main(exe): print("graph_vlabel peers") print("graph_category network") print("graph_info This graph shows the number of node to node sessions of this lokinet router") - print("{}.label lokinet peers".format(exe)) print("{}.outbound.info Number of outbound lokinet peers".format(exe)) print("{}.inbound.info Number of inbound lokinet peers".format(exe)) print("{}.outbound.label outbound peers".format(exe)) @@ -60,8 +58,8 @@ def peers_main(exe): except RequestException: pass - print("{}.outbound {}".format(exe, len(outbound))) - print("{}.inbound {}".format(exe, len(inbound))) + print("{}.outbound.value {}".format(exe, len(outbound))) + print("{}.inbound.value {}".format(exe, len(inbound))) if __name__ == '__main__': From 142b6313013e364841f9f9efb663927113943497 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 27 May 2019 08:00:02 -0400 Subject: [PATCH 15/23] aaAaAAaaaa --- contrib/munin/lokinet-munin.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/contrib/munin/lokinet-munin.py b/contrib/munin/lokinet-munin.py index bdcae3c9a..63c0bfc95 100644 --- a/contrib/munin/lokinet-munin.py +++ b/contrib/munin/lokinet-munin.py @@ -17,14 +17,14 @@ def jsonrpc(method, **args): {'method': method, 'params': args, 'id': 'munin'}), headers={'content-type': 'application/json'}).json() -def exit_sessions_main(exe): +def exit_sessions_main(): if len(sys.argv) == 2 and sys.argv[1] == 'config': print("graph_title lokinet exit sessions") print("graph_vlabel sessions") print("graph_category network") print("graph_info This graph shows the number of exit sessions on a lokinet exit") - print("{}.sessions.info Number of exit sessions".format(exe)) - print("{}.sessions.label sessions".format(exe)) + print("_exit_sessions.info Number of exit sessions") + print("_exit_sessions.label sessions") else: count = 0 try: @@ -32,19 +32,19 @@ def exit_sessions_main(exe): count = len(j['result']) except RequestException: pass - print("{}.sessions.value {}".format(exe, count)) + print("_exit_sessions.value {}".format(count)) -def peers_main(exe): +def peers_main(): if len(sys.argv) == 2 and sys.argv[1] == 'config': print("graph_title lokinet peers") print("graph_vlabel peers") print("graph_category network") print("graph_info This graph shows the number of node to node sessions of this lokinet router") - print("{}.outbound.info Number of outbound lokinet peers".format(exe)) - print("{}.inbound.info Number of inbound lokinet peers".format(exe)) - print("{}.outbound.label outbound peers".format(exe)) - print("{}.inbound.label inbound peers".format(exe)) + print("_peers_outbound.info Number of outbound lokinet peers") + print("_peers_inbound.info Number of inbound lokinet peers") + print("_peers_outbound.label outbound peers") + print("_peers_inbound.label inbound peers") else: inbound = Dict(int) outbound = Dict(int) @@ -58,16 +58,16 @@ def peers_main(exe): except RequestException: pass - print("{}.outbound.value {}".format(exe, len(outbound))) - print("{}.inbound.value {}".format(exe, len(inbound))) + print("_peers_outbound.value {}".format(len(outbound))) + print("_peers_inbound.value {}".format(len(inbound))) if __name__ == '__main__': exe = os.path.basename(sys.argv[0]).lower() if exe == 'lokinet_peers': - peers_main(exe) + peers_main() elif exe == 'lokinet_exit': - exit_sessions_main(exe) + exit_sessions_main() else: print( 'please symlink this as `lokinet_peers` or `lokinet_exit` in munin plugins dir') From 372bc40032767303325003455d23562ea3757296 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 27 May 2019 08:16:39 -0400 Subject: [PATCH 16/23] add member to rpc response indicating weither or not a peer is a service node --- llarp/rpc/rpc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/llarp/rpc/rpc.cpp b/llarp/rpc/rpc.cpp index d4a046c4e..d9f259e77 100644 --- a/llarp/rpc/rpc.cpp +++ b/llarp/rpc/rpc.cpp @@ -237,6 +237,7 @@ namespace llarp [&](const ILinkSession* session, bool outbound) { resp.emplace_back( Response{{"ident", RouterID(session->GetPubKey()).ToString()}, + {"svcnode", session->GetRemoteRC().IsPublicRouter()}, {"addr", session->GetRemoteEndpoint().ToString()}, {"outbound", outbound}}); }, From 1e57a7082d95aece2522fdbcab54ec636c1ed7cc Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 27 May 2019 08:17:21 -0400 Subject: [PATCH 17/23] don't log ips --- llarp/rpc/rpc.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/llarp/rpc/rpc.cpp b/llarp/rpc/rpc.cpp index d9f259e77..1da08bd91 100644 --- a/llarp/rpc/rpc.cpp +++ b/llarp/rpc/rpc.cpp @@ -238,7 +238,6 @@ namespace llarp resp.emplace_back( Response{{"ident", RouterID(session->GetPubKey()).ToString()}, {"svcnode", session->GetRemoteRC().IsPublicRouter()}, - {"addr", session->GetRemoteEndpoint().ToString()}, {"outbound", outbound}}); }, false); From dd2d69444fe2750ccb94f7047e7e5da24e099ab3 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 27 May 2019 08:22:51 -0400 Subject: [PATCH 18/23] differentiate between clients and service nodes --- contrib/munin/lokinet-munin.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/contrib/munin/lokinet-munin.py b/contrib/munin/lokinet-munin.py index 63c0bfc95..f9c067319 100644 --- a/contrib/munin/lokinet-munin.py +++ b/contrib/munin/lokinet-munin.py @@ -45,22 +45,28 @@ def peers_main(): print("_peers_inbound.info Number of inbound lokinet peers") print("_peers_outbound.label outbound peers") print("_peers_inbound.label inbound peers") + print("_peers_clients.info Number of lokinet client peers") + print("_peers_clients.label lokinet client peers") else: inbound = Dict(int) outbound = Dict(int) + clients = Dict(int) try: j = jsonrpc("llarp.admin.link.neighboors") for peer in j['result']: - if peer["outbound"]: - outbound[peer['ident']] += 1 + if peer["svcnode"]: + if peer["outbound"]: + outbound[peer['ident']] += 1 + else: + inbound[peer['ident']] += 1 else: - inbound[peer['ident']] += 1 + clients[peer['ident']] += 1 except RequestException: pass print("_peers_outbound.value {}".format(len(outbound))) print("_peers_inbound.value {}".format(len(inbound))) - + print("_peers_clients.value {}".format(len(clients))) if __name__ == '__main__': exe = os.path.basename(sys.argv[0]).lower() From a375f1103f129a2c229e7a04f2f24a58f5a75436 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 27 May 2019 15:01:09 -0400 Subject: [PATCH 19/23] explicitly lookup router if not connected to it on LRCM forward. --- llarp/path/path.cpp | 21 +++++++++++++++++++-- llarp/router/abstractrouter.hpp | 4 ++++ llarp/router/router.hpp | 4 +++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index 7c9291acd..bb7a71461 100644 --- a/llarp/path/path.cpp +++ b/llarp/path/path.cpp @@ -99,9 +99,26 @@ namespace llarp PathContext::ForwardLRCM(const RouterID& nextHop, const std::array< EncryptedFrame, 8 >& frames) { + auto msg = std::make_shared(frames); + LogDebug("forwarding LRCM to ", nextHop); - const LR_CommitMessage msg(frames); - return m_Router->SendToOrQueue(nextHop, &msg); + if(m_Router->HasSessionTo(nextHop)) + { + return m_Router->SendToOrQueue(nextHop, msg.get()); + } + const RouterID router = nextHop; + AbstractRouter * const r = m_Router; + m_Router->LookupRouter(nextHop, [msg, r, router](const std::vector & found) { + if(found.size()) + { + r->TryConnectAsync(found[0], 1); + r->SendToOrQueue(router, msg.get()); + } + else + LogError("dropped LRCM to ", router, " as we cannot find in via DHT"); + }); + LogInfo("we are not directly connected to ", router, " so we need to do a lookup"); + return true; } template < typename Map_t, typename Key_t, typename CheckValue_t, typename GetFunc_t > diff --git a/llarp/router/abstractrouter.hpp b/llarp/router/abstractrouter.hpp index 6de36e78f..883a65b6a 100644 --- a/llarp/router/abstractrouter.hpp +++ b/llarp/router/abstractrouter.hpp @@ -218,6 +218,10 @@ namespace llarp virtual bool ConnectionToRouterAllowed(const RouterID &router) const = 0; + /// return true if we have at least 1 session to this router in either direction + virtual bool + HasSessionTo(const RouterID & router) const = 0; + virtual util::StatusObject ExtractStatus() const = 0; }; diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index 12edd841d..178b341a7 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -533,7 +533,9 @@ namespace llarp const std::vector< RouterContact > &results); bool - HasSessionTo(const RouterID &remote) const; + HasSessionTo(const RouterID &remote) const override; + + void HandleDHTLookupForTryEstablishTo( From 9c15f87da126d406aba77c1bd1016f7c65138084 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 27 May 2019 19:59:18 -0400 Subject: [PATCH 20/23] uncomment --- llarp/router/router.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 38868435d..037f8aad9 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -359,11 +359,9 @@ namespace llarp } // we don't have the RC locally so do a dht lookup - /* _dht->impl->LookupRouter(remote, std::bind(&Router::HandleDHTLookupForSendTo, this, remote, std::placeholders::_1)); - */ return true; } From 2897141036d91afcc33aaba1832821018f8e2118 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 28 May 2019 07:35:26 -0400 Subject: [PATCH 21/23] make format and introduce new function EnsureRouter on router to check nodedb or do dht lookup --- llarp/path/path.cpp | 29 ++++++++++++++++------------- llarp/router/abstractrouter.cpp | 11 +++++++++++ llarp/router/abstractrouter.hpp | 8 ++++++-- llarp/router/router.cpp | 4 ++-- llarp/router/router.hpp | 2 -- llarp/service/context.cpp | 4 ++-- llarp/utp/linklayer.cpp | 3 +-- 7 files changed, 38 insertions(+), 23 deletions(-) diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index bb7a71461..d333d3ed6 100644 --- a/llarp/path/path.cpp +++ b/llarp/path/path.cpp @@ -99,25 +99,28 @@ namespace llarp PathContext::ForwardLRCM(const RouterID& nextHop, const std::array< EncryptedFrame, 8 >& frames) { - auto msg = std::make_shared(frames); + auto msg = std::make_shared< const LR_CommitMessage >(frames); LogDebug("forwarding LRCM to ", nextHop); if(m_Router->HasSessionTo(nextHop)) { return m_Router->SendToOrQueue(nextHop, msg.get()); } - const RouterID router = nextHop; - AbstractRouter * const r = m_Router; - m_Router->LookupRouter(nextHop, [msg, r, router](const std::vector & found) { - if(found.size()) - { - r->TryConnectAsync(found[0], 1); - r->SendToOrQueue(router, msg.get()); - } - else - LogError("dropped LRCM to ", router, " as we cannot find in via DHT"); - }); - LogInfo("we are not directly connected to ", router, " so we need to do a lookup"); + const RouterID router = nextHop; + AbstractRouter* const r = m_Router; + m_Router->EnsureRouter( + nextHop, [msg, r, router](const std::vector< RouterContact >& found) { + if(found.size()) + { + r->TryConnectAsync(found[0], 1); + r->SendToOrQueue(router, msg.get()); + } + else + LogError("dropped LRCM to ", router, + " as we cannot find in via DHT"); + }); + LogInfo("we are not directly connected to ", router, + " so we need to do a lookup"); return true; } template < typename Map_t, typename Key_t, typename CheckValue_t, diff --git a/llarp/router/abstractrouter.cpp b/llarp/router/abstractrouter.cpp index b0da46e73..9bb8be2f8 100644 --- a/llarp/router/abstractrouter.cpp +++ b/llarp/router/abstractrouter.cpp @@ -1,8 +1,19 @@ #include +#include namespace llarp { AbstractRouter::~AbstractRouter() { } + + void + AbstractRouter::EnsureRouter(RouterID router, RouterLookupHandler handler) + { + std::vector< RouterContact > found(1); + if(nodedb()->Get(router, found[0])) + handler(found); + else + LookupRouter(router, handler); + } } // namespace llarp diff --git a/llarp/router/abstractrouter.hpp b/llarp/router/abstractrouter.hpp index 883a65b6a..149adfbfe 100644 --- a/llarp/router/abstractrouter.hpp +++ b/llarp/router/abstractrouter.hpp @@ -218,12 +218,16 @@ namespace llarp virtual bool ConnectionToRouterAllowed(const RouterID &router) const = 0; - /// return true if we have at least 1 session to this router in either direction + /// return true if we have at least 1 session to this router in either + /// direction virtual bool - HasSessionTo(const RouterID & router) const = 0; + HasSessionTo(const RouterID &router) const = 0; virtual util::StatusObject ExtractStatus() const = 0; + + void + EnsureRouter(RouterID router, RouterLookupHandler handler); }; } // namespace llarp diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 037f8aad9..dd8ca77fd 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -360,8 +360,8 @@ namespace llarp // we don't have the RC locally so do a dht lookup _dht->impl->LookupRouter(remote, - std::bind(&Router::HandleDHTLookupForSendTo, this, - remote, std::placeholders::_1)); + std::bind(&Router::HandleDHTLookupForSendTo, this, + remote, std::placeholders::_1)); return true; } diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index 178b341a7..4c6e8f387 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -535,8 +535,6 @@ namespace llarp bool HasSessionTo(const RouterID &remote) const override; - - void HandleDHTLookupForTryEstablishTo( RouterID remote, const std::vector< RouterContact > &results); diff --git a/llarp/service/context.cpp b/llarp/service/context.cpp index 9a29cd86a..3c0d00a66 100644 --- a/llarp/service/context.cpp +++ b/llarp/service/context.cpp @@ -123,9 +123,9 @@ namespace llarp } } // tick active endpoints - for(const auto & item : m_Endpoints) + for(const auto &item : m_Endpoints) { - item.second->Tick(now); + item.second->Tick(now); } /* std::vector< RouterID > expired; diff --git a/llarp/utp/linklayer.cpp b/llarp/utp/linklayer.cpp index e27b0a98f..e02403645 100644 --- a/llarp/utp/linklayer.cpp +++ b/llarp/utp/linklayer.cpp @@ -329,8 +329,7 @@ namespace llarp LinkLayer::NewOutboundSession(const RouterContact& rc, const AddressInfo& addr) { - return std::make_shared< OutboundSession >( - this, NewSocket(), rc, addr); + return std::make_shared< OutboundSession >(this, NewSocket(), rc, addr); } uint64 From 068fec82fbe57aafc2960a80b3fbe5db7ab8b737 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 28 May 2019 10:06:01 -0400 Subject: [PATCH 22/23] set lifetime of paths --- llarp/messages/relay_commit.hpp | 2 +- llarp/path/pathbuilder.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/llarp/messages/relay_commit.hpp b/llarp/messages/relay_commit.hpp index 561d9f449..db90ab777 100644 --- a/llarp/messages/relay_commit.hpp +++ b/llarp/messages/relay_commit.hpp @@ -29,7 +29,7 @@ namespace llarp std::unique_ptr< RouterContact > nextRC; std::unique_ptr< PoW > work; uint64_t version = 0; - uint64_t lifetime = 0; + uint64_t lifetime = path::default_lifetime; bool BDecode(llarp_buffer_t *buf); diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index 7f16dd60c..057ee37d0 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -83,7 +83,7 @@ namespace llarp std::make_unique< RouterContact >(ctx->path->hops[ctx->idx].rc); } // build record - + record.lifetime = path::default_lifetime; record.version = LLARP_PROTO_VERSION; record.txid = hop.txID; record.rxid = hop.rxID; From e13e4646cc3e37041945ea4aeb8816e7b6504faa Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 28 May 2019 10:07:00 -0400 Subject: [PATCH 23/23] fix previous commit --- llarp/messages/relay_commit.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llarp/messages/relay_commit.hpp b/llarp/messages/relay_commit.hpp index db90ab777..561d9f449 100644 --- a/llarp/messages/relay_commit.hpp +++ b/llarp/messages/relay_commit.hpp @@ -29,7 +29,7 @@ namespace llarp std::unique_ptr< RouterContact > nextRC; std::unique_ptr< PoW > work; uint64_t version = 0; - uint64_t lifetime = path::default_lifetime; + uint64_t lifetime = 0; bool BDecode(llarp_buffer_t *buf);