RCGossipSentEvent

pull/1184/head
Thomas Winget 4 years ago
parent 7e0e8ab7bf
commit 6fc05ca1ff

@ -3,6 +3,7 @@
#include <dht/messages/gotrouter.hpp> #include <dht/messages/gotrouter.hpp>
#include <util/time.hpp> #include <util/time.hpp>
#include <constants/link_layer.hpp> #include <constants/link_layer.hpp>
#include <tooling/rc_event.hpp>
namespace llarp namespace llarp
{ {
@ -20,10 +21,11 @@ namespace llarp
} }
void void
RCGossiper::Init(ILinkManager* l, const RouterID& ourID) RCGossiper::Init(ILinkManager* l, const RouterID& ourID, AbstractRouter* router)
{ {
m_OurRouterID = ourID; m_OurRouterID = ourID;
m_LinkManager = l; m_LinkManager = l;
m_router = router;
} }
bool bool
@ -74,7 +76,6 @@ LogWarn("ShouldGossipOurRC: ", should);
m_LastGossipedOurRC = now; m_LastGossipedOurRC = now;
} }
LogWarn("Creating RC Gossip Message");
// send a GRCM as gossip method // send a GRCM as gossip method
DHTImmediateMessage gossip; DHTImmediateMessage gossip;
gossip.msgs.emplace_back( gossip.msgs.emplace_back(
@ -82,16 +83,13 @@ LogWarn("Creating RC Gossip Message");
// send it to everyone // send it to everyone
m_LinkManager->ForEachPeer([&](ILinkSession* peerSession) { m_LinkManager->ForEachPeer([&](ILinkSession* peerSession) {
LogWarn("Considering Peer to send RC Gossip Message");
// ensure connected session // ensure connected session
if(not(peerSession && peerSession->IsEstablished())) if(not(peerSession && peerSession->IsEstablished()))
return; return;
LogWarn("Peer has session established to send RC Gossip Message");
// check if public router // check if public router
const auto other_rc = peerSession->GetRemoteRC(); const auto other_rc = peerSession->GetRemoteRC();
if(not other_rc.IsPublicRouter()) if(not other_rc.IsPublicRouter())
return; return;
LogWarn("Peer is public router to send RC Gossip Message");
// encode message // encode message
ILinkSession::Message_t msg; ILinkSession::Message_t msg;
msg.resize(MAX_LINK_MSG_SIZE / 2); 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)) if(not gossip.BEncode(&buf))
return; return;
msg.resize(buf.cur - buf.base); msg.resize(buf.cur - buf.base);
tooling::RouterEventPtr event = std::make_unique<tooling::RCGossipSentEvent>(m_router->pubkey(), rc);
m_router->NotifyRouterEvent(std::move(event));
// send message // send message
LogWarn("Sending RC Gossip Message to ", RouterID(other_rc.pubkey).ShortString());
peerSession->SendMessageBuffer(std::move(msg), nullptr); peerSession->SendMessageBuffer(std::move(msg), nullptr);
}); });
return true; return true;

@ -5,6 +5,7 @@
#include <router/i_gossiper.hpp> #include <router/i_gossiper.hpp>
#include <router/i_outbound_message_handler.hpp> #include <router/i_outbound_message_handler.hpp>
#include <link/i_link_manager.hpp> #include <link/i_link_manager.hpp>
#include <router/abstractrouter.hpp>
namespace llarp namespace llarp
{ {
@ -27,13 +28,15 @@ namespace llarp
IsOurRC(const RouterContact &rc) const override; IsOurRC(const RouterContact &rc) const override;
void void
Init(ILinkManager *, const RouterID &); Init(ILinkManager *, const RouterID &, AbstractRouter*);
private: private:
RouterID m_OurRouterID; RouterID m_OurRouterID;
Time_t m_LastGossipedOurRC = 0s; Time_t m_LastGossipedOurRC = 0s;
ILinkManager *m_LinkManager = nullptr; ILinkManager *m_LinkManager = nullptr;
util::DecayingHashSet< RouterID > m_Filter; util::DecayingHashSet< RouterID > m_Filter;
AbstractRouter *m_router;
}; };
} // namespace llarp } // namespace llarp

@ -1057,7 +1057,7 @@ namespace llarp
const RouterID us = pubkey(); const RouterID us = pubkey();
LogInfo("initalized service node: ", us); LogInfo("initalized service node: ", us);
// init gossiper here // init gossiper here
_rcGossiper.Init(&_linkManager, us); _rcGossiper.Init(&_linkManager, us, this);
// relays do not use profiling // relays do not use profiling
routerProfiling().Disable(); routerProfiling().Disable();
} }

@ -20,5 +20,24 @@ namespace tooling
return RouterEvent::ToString() + " ---- RC: " + rc.ToString(); 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 } // namespace tooling

@ -17,5 +17,18 @@ namespace tooling
llarp::RouterContact rc; 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 } // namespace tooling

@ -52,6 +52,10 @@ namespace tooling
py::class_<RCGossipReceivedEvent, RouterEvent>(mod, "RCGossipReceivedEvent") py::class_<RCGossipReceivedEvent, RouterEvent>(mod, "RCGossipReceivedEvent")
.def_readonly("rc", &RCGossipReceivedEvent::rc) .def_readonly("rc", &RCGossipReceivedEvent::rc)
.def("LongString", &RCGossipReceivedEvent::LongString); .def("LongString", &RCGossipReceivedEvent::LongString);
py::class_<RCGossipSentEvent, RouterEvent>(mod, "RCGossipSentEvent")
.def_readonly("rc", &RCGossipSentEvent::rc)
.def("LongString", &RCGossipSentEvent::LongString);
} }
} // namespace tooling } // namespace tooling

Loading…
Cancel
Save