1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/include/llarp.hpp

104 lines
2 KiB
C++
Raw Normal View History

#ifndef LLARP_HPP
#define LLARP_HPP
#include <llarp.h>
2019-04-14 19:12:11 +02:00
#include <util/fs.hpp>
#include <util/types.hpp>
2019-04-08 14:01:52 +02:00
#include <ev/ev.hpp>
2020-06-29 21:55:59 +02:00
#include <nodedb.hpp>
#include <crypto/crypto.hpp>
2020-07-02 17:40:08 +02:00
#include <router/abstractrouter.hpp>
#include <iostream>
2019-04-14 18:08:51 +02:00
#include <map>
#include <memory>
#include <string>
#include <vector>
struct llarp_ev_loop;
namespace llarp
{
class Logic;
struct Config;
struct RouterContact;
2019-07-09 15:47:24 +02:00
namespace thread
{
class ThreadPool;
2019-07-09 15:47:24 +02:00
}
2020-06-29 21:55:59 +02:00
struct RuntimeOptions
{
2020-06-29 21:55:59 +02:00
bool background = false;
bool debug = false;
bool isRouter = false;
};
2020-06-29 21:55:59 +02:00
struct Context
{
2020-07-02 17:40:08 +02:00
std::unique_ptr<Crypto> crypto = nullptr;
std::unique_ptr<CryptoManager> cryptoManager = nullptr;
std::unique_ptr<AbstractRouter> router = nullptr;
std::shared_ptr<Logic> logic = nullptr;
std::unique_ptr<Config> config = nullptr;
std::unique_ptr<llarp_nodedb> nodedb = nullptr;
2019-04-08 14:01:52 +02:00
llarp_ev_loop_ptr mainloop;
2018-09-17 14:02:09 +02:00
std::string nodedb_dir;
void
Close();
2018-06-19 11:45:29 +02:00
int
LoadDatabase();
2020-06-29 21:55:59 +02:00
void
Setup(const RuntimeOptions& opts);
int
2020-06-29 21:55:59 +02: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 15:09:42 +02: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 14:42:10 +02:00
2018-07-09 05:34:29 +02:00
} // namespace llarp
#endif