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