Merge remote-tracking branch 'micheal/background_mode' into vpn-api-2019-10-03

pull/869/head
jeff 5 years ago
commit 52757fef0e

@ -44,6 +44,10 @@ matrix:
os: osx os: osx
osx_image: xcode10.2 osx_image: xcode10.2
env: BUILD_TYPE=Release PATH="/usr/local/opt/ccache/libexec:$PATH" env: BUILD_TYPE=Release PATH="/usr/local/opt/ccache/libexec:$PATH"
- name: "make iOS"
os: osx
osx_image: xcode10.2
env: MAKE_TARGET=ios PATH="/usr/local/opt/ccache/libexec:$PATH"
- name: "make windows (macOS)" - name: "make windows (macOS)"
os: osx os: osx
osx_image: xcode10.2 osx_image: xcode10.2

@ -42,22 +42,7 @@ endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
# Basic definitions include(cmake/basic_definitions.cmake)
set(LIB lokinet)
set(SHARED_LIB ${LIB}-shared)
set(STATIC_LIB ${LIB}-static)
set(CRYPTOGRAPHY_LIB ${LIB}-cryptography)
set(UTIL_LIB ${LIB}-util)
set(PLATFORM_LIB ${LIB}-platform)
set(ANDROID_LIB ${LIB}android)
set(ABYSS libabyss)
set(ABYSS_LIB abyss)
set(ABYSS_EXE ${ABYSS_LIB}-main)
get_filename_component(TT_ROOT "vendor/libtuntap-master" ABSOLUTE)
add_definitions(-D${CMAKE_SYSTEM_NAME})
get_filename_component(CORE_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/include" ABSOLUTE)
get_filename_component(ABYSS_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include" ABSOLUTE)
if(MSVC_VERSION) if(MSVC_VERSION)
enable_language(ASM_MASM) enable_language(ASM_MASM)
@ -211,7 +196,7 @@ if(NOT GIT_VERSION)
string(STRIP "${GIT_VERSION_UNSTRIP}" GIT_VERSION) string(STRIP "${GIT_VERSION_UNSTRIP}" GIT_VERSION)
endif(NOT GIT_VERSION) endif(NOT GIT_VERSION)
string(REGEX REPLACE ^fatal.*$ nogit GIT_VERSION_REAL "${GIT_VERSION}") string(REGEX REPLACE "^fatal.*$" nogit GIT_VERSION_REAL "${GIT_VERSION}")
add_definitions("-DGIT_REV=\"${GIT_VERSION_REAL}\"") add_definitions("-DGIT_REV=\"${GIT_VERSION_REAL}\"")
set(EXE lokinet) set(EXE lokinet)

@ -208,6 +208,10 @@ $(LIBUV_PREFIX):
mkdir -p $(BUILD_ROOT) mkdir -p $(BUILD_ROOT)
git clone -b "$(LIBUV_VERSION)" https://github.com/libuv/libuv "$(LIBUV_PREFIX)" git clone -b "$(LIBUV_VERSION)" https://github.com/libuv/libuv "$(LIBUV_PREFIX)"
ios:
cmake -S ui-ios -B build -G Xcode -DCMAKE_TOOLCHAIN_FILE=$(shell pwd)/ui-ios/ios-toolchain.cmake -DCMAKE_SYSTEM_NAME=iOS "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" -DCMAKE_OSX_DEPLOYMENT_TARGET=12.2 -DCMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO -DCMAKE_IOS_INSTALL_COMBINED=YES
cmake --build build
android-gradle-prepare: $(LIBUV_PREFIX) android-gradle-prepare: $(LIBUV_PREFIX)
rm -f $(ANDROID_PROPS) rm -f $(ANDROID_PROPS)
rm -f $(ANDROID_LOCAL_PROPS) rm -f $(ANDROID_LOCAL_PROPS)

@ -0,0 +1,16 @@
# Basic definitions
set(LIB lokinet)
set(SHARED_LIB ${LIB}-shared)
set(STATIC_LIB ${LIB}-static)
set(CRYPTOGRAPHY_LIB ${LIB}-cryptography)
set(UTIL_LIB ${LIB}-util)
set(PLATFORM_LIB ${LIB}-platform)
set(ANDROID_LIB ${LIB}android)
set(ABYSS libabyss)
set(ABYSS_LIB abyss)
set(ABYSS_EXE ${ABYSS_LIB}-main)
get_filename_component(TT_ROOT "vendor/libtuntap-master" ABSOLUTE)
add_definitions(-D${CMAKE_SYSTEM_NAME})
get_filename_component(CORE_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/include" ABSOLUTE)
get_filename_component(ABYSS_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include" ABSOLUTE)

@ -18,7 +18,7 @@ if(LIBUV_ROOT)
set(LIBUV_LIBRARY uv_a) set(LIBUV_LIBRARY uv_a)
add_definitions(-D_LARGEFILE_SOURCE) add_definitions(-D_LARGEFILE_SOURCE)
add_definitions(-D_FILE_OFFSET_BITS=64) add_definitions(-D_FILE_OFFSET_BITS=64)
else() elseif(NOT LIBUV_IN_SOURCE)
find_package(LibUV 1.28.0 REQUIRED) find_package(LibUV 1.28.0 REQUIRED)
endif() endif()
@ -46,7 +46,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "DragonFly") elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "DragonFly")
find_library(FS_LIB NAMES c++experimental) find_library(FS_LIB NAMES c++experimental)
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c) set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR ${CMAKE_SYSTEM_NAME} MATCHES "iOS")
find_library(FS_LIB NAMES c++fs c++experimental stdc++fs) find_library(FS_LIB NAMES c++fs c++experimental stdc++fs)
if(FS_LIB STREQUAL FS_LIB-NOTFOUND) if(FS_LIB STREQUAL FS_LIB-NOTFOUND)
include_directories("${CMAKE_CURRENT_LIST_DIR}/../vendor/cppbackport-master/lib") include_directories("${CMAKE_CURRENT_LIST_DIR}/../vendor/cppbackport-master/lib")
@ -69,7 +69,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
set(FS_LIB stdc++fs) set(FS_LIB stdc++fs)
endif() endif()
else() else()
message(FATAL_ERROR "Your operating system is not supported yet") message(FATAL_ERROR "Your operating system - ${CMAKE_SYSTEM_NAME} is not supported yet")
endif() endif()

