lokinet/include/llarp.hpp

104 lines
1.9 KiB
C++
Raw Normal View History

#ifndef LLARP_HPP
#define LLARP_HPP
#include <llarp.h>
2019-04-14 17:12:11 +00:00
#include <util/fs.hpp>
#include <util/types.hpp>
2019-04-08 12:01:52 +00:00
#include <ev/ev.hpp>
2020-06-29 19:55:59 +00:00
#include <nodedb.hpp>
#include <crypto/crypto.hpp>
#include <iostream>
2019-04-14 16:08:51 +00:00
#include <map>
#include <memory>
#include <string>
#include <vector>
struct llarp_ev_loop;
namespace llarp
{
class Logic;
struct AbstractRouter;
struct Config;
struct RouterContact;
2019-07-09 13:47:24 +00:00
namespace thread
{
class ThreadPool;
2019-07-09 13:47:24 +00:00
}
2020-06-29 19:55:59 +00:00
struct RuntimeOptions
{
2020-06-29 19:55:59 +00:00
bool background = false;
bool debug = false;
bool isRouter = false;
};
2020-06-29 19:55:59 +00:00
struct Context
{
std::unique_ptr<Crypto> crypto;
std::unique_ptr<CryptoManager> cryptoManager;
std::unique_ptr<AbstractRouter> router;
std::shared_ptr<Logic> logic;
std::unique_ptr<Config> config;
std::unique_ptr<llarp_nodedb> nodedb;
2019-04-08 12:01:52 +00:00
llarp_ev_loop_ptr mainloop;
2018-09-17 12:02:09 +00:00
std::string nodedb_dir;
void
Close();
2018-06-19 09:45:29 +00:00
int
LoadDatabase();
2020-06-29 19:55:59 +00:00
void
Setup(const RuntimeOptions& opts);
int
2020-06-29 19:55:59 +00:00
Run(const RuntimeOptions& opts);
void
HandleSignal(int sig);
bool
Configure(const RuntimeOptions& opts, std::optional<fs::path> dataDir);
bool
IsUp() const;
bool
LooksAlive() const;
/// close async
void
2019-10-09 13:09:42 +00:00
CloseAsync();
/// wait until closed and done
void
Wait();
/// call a function in logic thread
/// return true if queued for calling
/// return false if not queued for calling
bool
CallSafe(std::function<void(void)> f);
/// Creates a router. Can be overridden to allow a different class of router
/// to be created instead. Defaults to llarp::Router.
virtual std::unique_ptr<AbstractRouter>
makeRouter(
std::shared_ptr<llarp::thread::ThreadPool> worker,
llarp_ev_loop_ptr __netloop,
std::shared_ptr<Logic> logic);
private:
void
SigINT();
std::string configfile;
std::unique_ptr<std::promise<void>> closeWaiter;
};
2020-06-08 12:42:10 +00:00
2018-07-09 03:34:29 +00:00
} // namespace llarp
#endif