2018-05-27 19:44:01 +02:00
|
|
|
#ifndef LLARP_HPP
|
|
|
|
#define LLARP_HPP
|
2018-12-12 03:52:51 +01:00
|
|
|
|
2021-02-02 15:35:40 +01:00
|
|
|
#include <future>
|
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>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2021-02-02 15:35:40 +01:00
|
|
|
namespace vpn
|
|
|
|
{
|
|
|
|
class Platform;
|
|
|
|
}
|
|
|
|
|
2021-03-02 08:02:59 +01:00
|
|
|
class EventLoop;
|
2019-02-11 15:43:48 +01:00
|
|
|
struct Config;
|
2019-01-11 01:12:43 +01:00
|
|
|
struct RouterContact;
|
2021-02-02 15:35:40 +01:00
|
|
|
struct Config;
|
|
|
|
struct Crypto;
|
|
|
|
struct CryptoManager;
|
|
|
|
struct AbstractRouter;
|
|
|
|
class NodeDB;
|
|
|
|
|
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
|
|
|
{
|
2022-08-18 16:31:39 +02:00
|
|
|
bool showBanner = true;
|
2020-06-29 21:55:59 +02:00
|
|
|
bool debug = false;
|
2021-03-23 20:00:46 +01:00
|
|
|
bool isSNode = false;
|
2020-06-29 21:55:59 +02:00
|
|
|
};
|
2019-04-05 11:20:48 +02:00
|
|
|
|
2020-06-29 21:55:59 +02:00
|
|
|
struct Context
|
|
|
|
{
|
2021-02-02 15:35:40 +01:00
|
|
|
std::shared_ptr<Crypto> crypto = nullptr;
|
|
|
|
std::shared_ptr<CryptoManager> cryptoManager = nullptr;
|
|
|
|
std::shared_ptr<AbstractRouter> router = nullptr;
|
2021-03-02 08:02:59 +01:00
|
|
|
std::shared_ptr<EventLoop> loop = nullptr;
|
2021-02-02 15:35:40 +01:00
|
|
|
std::shared_ptr<NodeDB> nodedb = nullptr;
|
2018-05-27 19:44:01 +02:00
|
|
|
|
2022-10-27 19:51:45 +02:00
|
|
|
Context();
|
2020-08-12 16:17:13 +02:00
|
|
|
virtual ~Context() = default;
|
2020-08-12 16:12:09 +02:00
|
|
|
|
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);
|
|
|
|
|
2020-07-06 21:13:01 +02:00
|
|
|
/// Configure given the specified config.
|
|
|
|
void
|
2021-02-02 15:35:40 +01:00
|
|
|
Configure(std::shared_ptr<Config> conf);
|
2019-10-04 20:10:58 +02:00
|
|
|
|
2020-08-27 14:43:53 +02:00
|
|
|
/// handle SIGHUP
|
|
|
|
void
|
|
|
|
Reload();
|
|
|
|
|
2019-12-07 20:58:19 +01:00
|
|
|
bool
|
|
|
|
IsUp() const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
LooksAlive() const;
|
|
|
|
|
2021-04-01 13:13:39 +02:00
|
|
|
bool
|
|
|
|
IsStopping() 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.
|
2021-02-02 15:35:40 +01:00
|
|
|
virtual std::shared_ptr<AbstractRouter>
|
2021-03-02 08:02:59 +01:00
|
|
|
makeRouter(const std::shared_ptr<EventLoop>& loop);
|
2020-06-29 17:44:13 +02:00
|
|
|
|
2021-04-02 17:10:37 +02:00
|
|
|
/// create the nodedb given our current configs
|
|
|
|
virtual std::shared_ptr<NodeDB>
|
|
|
|
makeNodeDB();
|
|
|
|
|
2021-01-12 00:13:22 +01:00
|
|
|
/// create the vpn platform for use in creating network interfaces
|
2021-02-02 15:35:40 +01:00
|
|
|
virtual std::shared_ptr<llarp::vpn::Platform>
|
2021-01-12 00:13:22 +01:00
|
|
|
makeVPNPlatform();
|
|
|
|
|
2021-03-02 19:18:22 +01:00
|
|
|
int androidFD = -1;
|
|
|
|
|
2020-07-06 21:13:01 +02:00
|
|
|
protected:
|
2020-08-27 14:43:53 +02:00
|
|
|
std::shared_ptr<Config> config = nullptr;
|
2020-07-06 21:13:01 +02:00
|
|
|
|
2018-05-27 19:44:01 +02:00
|
|
|
private:
|
|
|
|
void
|
|
|
|
SigINT();
|
|
|
|
|
2021-04-01 13:13:39 +02:00
|
|
|
void
|
|
|
|
Close();
|
|
|
|
|
2020-04-07 22:41:11 +02:00
|
|
|
std::unique_ptr<std::promise<void>> closeWaiter;
|
2018-05-27 19:44:01 +02:00
|
|
|
};
|
2018-07-09 05:34:29 +02:00
|
|
|
} // namespace llarp
|
2018-05-27 19:44:01 +02:00
|
|
|
|
|
|
|
#endif
|