RCGossipSentEvent

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

@ -3,6 +3,7 @@
#include <dht/messages/gotrouter.hpp>
#include <util/time.hpp>
#include <constants/link_layer.hpp>
#include <tooling/rc_event.hpp>
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<tooling::RCGossipSentEvent>(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;

@ -5,6 +5,7 @@
#include <router/i_gossiper.hpp>
#include <router/i_outbound_message_handler.hpp>
#include <link/i_link_manager.hpp>
#include <router/abstractrouter.hpp>
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

@ -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();
}

@ -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

@ -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

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

Loading…
Cancel
Save