@ -1,6 +1,6 @@
set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
set(TOOLCHAIN_SUFFIX "") set(TOOLCHAIN_SUFFIX "-posix")
set(WIN64_CROSS_COMPILE ON) set(WIN64_CROSS_COMPILE ON)
set(TOOLCHAIN_PATHS set(TOOLCHAIN_PATHS

@ -1,4 +1,5 @@
#include <config/config.hpp> // for ensure_config #include <config/config.hpp> // for ensure_config
#include <constants/version.hpp>
#include <llarp.h> #include <llarp.h>
#include <util/fs.hpp> #include <util/fs.hpp>
#include <util/logging/logger.hpp> #include <util/logging/logger.hpp>
@ -13,6 +14,7 @@
#include <cxxopts.hpp> #include <cxxopts.hpp>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <future>
#ifdef _WIN32 #ifdef _WIN32
#define wmin(x, y) (((x) < (y)) ? (x) : (y)) #define wmin(x, y) (((x) < (y)) ? (x) : (y))
@ -84,12 +86,12 @@ resolvePath(std::string conffname)
/// this sets up, configures and runs the main context /// this sets up, configures and runs the main context
static void static void
run_main_context(std::string conffname, bool multiThreaded, bool debugMode) run_main_context(std::string conffname, llarp_main_runtime_opts opts)
{ {
// this is important, can downgrade from Info though // this is important, can downgrade from Info though
llarp::LogDebug("Running from: ", fs::current_path().string()); llarp::LogDebug("Running from: ", fs::current_path().string());
llarp::LogInfo("Using config file: ", conffname); llarp::LogInfo("Using config file: ", conffname);
ctx = llarp_main_init(conffname.c_str(), multiThreaded); ctx = llarp_main_init(conffname.c_str());
int code = 1; int code = 1;
if(ctx) if(ctx)
{ {
@ -98,10 +100,10 @@ run_main_context(std::string conffname, bool multiThreaded, bool debugMode)
#ifndef _WIN32 #ifndef _WIN32
signal(SIGHUP, handle_signal); signal(SIGHUP, handle_signal);
#endif #endif
code = llarp_main_setup(ctx, debugMode); code = llarp_main_setup(ctx);
llarp::util::SetThreadName("llarp-mainloop"); llarp::util::SetThreadName("llarp-mainloop");
if(code == 0) if(code == 0)
code = llarp_main_run(ctx); code = llarp_main_run(ctx, opts);
llarp_main_free(ctx); llarp_main_free(ctx);
} }
exit_code.set_value(code); exit_code.set_value(code);
@ -110,11 +112,11 @@ run_main_context(std::string conffname, bool multiThreaded, bool debugMode)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
bool multiThreaded = true; llarp_main_runtime_opts opts;
const char *singleThreadVar = getenv("LLARP_SHADOW"); const char *singleThreadVar = getenv("LLARP_SHADOW");
if(singleThreadVar && std::string(singleThreadVar) == "1") if(singleThreadVar && std::string(singleThreadVar) == "1")
{ {
multiThreaded = false; opts.singleThreaded = true;
} }
#ifdef _WIN32 #ifdef _WIN32
@ -136,22 +138,21 @@ main(int argc, char *argv[])
options.add_options() options.add_options()
("v,verbose", "Verbose", cxxopts::value<bool>()) ("v,verbose", "Verbose", cxxopts::value<bool>())
("h,help", "help", cxxopts::value<bool>()) ("h,help", "help", cxxopts::value<bool>())
("version", "version", cxxopts::value<bool>())
("g,generate", "generate client config", cxxopts::value<bool>()) ("g,generate", "generate client config", cxxopts::value<bool>())
("r,router", "generate router config", cxxopts::value<bool>()) ("r,router", "generate router config", cxxopts::value<bool>())
("f,force", "overwrite", cxxopts::value<bool>()) ("f,force", "overwrite", cxxopts::value<bool>())
("c,colour", "colour output", cxxopts::value<bool>()->default_value("true")) ("c,colour", "colour output", cxxopts::value<bool>()->default_value("true"))
("d,debug", "debug mode - UNENCRYPTED TRAFFIC", cxxopts::value<bool>()) ("b,background", "background mode (start, but do not connect to the network)", cxxopts::value<bool>())
("config","path to configuration file", cxxopts::value<std::string>()); ("config","path to configuration file", cxxopts::value<std::string>());
options.parse_positional("config"); options.parse_positional("config");
// clang-format on // clang-format on
bool genconfigOnly = false; bool genconfigOnly = false;
bool asRouter = false; bool asRouter = false;
bool overWrite = false; bool overWrite = false;
bool debugMode = false;
std::string conffname; // suggestions: confFName? conf_fname? std::string conffname; // suggestions: confFName? conf_fname?
try try
{ {
auto result = options.parse(argc, argv); auto result = options.parse(argc, argv);
@ -174,14 +175,20 @@ main(int argc, char *argv[])
return 0; return 0;
} }
if(result.count("version"))
{
std::cout << llarp_version() << std::endl;
return 0;
}
if(result.count("generate") > 0) if(result.count("generate") > 0)
{ {
genconfigOnly = true; genconfigOnly = true;
} }
if(result.count("debug") > 0) if(result.count("background") > 0)
{ {
debugMode = true; opts.background = true;
} }
if(result.count("force") > 0) if(result.count("force") > 0)
@ -313,7 +320,7 @@ main(int argc, char *argv[])
} }
std::thread main_thread{ std::thread main_thread{
std::bind(&run_main_context, conffname, multiThreaded, debugMode)}; std::bind(&run_main_context, conffname, opts)};
auto ftr = exit_code.get_future(); auto ftr = exit_code.get_future();
do do
{ {
@ -321,11 +328,9 @@ main(int argc, char *argv[])
} while(ftr.wait_for(std::chrono::seconds(1)) != std::future_status::ready); } while(ftr.wait_for(std::chrono::seconds(1)) != std::future_status::ready);
main_thread.join(); main_thread.join();
const auto code = ftr.get();
#ifdef _WIN32 #ifdef _WIN32
::WSACleanup(); ::WSACleanup();
#endif #endif
const auto code = ftr.get();
exit(code);
return code; return code;
} }

@ -1,6 +1,7 @@
#ifndef LLARP_H_ #ifndef LLARP_H_
#define LLARP_H_ #define LLARP_H_
#include <sys/socket.h> #include <stdint.h>
#include <unistd.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
@ -19,6 +20,14 @@ extern "C"
/// llarp application context for C api /// llarp application context for C api
struct llarp_main; struct llarp_main;
/// runtime options for main context from cli
struct llarp_main_runtime_opts
{
bool background = false;
bool debug = false;
bool singleThreaded = false;
};
/// llarp_application config /// llarp_application config
struct llarp_config; struct llarp_config;
@ -57,23 +66,24 @@ extern "C"
{ {
/// name of the network interface /// name of the network interface
char ifname[64]; char ifname[64];
/// interface's address /// interface's address as string
struct sockaddr_storage ifaddr; char ifaddr[128];
/// interface's netmask /// netmask bits
struct sockaddr_storage netmask; unsigned char netmask;
}; };
/// initialize llarp_vpn_io private implementation /// initialize llarp_vpn_io private implementation
void /// returns false if either parameter is nullptr
llarp_vpn_io_init(struct llarp_vpn_io *io); bool
llarp_vpn_io_init(struct llarp_main *m, struct llarp_vpn_io *io);
/// get the packet pipe for writing IP packets to lokinet internals /// get the packet pipe for writing IP packets to lokinet internals
/// can return nullptr /// returns nullptr if llarp_vpn_io is nullptr or not initialized
struct llarp_vpn_pkt_writer * struct llarp_vpn_pkt_writer *
llarp_vpn_io_packet_writer(struct llarp_vpn_io *io); llarp_vpn_io_packet_writer(struct llarp_vpn_io *io);
/// get the packet pipe for reading IP packets from lokinet internals /// get the packet pipe for reading IP packets from lokinet internals
/// can return nullptr /// returns nullptr if llarp_vpn_io is nullptr or not initialized
struct llarp_vpn_pkt_reader * struct llarp_vpn_pkt_reader *
llarp_vpn_io_packet_reader(struct llarp_vpn_io *io); llarp_vpn_io_packet_reader(struct llarp_vpn_io *io);
@ -107,18 +117,18 @@ extern "C"
/// associated info tries to give the vpn io to endpoint with name epName a /// associated info tries to give the vpn io to endpoint with name epName a
/// deferred call to llarp_vpn_io.injected is queued unconditionally /// deferred call to llarp_vpn_io.injected is queued unconditionally
/// thread safe /// thread safe
void bool
llarp_main_inject_vpn_by_name(struct llarp_main *m, const char *epName, llarp_main_inject_vpn_by_name(struct llarp_main *m, const char *epName,
struct llarp_vpn_io *io, struct llarp_vpn_io *io,
struct llarp_vpn_ifaddr_info info); struct llarp_vpn_ifaddr_info info);
/// give main context a vpn io on its default endpoint /// give main context a vpn io on its default endpoint
static void static bool
llarp_main_inject_default_vpn(struct llarp_main *m, struct llarp_vpn_io *io, llarp_main_inject_default_vpn(struct llarp_main *m, struct llarp_vpn_io *io,
struct llarp_vpn_ifaddr_info info) struct llarp_vpn_ifaddr_info info)
{ {
llarp_main_inject_vpn_by_name(m, llarp_main_get_default_endpoint_name(m), return llarp_main_inject_vpn_by_name(
io, info); m, llarp_main_get_default_endpoint_name(m), io, info);
} }
/// load config from file by name /// load config from file by name
@ -131,13 +141,13 @@ extern "C"
/// initialize application context and load config /// initialize application context and load config
static struct llarp_main * static struct llarp_main *
llarp_main_init(const char *fname, bool) llarp_main_init(const char *fname)
{ {
struct llarp_config *conf = NULL; struct llarp_config *conf = 0;
if(!llarp_config_load_file(fname, &conf)) if(!llarp_config_load_file(fname, &conf))
return NULL; return 0;
if(conf == NULL) if(conf == NULL)
return NULL; return 0;
return llarp_main_init_from_config(conf); return llarp_main_init_from_config(conf);
} }
@ -147,8 +157,8 @@ extern "C"
{ {
struct llarp_config *conf; struct llarp_config *conf;
conf = llarp_default_config(); conf = llarp_default_config();
if(conf == NULL) if(conf == 0)
return NULL; return 0;
return llarp_main_init_from_config(conf); return llarp_main_init_from_config(conf);
} }
@ -158,16 +168,20 @@ extern "C"
/// setup main context, returns 0 on success /// setup main context, returns 0 on success
int int
llarp_main_setup(struct llarp_main *ptr, bool debugMode); llarp_main_setup(struct llarp_main *ptr);
/// run main context, returns 0 on success, blocks until program end /// run main context, returns 0 on success, blocks until program end
int int
llarp_main_run(struct llarp_main *ptr); llarp_main_run(struct llarp_main *ptr, struct llarp_main_runtime_opts opts);
/// free main context and end all operations /// free main context and end all operations
void void
llarp_main_free(struct llarp_main *ptr); llarp_main_free(struct llarp_main *ptr);
/// get version string
const char *
llarp_version();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -1,6 +1,6 @@
#ifndef LLARP_HPP #ifndef LLARP_HPP
#define LLARP_HPP #define LLARP_HPP
#include <llarp.h>
#include <util/fs.hpp> #include <util/fs.hpp>
#include <util/types.hpp> #include <util/types.hpp>
#include <ev/ev.hpp> #include <ev/ev.hpp>
@ -43,6 +43,10 @@ namespace llarp
struct Context struct Context
{ {
/// get context from main pointer
static Context *
Get(llarp_main *);
Context(); Context();
~Context(); ~Context();
@ -72,23 +76,23 @@ namespace llarp
LoadDatabase(); LoadDatabase();
int int
IterateDatabase(llarp_nodedb_iter &i); Setup();
bool
PutDatabase(struct llarp::RouterContact &rc);
llarp::RouterContact *
GetDatabase(const byte_t *pk);
int
Setup(bool debug = false);
int int
Run(); Run(llarp_main_runtime_opts opts);
void void
HandleSignal(int sig); HandleSignal(int sig);
bool
Configure();
/// 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);
private: private:
void void
SetPIDFile(const std::string &fname); SetPIDFile(const std::string &fname);
@ -99,9 +103,6 @@ namespace llarp
void void
RemovePIDFile() const; RemovePIDFile() const;
bool
Configure();
void void
SigINT(); SigINT();
@ -119,7 +120,4 @@ namespace llarp
}; };
} // namespace llarp } // namespace llarp
llarp::Context *
llarp_main_get_context(llarp_main *m);
#endif #endif

