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 16:08:51 +00: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 13:47:24 +00:00
namespace thread
{
class ThreadPool;
2019-07-09 13:47:24 +00:00
}
2020-06-29 19:55:59 +00:00
struct RuntimeOptions
{
2020-06-29 19:55:59 +00:00
bool background = false;
bool debug = false;
bool isSNode = false;
2020-06-29 19:55:59 +00:00
};
2020-06-29 19:55:59 +00: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;
2018-09-17 12:02:09 +00:00
std::string nodedb_dir;
2020-08-12 14:17:13 +00:00
virtual ~Context() = default;
2020-06-29 19:55:59 +00:00
void
Setup(const RuntimeOptions& opts);
int
2020-06-29 19:55:59 +00:00
Run(const RuntimeOptions& opts);
void
HandleSignal(int sig);
/// Configure given the specified config.
void
Configure(std::shared_ptr<Config> conf);
2020-08-27 12:43:53 +00:00
/// handle SIGHUP
void
Reload();
bool
IsUp() const;
bool
LooksAlive() const;
2021-04-01 11:13:39 +00:00
bool
IsStopping() const;
/// close async
void
2019-10-09 13:09:42 +00: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 12:43:53 +00:00
std::shared_ptr<Config> config = nullptr;
private:
void
SigINT();
2021-04-01 11:13:39 +00:00
void
Close();
std::unique_ptr<std::promise<void>> closeWaiter;
};
2018-07-09 03:34:29 +00:00
} // namespace llarp
#endif