Peer stats test which artificially stops a router from gossiping its RC

pull/1312/head
Stephen Shelton 4 years ago
parent 63f41d6a98
commit bdac43e19f
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -81,6 +81,10 @@ namespace llarp
tooling::RouterHive* hive = nullptr; tooling::RouterHive* hive = nullptr;
#endif #endif
// XXX / TODO: this code shouldn't ever make it into a release binary
virtual void
stopGossipingRC() = 0;
virtual ~AbstractRouter() = default; virtual ~AbstractRouter() = default;
virtual bool virtual bool

@ -125,6 +125,9 @@ namespace llarp
void void
Router::GossipRCIfNeeded(const RouterContact rc) Router::GossipRCIfNeeded(const RouterContact rc)
{ {
if (not m_shouldGossipRC)
return;
/// if we are not a service node forget about gossip /// if we are not a service node forget about gossip
if (not IsServiceNode()) if (not IsServiceNode())
return; return;

@ -51,6 +51,14 @@ namespace llarp
{ {
struct Router final : public AbstractRouter struct Router final : public AbstractRouter
{ {
// XXX / TODO: this code shouldn't ever make it into a release binary
virtual void
stopGossipingRC()
{
m_shouldGossipRC = false;
}
bool m_shouldGossipRC = true;
llarp_time_t _lastPump = 0s; llarp_time_t _lastPump = 0s;
bool ready; bool ready;
// transient iwp encryption key // transient iwp encryption key

@ -10,6 +10,7 @@ namespace llarp
py::class_<AbstractRouter>(mod, "AbstractRouter") py::class_<AbstractRouter>(mod, "AbstractRouter")
.def("rc", &AbstractRouter::rc) .def("rc", &AbstractRouter::rc)
.def("Stop", &AbstractRouter::Stop) .def("Stop", &AbstractRouter::Stop)
.def("peerDb", &AbstractRouter::peerDb); .def("peerDb", &AbstractRouter::peerDb)
.def("stopGossipingRC", &AbstractRouter::stopGossipingRC);
} }
} // namespace llarp } // namespace llarp

@ -6,50 +6,72 @@ def test_peer_stats(HiveForPeerStats):
numRelays = 12 numRelays = 12
hive = HiveForPeerStats(n_relays=numRelays, n_clients=0, netid="hive") hive = HiveForPeerStats(n_relays=numRelays, n_clients=0, netid="hive")
someRouterId = None
start_time = time() def collectStatsForAWhile(duration):
cur_time = start_time print("collecting router hive stats for {} seconds...", duration)
test_duration = 30 #seconds
# we track the number of attempted sessions and inbound/outbound established sessions start_time = time()
numInbound = 0 cur_time = start_time
numOutbound = 0
numAttempts = 0
# we pick an arbitrary router out of our routers # we track the number of attempted sessions and inbound/outbound established sessions
someRouterId = None numInbound = 0
numOutbound = 0
numAttempts = 0
nonlocal someRouterId
while cur_time < start_time + duration:
hive.CollectAllEvents()
for event in hive.events:
event_name = event.__class__.__name__
if event_name == "LinkSessionEstablishedEvent":
if event.inbound:
numInbound += 1
else:
numOutbound += 1
if event_name == "ConnectionAttemptEvent":
numAttempts += 1
while cur_time < start_time + test_duration: # we pick an arbitrary router out of our routers
if someRouterId is None:
someRouterId = event.remoteId;
hive.CollectAllEvents() hive.events = []
cur_time = time()
for event in hive.events: # these should be strictly equal, although there is variation because of
event_name = event.__class__.__name__ # the time we sample
print("test duration exceeded")
print("in: {} out: {} attempts: {}", numInbound, numOutbound, numAttempts);
totalReceived = tally_rc_received_for_peer(hive.hive, someRouterId)
if event_name == "LinkSessionEstablishedEvent": # every router should have received this relay's RC exactly once
if event.inbound: print("total times RC received: {} numRelays: {}", totalReceived, numRelays)
numInbound += 1
else:
numOutbound += 1
if event_name == "ConnectionAttemptEvent": return {
numAttempts += 1 "numInbound": numInbound,
"numOutbound": numOutbound,
"numAttempts": numAttempts,
"totalTargetRCsReceived": totalReceived,
};
if someRouterId is None: results1 = collectStatsForAWhile(30);
someRouterId = event.remoteId; assert(results1["totalTargetRCsReceived"] == numRelays)
hive.events = [] # stop our router from gossiping
cur_time = time() router = hive.hive.GetRelay(someRouterId, True)
router.stopGossipingRC();
# these should be strictly equal, although there is variation because of ignore = collectStatsForAWhile(30);
# the time we sample
print("test duration exceeded")
print("in: {} out: {} attempts: {}", numInbound, numOutbound, numAttempts);
totalReceived = tally_rc_received_for_peer(hive.hive, someRouterId)
# every router should have received this relay's RC exactly once # ensure that no one hears a fresh RC from this router again
print("total times RC received: {} numRelays: {}", totalReceived, numRelays) print("Starting second (longer) stats collection...")
assert(totalReceived == numRelays) results2 = collectStatsForAWhile(3600);
assert(results2["totalTargetRCsReceived"] == numRelays) # should not have increased
def tally_rc_received_for_peer(hive, routerId): def tally_rc_received_for_peer(hive, routerId):

Loading…
Cancel
Save