@ -42,6 +42,8 @@
#endif #endif
#if defined Linux #if defined Linux
#include <netinet/in.h> #include <netinet/in.h>
#elif defined(iOS)
#include <net/ethernet.h>
#else #else
#include <netinet/if_ether.h> #include <netinet/if_ether.h>
#endif #endif

@ -78,6 +78,7 @@ set(LIB_PLATFORM_SRC
# for networking # for networking
ev/ev.cpp ev/ev.cpp
ev/pipe.cpp ev/pipe.cpp
ev/vpnio.cpp
net/ip.cpp net/ip.cpp
net/net.cpp net/net.cpp
net/net_addr.cpp net/net_addr.cpp

@ -1,5 +1,6 @@
#include <llarp.hpp> #include <llarp.hpp>
#include <llarp.h> #include <llarp.h>
#include <constants/version.hpp>
#include <config/config.hpp> #include <config/config.hpp>
#include <crypto/crypto_libsodium.hpp> #include <crypto/crypto_libsodium.hpp>
@ -7,8 +8,10 @@
#include <dht/context.hpp> #include <dht/context.hpp>
#include <dnsd.hpp> #include <dnsd.hpp>
#include <ev/ev.hpp> #include <ev/ev.hpp>
#include <ev/vpnio.hpp>
#include <nodedb.hpp> #include <nodedb.hpp>
#include <router/router.hpp> #include <router/router.hpp>
#include <service/context.hpp>
#include <util/logging/logger.h> #include <util/logging/logger.h>
#include <util/meta/memfn.hpp> #include <util/meta/memfn.hpp>
#include <util/metrics/json_publisher.hpp> #include <util/metrics/json_publisher.hpp>
@ -34,6 +37,12 @@ namespace llarp
m_scheduler->stop(); m_scheduler->stop();
} }
bool
Context::CallSafe(std::function< void(void) > f)
{
return logic && logic->queue_func(std::move(f));
}
void void
Context::progress() Context::progress()
{ {
@ -45,11 +54,14 @@ namespace llarp
{ {
logic = std::make_shared< Logic >(); logic = std::make_shared< Logic >();
// llarp::LogInfo("loading config at ", configfile); // llarp::LogInfo("loading config at ", configfile);
if(!config->Load(configfile.c_str())) if(configfile.size())
{ {
config.release(); if(!config->Load(configfile.c_str()))
llarp::LogError("failed to load config file ", configfile); {
return false; config.release();
llarp::LogError("failed to load config file ", configfile);
return false;
}
} }
// System config // System config
@ -176,56 +188,14 @@ __ ___ ____ _ _ ___ _ _ ____
return 1; return 1;
} }
bool
Context::PutDatabase(__attribute__((unused)) struct llarp::RouterContact &rc)
{
// FIXME
// return llarp_nodedb_put_rc(nodedb, rc);
return false;
}
llarp::RouterContact *
Context::GetDatabase(__attribute__((unused)) const byte_t *pk)
{
// FIXME
// return llarp_nodedb_get_rc(nodedb, pk);
return nullptr;
}
int int
Context::Setup(bool debug) Context::Setup()
{ {
llarp::LogInfo(LLARP_VERSION, " ", LLARP_RELEASE_MOTTO); llarp::LogInfo(LLARP_VERSION, " ", LLARP_RELEASE_MOTTO);
llarp::LogInfo("starting up"); llarp::LogInfo("starting up");
mainloop = llarp_make_ev_loop(); mainloop = llarp_make_ev_loop();
if(debug) crypto = std::make_unique< sodium::CryptoLibSodium >();
{
static std::string WARNING = R"(
__ ___ ____ _ _ ___ _ _ ____
\ \ / / \ | _ \| \ | |_ _| \ | |/ ___|
\ \ /\ / / _ \ | |_) | \| || || \| | | _
\ V V / ___ \| _ <| |\ || || |\ | |_| |
\_/\_/_/ \_\_| \_\_| \_|___|_| \_|\____|
This Lokinet session is not private!!
Sending traffic unencrypted!!
__ ___ ____ _ _ ___ _ _ ____
\ \ / / \ | _ \| \ | |_ _| \ | |/ ___|
\ \ /\ / / _ \ | |_) | \| || || \| | | _
\ V V / ___ \| _ <| |\ || || |\ | |_| |
\_/\_/_/ \_\_| \_\_| \_|___|_| \_|\____|
)";
std::cerr << WARNING << '\n';
crypto = std::make_unique< NoOpCrypto >();
}
else
{
crypto = std::make_unique< sodium::CryptoLibSodium >();
}
cryptoManager = std::make_unique< CryptoManager >(crypto.get()); cryptoManager = std::make_unique< CryptoManager >(crypto.get());
router = std::make_unique< Router >(worker, mainloop, logic); router = std::make_unique< Router >(worker, mainloop, logic);
@ -248,7 +218,7 @@ __ ___ ____ _ _ ___ _ _ ____
} }
int int
Context::Run() Context::Run(llarp_main_runtime_opts opts)
{ {
if(router == nullptr) if(router == nullptr)
{ {
@ -259,9 +229,15 @@ __ ___ ____ _ _ ___ _ _ ____
if(!WritePIDFile()) if(!WritePIDFile())
return 1; return 1;
// run // run
if(!router->Run(nodedb.get())) if(!router->StartJsonRpc())
return 1; return 1;
if(!opts.background)
{
if(!router->Run())
return 2;
}
// run net io thread // run net io thread
llarp::LogInfo("running mainloop"); llarp::LogInfo("running mainloop");
llarp_ev_loop_run_single_process(mainloop, logic); llarp_ev_loop_run_single_process(mainloop, logic);
@ -395,39 +371,62 @@ __ ___ ____ _ _ ___ _ _ ____
} }
} // namespace llarp } // namespace llarp
struct llarp_main
{
std::unique_ptr< llarp::Context > ctx;
};
llarp::Context *
llarp_main_get_context(llarp_main *m)
{
return m->ctx.get();
}
extern "C" extern "C"
{ {
struct llarp_main * struct llarp_main
llarp_main_init(const char *fname, bool multiProcess)
{ {
(void)multiProcess; llarp_main(llarp_config *conf);
if(!fname) ~llarp_main() = default;
fname = "daemon.ini"; std::unique_ptr< llarp::Context > ctx;
char *var = getenv("LLARP_DEBUG"); };
if(var && *var == '1')
struct llarp_config
{
llarp::Config impl;
llarp_config() = default;
llarp_config(const llarp_config *other) : impl(other->impl)
{ {
cSetLogLevel(eLogDebug);
} }
auto *m = new llarp_main; };
m->ctx = std::make_unique< llarp::Context >();
if(!m->ctx->LoadConfig(fname)) struct llarp_config *
llarp_default_config()
{
static llarp_config conf;
#ifdef ANDROID
// put andrid config overrides here
#endif
#ifdef IOS
// put IOS config overrides here
#endif
return &conf;
}
struct llarp_main *
llarp_main_init_from_config(struct llarp_config *conf)
{
if(conf == nullptr)
conf = new llarp_config(llarp_default_config());
llarp_main *m = new llarp_main(conf);
if(m->ctx->Configure())
return m;
delete m;
return nullptr;
}
bool
llarp_config_load_file(const char *fname, struct llarp_config **conf)
{
llarp_config *c = new llarp_config();
if(c->impl.Load(fname))
{ {
m->ctx->Close(); *conf = c;
delete m; return true;
return nullptr;
} }
return m; delete c;
*conf = nullptr;
return false;
} }
void void
@ -438,53 +437,103 @@ extern "C"
} }
int int
llarp_main_setup(struct llarp_main *ptr, bool debug) llarp_main_setup(struct llarp_main *ptr)
{ {
return ptr->ctx->Setup(debug); return ptr->ctx->Setup();
} }
int int
llarp_main_run(struct llarp_main *ptr) llarp_main_run(struct llarp_main *ptr, struct llarp_main_runtime_opts opts)
{ {
if(!ptr) return ptr->ctx->Run(opts);
{
llarp::LogError("No ptr passed in");
return 1;
}
return ptr->ctx->Run();
} }
void const char *
llarp_main_abort(struct llarp_main *ptr) llarp_version()
{ {
ptr->ctx->router->logic()->stop_timer(); return LLARP_VERSION;
} }
void ssize_t
llarp_main_queryDHT_RC(struct llarp_main *ptr, llarp_vpn_io_readpkt(struct llarp_vpn_pkt_reader *r, unsigned char *dst,
struct llarp_router_lookup_job *job) size_t dstlen)
{ {
llarp_dht_lookup_router(ptr->ctx->router->dht(), job); if(r == nullptr)
return -1;
if(not r->queue.enabled())
return -1;
auto pkt = r->queue.popFront();
ManagedBuffer mbuf = pkt.ConstBuffer();
const llarp_buffer_t &buf = mbuf;
if(buf.sz > dstlen || buf.sz == 0)
return -1;
std::copy_n(buf.base, buf.sz, dst);
return buf.sz;
} }
bool bool
llarp_main_init_dnsd(struct llarp_main *ptr, struct dnsd_context *dnsd, llarp_vpn_io_writepkt(struct llarp_vpn_pkt_writer *w, unsigned char *pktbuf,
const llarp::Addr &dnsd_sockaddr, size_t pktlen)
const llarp::Addr &dnsc_sockaddr)
{ {
return llarp_dnsd_init(dnsd, ptr->ctx->logic.get(), if(pktlen == 0 || pktbuf == nullptr)
ptr->ctx->mainloop.get(), dnsd_sockaddr, return false;
dnsc_sockaddr); if(w == nullptr)
return false;
llarp_vpn_pkt_queue::Packet_t pkt;
llarp_buffer_t buf(pktbuf, pktlen);
if(not pkt.Load(buf))
return false;
return w->queue.pushBack(std::move(pkt))
== llarp::thread::QueueReturn::Success;
} }
bool bool
llarp_main_init_dotLokiLookup(struct llarp_main *ptr, llarp_main_inject_vpn_by_name(struct llarp_main *ptr, const char *name,
struct dotLokiLookup *dll) struct llarp_vpn_io *io,
struct llarp_vpn_ifaddr_info info)
{ {
(void)ptr; if(name == nullptr || io == nullptr)
(void)dll; return false;
// TODO: gut me if(ptr == nullptr || ptr->ctx == nullptr || ptr->ctx->router == nullptr)
return false; return false;
auto ep = ptr->ctx->router->hiddenServiceContext().GetEndpointByName(name);
return ep && ep->InjectVPN(io, info);
}
void
llarp_vpn_io_close_async(struct llarp_vpn_io *io)
{
if(io == nullptr || io->impl == nullptr)
return;
static_cast< llarp_vpn_io_impl * >(io->impl)->AsyncClose();
}
bool
llarp_vpn_io_init(struct llarp_main *ptr, struct llarp_vpn_io *io)
{
if(io == nullptr || ptr == nullptr)
return false;
llarp_vpn_io_impl *impl = new llarp_vpn_io_impl(ptr, io);
io->impl = impl;
return true;
}
struct llarp_vpn_pkt_writer *
llarp_vpn_io_packet_writer(struct llarp_vpn_io *io)
{
if(io == nullptr || io->impl == nullptr)
return nullptr;
llarp_vpn_io_impl *vpn = static_cast< llarp_vpn_io_impl * >(io->impl);
return &vpn->writer;
}
struct llarp_vpn_pkt_reader *
llarp_vpn_io_packet_reader(struct llarp_vpn_io *io)
{
if(io == nullptr || io->impl == nullptr)
return nullptr;
llarp_vpn_io_impl *vpn = static_cast< llarp_vpn_io_impl * >(io->impl);
return &vpn->reader;
} }
void void
@ -493,49 +542,27 @@ extern "C"
delete ptr; delete ptr;
} }
int const char *
llarp_main_loadDatabase(struct llarp_main *ptr) llarp_main_get_default_endpoint_name(struct llarp_main *)
{ {
return ptr->ctx->LoadDatabase(); return "default";
} }
}
const char * llarp_main::llarp_main(llarp_config *conf)
handleBaseCmdLineArgs(int argc, char *argv[])
{
// clang-format off
cxxopts::Options options(
"lokinet",
"Lokinet is a private, decentralized and IP based overlay network for the internet"
);
options.add_options()
("c,config", "Config file", cxxopts::value< std::string >()->default_value("daemon.ini"))
("o,logLevel", "logging level");
// clang-format on
auto result = options.parse(argc, argv);
std::string logLevel = result["logLevel"].as< std::string >();
if(logLevel == "debug")
{
cSetLogLevel(eLogDebug);
}
else if(logLevel == "info")
{
cSetLogLevel(eLogInfo);
}
else if(logLevel == "warn")
{
cSetLogLevel(eLogWarn);
}
else if(logLevel == "error")
{
cSetLogLevel(eLogError);
}
// this isn't thread safe, but reconfiguring during run is likely unsafe : ctx(new llarp::Context())
// either way {
static std::string confname = result["config"].as< std::string >(); ctx->config.reset(new llarp::Config(conf->impl));
}
return confname.c_str(); namespace llarp
{
Context *
Context::Get(llarp_main *m)
{
if(m == nullptr || m->ctx == nullptr)
return nullptr;
return m->ctx.get();
} }
} } // namespace llarp

