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