diff --git a/contrib/android-configure.sh b/contrib/android-configure.sh index 6a11c3778..2d669cae2 100755 --- a/contrib/android-configure.sh +++ b/contrib/android-configure.sh @@ -1,17 +1,18 @@ #!/bin/bash set -e -set +x default_abis="armeabi-v7a arm64-v8a x86_64" build_abis=${ABIS:-$default_abis} -test x$NDK = x && echo "NDK env var not set" +test x$NDK = x && test -e /usr/lib/android-ndk && export NDK=/usr/lib/android-ndk test x$NDK = x && exit 1 echo "building abis: $build_abis" -root="$(readlink -f $(dirname $0)/../)" -build=$root/build-android +root=$(readlink -f "$1") +shift +build=$(readlink -f "$1") +shift mkdir -p $build cd $build @@ -19,6 +20,7 @@ for abi in $build_abis; do mkdir -p build-$abi cd build-$abi cmake \ + -S "$root" -B . \ -G 'Unix Makefiles' \ -DANDROID=ON \ -DANDROID_ABI=$abi \ @@ -37,12 +39,13 @@ for abi in $build_abis; do -DWITH_SYSTEMD=OFF \ -DFORCE_OXENMQ_SUBMODULE=ON \ -DFORCE_OXENC_SUBMODULE=ON \ - -DFORCE_LOGGING_SUBMODULE=ON \ + -DFORCE_FMT_SUBMODULE=ON \ + -DFORCE_SPDLOG_SUBMODULE=ON \ -DFORCE_NLOHMANN_SUBMODULE=ON \ -DSUBMODULE_CHECK=OFF \ -DWITH_LTO=OFF \ -DCMAKE_BUILD_TYPE=Release \ - $@ $root + $@ cd - done rm -f $build/Makefile @@ -53,4 +56,11 @@ for abi in $build_abis; do echo -ne '$(MAKE) -C ' >> $build/Makefile echo "build-$abi lokinet-android" >> $build/Makefile echo -ne "\tmkdir -p out/$abi && cp build-$abi/jni/liblokinet-android.so out/$abi/liblokinet-android.so\n\n" >> $build/Makefile + echo -ne "clean-$abi:\n\t" >> $build/Makefile + echo -ne '$(MAKE) -C ' >> $build/Makefile + echo "build-$abi clean" >> $build/Makefile done + +echo -ne "clean:" >> $build/Makefile +for targ in $build_abis ; do echo -ne " clean-$targ" >> $build/Makefile ; done +echo "" >> $build/Makefile diff --git a/contrib/android.sh b/contrib/android.sh index a5d720206..59b8944e0 100755 --- a/contrib/android.sh +++ b/contrib/android.sh @@ -2,9 +2,7 @@ set -e set +x -test x$NDK = x && echo "NDK env var not set" -test x$NDK = x && exit 1 root="$(readlink -f $(dirname $0)/../)" cd "$root" -./contrib/android-configure.sh $@ +./contrib/android-configure.sh . build-android $@ make -C build-android -j ${JOBS:-$(nproc)} diff --git a/contrib/windows-configure.sh b/contrib/windows-configure.sh new file mode 100755 index 000000000..50f7b0624 --- /dev/null +++ b/contrib/windows-configure.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -e +set -x + +root=$(readlink -f "$1") +shift +mkdir -p "$1" +build=$(readlink -f "$1") +shift +cd "$build" +cmake \ + -S "$root" -B "$build" \ + -G 'Unix Makefiles' \ + -DCMAKE_EXE_LINKER_FLAGS=-fstack-protector \ + -DCMAKE_CXX_FLAGS=-fdiagnostics-color=always \ + -DCMAKE_TOOLCHAIN_FILE="$root/contrib/cross/mingw64.cmake" \ + -DBUILD_STATIC_DEPS=ON \ + -DBUILD_PACKAGE=ON \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_TESTING=OFF \ + -DBUILD_LIBLOKINET=OFF \ + -DWITH_TESTS=OFF \ + -DNATIVE_BUILD=OFF \ + -DSTATIC_LINK=ON \ + -DWITH_SYSTEMD=OFF \ + -DFORCE_OXENMQ_SUBMODULE=ON \ + -DFORCE_OXENC_SUBMODULE=ON \ + -DFORCE_FMT_SUBMODULE=ON \ + -DFORCE_SPDLOG_SUBMODULE=ON \ + -DFORCE_NLOHMANN_SUBMODULE=ON \ + -DSUBMODULE_CHECK=OFF \ + -DWITH_LTO=OFF \ + $@ diff --git a/contrib/windows.sh b/contrib/windows.sh index 1c1a816f0..ebc20c035 100755 --- a/contrib/windows.sh +++ b/contrib/windows.sh @@ -6,28 +6,9 @@ set -e set +x -mkdir -p build-windows -cd build-windows -cmake \ - -G 'Unix Makefiles' \ - -DCMAKE_EXE_LINKER_FLAGS=-fstack-protector \ - -DCMAKE_CXX_FLAGS=-fdiagnostics-color=always\ - -DCMAKE_TOOLCHAIN_FILE=../contrib/cross/mingw64.cmake\ - -DBUILD_STATIC_DEPS=ON \ - -DBUILD_PACKAGE=ON \ - -DBUILD_SHARED_LIBS=OFF \ - -DBUILD_TESTING=OFF \ - -DBUILD_LIBLOKINET=OFF \ - -DWITH_TESTS=OFF \ - -DNATIVE_BUILD=OFF \ - -DSTATIC_LINK=ON \ - -DWITH_SYSTEMD=OFF \ - -DFORCE_OXENMQ_SUBMODULE=ON \ - -DFORCE_OXENC_SUBMODULE=ON \ - -DFORCE_LOGGING_SUBMODULE=ON \ - -DFORCE_NLOHMANN_SUBMODULE=ON \ - -DSUBMODULE_CHECK=OFF \ - -DWITH_LTO=OFF \ - -DCMAKE_BUILD_TYPE=Release \ - $@ .. -make package -j${JOBS:-$(nproc)} + + +root="$(readlink -f $(dirname $0)/../)" +cd "$root" +./contrib/windows-configure.sh . build-windows $@ +make package -j${JOBS:-$(nproc)} -C build-windows diff --git a/include/llarp.hpp b/include/llarp.hpp index 5838d3569..f6bf5dad2 100644 --- a/include/llarp.hpp +++ b/include/llarp.hpp @@ -100,14 +100,8 @@ namespace llarp virtual std::shared_ptr makeVPNPlatform(); -#ifdef ANDROID - int androidFD = -1; - int - GetUDPSocket(); -#endif - protected: std::shared_ptr config = nullptr; diff --git a/jni/lokinet_daemon.cpp b/jni/lokinet_daemon.cpp index bec31c147..4d4fa1638 100644 --- a/jni/lokinet_daemon.cpp +++ b/jni/lokinet_daemon.cpp @@ -77,24 +77,24 @@ extern "C" JNIEXPORT void JNICALL Java_network_loki_lokinet_LokinetDaemon_InjectVPNFD(JNIEnv* env, jobject self) { - auto ptr = GetImpl(env, self); - - ptr->androidFD = GetObjectMemberAsInt(env, self, "m_FD"); + if (auto ptr = GetImpl(env, self)) + ptr->androidFD = GetObjectMemberAsInt(env, self, "m_FD"); } JNIEXPORT jint JNICALL Java_network_loki_lokinet_LokinetDaemon_GetUDPSocket(JNIEnv* env, jobject self) { auto ptr = GetImpl(env, self); - - return ptr->router.m_OutboundUDPSocket; + if (const auto& router = ptr->router; ptr and ptr->router) + return router->OutboundUDPSocket(); + return -1; } JNIEXPORT jstring JNICALL Java_network_loki_lokinet_LokinetDaemon_DetectFreeRange(JNIEnv* env, jclass) { std::string rangestr{}; - if (auto maybe = llarp::net::Platform::Default().FindFreeRange()) + if (auto maybe = llarp::net::Platform::Default_ptr()->FindFreeRange()) { rangestr = maybe->ToString(); } diff --git a/llarp/apple/context_wrapper.cpp b/llarp/apple/context_wrapper.cpp index 3c91cdb06..26cbd21ed 100644 --- a/llarp/apple/context_wrapper.cpp +++ b/llarp/apple/context_wrapper.cpp @@ -54,7 +54,7 @@ llarp_apple_init(llarp_apple_config* appleconf) auto& range = config->network.m_ifaddr; if (!range.addr.h) { - if (auto maybe = llarp::net::Platform::Default().FindFreeRange()) + if (auto maybe = llarp::net::Platform::Default_ptr()->FindFreeRange()) range = *maybe; else throw std::runtime_error{"Could not find any free IP range"}; diff --git a/llarp/context.cpp b/llarp/context.cpp index 6bc5a3c3e..64636ea77 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -211,12 +211,4 @@ namespace llarp loop.reset(); } -#if defined(ANDROID) - int - Context::GetUDPSocket() - { - return router->GetOutboundUDPSocket(); - } -#endif - } // namespace llarp diff --git a/llarp/router/abstractrouter.hpp b/llarp/router/abstractrouter.hpp index 6a3cd2c3b..243f0a47b 100644 --- a/llarp/router/abstractrouter.hpp +++ b/llarp/router/abstractrouter.hpp @@ -354,10 +354,8 @@ namespace llarp HandleRouterEvent(std::move(event)); } -#if defined(ANDROID) virtual int - GetOutboundUDPSocket() const = 0; -#endif + OutboundUDPSocket() const = 0; protected: /// Virtual function to handle RouterEvent. HiveRouter overrides this in diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index e8a175d64..4aa05f81f 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -1190,6 +1190,12 @@ namespace llarp return true; } + int + Router::OutboundUDPSocket() const + { + return m_OutboundUDPSocket; + } + bool Router::Run() { diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index dc4b901a1..3500ed9cf 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -211,6 +211,9 @@ namespace llarp bool ShouldTestOtherRouters() const; + int + OutboundUDPSocket() const override; + std::optional _ourAddress; EventLoop_ptr _loop;