@ -0,0 +1,31 @@
#include <ev/vpnio.hpp>
#include <llarp.hpp>
#include <router/abstractrouter.hpp>
#include <util/thread/logic.hpp>
void
llarp_vpn_io_impl::AsyncClose()
{
reader.queue.disable();
writer.queue.disable();
CallSafe(std::bind(&llarp_vpn_io_impl::Expunge, this));
}
void
llarp_vpn_io_impl::CallSafe(std::function< void(void) > f)
{
llarp::Context* ctx = llarp::Context::Get(ptr);
if(ctx && ctx->CallSafe(f))
return;
else if(ctx == nullptr || ctx->logic == nullptr)
f();
}
void
llarp_vpn_io_impl::Expunge()
{
parent->impl = nullptr;
if(parent->closed)
parent->closed(parent);
delete this;
}

@ -0,0 +1,51 @@
#ifndef LLARP_EV_VPNIO_HPP
#define LLARP_EV_VPNIO_HPP
#include <net/ip.hpp>
#include <util/thread/queue.hpp>
#include <functional>
struct llarp_main;
struct llarp_vpn_io;
struct llarp_vpn_pkt_queue
{
using Packet_t = llarp::net::IPPacket;
llarp::thread::Queue< Packet_t > queue;
llarp_vpn_pkt_queue() : queue(1024){};
~llarp_vpn_pkt_queue() = default;
};
struct llarp_vpn_pkt_writer : public llarp_vpn_pkt_queue
{
};
struct llarp_vpn_pkt_reader : public llarp_vpn_pkt_queue
{
};
struct llarp_vpn_io_impl
{
llarp_vpn_io_impl(llarp_main* p, llarp_vpn_io* io) : ptr(p), parent(io)
{
}
~llarp_vpn_io_impl() = default;
llarp_main* ptr;
llarp_vpn_io* parent;
llarp_vpn_pkt_writer writer;
llarp_vpn_pkt_reader reader;
void
AsyncClose();
private:
void
CallSafe(std::function< void(void) > f);
void
Expunge();
};
#endif

