mirror of https://github.com/oxen-io/lokinet
LRSM RouterEvent, added to hive test and test passes.
This commit is contained in:
parent
138a0b33fb
commit
df0380e746
|
@ -10,6 +10,7 @@
|
|||
#include <util/logging/logger.hpp>
|
||||
#include <util/meta/memfn.hpp>
|
||||
#include <util/thread/logic.hpp>
|
||||
#include <tooling/router_event.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
@ -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<tooling::PathStatusReceivedEvent>(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();
|
||||
|
||||
|
|
|
@ -23,7 +23,9 @@ namespace tooling
|
|||
}
|
||||
|
||||
PathAttemptEvent::PathAttemptEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::Path> 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
|
||||
|
|
|
@ -54,6 +54,8 @@ namespace tooling
|
|||
std::string ToString() const override;
|
||||
|
||||
std::vector<llarp::path::PathHopConfig> 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
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "tooling/router_event.hpp"
|
||||
#include "tooling/dht_event.hpp"
|
||||
|
||||
#include <messages/relay_status.hpp>
|
||||
#include <path/path.hpp>
|
||||
|
||||
namespace tooling
|
||||
|
@ -27,6 +28,13 @@ namespace tooling
|
|||
.def_readonly("rxid", &PathRequestReceivedEvent::rxid)
|
||||
.def_readonly("isEndpoint", &PathRequestReceivedEvent::isEndpoint);
|
||||
|
||||
py::class_<PathStatusReceivedEvent, RouterEvent>(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_<PubIntroReceivedEvent, RouterEvent>(mod, "DhtPubIntroReceivedEvent")
|
||||
.def_readonly("from", &PubIntroReceivedEvent::From)
|
||||
.def_readonly("location", &PubIntroReceivedEvent::IntrosetLocation)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue