From fadedb4a7bd18e4bf96e6b6d213371ce48a67a07 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 30 Sep 2019 09:59:34 +0100 Subject: [PATCH 01/11] Distinct ios build --- .travis.yml | 4 + CMakeLists.txt | 19 +--- Makefile | 4 + cmake/basic_definitions.cmake | 16 +++ cmake/unix.cmake | 6 +- include/tuntap.h | 2 + ui-ios/CMakeLists.txt | 58 +++++++++++ ui-ios/ios-toolchain.cmake | 4 + ui-ios/lokinet/AppDelegate.swift | 92 +++++++++++++++++ .../AppIcon.appiconset/Contents.json | 98 +++++++++++++++++++ ui-ios/lokinet/Assets.xcassets/Contents.json | 6 ++ .../Base.lproj/LaunchScreen.storyboard | 25 +++++ ui-ios/lokinet/Base.lproj/Main.storyboard | 24 +++++ ui-ios/lokinet/CMakeLists.txt | 1 + ui-ios/lokinet/Info.plist | 45 +++++++++ ui-ios/lokinet/ViewController.swift | 19 ++++ ui-ios/lokinet/lokinet.entitlements | 15 +++ .../lokinet.xcdatamodeld/.xccurrentversion | 8 ++ .../lokinet.xcdatamodel/contents | 4 + vendor/cxxopts/test/options.cpp | 2 +- 20 files changed, 431 insertions(+), 21 deletions(-) create mode 100644 cmake/basic_definitions.cmake create mode 100644 ui-ios/CMakeLists.txt create mode 100644 ui-ios/ios-toolchain.cmake create mode 100644 ui-ios/lokinet/AppDelegate.swift create mode 100644 ui-ios/lokinet/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 ui-ios/lokinet/Assets.xcassets/Contents.json create mode 100644 ui-ios/lokinet/Base.lproj/LaunchScreen.storyboard create mode 100644 ui-ios/lokinet/Base.lproj/Main.storyboard create mode 100644 ui-ios/lokinet/CMakeLists.txt create mode 100644 ui-ios/lokinet/Info.plist create mode 100644 ui-ios/lokinet/ViewController.swift create mode 100644 ui-ios/lokinet/lokinet.entitlements create mode 100644 ui-ios/lokinet/lokinet.xcdatamodeld/.xccurrentversion create mode 100644 ui-ios/lokinet/lokinet.xcdatamodeld/lokinet.xcdatamodel/contents diff --git a/.travis.yml b/.travis.yml index ff4ccdb96..192bd8b7d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,6 +44,10 @@ matrix: os: osx osx_image: xcode10.2 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)" os: osx osx_image: xcode10.2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 2351ea436..8dd26f7f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,22 +41,7 @@ endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") -# 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) +include(cmake/basic_definitions.cmake) if(MSVC_VERSION) enable_language(ASM_MASM) @@ -210,7 +195,7 @@ if(NOT GIT_VERSION) string(STRIP "${GIT_VERSION_UNSTRIP}" 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}\"") set(EXE lokinet) diff --git a/Makefile b/Makefile index f9081b175..a1f2bcfde 100644 --- a/Makefile +++ b/Makefile @@ -204,6 +204,10 @@ $(LIBUV_PREFIX): mkdir -p $(BUILD_ROOT) 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) rm -f $(ANDROID_PROPS) rm -f $(ANDROID_LOCAL_PROPS) diff --git a/cmake/basic_definitions.cmake b/cmake/basic_definitions.cmake new file mode 100644 index 000000000..d89364363 --- /dev/null +++ b/cmake/basic_definitions.cmake @@ -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) diff --git a/cmake/unix.cmake b/cmake/unix.cmake index 817adc79f..3d437f159 100644 --- a/cmake/unix.cmake +++ b/cmake/unix.cmake @@ -18,7 +18,7 @@ if(LIBUV_ROOT) set(LIBUV_LIBRARY uv_a) add_definitions(-D_LARGEFILE_SOURCE) add_definitions(-D_FILE_OFFSET_BITS=64) -else() +elseif(NOT LIBUV_IN_SOURCE) find_package(LibUV 1.28.0 REQUIRED) endif() @@ -46,7 +46,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "DragonFly") find_library(FS_LIB NAMES c++experimental) 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) if(FS_LIB STREQUAL FS_LIB-NOTFOUND) 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) endif() 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() diff --git a/include/tuntap.h b/include/tuntap.h index 6cc444a70..5981793f6 100644 --- a/include/tuntap.h +++ b/include/tuntap.h @@ -42,6 +42,8 @@ #endif #if defined Linux #include +#elif defined(iOS) +#include #else #include #endif diff --git a/ui-ios/CMakeLists.txt b/ui-ios/CMakeLists.txt new file mode 100644 index 000000000..7311a82f3 --- /dev/null +++ b/ui-ios/CMakeLists.txt @@ -0,0 +1,58 @@ +cmake_minimum_required(VERSION 3.15) +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) diff --git a/ui-ios/ios-toolchain.cmake b/ui-ios/ios-toolchain.cmake new file mode 100644 index 000000000..8d36fe7fc --- /dev/null +++ b/ui-ios/ios-toolchain.cmake @@ -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 "") diff --git a/ui-ios/lokinet/AppDelegate.swift b/ui-ios/lokinet/AppDelegate.swift new file mode 100644 index 000000000..dbb3fcde6 --- /dev/null +++ b/ui-ios/lokinet/AppDelegate.swift @@ -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)") + } + } + } + +} + diff --git a/ui-ios/lokinet/Assets.xcassets/AppIcon.appiconset/Contents.json b/ui-ios/lokinet/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..d8db8d65f --- /dev/null +++ b/ui-ios/lokinet/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -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" + } +} \ No newline at end of file diff --git a/ui-ios/lokinet/Assets.xcassets/Contents.json b/ui-ios/lokinet/Assets.xcassets/Contents.json new file mode 100644 index 000000000..da4a164c9 --- /dev/null +++ b/ui-ios/lokinet/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/ui-ios/lokinet/Base.lproj/LaunchScreen.storyboard b/ui-ios/lokinet/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 000000000..bfa361294 --- /dev/null +++ b/ui-ios/lokinet/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ui-ios/lokinet/Base.lproj/Main.storyboard b/ui-ios/lokinet/Base.lproj/Main.storyboard new file mode 100644 index 000000000..f1bcf3840 --- /dev/null +++ b/ui-ios/lokinet/Base.lproj/Main.storyboard @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ui-ios/lokinet/CMakeLists.txt b/ui-ios/lokinet/CMakeLists.txt new file mode 100644 index 000000000..35fa08bd5 --- /dev/null +++ b/ui-ios/lokinet/CMakeLists.txt @@ -0,0 +1 @@ +add_executable(lokinet AppDelegate.swift ViewController.swift) diff --git a/ui-ios/lokinet/Info.plist b/ui-ios/lokinet/Info.plist new file mode 100644 index 000000000..16be3b681 --- /dev/null +++ b/ui-ios/lokinet/Info.plist @@ -0,0 +1,45 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/ui-ios/lokinet/ViewController.swift b/ui-ios/lokinet/ViewController.swift new file mode 100644 index 000000000..26e307e09 --- /dev/null +++ b/ui-ios/lokinet/ViewController.swift @@ -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. + } + + +} + diff --git a/ui-ios/lokinet/lokinet.entitlements b/ui-ios/lokinet/lokinet.entitlements new file mode 100644 index 000000000..8f2ff3f1e --- /dev/null +++ b/ui-ios/lokinet/lokinet.entitlements @@ -0,0 +1,15 @@ + + + + + com.apple.developer.networking.networkextension + + dns-proxy + packet-tunnel-provider + + com.apple.developer.networking.vpn.api + + allow-vpn + + + diff --git a/ui-ios/lokinet/lokinet.xcdatamodeld/.xccurrentversion b/ui-ios/lokinet/lokinet.xcdatamodeld/.xccurrentversion new file mode 100644 index 000000000..bf2d08f0a --- /dev/null +++ b/ui-ios/lokinet/lokinet.xcdatamodeld/.xccurrentversion @@ -0,0 +1,8 @@ + + + + + _XCCurrentVersionName + lokinet.xcdatamodel + + diff --git a/ui-ios/lokinet/lokinet.xcdatamodeld/lokinet.xcdatamodel/contents b/ui-ios/lokinet/lokinet.xcdatamodeld/lokinet.xcdatamodel/contents new file mode 100644 index 000000000..476e5b6cf --- /dev/null +++ b/ui-ios/lokinet/lokinet.xcdatamodeld/lokinet.xcdatamodel/contents @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/vendor/cxxopts/test/options.cpp b/vendor/cxxopts/test/options.cpp index d110e0125..d3d3c7a69 100644 --- a/vendor/cxxopts/test/options.cpp +++ b/vendor/cxxopts/test/options.cpp @@ -9,7 +9,7 @@ class Argv { Argv(std::initializer_list args) : m_argv(new char*[args.size()]) - , m_argc(args.size()) + , m_argc(static_cast(args.size())) { int i = 0; auto iter = args.begin(); From dd63a7c84bc0b07b189bc878fb5cc96387aa1e31 Mon Sep 17 00:00:00 2001 From: michael-loki Date: Mon, 30 Sep 2019 15:12:28 +0100 Subject: [PATCH 02/11] Make Travis happy --- ui-ios/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-ios/CMakeLists.txt b/ui-ios/CMakeLists.txt index 7311a82f3..87022d5ec 100644 --- a/ui-ios/CMakeLists.txt +++ b/ui-ios/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.14) set(PROJECT_NAME lokinet) project(${PROJECT_NAME} C CXX Swift) From c9b862a12b6fc3ab7d19d3952d7da0725ef389d3 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Wed, 2 Oct 2019 12:08:45 -0600 Subject: [PATCH 03/11] Add a --version flag to lokinet CLI args --- daemon/main.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/daemon/main.cpp b/daemon/main.cpp index ec6d938f4..d3ec8de27 100644 --- a/daemon/main.cpp +++ b/daemon/main.cpp @@ -1,4 +1,5 @@ #include // for ensure_config +#include #include #include #include @@ -134,6 +135,7 @@ main(int argc, char *argv[]) options.add_options() ("v,verbose", "Verbose", cxxopts::value()) ("h,help", "help", cxxopts::value()) + ("version", "version", cxxopts::value()) ("g,generate", "generate client config", cxxopts::value()) ("r,router", "generate router config", cxxopts::value()) ("f,force", "overwrite", cxxopts::value()) @@ -172,6 +174,12 @@ main(int argc, char *argv[]) return 0; } + if(result.count("version")) + { + std::cout << LLARP_VERSION << std::endl; + return 0; + } + if(result.count("generate") > 0) { genconfigOnly = true; From d467e2618b5a9a13939e84890628703cedb7dc50 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 2 Oct 2019 21:27:34 +0100 Subject: [PATCH 04/11] Support version over jsonrcp --- llarp/rpc/rpc.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/llarp/rpc/rpc.cpp b/llarp/rpc/rpc.cpp index e2830389b..7c0458749 100644 --- a/llarp/rpc/rpc.cpp +++ b/llarp/rpc/rpc.cpp @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -259,6 +260,13 @@ namespace llarp return resp; } + Response + DumpVersion() const + { + const Response resp{{"version", LLARP_VERSION}}; + return resp; + } + absl::optional< Response > HandleJSONRPC(Method_t method, ABSL_ATTRIBUTE_UNUSED const Params& params) override @@ -279,6 +287,10 @@ namespace llarp { return DumpStatus(); } + if(method == "llarp.version") + { + return DumpVersion(); + } return false; } }; From 15cb49c9bde8aff4e3eb8a78bab6d91e4580b3ff Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 4 Oct 2019 10:10:55 +0100 Subject: [PATCH 05/11] Introduce --background to only start JSON RPC fixes #853 --- daemon/main.cpp | 22 +++++++-------- include/llarp.h | 4 +-- include/llarp.hpp | 4 +-- llarp/context.cpp | 48 ++++++++++----------------------- llarp/router/abstractrouter.hpp | 5 +++- llarp/router/router.cpp | 32 ++++++++++++++++------ llarp/router/router.hpp | 5 +++- llarp/rpc/rpc.cpp | 11 ++++++++ 8 files changed, 72 insertions(+), 59 deletions(-) diff --git a/daemon/main.cpp b/daemon/main.cpp index d3ec8de27..a7e3f4e0f 100644 --- a/daemon/main.cpp +++ b/daemon/main.cpp @@ -83,7 +83,7 @@ resolvePath(std::string conffname) /// this sets up, configures and runs the main context static void -run_main_context(std::string conffname, bool multiThreaded, bool debugMode) +run_main_context(std::string conffname, bool multiThreaded, bool backgroundMode) { // this is important, can downgrade from Info though llarp::LogDebug("Running from: ", fs::current_path().string()); @@ -97,10 +97,10 @@ run_main_context(std::string conffname, bool multiThreaded, bool debugMode) #ifndef _WIN32 signal(SIGHUP, handle_signal); #endif - code = llarp_main_setup(ctx, debugMode); + code = llarp_main_setup(ctx); llarp::util::SetThreadName("llarp-mainloop"); if(code == 0) - code = llarp_main_run(ctx); + code = llarp_main_run(ctx, backgroundMode); llarp_main_free(ctx); } exit_code.set_value(code); @@ -140,16 +140,16 @@ main(int argc, char *argv[]) ("r,router", "generate router config", cxxopts::value()) ("f,force", "overwrite", cxxopts::value()) ("c,colour", "colour output", cxxopts::value()->default_value("true")) - ("d,debug", "debug mode - UNENCRYPTED TRAFFIC", cxxopts::value()) + ("b,background", "background mode (start, but do not connect to the network)", cxxopts::value()) ("config","path to configuration file", cxxopts::value()); options.parse_positional("config"); // clang-format on - bool genconfigOnly = false; - bool asRouter = false; - bool overWrite = false; - bool debugMode = false; + bool genconfigOnly = false; + bool asRouter = false; + bool overWrite = false; + bool backgroundMode = false; std::string conffname; // suggestions: confFName? conf_fname? try @@ -185,9 +185,9 @@ main(int argc, char *argv[]) genconfigOnly = true; } - if(result.count("debug") > 0) + if(result.count("background") > 0) { - debugMode = true; + backgroundMode = true; } if(result.count("force") > 0) @@ -319,7 +319,7 @@ main(int argc, char *argv[]) } std::thread main_thread{ - std::bind(&run_main_context, conffname, multiThreaded, debugMode)}; + std::bind(&run_main_context, conffname, multiThreaded, backgroundMode)}; auto ftr = exit_code.get_future(); do { diff --git a/include/llarp.h b/include/llarp.h index 24779c17d..72f4856d5 100644 --- a/include/llarp.h +++ b/include/llarp.h @@ -41,11 +41,11 @@ extern "C" /// setup main context, returns 0 on success 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 int - llarp_main_run(struct llarp_main *ptr); + llarp_main_run(struct llarp_main *ptr, bool backgroundMode); /// free main context and end all operations void diff --git a/include/llarp.hpp b/include/llarp.hpp index d380350eb..9f34e22bf 100644 --- a/include/llarp.hpp +++ b/include/llarp.hpp @@ -81,10 +81,10 @@ namespace llarp GetDatabase(const byte_t *pk); int - Setup(bool debug = false); + Setup(); int - Run(); + Run(bool daemonMode); void HandleSignal(int sig); diff --git a/llarp/context.cpp b/llarp/context.cpp index 509902a4d..588ad0e41 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -192,40 +192,14 @@ __ ___ ____ _ _ ___ _ _ ____ } int - Context::Setup(bool debug) + Context::Setup() { llarp::LogInfo(LLARP_VERSION, " ", LLARP_RELEASE_MOTTO); llarp::LogInfo("starting up"); mainloop = llarp_make_ev_loop(); logic = std::make_shared< Logic >(); - if(debug) - { - 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 >(); - } + crypto = std::make_unique< sodium::CryptoLibSodium >(); cryptoManager = std::make_unique< CryptoManager >(crypto.get()); router = std::make_unique< Router >(worker, mainloop, logic); @@ -248,7 +222,7 @@ __ ___ ____ _ _ ___ _ _ ____ } int - Context::Run() + Context::Run(bool backgroundMode) { if(router == nullptr) { @@ -259,9 +233,15 @@ __ ___ ____ _ _ ___ _ _ ____ if(!WritePIDFile()) return 1; // run - if(!router->Run(nodedb.get())) + if(!router->StartJsonRpc()) return 1; + if(!backgroundMode) + { + if(!router->Run()) + return 2; + } + // run net io thread llarp::LogInfo("running mainloop"); llarp_ev_loop_run_single_process(mainloop, logic); @@ -437,20 +417,20 @@ extern "C" } 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 - llarp_main_run(struct llarp_main *ptr) + llarp_main_run(struct llarp_main *ptr, bool backgroundMode) { if(!ptr) { llarp::LogError("No ptr passed in"); return 1; } - return ptr->ctx->Run(); + return ptr->ctx->Run(backgroundMode); } void diff --git a/llarp/router/abstractrouter.hpp b/llarp/router/abstractrouter.hpp index ad2891834..08fbf449e 100644 --- a/llarp/router/abstractrouter.hpp +++ b/llarp/router/abstractrouter.hpp @@ -127,7 +127,10 @@ namespace llarp Configure(Config *conf, llarp_nodedb *nodedb) = 0; virtual bool - Run(struct llarp_nodedb *nodedb) = 0; + StartJsonRpc() = 0; + + virtual bool + Run() = 0; /// stop running the router logic gracefully virtual void diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 315eeb805..858242d2e 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -110,11 +110,18 @@ namespace llarp util::StatusObject Router::ExtractStatus() const { - return util::StatusObject{ - {"dht", _dht->impl->ExtractStatus()}, - {"services", _hiddenServiceContext.ExtractStatus()}, - {"exit", _exitContext.ExtractStatus()}, - {"links", _linkManager.ExtractStatus()}}; + if(_running) + { + return util::StatusObject{ + {"dht", _dht->impl->ExtractStatus()}, + {"services", _hiddenServiceContext.ExtractStatus()}, + {"exit", _exitContext.ExtractStatus()}, + {"links", _linkManager.ExtractStatus()}}; + } + else + { + return util::StatusObject{{"notRunning", true}}; + } } bool @@ -825,11 +832,10 @@ namespace llarp } bool - Router::Run(struct llarp_nodedb *nodedb) + Router::StartJsonRpc() { if(_running || _stopping) return false; - this->_nodedb = nodedb; if(enableRPCServer) { @@ -849,6 +855,16 @@ namespace llarp } LogInfo("Bound RPC server to ", rpcBindAddr); } + + return true; + } + + bool + Router::Run() + { + if(_running || _stopping) + return false; + if(whitelistRouters) { rpcCaller = std::make_unique< rpc::Caller >(this); @@ -1001,7 +1017,7 @@ namespace llarp _dht->impl->Nodes()->PutNode(rc); } - LogInfo("have ", nodedb->num_loaded(), " routers"); + LogInfo("have ", _nodedb->num_loaded(), " routers"); ScheduleTicker(1000); _running.store(true); diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index dce19004f..e2d94536e 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -327,7 +327,10 @@ namespace llarp Configure(Config *conf, llarp_nodedb *nodedb = nullptr) override; bool - Run(struct llarp_nodedb *nodedb) override; + StartJsonRpc() override; + + bool + Run() override; /// stop running the router logic gracefully void diff --git a/llarp/rpc/rpc.cpp b/llarp/rpc/rpc.cpp index 7c0458749..c1447e29c 100644 --- a/llarp/rpc/rpc.cpp +++ b/llarp/rpc/rpc.cpp @@ -195,6 +195,13 @@ namespace llarp ~Handler() override = default; + Response + StartRouter() const + { + const bool rc = router->Run(); + return Response{{"status", rc}}; + } + Response DumpState() const { @@ -271,6 +278,10 @@ namespace llarp HandleJSONRPC(Method_t method, ABSL_ATTRIBUTE_UNUSED const Params& params) override { + if(method == "llarp.admin.start") + { + return StartRouter(); + } if(method == "llarp.admin.link.neighboors") { return ListNeighboors(); From f326c93b5b76ee97037741fe82dd62c067e4a4eb Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 4 Oct 2019 20:43:30 +0100 Subject: [PATCH 06/11] Apply Jeff's comments --- llarp/router/router.cpp | 3 ++- llarp/rpc/rpc.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 858242d2e..7bf9d2a10 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -113,6 +113,7 @@ namespace llarp if(_running) { return util::StatusObject{ + {"running", true}, {"dht", _dht->impl->ExtractStatus()}, {"services", _hiddenServiceContext.ExtractStatus()}, {"exit", _exitContext.ExtractStatus()}, @@ -120,7 +121,7 @@ namespace llarp } else { - return util::StatusObject{{"notRunning", true}}; + return util::StatusObject{{"running", false}}; } } diff --git a/llarp/rpc/rpc.cpp b/llarp/rpc/rpc.cpp index c1447e29c..12cc3725c 100644 --- a/llarp/rpc/rpc.cpp +++ b/llarp/rpc/rpc.cpp @@ -278,7 +278,7 @@ namespace llarp HandleJSONRPC(Method_t method, ABSL_ATTRIBUTE_UNUSED const Params& params) override { - if(method == "llarp.admin.start") + if(method == "llarp.admin.wakeup") { return StartRouter(); } From abc527ca35f3c4e77053a9f1780d373e04b86b4b Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 5 Oct 2019 16:03:25 +0100 Subject: [PATCH 07/11] Split cmake files for executables into src dirs --- CMakeLists.txt | 75 +++-------------------------------------- daemon/CMakeLists.txt | 42 +++++++++++++++++++++++ libabyss/CMakeLists.txt | 20 ++++++++++- 3 files changed, 65 insertions(+), 72 deletions(-) create mode 100644 daemon/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 8dd26f7f6..dad81fce6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -198,9 +198,6 @@ endif(NOT GIT_VERSION) string(REGEX REPLACE "^fatal.*$" nogit GIT_VERSION_REAL "${GIT_VERSION}") add_definitions("-DGIT_REV=\"${GIT_VERSION_REAL}\"") -set(EXE lokinet) -set(EXE_SRC daemon/main.cpp) - # HeapAlloc(2) on Windows was significantly revamped in 2009 # but the old algorithm isn't too bad either # this is _the_ system allocator on BSD UNIX @@ -232,80 +229,16 @@ set(LIBS ${MALLOC_LIB} ${FS_LIB} ${LIBUV_LIBRARY}) add_subdirectory(crypto) add_subdirectory(llarp) add_subdirectory(libabyss) +add_subdirectory(daemon) -if (NOT WIN32) - add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp) - target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} Threads::Threads ${LIBS}) -elseif(NOT MSVC_VERSION) - add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp llarp/win32/abyss.rc) - target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32) -else() - add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp) - target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32) -endif(NOT WIN32) - -# Why does abyss not inherit the existing include folders? -target_include_directories(${ABYSS_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include" llarp vendor/nlohmann/include include crypto/include) -target_include_directories(${ABYSS_EXE} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include" llarp vendor/nlohmann/include include crypto/include) - -# for freebsd -if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") - target_link_directories(${ABYSS_EXE} PRIVATE /usr/local/lib) - target_include_directories(${ABYSS_LIB} SYSTEM PUBLIC /usr/local/include) -endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") -add_log_tag(${ABYSS_EXE}) -add_log_tag(${ABYSS_LIB}) - - -if(SHADOW) - set(LOKINET_SHADOW shadow-plugin-${SHARED_LIB}) - set(LOKINET_SHADOW_LIBS ${SHARED_LIB}) - add_shadow_plugin(${LOKINET_SHADOW} ${EXE_SRC}) - target_link_libraries(${LOKINET_SHADOW} ${LOKINET_SHADOW_LIBS}) - target_include_directories(${LOKINET_SHADOW} PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/llarp ${PROJECT_SOURCE_DIR}/crypto/include) -else() - if(NOT WIN32) - add_executable(${EXE} ${EXE_SRC}) - add_executable(lokinet-rcutil daemon/rcutil.cpp) - elseif(NOT MSVC_VERSION) - add_executable(${EXE} ${EXE_SRC} llarp/win32/version.rc) - add_executable(lokinet-rcutil daemon/rcutil.cpp llarp/win32/version.rc) - else() - add_executable(${EXE} ${EXE_SRC}) - add_executable(lokinet-rcutil daemon/rcutil.cpp) - endif(NOT WIN32) - - add_log_tag(${EXE}) - add_log_tag(lokinet-rcutil) - - install(TARGETS ${EXE} RUNTIME DESTINATION bin) - install(TARGETS lokinet-rcutil RUNTIME DESTINATION bin) - if(WIN32) - install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap.exe DESTINATION bin) - else() - install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap DESTINATION bin) - endif() - - if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - install(CODE "execute_process(COMMAND setcap cap_net_admin,cap_net_bind_service=+eip ${CMAKE_INSTALL_PREFIX}/bin/lokinet)") - endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") - target_link_directories(${EXE} PRIVATE /usr/local/lib) - target_link_directories(lokinet-rcutil PRIVATE /usr/local/lib) - endif() - target_link_libraries(${EXE} PUBLIC ${EXE_LIBS} ${LIBS}) - target_link_libraries(lokinet-rcutil PUBLIC ${EXE_LIBS} ${LIBS}) +enable_testing() +if (NOT SHADOW) + add_subdirectory(test) if(ANDROID) add_library(${ANDROID_LIB} SHARED jni/lokinet_android.cpp) set_property(TARGET ${ANDROID_LIB} PROPERTY CXX_STANDARD 14) add_log_tag(${ANDROID_LIB}) target_link_libraries(${ANDROID_LIB} ${STATIC_LIB} ${LIBS}) endif(ANDROID) -endif(SHADOW) - -enable_testing() - -if (NOT SHADOW) - add_subdirectory(test) endif() diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt new file mode 100644 index 000000000..d9131e0ae --- /dev/null +++ b/daemon/CMakeLists.txt @@ -0,0 +1,42 @@ +set(EXE lokinet) +set(EXE_SRC main.cpp) + +if(SHADOW) + set(LOKINET_SHADOW shadow-plugin-${SHARED_LIB}) + set(LOKINET_SHADOW_LIBS ${SHARED_LIB}) + add_shadow_plugin(${LOKINET_SHADOW} ${EXE_SRC}) + target_link_libraries(${LOKINET_SHADOW} ${LOKINET_SHADOW_LIBS}) + target_include_directories(${LOKINET_SHADOW} PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/llarp ${PROJECT_SOURCE_DIR}/crypto/include) +else() + if(NOT WIN32) + add_executable(${EXE} ${EXE_SRC}) + add_executable(lokinet-rcutil rcutil.cpp) + elseif(NOT MSVC_VERSION) + add_executable(${EXE} ${EXE_SRC} llarp/win32/version.rc) + add_executable(lokinet-rcutil rcutil.cpp llarp/win32/version.rc) + else() + add_executable(${EXE} ${EXE_SRC}) + add_executable(lokinet-rcutil rcutil.cpp) + endif(NOT WIN32) + + add_log_tag(${EXE}) + add_log_tag(lokinet-rcutil) + + install(TARGETS ${EXE} RUNTIME DESTINATION bin) + install(TARGETS lokinet-rcutil RUNTIME DESTINATION bin) + if(WIN32) + install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap.exe DESTINATION bin) + else() + install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap DESTINATION bin) + endif() + + if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + install(CODE "execute_process(COMMAND setcap cap_net_admin,cap_net_bind_service=+eip ${CMAKE_INSTALL_PREFIX}/bin/lokinet)") + endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + target_link_directories(${EXE} PRIVATE /usr/local/lib) + target_link_directories(lokinet-rcutil PRIVATE /usr/local/lib) + endif() + target_link_libraries(${EXE} PUBLIC ${EXE_LIBS} ${LIBS}) + target_link_libraries(lokinet-rcutil PUBLIC ${EXE_LIBS} ${LIBS}) +endif(SHADOW) diff --git a/libabyss/CMakeLists.txt b/libabyss/CMakeLists.txt index 7a7f71b2f..d7ba91c03 100644 --- a/libabyss/CMakeLists.txt +++ b/libabyss/CMakeLists.txt @@ -4,6 +4,24 @@ add_library(${ABYSS_LIB} "${CMAKE_CURRENT_SOURCE_DIR}/src/md5.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/server.cpp") target_include_directories(${ABYSS_LIB} PUBLIC include) + if(NOT WIN32) target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB} ${LIBUV_LIBRARY}) -endif() + add_executable(${ABYSS_EXE} main.cpp) + target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} Threads::Threads ${LIBS}) +elseif(NOT MSVC_VERSION) + add_executable(${ABYSS_EXE} main.cpp llarp/win32/abyss.rc) + target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32) +else() + add_executable(${ABYSS_EXE} main.cpp) + target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32) +endif(NOT WIN32) + +# for freebsd +if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + target_link_directories(${ABYSS_EXE} PRIVATE /usr/local/lib) + target_include_directories(${ABYSS_LIB} SYSTEM PUBLIC /usr/local/include) +endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + +add_log_tag(${ABYSS_EXE}) +add_log_tag(${ABYSS_LIB}) From 4b6dab56511622c5ff729727d62b73e93579688b Mon Sep 17 00:00:00 2001 From: michael-loki Date: Sat, 5 Oct 2019 17:06:35 +0100 Subject: [PATCH 08/11] Fixup --- daemon/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index d9131e0ae..9b3811466 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -32,7 +32,6 @@ else() if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") install(CODE "execute_process(COMMAND setcap cap_net_admin,cap_net_bind_service=+eip ${CMAKE_INSTALL_PREFIX}/bin/lokinet)") - endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") target_link_directories(${EXE} PRIVATE /usr/local/lib) target_link_directories(lokinet-rcutil PRIVATE /usr/local/lib) From 07927746b8ef14c454e10cb36bab32876f94b2cc Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 5 Oct 2019 17:48:58 +0100 Subject: [PATCH 09/11] Fix makefile location --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a1f2bcfde..c7d73e495 100644 --- a/Makefile +++ b/Makefile @@ -116,7 +116,7 @@ endif TARGETS = $(REPO)/lokinet SIGS = $(TARGETS:=.sig) -EXE = $(BUILD_ROOT)/lokinet +EXE = $(BUILD_ROOT)/daemon/lokinet TEST_EXE = $(BUILD_ROOT)/test/testAll ABYSS_EXE = $(BUILD_ROOT)/abyss-main From 394f3e6943fc8fffb2201ab89a9dcbab4a33e567 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 6 Oct 2019 21:51:19 +0100 Subject: [PATCH 10/11] More CI fixes --- docker/compose/compose-base.Dockerfile | 4 ++-- docker/router.Dockerfile | 2 +- libabyss/CMakeLists.txt | 2 ++ ui-ios/CMakeLists.txt | 4 ++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docker/compose/compose-base.Dockerfile b/docker/compose/compose-base.Dockerfile index 208b1bced..07caebd24 100644 --- a/docker/compose/compose-base.Dockerfile +++ b/docker/compose/compose-base.Dockerfile @@ -12,5 +12,5 @@ RUN make NINJA=ninja STATIC_LINK=ON BUILD_TYPE=Release FROM alpine:latest -COPY --from=builder /src/build/lokinet / -COPY --from=builder /src/build/lokinet-rcutil / +COPY --from=builder /src/build/daemon/lokinet / +COPY --from=builder /src/build/daemon/lokinet-rcutil / diff --git a/docker/router.Dockerfile b/docker/router.Dockerfile index 33c913bdf..1b933046e 100644 --- a/docker/router.Dockerfile +++ b/docker/router.Dockerfile @@ -13,7 +13,7 @@ RUN ./lokinet-bootstrap ${bootstrap} FROM alpine:latest COPY lokinet-docker.ini /root/.lokinet/lokinet.ini -COPY --from=builder /src/build/lokinet . +COPY --from=builder /src/build/daemon/lokinet . COPY --from=builder /root/.lokinet/bootstrap.signed /root/.lokinet/ CMD ["./lokinet"] diff --git a/libabyss/CMakeLists.txt b/libabyss/CMakeLists.txt index d7ba91c03..a92f86786 100644 --- a/libabyss/CMakeLists.txt +++ b/libabyss/CMakeLists.txt @@ -10,9 +10,11 @@ if(NOT WIN32) add_executable(${ABYSS_EXE} main.cpp) target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} Threads::Threads ${LIBS}) elseif(NOT MSVC_VERSION) + target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB}) add_executable(${ABYSS_EXE} main.cpp llarp/win32/abyss.rc) target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32) else() + target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB}) add_executable(${ABYSS_EXE} main.cpp) target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32) endif(NOT WIN32) diff --git a/ui-ios/CMakeLists.txt b/ui-ios/CMakeLists.txt index 87022d5ec..52237af85 100644 --- a/ui-ios/CMakeLists.txt +++ b/ui-ios/CMakeLists.txt @@ -51,6 +51,10 @@ include_directories("${libuv_SOURCE_DIR}/include") add_loki_dir(vendor/gtest) add_subdirectory(${ABSEIL_DIR} "vendor/abseil-cpp") +if (FS_LIB STREQUAL "cppbackport") + add_loki_dir(vendor) +endif() + add_loki_dir(crypto) add_loki_dir(llarp) add_loki_dir(libabyss) From 77b4efd78be5ec73ef93d42415e87421f0b23cc3 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 7 Oct 2019 00:23:30 +0100 Subject: [PATCH 11/11] fixup ios --- CMakeLists.txt | 11 ----------- cmake/add_log_tag.cmake | 10 ++++++---- cmake/basic_definitions.cmake | 6 +++++- cmake/unix.cmake | 15 ++++++++------- cmake/win32.cmake | 16 ++++++++-------- libabyss/CMakeLists.txt | 17 ++++++++--------- ui-ios/CMakeLists.txt | 2 ++ 7 files changed, 37 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dad81fce6..026a96faf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,17 +213,6 @@ if(ANDROID) set(ANDROID_PLATFORM_SRC android/ifaddrs.c) endif(ANDROID) -set(LIBTUNTAP_SRC_BASE - ${TT_ROOT}/tuntap.cpp - ${TT_ROOT}/tuntap_log.cpp - ${LIBTUNTAP_IMPL}) - -if(UNIX) - set(LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix.c ${LIBTUNTAP_SRC_BASE}) -else() - set(LIBTUNTAP_SRC ${LIBTUNTAP_SRC_BASE}) -endif() - set(LIBS ${MALLOC_LIB} ${FS_LIB} ${LIBUV_LIBRARY}) add_subdirectory(crypto) diff --git a/cmake/add_log_tag.cmake b/cmake/add_log_tag.cmake index 77f1de1cf..c91fc809f 100644 --- a/cmake/add_log_tag.cmake +++ b/cmake/add_log_tag.cmake @@ -1,6 +1,8 @@ function(add_log_tag target) - get_target_property(TARGET_SRCS ${target} SOURCES) - foreach(F ${TARGET_SRCS}) - set_source_files_properties(${F} PROPERTIES COMPILE_FLAGS -DLOG_TAG=\\\"${F}\\\") - endforeach(F) + if(TARGET ${target}) + get_target_property(TARGET_SRCS ${target} SOURCES) + foreach(F ${TARGET_SRCS}) + set_source_files_properties(${F} PROPERTIES COMPILE_FLAGS -DLOG_TAG=\\\"${F}\\\") + endforeach(F) + endif() endfunction() diff --git a/cmake/basic_definitions.cmake b/cmake/basic_definitions.cmake index d89364363..7362e70ca 100644 --- a/cmake/basic_definitions.cmake +++ b/cmake/basic_definitions.cmake @@ -9,8 +9,12 @@ 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) +get_filename_component(TT_ROOT "${CMAKE_CURRENT_LIST_DIR}/../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) + +set(LIBTUNTAP_SRC + ${TT_ROOT}/tuntap.cpp + ${TT_ROOT}/tuntap_log.cpp) diff --git a/cmake/unix.cmake b/cmake/unix.cmake index 3d437f159..ebca06117 100644 --- a/cmake/unix.cmake +++ b/cmake/unix.cmake @@ -7,6 +7,7 @@ include(CheckLibraryExists) add_definitions(-DUNIX) add_definitions(-DPOSIX) +list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix.c) if (STATIC_LINK_RUNTIME OR STATIC_LINK) set(LIBUV_USE_STATIC ON) @@ -30,7 +31,7 @@ endif() if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(FS_LIB stdc++fs) - get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE) + list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-linux.c) elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android") find_library(FS_LIB NAMES c++fs c++experimental stdc++fs) if(FS_LIB STREQUAL FS_LIB-NOTFOUND) @@ -38,14 +39,14 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android") add_definitions(-DLOKINET_USE_CPPBACKPORT) set(FS_LIB cppbackport) endif() - get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE) + list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-linux.c) elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") - set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-openbsd.c ${TT_ROOT}/tuntap-unix-bsd.c) + list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-openbsd.c ${TT_ROOT}/tuntap-unix-bsd.c) elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") - set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-netbsd.c ${TT_ROOT}/tuntap-unix-bsd.c) + list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-netbsd.c ${TT_ROOT}/tuntap-unix-bsd.c) elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "DragonFly") find_library(FS_LIB NAMES c++experimental) - set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c) + list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c) elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR ${CMAKE_SYSTEM_NAME} MATCHES "iOS") find_library(FS_LIB NAMES c++fs c++experimental stdc++fs) if(FS_LIB STREQUAL FS_LIB-NOTFOUND) @@ -53,9 +54,9 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR ${CMAKE_SYSTEM_NAME} MATCHES "i add_definitions(-DLOKINET_USE_CPPBACKPORT) set(FS_LIB cppbackport) endif() - set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-darwin.c ${TT_ROOT}/tuntap-unix-bsd.c) + list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-darwin.c ${TT_ROOT}/tuntap-unix-bsd.c) elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") - set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-sunos.c) + list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-sunos.c) # Apple C++ screws up name decorations in stdc++fs, causing link to fail # Samsung does not build c++experimental or c++fs in their Apple libc++ pkgsrc build if (LIBUV_USE_STATIC) diff --git a/cmake/win32.cmake b/cmake/win32.cmake index a875a189a..05dbd7f40 100644 --- a/cmake/win32.cmake +++ b/cmake/win32.cmake @@ -21,17 +21,17 @@ if(NOT MSVC_VERSION) # to .r[o]data section one after the other! add_compile_options(-fno-ident -Wa,-mbig-obj) link_libraries( -lws2_32 -liphlpapi -lshlwapi -ldbghelp ) - add_definitions(-DWINVER=0x0500 -D_WIN32_WINNT=0x0500) - # Wait a minute, if we're not Microsoft C++, nor a Clang paired with Microsoft C++, - # then the only possible option has to be GNU or a GNU-linked Clang! + add_definitions(-DWINVER=0x0500 -D_WIN32_WINNT=0x0500) + # Wait a minute, if we're not Microsoft C++, nor a Clang paired with Microsoft C++, + # then the only possible option has to be GNU or a GNU-linked Clang! set(FS_LIB stdc++fs) endif() - -if(EMBEDDED_CFG) - link_libatomic() + +if(EMBEDDED_CFG) + link_libatomic() endif() - -get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-windows.c ABSOLUTE) + +list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-windows.c) get_filename_component(EV_SRC "llarp/ev/ev_win32.cpp" ABSOLUTE) add_definitions(-DWIN32_LEAN_AND_MEAN -DWIN32 -DWINVER=0x0500) set(EXE_LIBS ${STATIC_LIB} ${FS_LIB} ws2_32 iphlpapi) diff --git a/libabyss/CMakeLists.txt b/libabyss/CMakeLists.txt index a92f86786..f013d14a0 100644 --- a/libabyss/CMakeLists.txt +++ b/libabyss/CMakeLists.txt @@ -4,20 +4,19 @@ add_library(${ABYSS_LIB} "${CMAKE_CURRENT_SOURCE_DIR}/src/md5.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/server.cpp") target_include_directories(${ABYSS_LIB} PUBLIC include) +target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB}) -if(NOT WIN32) - target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB} ${LIBUV_LIBRARY}) +if(NOT WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL iOS) + target_link_libraries(${ABYSS_LIB} PUBLIC ${LIBUV_LIBRARY}) add_executable(${ABYSS_EXE} main.cpp) target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} Threads::Threads ${LIBS}) -elseif(NOT MSVC_VERSION) - target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB}) - add_executable(${ABYSS_EXE} main.cpp llarp/win32/abyss.rc) - target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32) -else() - target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB}) +elseif(MSVC_VERSION) add_executable(${ABYSS_EXE} main.cpp) target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32) -endif(NOT WIN32) +elseif(NOT CMAKE_SYSTEM_NAME STREQUAL iOS) + add_executable(${ABYSS_EXE} main.cpp llarp/win32/abyss.rc) + target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32) +endif() # for freebsd if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") diff --git a/ui-ios/CMakeLists.txt b/ui-ios/CMakeLists.txt index 52237af85..8e1a98e67 100644 --- a/ui-ios/CMakeLists.txt +++ b/ui-ios/CMakeLists.txt @@ -31,7 +31,9 @@ add_subdirectory(${libuv_SOURCE_DIR} ${libuv_BINARY_DIR}) include("${LOKINET_ROOT}/cmake/basic_definitions.cmake") set(LIBUV_IN_SOURCE ON) +set(LIBUV_LIBRARY uv_a) include("${LOKINET_ROOT}/cmake/unix.cmake") +unset(LIBTUNTAP_SRC) find_package(Threads REQUIRED)