From 6fc05ca1ff97863bbaa9e685c9cb0540f265b538 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Tue, 3 Mar 2020 19:50:20 -0500 Subject: [PATCH] RCGossipSentEvent --- llarp/router/rc_gossiper.cpp | 13 +++++++------ llarp/router/rc_gossiper.hpp | 5 ++++- llarp/router/router.cpp | 2 +- llarp/tooling/rc_event.cpp | 19 +++++++++++++++++++ llarp/tooling/rc_event.hpp | 13 +++++++++++++ pybind/llarp/tooling/router_event.cpp | 4 ++++ 6 files changed, 48 insertions(+), 8 deletions(-) diff --git a/llarp/router/rc_gossiper.cpp b/llarp/router/rc_gossiper.cpp index 29b0c9c81..6c126ce96 100644 --- a/llarp/router/rc_gossiper.cpp +++ b/llarp/router/rc_gossiper.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace llarp { @@ -20,10 +21,11 @@ namespace llarp } void - RCGossiper::Init(ILinkManager* l, const RouterID& ourID) + RCGossiper::Init(ILinkManager* l, const RouterID& ourID, AbstractRouter* router) { m_OurRouterID = ourID; m_LinkManager = l; + m_router = router; } bool @@ -74,7 +76,6 @@ LogWarn("ShouldGossipOurRC: ", should); m_LastGossipedOurRC = now; } -LogWarn("Creating RC Gossip Message"); // send a GRCM as gossip method DHTImmediateMessage gossip; gossip.msgs.emplace_back( @@ -82,16 +83,13 @@ LogWarn("Creating RC Gossip Message"); // send it to everyone m_LinkManager->ForEachPeer([&](ILinkSession* peerSession) { -LogWarn("Considering Peer to send RC Gossip Message"); // ensure connected session if(not(peerSession && peerSession->IsEstablished())) return; -LogWarn("Peer has session established to send RC Gossip Message"); // check if public router const auto other_rc = peerSession->GetRemoteRC(); if(not other_rc.IsPublicRouter()) return; -LogWarn("Peer is public router to send RC Gossip Message"); // encode message ILinkSession::Message_t msg; msg.resize(MAX_LINK_MSG_SIZE / 2); @@ -99,8 +97,11 @@ LogWarn("Peer is public router to send RC Gossip Message"); if(not gossip.BEncode(&buf)) return; msg.resize(buf.cur - buf.base); + + tooling::RouterEventPtr event = std::make_unique(m_router->pubkey(), rc); + m_router->NotifyRouterEvent(std::move(event)); + // send message -LogWarn("Sending RC Gossip Message to ", RouterID(other_rc.pubkey).ShortString()); peerSession->SendMessageBuffer(std::move(msg), nullptr); }); return true; diff --git a/llarp/router/rc_gossiper.hpp b/llarp/router/rc_gossiper.hpp index e0758032d..2f4227c44 100644 --- a/llarp/router/rc_gossiper.hpp +++ b/llarp/router/rc_gossiper.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace llarp { @@ -27,13 +28,15 @@ namespace llarp IsOurRC(const RouterContact &rc) const override; void - Init(ILinkManager *, const RouterID &); + Init(ILinkManager *, const RouterID &, AbstractRouter*); private: RouterID m_OurRouterID; Time_t m_LastGossipedOurRC = 0s; ILinkManager *m_LinkManager = nullptr; util::DecayingHashSet< RouterID > m_Filter; + + AbstractRouter *m_router; }; } // namespace llarp diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 2feddad80..d2e778114 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -1057,7 +1057,7 @@ namespace llarp const RouterID us = pubkey(); LogInfo("initalized service node: ", us); // init gossiper here - _rcGossiper.Init(&_linkManager, us); + _rcGossiper.Init(&_linkManager, us, this); // relays do not use profiling routerProfiling().Disable(); } diff --git a/llarp/tooling/rc_event.cpp b/llarp/tooling/rc_event.cpp index 5907cf333..b5894bc17 100644 --- a/llarp/tooling/rc_event.cpp +++ b/llarp/tooling/rc_event.cpp @@ -20,5 +20,24 @@ namespace tooling return RouterEvent::ToString() + " ---- RC: " + rc.ToString(); } + + RCGossipSentEvent::RCGossipSentEvent(const llarp::RouterID& routerID, const llarp::RouterContact& rc) + : RouterEvent("RCGossipSentEvent", routerID, true) + , rc(rc) + { + } + + std::string + RCGossipSentEvent::ToString() const + { + return RouterEvent::ToString() + " ---- sending RC for RouterID: " + llarp::RouterID(rc.pubkey).ShortString(); + } + + std::string + RCGossipSentEvent::LongString() const + { + return RouterEvent::ToString() + " ---- RC: " + rc.ToString(); + } + } // namespace tooling diff --git a/llarp/tooling/rc_event.hpp b/llarp/tooling/rc_event.hpp index 532b5df53..02f361220 100644 --- a/llarp/tooling/rc_event.hpp +++ b/llarp/tooling/rc_event.hpp @@ -17,5 +17,18 @@ namespace tooling llarp::RouterContact rc; }; + struct RCGossipSentEvent : public RouterEvent + { + RCGossipSentEvent(const llarp::RouterID& routerID, const llarp::RouterContact& rc); + + std::string + ToString() const override; + + std::string + LongString() const; + + llarp::RouterContact rc; + }; + } // namespace tooling diff --git a/pybind/llarp/tooling/router_event.cpp b/pybind/llarp/tooling/router_event.cpp index dc3a4a167..808877148 100644 --- a/pybind/llarp/tooling/router_event.cpp +++ b/pybind/llarp/tooling/router_event.cpp @@ -52,6 +52,10 @@ namespace tooling py::class_(mod, "RCGossipReceivedEvent") .def_readonly("rc", &RCGossipReceivedEvent::rc) .def("LongString", &RCGossipReceivedEvent::LongString); + + py::class_(mod, "RCGossipSentEvent") + .def_readonly("rc", &RCGossipSentEvent::rc) + .def("LongString", &RCGossipSentEvent::LongString); } } // namespace tooling