From df0380e7460293b70d37d2d577daeea8ad8098a2 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Tue, 3 Mar 2020 00:26:25 -0500 Subject: [PATCH] LRSM RouterEvent, added to hive test and test passes. --- llarp/messages/relay_status.cpp | 10 +++++++-- llarp/tooling/router_event.cpp | 21 +++++++++++++++++- llarp/tooling/router_event.hpp | 13 +++++++++++ pybind/llarp/tooling/router_event.cpp | 8 +++++++ test/hive/test_path_builds.py | 31 +++++++++++++++++++-------- 5 files changed, 71 insertions(+), 12 deletions(-) diff --git a/llarp/messages/relay_status.cpp b/llarp/messages/relay_status.cpp index 02bd7ea78..7d839707e 100644 --- a/llarp/messages/relay_status.cpp +++ b/llarp/messages/relay_status.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -25,13 +26,15 @@ namespace llarp uint64_t status = 0; HopHandler_ptr path; AbstractRouter* router; + PathID_t pathid; LRSM_AsyncHandler(std::array< EncryptedFrame, 8 > _frames, uint64_t _status, - HopHandler_ptr _path, AbstractRouter* _router) + HopHandler_ptr _path, AbstractRouter* _router, const PathID_t& pathid) : frames(std::move(_frames)) , status(_status) , path(std::move(_path)) , router(_router) + , pathid(pathid) { } @@ -40,6 +43,9 @@ namespace llarp void handle() { + auto ev = std::make_unique(router->pubkey(), pathid, status); + router->NotifyRouterEvent(std::move(ev)); + path->HandleLRSM(status, frames, router); } @@ -141,7 +147,7 @@ namespace llarp } auto handler = - std::make_shared< LRSM_AsyncHandler >(frames, status, path, router); + std::make_shared< LRSM_AsyncHandler >(frames, status, path, router, pathid); handler->queue_handle(); diff --git a/llarp/tooling/router_event.cpp b/llarp/tooling/router_event.cpp index 470dc6716..4f6144a95 100644 --- a/llarp/tooling/router_event.cpp +++ b/llarp/tooling/router_event.cpp @@ -23,7 +23,9 @@ namespace tooling } PathAttemptEvent::PathAttemptEvent(const llarp::RouterID& routerID, std::shared_ptr path) - : RouterEvent("PathAttemptEvent", routerID, false), hops(path->hops) + : RouterEvent("PathAttemptEvent", routerID, false) + , hops(path->hops) + , pathid(path->hops[0].rxID) { } @@ -88,4 +90,21 @@ namespace tooling return result; } + PathStatusReceivedEvent::PathStatusReceivedEvent(const llarp::RouterID& routerID, const llarp::PathID_t rxid, uint64_t status) + : RouterEvent("PathStatusReceivedEvent", routerID, true) + , rxid(rxid) + , status(status) + { + } + + std::string + PathStatusReceivedEvent::ToString() const + { + std::string result = RouterEvent::ToString(); + result += "---- path rxid: " + rxid.ShortHex(); + result += ", status: " + std::to_string(status); + + return result; + } + } // namespace tooling diff --git a/llarp/tooling/router_event.hpp b/llarp/tooling/router_event.hpp index 3a1c1d53b..175a67e22 100644 --- a/llarp/tooling/router_event.hpp +++ b/llarp/tooling/router_event.hpp @@ -54,6 +54,8 @@ namespace tooling std::string ToString() const override; std::vector hops; + + llarp::PathID_t pathid; }; struct PathRequestReceivedEvent : public RouterEvent @@ -71,4 +73,15 @@ namespace tooling bool isEndpoint = false; }; + struct PathStatusReceivedEvent : public RouterEvent + { + PathStatusReceivedEvent(const llarp::RouterID& routerID, const llarp::PathID_t rxid, uint64_t status); + + std::string ToString() const override; + + llarp::PathID_t rxid; + + uint64_t status; + }; + } // namespace tooling diff --git a/pybind/llarp/tooling/router_event.cpp b/pybind/llarp/tooling/router_event.cpp index 5ee55658b..3dd529ef9 100644 --- a/pybind/llarp/tooling/router_event.cpp +++ b/pybind/llarp/tooling/router_event.cpp @@ -4,6 +4,7 @@ #include "tooling/router_event.hpp" #include "tooling/dht_event.hpp" +#include #include namespace tooling @@ -27,6 +28,13 @@ namespace tooling .def_readonly("rxid", &PathRequestReceivedEvent::rxid) .def_readonly("isEndpoint", &PathRequestReceivedEvent::isEndpoint); + py::class_(mod, "PathStatusReceivedEvent") + .def_readonly("rxid", &PathStatusReceivedEvent::rxid) + .def_readonly("status", &PathStatusReceivedEvent::rxid) + .def_property_readonly("Successful", [](const PathStatusReceivedEvent* const ev) { + return ev->status == llarp::LR_StatusRecord::SUCCESS; + }); + py::class_(mod, "DhtPubIntroReceivedEvent") .def_readonly("from", &PubIntroReceivedEvent::From) .def_readonly("location", &PubIntroReceivedEvent::IntrosetLocation) diff --git a/test/hive/test_path_builds.py b/test/hive/test_path_builds.py index 2d49750db..677f46303 100644 --- a/test/hive/test_path_builds.py +++ b/test/hive/test_path_builds.py @@ -26,6 +26,8 @@ def test_path_builds(HiveTenTen): for i in range(1, len(event.hops)): path["prev"][i] = event.hops[i-1].rc.routerID path["prev"][0] = event.routerID + path["rxid"] = event.hops[0].rxid + path["status"] = None paths.append(path) elif event_name == "PathRequestReceivedEvent": @@ -41,6 +43,11 @@ def test_path_builds(HiveTenTen): path["hops"][i].rxid == event.rxid): path["received"][i] = True + elif event_name == "PathStatusReceivedEvent": + for path in paths: + if event.rxid == path["rxid"]: + path["status"] = event + h.events = [] cur_time = time() @@ -50,22 +57,28 @@ def test_path_builds(HiveTenTen): assert len(paths) > 0 - fail_count = 0 + fail_status_count = 0 + missing_status_count = 0 + missing_rcv_count = 0 expected_count = 0 - paths_ok = [] for path in paths: - path_ok = True + if path["status"]: + if not path["status"].Successful: + print(path["status"]) + fail_status_count = fail_status_count + 1 + else: + missing_status_count = missing_status_count + 1 + for rcv in path["received"]: expected_count = expected_count + 1 if not rcv: - path_ok = False - fail_count = fail_count + 1 + missing_rcv_count = missing_rcv_count + 1 - paths_ok.append(path_ok) - print("Path count: {}, Expected rcv: {}, Failed rcv: {}".format(len(paths), expected_count, fail_count)) + print("Path count: {}, Expected rcv: {}, missing rcv: {}, fail_status_count: {}, missing_status_count: {}".format(len(paths), expected_count, missing_rcv_count, fail_status_count, missing_status_count)) - for path_ok in paths_ok: - assert path_ok + assert fail_status_count == 0 + assert missing_rcv_count == 0 + assert missing_status_count == 0