Initial test_peer_stats hive test

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

@ -76,7 +76,7 @@ namespace llarp
GotLIM = util::memFn(&Session::GotRenegLIM, this);
m_RemoteRC = msg->rc;
m_Parent->MapAddr(m_RemoteRC.pubkey, this);
return m_Parent->SessionEstablished(this);
return m_Parent->SessionEstablished(this, true);
}
bool
@ -96,7 +96,7 @@ namespace llarp
{
self->m_State = State::Ready;
self->m_Parent->MapAddr(self->m_RemoteRC.pubkey, self.get());
self->m_Parent->SessionEstablished(self.get());
self->m_Parent->SessionEstablished(self.get(), false);
}
});
return true;

@ -43,7 +43,7 @@ namespace llarp
/// return true to accept
///
/// currently called in iwp::Session when a valid LIM is received.
using SessionEstablishedHandler = std::function<bool(ILinkSession*)>;
using SessionEstablishedHandler = std::function<bool(ILinkSession*, bool)>;
/// f(new, old)
/// handler of session renegotiation

@ -21,6 +21,7 @@
#include <util/meta/memfn.hpp>
#include <util/str.hpp>
#include <ev/ev.hpp>
#include <tooling/peer_stats_event.hpp>
#include "tooling/router_event.hpp"
#include "util/status.hpp"
@ -837,14 +838,15 @@ namespace llarp
}
bool
Router::ConnectionEstablished(ILinkSession* session)
Router::ConnectionEstablished(ILinkSession* session, bool inbound)
{
RouterID id{session->GetPubKey()};
if (m_peerDb)
{
RouterID id{session->GetPubKey()};
// TODO: make sure this is a public router (on whitelist)?
m_peerDb->modifyPeerStats(id, [&](PeerStats& stats) { stats.numConnectionSuccesses++; });
}
NotifyRouterEvent<tooling::LinkSessionEstablishedEvent>(pubkey(), id, inbound);
return _outboundSessionMaker.OnSessionEstablished(session);
}

@ -440,7 +440,7 @@ namespace llarp
/// called by link when session is fully established
bool
ConnectionEstablished(ILinkSession* session);
ConnectionEstablished(ILinkSession* session, bool inbound);
/// call internal router ticker
void

@ -5,6 +5,7 @@
#include "tooling/dht_event.hpp"
#include "tooling/path_event.hpp"
#include "tooling/rc_event.hpp"
#include "tooling/peer_stats_event.hpp"
#include <messages/relay_status.hpp>
#include <path/path.hpp>
@ -73,6 +74,10 @@ namespace tooling
mod, "FindRouterReceivedEvent");
py::class_<FindRouterSentEvent, FindRouterEvent, RouterEvent>(mod, "FindRouterSentEvent");
py::class_<LinkSessionEstablishedEvent, RouterEvent>(mod, "LinkSessionEstablishedEvent")
.def_readonly("remoteId", &LinkSessionEstablishedEvent::remoteId)
.def_readonly("inbound", &LinkSessionEstablishedEvent::inbound);
}
} // namespace tooling

@ -33,3 +33,15 @@ def HiveArbitrary():
router_hive.Stop()
@pytest.fixture()
def HiveForPeerStats():
router_hive = None
def _make(n_relays, n_clients, netid):
nonlocal router_hive
router_hive = hive.RouterHive(n_relays, n_clients, netid)
router_hive.Start()
return router_hive
yield _make
router_hive.Stop()

Loading…
Cancel
Save