From d69d538f1a36bbdf518c9c7ce79de3c09e66704b Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Mon, 15 Jun 2020 11:34:40 -0600 Subject: [PATCH] Add missing files --- llarp/tooling/peer_stats_event.hpp | 44 +++++++++++++++++++++++ pybind/llarp/tooling/peer_stats_event.hpp | 28 +++++++++++++++ test/hive/test_peer_stats.py | 44 +++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 llarp/tooling/peer_stats_event.hpp create mode 100644 pybind/llarp/tooling/peer_stats_event.hpp create mode 100644 test/hive/test_peer_stats.py diff --git a/llarp/tooling/peer_stats_event.hpp b/llarp/tooling/peer_stats_event.hpp new file mode 100644 index 000000000..34d1f6519 --- /dev/null +++ b/llarp/tooling/peer_stats_event.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include "router_event.hpp" + +namespace tooling +{ + struct LinkSessionEstablishedEvent : public RouterEvent + { + llarp::RouterID remoteId; + bool inbound = false; + + LinkSessionEstablishedEvent( + const llarp::RouterID& ourRouterId, const llarp::RouterID& remoteId_, bool inbound_) + : RouterEvent("Link: LinkSessionEstablishedEvent", ourRouterId, false) + , remoteId(remoteId_) + , inbound(inbound_) + { + } + + std::string + ToString() const + { + return RouterEvent::ToString() + (inbound ? "inbound" : "outbound") + + " : LinkSessionEstablished with " + remoteId.ToString(); + } + }; + + struct ConnectionAttemptEvent : public RouterEvent + { + llarp::RouterID remoteId; + + ConnectionAttemptEvent(const llarp::RouterID& ourRouterId, const llarp::RouterID& remoteId_) + : RouterEvent("Link: ConnectionAttemptEvent", ourRouterId, false), remoteId(remoteId_) + { + } + + std::string + ToString() const + { + return RouterEvent::ToString() + " : LinkSessionEstablished with " + remoteId.ToString(); + } + }; + +} // namespace tooling diff --git a/pybind/llarp/tooling/peer_stats_event.hpp b/pybind/llarp/tooling/peer_stats_event.hpp new file mode 100644 index 000000000..92e7c7381 --- /dev/null +++ b/pybind/llarp/tooling/peer_stats_event.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include "router_event.hpp" + +namespace tooling +{ + struct LinkSessionEstablishedEvent : public RouterEvent + { + llarp::RouterID remoteId; + bool inbound = false; + + LinkSessionEstablishedEvent( + const llarp::RouterID& ourRouterId, const llarp::RouterID& remoteId_, bool inbound_) + : RouterEvent("Link: LinkSessionEstablishedEvent", ourRouterId, false) + , remoteId(remoteId_) + , inbound(inbound_) + { + } + + std::string + ToString() const + { + return RouterEvent::ToString() + (inbound ? "inbound" : "outbound") + + " : LinkSessionEstablished with " + remoteId.ToString(); + } + }; + +} // namespace tooling diff --git a/test/hive/test_peer_stats.py b/test/hive/test_peer_stats.py new file mode 100644 index 000000000..844e76377 --- /dev/null +++ b/test/hive/test_peer_stats.py @@ -0,0 +1,44 @@ +import pyllarp +from time import time + +def test_peer_stats(HiveForPeerStats): + hive = HiveForPeerStats(n_relays=5, n_clients=0, netid="hive") + + start_time = time() + cur_time = start_time + test_duration = 30 #seconds + + paths = [] + + print("looking for events...") + + numInbound = 0 + numOutbound = 0 + numAttempts = 0 + + while cur_time < start_time + test_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 + + hive.events = [] + cur_time = time() + + print("test duration exceeded") + print("in: {} out: {} attempts: {}", numInbound, numOutbound, numAttempts); + assert(numInbound == numOutbound) + assert(numOutbound == numAttempts) + +if __name__ == "__main__": + main()