From d1b629f494a1c49084f7b064739298462b08ae52 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Mon, 15 Jun 2020 11:37:57 -0600 Subject: [PATCH] RouterHive ConnectionAttemptEvent --- llarp/router/outbound_session_maker.cpp | 18 ++++++++++++++++-- llarp/router/outbound_session_maker.hpp | 2 ++ llarp/router/router.cpp | 1 + pybind/llarp/tooling/router_event.cpp | 3 +++ test/hive/test_peer_stats.py | 2 +- 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/llarp/router/outbound_session_maker.cpp b/llarp/router/outbound_session_maker.cpp index f7e50185d..c03dc34f7 100644 --- a/llarp/router/outbound_session_maker.cpp +++ b/llarp/router/outbound_session_maker.cpp @@ -1,5 +1,7 @@ #include +#include +#include #include #include #include @@ -152,6 +154,7 @@ namespace llarp void OutboundSessionMaker::Init( + AbstractRouter* router, ILinkManager* linkManager, I_RCLookupHandler* rcLookup, Profiling* profiler, @@ -159,6 +162,7 @@ namespace llarp llarp_nodedb* nodedb, WorkerFunc_t dowork) { + _router = router; _linkManager = linkManager; _rcLookup = rcLookup; _logic = logic; @@ -298,8 +302,18 @@ namespace llarp void OutboundSessionMaker::CreatePendingSession(const RouterID& router) { - util::Lock l(_mutex); - pendingSessions.emplace(router, nullptr); + { + util::Lock l(_mutex); + pendingSessions.emplace(router, nullptr); + } + + auto peerDb = _router->peerDb(); + if (peerDb) + { + peerDb->modifyPeerStats(router, [](PeerStats& stats) { stats.numConnectionAttempts++; }); + } + + _router->NotifyRouterEvent(_router->pubkey(), router); } void diff --git a/llarp/router/outbound_session_maker.hpp b/llarp/router/outbound_session_maker.hpp index 63069f65e..063594cbd 100644 --- a/llarp/router/outbound_session_maker.hpp +++ b/llarp/router/outbound_session_maker.hpp @@ -58,6 +58,7 @@ namespace llarp void Init( + AbstractRouter* router, ILinkManager* linkManager, I_RCLookupHandler* rcLookup, Profiling* profiler, @@ -110,6 +111,7 @@ namespace llarp std::unordered_map pendingCallbacks GUARDED_BY(_mutex); + AbstractRouter* _router = nullptr; ILinkManager* _linkManager = nullptr; I_RCLookupHandler* _rcLookup = nullptr; Profiling* _profiler = nullptr; diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 0a1b5c667..e92be092e 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -523,6 +523,7 @@ namespace llarp // Init components after relevant config settings loaded _outboundMessageHandler.Init(&_linkManager, _logic); _outboundSessionMaker.Init( + this, &_linkManager, &_rcLookupHandler, &_routerProfiling, diff --git a/pybind/llarp/tooling/router_event.cpp b/pybind/llarp/tooling/router_event.cpp index 906469044..3fe62db18 100644 --- a/pybind/llarp/tooling/router_event.cpp +++ b/pybind/llarp/tooling/router_event.cpp @@ -78,6 +78,9 @@ namespace tooling py::class_(mod, "LinkSessionEstablishedEvent") .def_readonly("remoteId", &LinkSessionEstablishedEvent::remoteId) .def_readonly("inbound", &LinkSessionEstablishedEvent::inbound); + + py::class_(mod, "ConnectionAttemptEvent") + .def_readonly("remoteId", &ConnectionAttemptEvent::remoteId); } } // namespace tooling diff --git a/test/hive/test_peer_stats.py b/test/hive/test_peer_stats.py index 844e76377..d618279c0 100644 --- a/test/hive/test_peer_stats.py +++ b/test/hive/test_peer_stats.py @@ -2,7 +2,7 @@ import pyllarp from time import time def test_peer_stats(HiveForPeerStats): - hive = HiveForPeerStats(n_relays=5, n_clients=0, netid="hive") + hive = HiveForPeerStats(n_relays=12, n_clients=0, netid="hive") start_time = time() cur_time = start_time