@ -24,10 +24,12 @@ namespace llarp
{ {
namespace handlers namespace handlers
{ {
static llarp_fd_promise * void
get_tun_fd_promise(llarp_tun_io *tun) TunEndpoint::FlushToUser(std::function< bool(net::IPPacket &) > send)
{ {
return static_cast< TunEndpoint * >(tun->user)->Promise.get(); m_ExitMap.ForEachValue([](const auto &exit) { exit->FlushDownstream(); });
// flush network to user
m_NetworkToUserPktQueue.Process(send);
} }
static void static void
@ -38,7 +40,7 @@ namespace llarp
} }
TunEndpoint::TunEndpoint(const std::string &nickname, AbstractRouter *r, TunEndpoint::TunEndpoint(const std::string &nickname, AbstractRouter *r,
service::Context *parent) service::Context *parent, bool lazyVPN)
: service::Endpoint(nickname, r, parent) : service::Endpoint(nickname, r, parent)
, m_UserToNetworkPktQueue(nickname + "_sendq", r->netloop(), , m_UserToNetworkPktQueue(nickname + "_sendq", r->netloop(),
r->netloop()) r->netloop())
@ -47,22 +49,19 @@ namespace llarp
, m_Resolver(std::make_shared< dns::Proxy >( , m_Resolver(std::make_shared< dns::Proxy >(
r->netloop(), r->logic(), r->netloop(), r->logic(), this)) r->netloop(), r->logic(), r->netloop(), r->logic(), this))
{ {
std::fill(tunif.ifaddr, tunif.ifaddr + sizeof(tunif.ifaddr), 0); if(not lazyVPN)
std::fill(tunif.ifname, tunif.ifname + sizeof(tunif.ifname), 0); {
tunif.netmask = 0; tunif.reset(new llarp_tun_io());
std::fill(tunif->ifaddr, tunif->ifaddr + sizeof(tunif->ifaddr), 0);
#ifdef ANDROID std::fill(tunif->ifname, tunif->ifname + sizeof(tunif->ifname), 0);
tunif.get_fd_promise = &get_tun_fd_promise; tunif->netmask = 0;
Promise.reset(new llarp_fd_promise(&m_VPNPromise)); tunif->get_fd_promise = nullptr;
#else tunif->user = this;
tunif.get_fd_promise = nullptr; // eh this shouldn't do anything on windows anyway
#endif tunif->tick = &tunifTick;
tunif.user = this; tunif->before_write = &tunifBeforeWrite;
tunif->recvpkt = &tunifRecvPkt;
// eh this shouldn't do anything on windows anyway }
tunif.tick = &tunifTick;
tunif.before_write = &tunifBeforeWrite;
tunif.recvpkt = &tunifRecvPkt;
} }
util::StatusObject util::StatusObject
@ -241,18 +240,18 @@ namespace llarp
} }
return MapAddress(addr, ipv6, false); return MapAddress(addr, ipv6, false);
} }
if(k == "ifname") if(k == "ifname" && tunif)
{ {
if(v.length() >= sizeof(tunif.ifname)) if(v.length() >= sizeof(tunif->ifname))
{ {
llarp::LogError(Name() + " ifname '", v, "' is too long"); llarp::LogError(Name() + " ifname '", v, "' is too long");
return false; return false;
} }
strncpy(tunif.ifname, v.c_str(), sizeof(tunif.ifname) - 1); strncpy(tunif->ifname, v.c_str(), sizeof(tunif->ifname) - 1);
llarp::LogInfo(Name() + " setting ifname to ", tunif.ifname); llarp::LogInfo(Name() + " setting ifname to ", tunif->ifname);
return true; return true;
} }
if(k == "ifaddr") if(k == "ifaddr" && tunif)
{ {
std::string addr; std::string addr;
m_UseV6 = addr.find(":") != std::string::npos; m_UseV6 = addr.find(":") != std::string::npos;
@ -268,8 +267,8 @@ namespace llarp
#endif #endif
if(num > 0) if(num > 0)
{ {
tunif.netmask = num; tunif->netmask = num;
addr = v.substr(0, pos); addr = v.substr(0, pos);
} }
else else
{ {
@ -280,14 +279,14 @@ namespace llarp
else else
{ {
if(m_UseV6) if(m_UseV6)
tunif.netmask = 128; tunif->netmask = 128;
else else
tunif.netmask = 32; tunif->netmask = 32;
addr = v; addr = v;
} }
llarp::LogInfo(Name() + " set ifaddr to ", addr, " with netmask ", llarp::LogInfo(Name() + " set ifaddr to ", addr, " with netmask ",
tunif.netmask); tunif->netmask);
strncpy(tunif.ifaddr, addr.c_str(), sizeof(tunif.ifaddr) - 1); strncpy(tunif->ifaddr, addr.c_str(), sizeof(tunif->ifaddr) - 1);
return true; return true;
} }
return Endpoint::SetOption(k, v); return Endpoint::SetOption(k, v);
@ -585,80 +584,120 @@ namespace llarp
bool bool
TunEndpoint::SetupTun() TunEndpoint::SetupTun()
{ {
lazy_vpn vpn;
huint32_t ip;
auto loop = EndpointNetLoop(); auto loop = EndpointNetLoop();
if(!llarp_ev_add_tun(loop.get(), &tunif)) if(tunif == nullptr)
{
llarp::LogError(Name(),
" failed to set up tun interface: ", tunif.ifaddr,
" on ", tunif.ifname);
return false;
}
struct addrinfo hint, *res = nullptr;
int ret;
memset(&hint, 0, sizeof hint);
hint.ai_family = PF_UNSPEC;
hint.ai_flags = AI_NUMERICHOST;
ret = getaddrinfo(tunif.ifaddr, nullptr, &hint, &res);
if(ret)
{
llarp::LogError(Name(),
" failed to set up tun interface, cant determine "
"family from ",
tunif.ifaddr);
return false;
}
/*
// output is in network byte order
unsigned char buf[sizeof(struct in6_addr)];
int s = inet_pton(res->ai_family, tunif.ifaddr, buf);
if (s <= 0)
{
llarp::LogError(Name(), " failed to set up tun interface, cant parse
", tunif.ifaddr); return false;
}
*/
if(res->ai_family == AF_INET6)
{ {
m_UseV6 = true; llarp::LogInfo(Name(), " waiting for vpn to start");
} vpn = m_LazyVPNPromise.get_future().get();
vpnif = vpn.io;
if(vpnif == nullptr)
{
llarp::LogError(Name(), " failed to recieve vpn interface");
return false;
}
llarp::LogInfo(Name(), " got vpn interface");
auto self = shared_from_this();
// function to queue a packet to send to vpn interface
auto sendpkt = [self](net::IPPacket &pkt) -> bool {
// drop if no endpoint
auto impl = self->GetVPNImpl();
// drop if no vpn interface
if(impl == nullptr)
return true;
// drop if queue to vpn not enabled
if(not impl->reader.queue.enabled())
return true;
// drop if queue to vpn full
if(impl->reader.queue.full())
return true;
// queue to reader
impl->reader.queue.pushBack(pkt);
return false;
};
// event loop ticker
auto ticker = [self, sendpkt]() {
TunEndpoint *ep = self.get();
const bool running = not ep->IsStopped();
auto impl = ep->GetVPNImpl();
if(impl)
{
/// get packets from vpn
while(not impl->writer.queue.empty())
{
// queue it to be sent over lokinet
auto pkt = impl->writer.queue.popFront();
if(running)
ep->m_UserToNetworkPktQueue.Emplace(pkt);
}
}
freeaddrinfo(res); // process packets queued from vpn
if(m_UseV6) if(running)
{ {
llarp::LogInfo(Name(), " using IPV6"); ep->Flush();
ep->FlushToUser(sendpkt);
}
// if impl has a tick function call it
if(impl && impl->parent && impl->parent->tick)
impl->parent->tick(impl->parent);
};
if(not loop->add_ticker(ticker))
{
llarp::LogError(Name(), " failed to add vpn to event loop");
if(vpnif->injected)
vpnif->injected(vpnif, false);
return false;
}
} }
else else
{ {
struct in_addr addr; // network byte order if(!llarp_ev_add_tun(loop.get(), tunif.get()))
if(inet_aton(tunif.ifaddr, &addr) == 0)
{ {
llarp::LogError(Name(), llarp::LogError(Name(),
" failed to set up tun interface, cant parse ", " failed to set up tun interface: ", tunif->ifaddr,
tunif.ifaddr); " on ", tunif->ifname);
return false; return false;
} }
} }
huint32_t ip; const char *ifname;
if(ip.FromString(tunif.ifaddr)) const char *ifaddr;
unsigned char netmask;
if(tunif)
{
ifname = tunif->ifname;
ifaddr = tunif->ifaddr;
netmask = tunif->netmask;
}
else
{
ifname = vpn.info.ifname;
ifaddr = vpn.info.ifaddr;
netmask = vpn.info.netmask;
}
if(ip.FromString(ifaddr))
{ {
m_OurIP = net::IPPacket::ExpandV4(ip); m_OurIP = net::IPPacket::ExpandV4(ip);
m_OurRange.netmask_bits = netmask_ipv6_bits(tunif.netmask + 96); m_OurRange.netmask_bits = netmask_ipv6_bits(netmask + 96);
} }
else if(m_OurIP.FromString(tunif.ifaddr)) else if(m_OurIP.FromString(ifaddr))
{ {
m_OurRange.netmask_bits = netmask_ipv6_bits(tunif.netmask); m_OurRange.netmask_bits = netmask_ipv6_bits(netmask);
m_UseV6 = true;
}
else
{
LogError(Name(), " invalid interface address given, ifaddr=", ifaddr);
if(vpnif && vpnif->injected)
vpnif->injected(vpnif, false);
return false;
} }
m_NextIP = m_OurIP; m_NextIP = m_OurIP;
m_OurRange.addr = m_OurIP; m_OurRange.addr = m_OurIP;
m_MaxIP = m_OurRange.HighestAddr(); m_MaxIP = m_OurRange.HighestAddr();
llarp::LogInfo(Name(), " set ", tunif.ifname, " to have address ", llarp::LogInfo(Name(), " set ", ifname, " to have address ", m_OurIP);
m_OurIP);
llarp::LogInfo(Name(), " allocated up to ", m_MaxIP, " on range ", llarp::LogInfo(Name(), " allocated up to ", m_MaxIP, " on range ",
m_OurRange); m_OurRange);
@ -667,6 +706,10 @@ namespace llarp
{ {
m_OnUp->NotifyAsync(NotifyParams()); m_OnUp->NotifyAsync(NotifyParams());
} }
if(vpnif && vpnif->injected)
{
vpnif->injected(vpnif, true);
}
return true; return true;
} }
@ -676,7 +719,8 @@ namespace llarp
auto env = Endpoint::NotifyParams(); auto env = Endpoint::NotifyParams();
env.emplace("IP_ADDR", m_OurIP.ToString()); env.emplace("IP_ADDR", m_OurIP.ToString());
env.emplace("IF_ADDR", m_OurRange.ToString()); env.emplace("IF_ADDR", m_OurRange.ToString());
env.emplace("IF_NAME", tunif.ifname); if(tunif)
env.emplace("IF_NAME", tunif->ifname);
std::string strictConnect; std::string strictConnect;
for(const auto &addr : m_StrictConnectAddrs) for(const auto &addr : m_StrictConnectAddrs)
strictConnect += addr.ToString() + " "; strictConnect += addr.ToString() + " ";
@ -929,20 +973,17 @@ namespace llarp
TunEndpoint::tunifBeforeWrite(llarp_tun_io *tun) TunEndpoint::tunifBeforeWrite(llarp_tun_io *tun)
{ {
// called in the isolated network thread // called in the isolated network thread
auto *self = static_cast< TunEndpoint * >(tun->user); auto *self = static_cast< TunEndpoint * >(tun->user);
// flush user to network auto sendpkt = [self, tun](net::IPPacket &pkt) -> bool {
self->EndpointLogic()->queue_func(
std::bind(&TunEndpoint::FlushSend, self));
// flush exit traffic queues if it's there
self->EndpointLogic()->queue_func([self] {
self->m_ExitMap.ForEachValue(
[](const auto &exit) { exit->FlushDownstream(); });
});
// flush network to user
self->m_NetworkToUserPktQueue.Process([tun](net::IPPacket &pkt) {
if(!llarp_ev_tun_async_write(tun, pkt.Buffer())) if(!llarp_ev_tun_async_write(tun, pkt.Buffer()))
llarp::LogWarn("packet dropped"); {
}); llarp::LogWarn(self->Name(), " packet dropped");
return true;
}
return false;
};
self->EndpointLogic()->queue_func(std::bind(
&TunEndpoint::FlushToUser, self->shared_from_this(), sendpkt));
} }
void void

@ -3,6 +3,7 @@
#include <dns/server.hpp> #include <dns/server.hpp>
#include <ev/ev.h> #include <ev/ev.h>
#include <ev/vpnio.hpp>
#include <net/ip.hpp> #include <net/ip.hpp>
#include <net/net.hpp> #include <net/net.hpp>
#include <service/endpoint.hpp> #include <service/endpoint.hpp>
@ -20,7 +21,7 @@ namespace llarp
public std::enable_shared_from_this< TunEndpoint > public std::enable_shared_from_this< TunEndpoint >
{ {
TunEndpoint(const std::string& nickname, AbstractRouter* r, TunEndpoint(const std::string& nickname, AbstractRouter* r,
llarp::service::Context* parent); llarp::service::Context* parent, bool lazyVPN = false);
~TunEndpoint() override; ~TunEndpoint() override;
path::PathSet_ptr path::PathSet_ptr
@ -114,8 +115,17 @@ namespace llarp
bool bool
HasLocalIP(const huint128_t& ip) const; HasLocalIP(const huint128_t& ip) const;
llarp_tun_io tunif; std::unique_ptr< llarp_tun_io > tunif;
std::unique_ptr< llarp_fd_promise > Promise; llarp_vpn_io* vpnif = nullptr;
bool
InjectVPN(llarp_vpn_io* io, llarp_vpn_ifaddr_info info)
{
if(tunif)
return false;
m_LazyVPNPromise.set_value(lazy_vpn{info, io});
return true;
}
/// called before writing to tun interface /// called before writing to tun interface
static void static void
@ -206,6 +216,14 @@ namespace llarp
m_SNodes; m_SNodes;
private: private:
llarp_vpn_io_impl*
GetVPNImpl()
{
if(vpnif && vpnif->impl)
return static_cast< llarp_vpn_io_impl* >(vpnif->impl);
return nullptr;
}
bool bool
QueueInboundPacketForExit(const llarp_buffer_t& buf) QueueInboundPacketForExit(const llarp_buffer_t& buf)
{ {
@ -255,12 +273,6 @@ namespace llarp
reply(*query); reply(*query);
delete query; delete query;
} }
#ifndef WIN32
/// handles fd injection force android
std::promise< std::pair< int, int > > m_VPNPromise;
#endif
/// our dns resolver /// our dns resolver
std::shared_ptr< dns::Proxy > m_Resolver; std::shared_ptr< dns::Proxy > m_Resolver;
@ -283,6 +295,18 @@ namespace llarp
std::vector< llarp::Addr > m_StrictConnectAddrs; std::vector< llarp::Addr > m_StrictConnectAddrs;
/// use v6? /// use v6?
bool m_UseV6; bool m_UseV6;
struct lazy_vpn
{
llarp_vpn_ifaddr_info info;
llarp_vpn_io* io;
};
std::promise< lazy_vpn > m_LazyVPNPromise;
/// send packets on endpoint to user using send function
/// send function returns true to indicate stop iteration and do codel
/// drop
void
FlushToUser(std::function< bool(net::IPPacket&) > sendfunc);
}; };
} // namespace handlers } // namespace handlers
} // namespace llarp } // namespace llarp

