RouterHive initial commit, minor changes to RouterEvent

pull/1184/head
Thomas Winget 4 years ago
parent 07c5d6f5df
commit 6a0ee9dc55

@ -1,14 +1,24 @@
#include "tooling/router_event.cpp"
#include "llarp/router_id.hpp"
#include <tooling/router_event.hpp>
#include <tooling/router_hive.hpp>
#include <llarp/router_id.hpp>
#include <llarp/path/path.hpp>
namespace tooling
{
PathBuildAttemptEvent::PathBuildAttemptEvent(const llarp::RouterID& routerID, std::vector<llarp::RouterID> hops)
PathBuildAttemptEvent::PathBuildAttemptEvent(const llarp::RouterID& routerID, std::vector<llarp::path::PathHopConfig> hops)
: routerID(routerID), hops(hops)
{
}
void
PathBuildAttemptEvent::Process(RouterHive& hive) const
{
hive.ProcessPathBuildAttempt(*this);
}
std::string
PathBuildAttemptEvent::ToString() const
{
@ -21,7 +31,7 @@ namespace tooling
{
i++;
result += hop.ToString().substr(0, 8);
result += hop.rc.pubkey.ToString().substr(0, 8);
result += "]";
if (i != hops.size())

@ -8,16 +8,26 @@ namespace llarp
struct RouterID;
namespace path
{
struct PathHopConfig;
} // namespace llarp::path
} // namespace llarp
namespace tooling
{
struct RouterHive;
struct RouterEvent
{
virtual ~RouterEvent() = default;
virtual void Process(RouterHive& hive) const = 0;
virtual std::string ToString() const = 0;
llarp::RouterID routerID;
@ -25,11 +35,13 @@ namespace tooling
struct PathBuildAttemptEvent : public RouterEvent
{
PathBuildAttemptEvent(const llarp::RouterID& routerID, std::vector<llarp::RouterID> hops);
PathBuildAttemptEvent(const llarp::RouterID& routerID, std::vector<llarp::path::PathHopConfig> hops);
void Process(RouterHive& hive) const;
std::string ToString() const override;
std::vector<llarp::RouterID> hops;
std::vector<llarp::path::PathHopConfig> hops;
}
} // namespace tooling

@ -0,0 +1,39 @@
#include <tooling/router_hive.hpp>
namespace tooling
{
RouterHive::RouterHive(size_t eventQueueSize) : eventQueue(eventQueueSize)
{
}
void
RouterHive::InformEvent(RouterEvent event)
{
if(eventQueue.tryPushBack(std::move(event))
!= llarp::thread::QueueReturn::Success)
{
LogError("RouterHive Event Queue appears to be full. Either implement/change time dilation or increase the queue size.");
}
}
void
RouterHive::ProcessEventQueue()
{
while(not eventQueue.empty())
{
RouterEvent event = eventQueue.popFront();
event.Process(*this);
}
}
void
ProcessPathBuildAttempt(PathBuildAttemptEvent event)
{
}
} // namespace tooling

@ -0,0 +1,35 @@
#pragma once
#include <tooling/router_event.hpp>
#include <util/thread/queue.hpp>
namespace tooling
{
struct RouterHive
{
constexpr size_t MAX_EVENT_QUEUE_SIZE = 200;
RouterHive(size_t eventQueueSize = MAX_EVENT_QUEUE_SIZE);
void
InformEvent(RouterEvent event);
void
ProcessEventQueue();
/*
* Event processing function declarations
*/
void
ProcessPathBuildAttempt(PathBuildAttemptEvent event);
llarp::thread::Queue<RouterEvent> eventQueue;
};
} // namespace tooling
Loading…
Cancel
Save