lokinet/include/llarp.hpp

120 lines
2.2 KiB
C++
Raw Normal View History

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