@ -90,20 +90,24 @@ namespace llarp
if(pkt.sz > sizeof(buf)) if(pkt.sz > sizeof(buf))
return false; return false;
sz = pkt.sz; sz = pkt.sz;
memcpy(buf, pkt.base, sz); std::copy_n(pkt.base, sz, buf);
return true; return true;
} }
llarp_buffer_t ManagedBuffer
IPPacket::ConstBuffer() const IPPacket::ConstBuffer() const
{ {
return {buf, sz}; const byte_t *ptr = buf;
llarp_buffer_t b(ptr, sz);
return ManagedBuffer(b);
} }
llarp_buffer_t ManagedBuffer
IPPacket::Buffer() IPPacket::Buffer()
{ {
return {buf, sz}; byte_t *ptr = buf;
llarp_buffer_t b(ptr, sz);
return ManagedBuffer(b);
} }
huint32_t huint32_t

@ -116,10 +116,10 @@ namespace llarp
size_t sz; size_t sz;
byte_t buf[MaxSize]; byte_t buf[MaxSize];
llarp_buffer_t ManagedBuffer
Buffer(); Buffer();
llarp_buffer_t ManagedBuffer
ConstBuffer() const; ConstBuffer() const;
bool bool

@ -127,7 +127,10 @@ namespace llarp
Configure(Config *conf, llarp_nodedb *nodedb) = 0; Configure(Config *conf, llarp_nodedb *nodedb) = 0;
virtual bool virtual bool
Run(struct llarp_nodedb *nodedb) = 0; StartJsonRpc() = 0;
virtual bool
Run() = 0;
/// stop running the router logic gracefully /// stop running the router logic gracefully
virtual void virtual void

