more router hive stuff, read below the fold

Router now has a hive pointer if LOKINET_HIVE is set.
llarp::Context has a method InjectHive to give Router the pointer.
Router has a method NotifyRouterEvent which does:
  - when LOKINET_HIVE is set, passes the event to RouterHive
  - else when LOKINET_DEBUG is set, prints the event at a low log level
  - else NOP
pull/1184/head
Thomas Winget 4 years ago
parent cd48b3946e
commit 8d03e6dd3c

@ -16,6 +16,13 @@ struct llarp_nodedb;
struct llarp_nodedb_iter;
struct llarp_main;
#ifdef LOKINET_HIVE
namespace tooling
{
struct RouterHive;
} // namespace tooling
#endif
namespace llarp
{
class Logic;
@ -88,6 +95,11 @@ namespace llarp
bool
CallSafe(std::function< void(void) > f);
#ifdef LOKINET_HIVE
void
InjectHive(tooling::RouterHive* hive);
#endif
private:
void
SetPIDFile(const std::string &fname);

@ -298,6 +298,14 @@ namespace llarp
configfile = fname;
return Configure();
}
#ifdef LOKINET_HIVE
void
Context::InjectHive(tooling::RouterHive* hive)
{
router->hive = hive;
}
#endif
} // namespace llarp
struct llarp_main

@ -16,6 +16,11 @@ struct llarp_dht_context;
struct llarp_nodedb;
struct llarp_threadpool;
namespace tooling
{
struct RouterEvent;
} // namespace tooling
namespace llarp
{
class Logic;
@ -260,6 +265,9 @@ namespace llarp
/// gossip an rc if required
virtual void
GossipRCIfNeeded(const RouterContact rc) = 0;
virtual void
NotifyRouterEvent(RouterEvent event) const = 0;
};
} // namespace llarp

@ -125,6 +125,16 @@ namespace llarp
_rcGossiper.GossipRC(rc);
}
void
Router::NotifyRouterEvent(RouterEvent event) const
{
#ifdef LOKINET_HIVE
hive->NotifyEvent(event);
#elif LOKINET_DEBUG
LogDebug(event.ToString);
#endif
}
bool
Router::GetRandomGoodRouter(RouterID &router)
{

@ -43,6 +43,12 @@
#include <unordered_map>
#include <vector>
namespace tooling
{
struct RouterHive;
struct RouterEvent;
} // namespace tooling
namespace llarp
{
struct Config;
@ -282,6 +288,10 @@ namespace llarp
TimePoint_t m_NextExploreAt;
#ifdef LOKINET_HIVE
RouterHive* hive;
#endif
IOutboundMessageHandler &
outboundMessageHandler() override
{
@ -309,6 +319,9 @@ namespace llarp
void
GossipRCIfNeeded(const RouterContact rc) override;
void
NotifyRouterEvent(RouterEvent event) const override;
Router(std::shared_ptr< llarp::thread::ThreadPool > worker,
llarp_ev_loop_ptr __netloop, std::shared_ptr< Logic > logic);

@ -1,5 +1,8 @@
#include <tooling/router_hive.hpp>
#include "include/llarp.h"
#include "include/llarp.hpp"
#include <chrono>
namespace tooling
@ -13,6 +16,7 @@ namespace tooling
RouterHive::AddRouter(llarp_config* conf)
{
llarp_main* ctx = llarp_main_init_from_config(conf);
llarp::Context::Get(ctx)->InjectHive(this);
routers.push_back(ctx);
}
@ -47,7 +51,7 @@ namespace tooling
}
void
RouterHive::InformEvent(RouterEvent event)
RouterHive::NotifyEvent(RouterEvent event)
{
if(eventQueue.tryPushBack(std::move(event))
!= llarp::thread::QueueReturn::Success)
@ -67,10 +71,8 @@ namespace tooling
}
}
void
ProcessPathBuildAttempt(PathBuildAttemptEvent event)
RouterHive::ProcessPathBuildAttempt(PathBuildAttemptEvent event)
{
}

@ -5,7 +5,11 @@
#include <llarp.h>
#include <util/thread/queue.hpp>
#include <vector>
#include <thread>
struct llarp_config;
struct llarp_main;
namespace tooling
{
@ -20,7 +24,13 @@ namespace tooling
AddRouter(llarp_config* conf);
void
InformEvent(RouterEvent event);
StartRouters();
void
StopRouters();
void
NotifyEvent(RouterEvent event);
void
ProcessEventQueue();
@ -34,6 +44,9 @@ namespace tooling
ProcessPathBuildAttempt(PathBuildAttemptEvent event);
std::vector<llarp_main *> routers;
std::vector<std::thread> routerMainThreads;
llarp::thread::Queue<RouterEvent> eventQueue;
};

Loading…
Cancel
Save