2018-05-27 19:44:01 +02:00
|
|
|
#ifndef LLARP_HPP
|
|
|
|
#define LLARP_HPP
|
2019-10-04 20:10:58 +02:00
|
|
|
#include <llarp.h>
|
2019-04-14 19:12:11 +02:00
|
|
|
#include <util/fs.hpp>
|
2019-01-13 17:30:07 +01:00
|
|
|
#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>
|
2020-06-30 17:45:26 +02:00
|
|
|
#include <crypto/crypto.hpp>
|
2020-07-02 17:40:08 +02:00
|
|
|
#include <router/abstractrouter.hpp>
|
2018-12-12 03:52:51 +01:00
|
|
|
|
|
|
|
#include <iostream>
|
2019-04-14 18:08:51 +02:00
|
|
|
#include <map>
|
2018-12-11 01:53:11 +01:00
|
|
|
#include <memory>
|
2018-05-27 19:44:01 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-01-11 01:12:43 +01:00
|
|
|
struct llarp_ev_loop;
|
2018-12-10 17:26:46 +01:00
|
|
|
|
2018-05-27 19:44:01 +02:00
|
|
|
namespace llarp
|
|
|
|
{
|
2019-07-02 23:28:28 +02:00
|
|
|
class Logic;
|
2019-02-11 15:43:48 +01:00
|
|
|
struct Config;
|
2019-01-11 01:12:43 +01:00
|
|
|
struct RouterContact;
|
2019-07-09 15:47:24 +02:00
|
|
|
namespace thread
|
|
|
|
{
|
2019-07-15 11:15:51 +02:00
|
|
|
class ThreadPool;
|
2019-07-09 15:47:24 +02:00
|
|
|
}
|
2019-01-11 01:12:43 +01:00
|
|
|
|
2020-06-29 21:55:59 +02:00
|
|
|
struct RuntimeOptions
|
2018-05-27 19:44:01 +02:00
|
|
|
{
|
2020-06-29 21:55:59 +02:00
|
|
|
bool background = false;
|
|
|
|
bool debug = false;
|
|
|
|
bool isRouter = false;
|
|
|
|
};
|
2019-04-05 11:20:48 +02:00
|
|
|
|
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;
|
2018-05-27 19:44:01 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
Close();
|
|
|
|
|
2018-06-19 11:45:29 +02:00
|
|
|
int
|
|
|
|
LoadDatabase();
|
|
|
|
|
2020-06-29 21:55:59 +02:00
|
|
|
void
|
2020-07-01 16:38:56 +02:00
|
|
|
Setup(const RuntimeOptions& opts);
|
2018-06-23 16:56:59 +02:00
|
|
|
|
2018-05-27 19:44:01 +02:00
|
|
|
int
|
2020-06-29 21:55:59 +02:00
|
|
|
Run(const RuntimeOptions& opts);
|
2018-05-27 19:44:01 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
HandleSignal(int sig);
|
|
|
|
|
2019-10-04 20:10:58 +02:00
|
|
|
bool
|
2020-07-01 16:38:56 +02:00
|
|
|
Configure(const RuntimeOptions& opts, std::optional<fs::path> dataDir);
|
2019-10-04 20:10:58 +02:00
|
|
|
|
2019-12-07 20:58:19 +01:00
|
|
|
bool
|
|
|
|
IsUp() const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
LooksAlive() const;
|
|
|
|
|
2019-10-09 15:08:38 +02:00
|
|
|
/// close async
|
|
|
|
void
|
2019-10-09 15:09:42 +02:00
|
|
|
CloseAsync();
|
2019-10-09 15:08:38 +02:00
|
|
|
|
|
|
|
/// wait until closed and done
|
|
|
|
void
|
|
|
|
Wait();
|
|
|
|
|
2019-10-04 20:10:58 +02:00
|
|
|
/// call a function in logic thread
|
|
|
|
/// return true if queued for calling
|
|
|
|
/// return false if not queued for calling
|
|
|
|
bool
|
2020-04-07 20:38:56 +02:00
|
|
|
CallSafe(std::function<void(void)> f);
|
2019-10-04 20:10:58 +02:00
|
|
|
|
2020-06-29 17:44:13 +02:00
|
|
|
/// 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);
|
|
|
|
|
2018-05-27 19:44:01 +02:00
|
|
|
private:
|
|
|
|
void
|
|
|
|
SigINT();
|
|
|
|
|
|
|
|
std::string configfile;
|
2020-04-07 22:41:11 +02:00
|
|
|
std::unique_ptr<std::promise<void>> closeWaiter;
|
2018-05-27 19:44:01 +02:00
|
|
|
};
|
2020-06-08 14:42:10 +02:00
|
|
|
|
2018-07-09 05:34:29 +02:00
|
|
|
} // namespace llarp
|
2018-05-27 19:44:01 +02:00
|
|
|
|
|
|
|
#endif
|