@ -110,11 +110,18 @@ namespace llarp
util::StatusObject util::StatusObject
Router::ExtractStatus() const Router::ExtractStatus() const
{ {
return util::StatusObject{ if(_running)
{"dht", _dht->impl->ExtractStatus()}, {
{"services", _hiddenServiceContext.ExtractStatus()}, return util::StatusObject{
{"exit", _exitContext.ExtractStatus()}, {"dht", _dht->impl->ExtractStatus()},
{"links", _linkManager.ExtractStatus()}}; {"services", _hiddenServiceContext.ExtractStatus()},
{"exit", _exitContext.ExtractStatus()},
{"links", _linkManager.ExtractStatus()}};
}
else
{
return util::StatusObject{{"notRunning", true}};
}
} }
bool bool
@ -836,11 +843,10 @@ namespace llarp
} }
bool bool
Router::Run(struct llarp_nodedb *nodedb) Router::StartJsonRpc()
{ {
if(_running || _stopping) if(_running || _stopping)
return false; return false;
this->_nodedb = nodedb;
if(enableRPCServer) if(enableRPCServer)
{ {
@ -860,6 +866,16 @@ namespace llarp
} }
LogInfo("Bound RPC server to ", rpcBindAddr); LogInfo("Bound RPC server to ", rpcBindAddr);
} }
return true;
}
bool
Router::Run()
{
if(_running || _stopping)
return false;
if(whitelistRouters) if(whitelistRouters)
{ {
rpcCaller = std::make_unique< rpc::Caller >(this); rpcCaller = std::make_unique< rpc::Caller >(this);
@ -1012,7 +1028,7 @@ namespace llarp
_dht->impl->Nodes()->PutNode(rc); _dht->impl->Nodes()->PutNode(rc);
} }
LogInfo("have ", nodedb->num_loaded(), " routers"); LogInfo("have ", _nodedb->num_loaded(), " routers");
_netloop->add_ticker(std::bind(&Router::PumpLL, this)); _netloop->add_ticker(std::bind(&Router::PumpLL, this));
ScheduleTicker(1000); ScheduleTicker(1000);
_running.store(true); _running.store(true);

@ -327,7 +327,10 @@ namespace llarp
Configure(Config *conf, llarp_nodedb *nodedb = nullptr) override; Configure(Config *conf, llarp_nodedb *nodedb = nullptr) override;
bool bool
Run(struct llarp_nodedb *nodedb) override; StartJsonRpc() override;
bool
Run() override;
/// stop running the router logic gracefully /// stop running the router logic gracefully
void void

@ -1,5 +1,6 @@
#include <rpc/rpc.hpp> #include <rpc/rpc.hpp>
#include <constants/version.hpp>
#include <router/abstractrouter.hpp> #include <router/abstractrouter.hpp>
#include <service/context.hpp> #include <service/context.hpp>
#include <util/logging/logger.hpp> #include <util/logging/logger.hpp>
@ -194,6 +195,13 @@ namespace llarp
~Handler() override = default; ~Handler() override = default;
Response
StartRouter() const
{
const bool rc = router->Run();
return Response{{"status", rc}};
}
Response Response
DumpState() const DumpState() const
{ {
@ -259,10 +267,21 @@ namespace llarp
return resp; return resp;
} }
Response
DumpVersion() const
{
const Response resp{{"version", LLARP_VERSION}};
return resp;
}
absl::optional< Response > absl::optional< Response >
HandleJSONRPC(Method_t method, HandleJSONRPC(Method_t method,
ABSL_ATTRIBUTE_UNUSED const Params& params) override ABSL_ATTRIBUTE_UNUSED const Params& params) override
{ {
if(method == "llarp.admin.start")
{
return StartRouter();
}
if(method == "llarp.admin.link.neighboors") if(method == "llarp.admin.link.neighboors")
{ {
return ListNeighboors(); return ListNeighboors();
@ -279,6 +298,10 @@ namespace llarp
{ {
return DumpStatus(); return DumpStatus();
} }
if(method == "llarp.version")
{
return DumpVersion();
}
return false; return false;
} }
}; };

@ -20,23 +20,18 @@ namespace llarp
{"tun", {"tun",
[](const std::string &nick, AbstractRouter *r, [](const std::string &nick, AbstractRouter *r,
service::Context *c) -> service::Endpoint_ptr { service::Context *c) -> service::Endpoint_ptr {
return std::make_shared< handlers::TunEndpoint >(nick, r, c); return std::make_shared< handlers::TunEndpoint >(nick, r, c,
false);
}}, }},
{"android-tun", {"android",
[](const std::string &, AbstractRouter *, [](const std::string &nick, AbstractRouter *r,
service::Context *) -> service::Endpoint_ptr { service::Context *c) -> service::Endpoint_ptr {
return nullptr; return std::make_shared< handlers::TunEndpoint >(nick, r, c, true);
/// SOOOOOOON (tm)
// return std::make_shared<handlers::AndroidTunEndpoint>(nick,
// r, c);
}}, }},
{"ios-tun", {"ios",
[](const std::string &, AbstractRouter *, [](const std::string &nick, AbstractRouter *r,
service::Context *) -> service::Endpoint_ptr { service::Context *c) -> service::Endpoint_ptr {
return nullptr; return std::make_shared< handlers::TunEndpoint >(nick, r, c, true);
/// SOOOOOOON (tm)
// return std::make_shared<handlers::IOSTunEndpoint>(nick, r,
// c);
}}, }},
{"null", {"null",
[](const std::string &nick, AbstractRouter *r, [](const std::string &nick, AbstractRouter *r,
@ -133,12 +128,22 @@ namespace llarp
return m_Endpoints.size() ? true : false; return m_Endpoints.size() ? true : false;
} }
static const char *
DefaultEndpointType()
{
#ifdef ANDROID
return "android";
#else
return "tun";
#endif
}
bool bool
Context::AddDefaultEndpoint( Context::AddDefaultEndpoint(
const std::unordered_multimap< std::string, std::string > &opts) const std::unordered_multimap< std::string, std::string > &opts)
{ {
Config::section_values_t configOpts; Config::section_values_t configOpts;
configOpts.push_back({"type", "tun"}); configOpts.push_back({"type", DefaultEndpointType()});
{ {
auto itr = opts.begin(); auto itr = opts.begin();
while(itr != opts.end()) while(itr != opts.end())
@ -167,6 +172,15 @@ namespace llarp
return true; return true;
} }
Endpoint_ptr
Context::GetEndpointByName(const std::string & name)
{
auto itr = m_Endpoints.find(name);
if(itr != m_Endpoints.end())
return itr->second;
return nullptr;
}
bool bool
Context::AddEndpoint(const Config::section_t &conf, bool autostart) Context::AddEndpoint(const Config::section_t &conf, bool autostart)
{ {
@ -180,7 +194,7 @@ namespace llarp
} }
} }
// extract type // extract type
std::string endpointType = "tun"; std::string endpointType = DefaultEndpointType();
std::string keyfile; std::string keyfile;
for(const auto &option : conf.second) for(const auto &option : conf.second)
{ {

@ -51,6 +51,9 @@ namespace llarp
bool bool
RemoveEndpoint(const std::string &name); RemoveEndpoint(const std::string &name);
Endpoint_ptr
GetEndpointByName(const std::string &name);
bool bool
StartAll(); StartAll();

@ -1,6 +1,6 @@
#ifndef LLARP_SERVICE_ENDPOINT_HPP #ifndef LLARP_SERVICE_ENDPOINT_HPP
#define LLARP_SERVICE_ENDPOINT_HPP #define LLARP_SERVICE_ENDPOINT_HPP
#include <llarp.h>
#include <dht/messages/gotrouter.hpp> #include <dht/messages/gotrouter.hpp>
#include <ev/ev.h> #include <ev/ev.h>
#include <exit/session.hpp> #include <exit/session.hpp>
@ -105,6 +105,14 @@ namespace llarp
return false; return false;
} }
/// inject vpn io
/// return false if not supported
virtual bool
InjectVPN(llarp_vpn_io*, llarp_vpn_ifaddr_info)
{
return false;
}
/// get our ifaddr if it is set /// get our ifaddr if it is set
virtual huint128_t virtual huint128_t
GetIfAddr() const GetIfAddr() const
@ -254,9 +262,6 @@ namespace llarp
bool bool
ShouldBundleRC() const override; ShouldBundleRC() const override;
static void
HandlePathDead(void*);
/// return true if we have a convotag as an exit session /// return true if we have a convotag as an exit session
/// or as a hidden service session /// or as a hidden service session
/// set addr and issnode /// set addr and issnode

@ -0,0 +1,58 @@
cmake_minimum_required(VERSION 3.14)
set(PROJECT_NAME lokinet)
project(${PROJECT_NAME} C CXX Swift)
get_filename_component(LOKINET_ROOT .. ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}")
include("${LOKINET_ROOT}/cmake/target_link_libraries_system.cmake")
include("${LOKINET_ROOT}/cmake/add_import_library.cmake")
include("${LOKINET_ROOT}/cmake/add_log_tag.cmake")
include("${LOKINET_ROOT}/cmake/libatomic.cmake")
if (STATIC_LINK AND STATIC_LINK_RUNTIME)
message(FATAL "Cannot set both STATIC_LINK and STATIC_LINK_RUNTIME")
endif()
set(CMAKE_Swift_LANGUAGE_VERSION 5.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
list(APPEND CMAKE_MODULE_PATH "${LOKINET_ROOT}/cmake")
include(FetchContent)
FetchContent_Declare(
libuv
GIT_REPOSITORY https://github.com/libuv/libuv.git
GIT_TAG v1.32.0
)
FetchContent_Populate(libuv)
add_subdirectory(${libuv_SOURCE_DIR} ${libuv_BINARY_DIR})
include("${LOKINET_ROOT}/cmake/basic_definitions.cmake")
set(LIBUV_IN_SOURCE ON)
include("${LOKINET_ROOT}/cmake/unix.cmake")
find_package(Threads REQUIRED)
set(ABSEIL_DIR "${LOKINET_ROOT}/vendor/abseil-cpp")
macro(add_loki_dir name)
add_subdirectory("${LOKINET_ROOT}/${name}" "${name}")
endmacro()
include_directories(SYSTEM ${ABSEIL_DIR})
add_loki_dir(vendor/cxxopts)
add_loki_dir(vendor/nlohmann)
include_directories(SYSTEM "${LOKINET_ROOT}/vendor/cxxopts/include")
include_directories("${LOKINET_ROOT}/include")
include_directories("${libuv_SOURCE_DIR}/include")
add_loki_dir(vendor/gtest)
add_subdirectory(${ABSEIL_DIR} "vendor/abseil-cpp")
add_loki_dir(crypto)
add_loki_dir(llarp)
add_loki_dir(libabyss)
add_subdirectory(lokinet)

@ -0,0 +1,4 @@
set(CMAKE_MACOSX_BUNDLE YES)
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
set(CMAKE_OSX_SYSROOT iphoneos)
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")

@ -0,0 +1,92 @@
//
// AppDelegate.swift
// lokinet
//
// Copyright © 2019 Loki. All rights reserved.
//
import UIKit
import CoreData
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Saves changes in the application's managed object context before the application terminates.
self.saveContext()
}
// MARK: - Core Data stack
lazy var persistentContainer: NSPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let container = NSPersistentContainer(name: "lokinet")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()
// MARK: - Core Data Saving support
func saveContext () {
let context = persistentContainer.viewContext
if context.hasChanges {
do {
try context.save()
} catch {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}
}

@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>

@ -0,0 +1 @@
add_executable(lokinet AppDelegate.swift ViewController.swift)

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

@ -0,0 +1,19 @@
//
// ViewController.swift
// lokinet
//
// Copyright © 2019 Loki. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.networking.networkextension</key>
<array>
<string>dns-proxy</string>
<string>packet-tunnel-provider</string>
</array>
<key>com.apple.developer.networking.vpn.api</key>
<array>
<string>allow-vpn</string>
</array>
</dict>
</plist>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>lokinet.xcdatamodel</string>
</dict>
</plist>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1" systemVersion="11A491" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<elements/>
</model>

@ -9,7 +9,7 @@ class Argv {
Argv(std::initializer_list<const char*> args) Argv(std::initializer_list<const char*> args)
: m_argv(new char*[args.size()]) : m_argv(new char*[args.size()])
, m_argc(args.size()) , m_argc(static_cast<int>(args.size()))
{ {
int i = 0; int i = 0;
auto iter = args.begin(); auto iter = args.begin();

Loading…
Cancel
Save