mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-10-31 09:20:21 +00:00
Merge pull request #729 from majestrate/fix-android-2019-07-24
make android compile again
This commit is contained in:
commit
183ec25717
22
Makefile
22
Makefile
@ -4,6 +4,8 @@ SIGN = gpg --sign --detach
|
||||
|
||||
REPO := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||
|
||||
BUILD_ROOT = $(REPO)/build
|
||||
|
||||
DESTDIR ?=
|
||||
|
||||
CC ?= cc
|
||||
@ -26,6 +28,9 @@ SHADOW_PARSE ?= $(PYTHON) $(SHADOW_SRC)/src/tools/parse-shadow.py - -m 0 --packe
|
||||
SHADOW_PLOT ?= $(PYTHON) $(SHADOW_SRC)/src/tools/plot-shadow.py -d $(REPO) LokiNET -c $(SHADOW_CONFIG) -r 10000 -e '.*'
|
||||
SHADOW_OPTS ?=
|
||||
|
||||
LIBUV_VERSION ?= v1.30.1
|
||||
LIBUV_PREFIX = $(BUILD_ROOT)/libuv
|
||||
|
||||
TESTNET_ROOT=/tmp/lokinet_testnet_tmp
|
||||
TESTNET_CONF=$(TESTNET_ROOT)/supervisor.conf
|
||||
TESTNET_LOG=$(TESTNET_ROOT)/testnet.log
|
||||
@ -83,7 +88,6 @@ ifdef NINJA
|
||||
endif
|
||||
|
||||
|
||||
BUILD_ROOT = $(REPO)/build
|
||||
|
||||
SCAN_BUILD ?= scan-build
|
||||
|
||||
@ -113,13 +117,16 @@ LINT_FILES = $(wildcard llarp/*.cpp)
|
||||
|
||||
LINT_CHECK = $(LINT_FILES:.cpp=.cpp-check)
|
||||
|
||||
clean:
|
||||
clean: android-clean
|
||||
rm -f $(TARGETS)
|
||||
rm -rf $(BUILD_ROOT)
|
||||
rm -f $(SHADOW_PLUGIN) $(SHADOW_CONFIG)
|
||||
rm -f *.sig
|
||||
rm -f *.a *.so
|
||||
|
||||
android-clean:
|
||||
rm -rf $(ANDROID_DIR)/.externalNativeBuild
|
||||
|
||||
debug-configure:
|
||||
mkdir -p '$(BUILD_ROOT)'
|
||||
(test x$(TOOLCHAIN) = x && $(CONFIG_CMD) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_C_FLAGS='$(CFLAGS)' -DCMAKE_CXX_FLAGS='$(CXXFLAGS)') || (test x$(TOOLCHAIN) != x && $(CONFIG_CMD) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_C_FLAGS='$(CFLAGS)' -DCMAKE_CXX_FLAGS='$(CXXFLAGS)' -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN) )
|
||||
@ -184,10 +191,17 @@ $(TEST_EXE): debug
|
||||
test: $(TEST_EXE)
|
||||
test x$(CROSS) = xOFF && $(TEST_EXE) || test x$(CROSS) = xON
|
||||
|
||||
android-gradle-prepare:
|
||||
|
||||
|
||||
$(LIBUV_PREFIX):
|
||||
mkdir -p $(BUILD_ROOT)
|
||||
git clone -b "$(LIBUV_VERSION)" https://github.com/libuv/libuv "$(LIBUV_PREFIX)"
|
||||
|
||||
android-gradle-prepare: $(LIBUV_PREFIX)
|
||||
rm -f $(ANDROID_PROPS)
|
||||
rm -f $(ANDROID_LOCAL_PROPS)
|
||||
echo "#auto generated don't modify kthnx" >> $(ANDROID_PROPS)
|
||||
echo "libuvsrc=$(LIBUV_PREFIX)" >> $(ANDROID_PROPS)
|
||||
echo "lokinetCMake=$(REPO)/CMakeLists.txt" >> $(ANDROID_PROPS)
|
||||
echo "org.gradle.parallel=true" >> $(ANDROID_PROPS)
|
||||
echo "org.gradle.jvmargs=-Xmx1536M" >> $(ANDROID_PROPS)
|
||||
@ -223,7 +237,7 @@ abyss: debug
|
||||
$(ABYSS_EXE)
|
||||
|
||||
format:
|
||||
clang-format -i $$(find daemon llarp include libabyss | grep -E '\.[h,c](pp)?$$')
|
||||
clang-format -i $$(find jni daemon llarp include libabyss | grep -E '\.[h,c](pp)?$$')
|
||||
|
||||
analyze-config: clean
|
||||
mkdir -p '$(BUILD_ROOT)'
|
||||
|
@ -33,7 +33,7 @@ android {
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
targets "lokinetandroid"
|
||||
arguments "-DANDROID=ON", "-DANDROID_STL=c++_static", "-DANDROID_ARM_NEON=TRUE"
|
||||
arguments "-DANDROID=ON", "-DANDROID_STL=c++_static", "-DANDROID_ARM_NEON=TRUE", "-DLIBUV_ROOT=" + libuvsrc, "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_MODE=arm"
|
||||
cppFlags "-fexceptions -std=c++14 -frtti"
|
||||
}
|
||||
}
|
||||
@ -68,7 +68,6 @@ android {
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path lokinetCMake
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,14 +9,29 @@ if (STATIC_LINK_RUNTIME)
|
||||
set(LIBUV_USE_STATIC ON)
|
||||
endif()
|
||||
|
||||
find_package(LibUV 1.28.0 REQUIRED)
|
||||
include_directories(SYSTEM ${LIBUV_INCLUDE_DIRS})
|
||||
if(LIBUV_ROOT)
|
||||
add_subdirectory(${LIBUV_ROOT})
|
||||
set(LIBUV_INCLUDE_DIRS ${LIBUV_ROOT}/include)
|
||||
set(LIBUV_LIBRARY uv_a)
|
||||
add_definitions(-D_LARGEFILE_SOURCE)
|
||||
add_definitions(-D_FILE_OFFSET_BITS=64)
|
||||
else()
|
||||
find_package(LibUV 1.28.0 REQUIRED)
|
||||
endif()
|
||||
|
||||
include_directories(${LIBUV_INCLUDE_DIRS})
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
set(FS_LIB stdc++fs)
|
||||
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE)
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
|
||||
set(FS_LIB stdc++fs)
|
||||
find_library(FS_LIB NAMES c++fs c++experimental stdc++fs)
|
||||
if(FS_LIB STREQUAL FS_LIB-NOTFOUND)
|
||||
add_subdirectory(vendor)
|
||||
include_directories("${CMAKE_CURRENT_LIST_DIR}/../vendor/cppbackport-master/lib")
|
||||
add_definitions(-DLOKINET_USE_CPPBACKPORT)
|
||||
set(FS_LIB cppbackport)
|
||||
endif()
|
||||
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE)
|
||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
|
||||
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-openbsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
|
||||
|
@ -115,9 +115,6 @@ extern "C"
|
||||
llarp::RouterContact *
|
||||
llarp_main_getDatabase(struct llarp_main *ptr, byte_t *pk);
|
||||
|
||||
llarp::handlers::TunEndpoint *
|
||||
main_router_getFirstTunEndpoint(struct llarp_main *ptr);
|
||||
|
||||
llarp_tun_io *
|
||||
main_router_getRange(struct llarp_main *ptr);
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
struct llarp_ev_loop;
|
||||
struct llarp_nodedb;
|
||||
struct llarp_nodedb_iter;
|
||||
struct llarp_main;
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
@ -118,4 +119,7 @@ namespace llarp
|
||||
};
|
||||
} // namespace llarp
|
||||
|
||||
llarp::Context *
|
||||
llarp_main_get_context(llarp_main *m);
|
||||
|
||||
#endif
|
||||
|
46
jni/lokinet_android.cpp
Executable file → Normal file
46
jni/lokinet_android.cpp
Executable file → Normal file
@ -1,6 +1,8 @@
|
||||
#include <llarp.h>
|
||||
#include <config.hpp>
|
||||
#include <config/config.hpp>
|
||||
#include <util/fs.hpp>
|
||||
#include <llarp.hpp>
|
||||
#include <router/router.hpp>
|
||||
|
||||
#include <jni.h>
|
||||
#include <signal.h>
|
||||
@ -40,7 +42,7 @@ struct AndroidMain
|
||||
m_impl = llarp_main_init(configFile.c_str(), true);
|
||||
if(m_impl == nullptr)
|
||||
return false;
|
||||
if(llarp_main_setup(m_impl))
|
||||
if(llarp_main_setup(m_impl, false))
|
||||
{
|
||||
llarp_main_free(m_impl);
|
||||
m_impl = nullptr;
|
||||
@ -75,13 +77,33 @@ struct AndroidMain
|
||||
const char*
|
||||
GetIfAddr()
|
||||
{
|
||||
std::string addr;
|
||||
if(m_impl)
|
||||
{
|
||||
auto tun = main_router_getFirstTunEndpoint(m_impl);
|
||||
if(tun)
|
||||
return tun->tunif.ifaddr;
|
||||
auto* ctx = llarp_main_get_context(m_impl);
|
||||
if(!ctx)
|
||||
return "";
|
||||
|
||||
ctx->router->hiddenServiceContext().ForEachService(
|
||||
[&addr](const std::string&,
|
||||
const llarp::service::Endpoint_ptr& ep) -> bool {
|
||||
if(addr.empty())
|
||||
{
|
||||
if(ep->HasIfAddr())
|
||||
{
|
||||
// TODO: v4
|
||||
const auto ip = ep->GetIfAddr();
|
||||
if(ip.h)
|
||||
{
|
||||
addr = ip.ToString();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
return "";
|
||||
return addr.c_str();
|
||||
}
|
||||
|
||||
int
|
||||
@ -89,9 +111,9 @@ struct AndroidMain
|
||||
{
|
||||
if(m_impl)
|
||||
{
|
||||
auto tun = main_router_getFirstTunEndpoint(m_impl);
|
||||
if(tun)
|
||||
return tun->tunif.netmask;
|
||||
auto* ctx = llarp_main_get_context(m_impl);
|
||||
if(!ctx)
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@ -99,8 +121,10 @@ struct AndroidMain
|
||||
void
|
||||
SetVPN_FD(int rfd, int wfd)
|
||||
{
|
||||
if(m_impl)
|
||||
llarp_main_inject_vpn_fd(m_impl, rfd, wfd);
|
||||
(void)rfd;
|
||||
(void)wfd;
|
||||
// if(m_impl)
|
||||
// llarp_main_inject_vpn_fd(m_impl, rfd, wfd);
|
||||
}
|
||||
|
||||
/// stop daemon thread
|
||||
|
@ -53,7 +53,12 @@ set(LIB_UTIL_SRC
|
||||
|
||||
add_library(${UTIL_LIB} STATIC ${LIB_UTIL_SRC})
|
||||
target_include_directories(${UTIL_LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include)
|
||||
target_link_libraries(${UTIL_LIB} PUBLIC ${CRYPTOGRAPHY_LIB} ${FS_LIB})
|
||||
if(ANDROID)
|
||||
set(LOG_LIB log)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${UTIL_LIB} PUBLIC ${CRYPTOGRAPHY_LIB} ${FS_LIB} ${LOG_LIB})
|
||||
|
||||
target_link_libraries_system(${UTIL_LIB} absl::synchronization absl::hash absl::container nlohmann_json::nlohmann_json)
|
||||
|
||||
# cut back on fluff
|
||||
|
@ -402,6 +402,12 @@ struct llarp_main
|
||||
std::unique_ptr< llarp::Context > ctx;
|
||||
};
|
||||
|
||||
llarp::Context *
|
||||
llarp_main_get_context(llarp_main *m)
|
||||
{
|
||||
return m->ctx.get();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
struct llarp_main *
|
||||
|
@ -6,7 +6,8 @@ namespace llarp
|
||||
{
|
||||
void
|
||||
AndroidLogStream::PreLog(std::stringstream& ss, LogLevel lvl,
|
||||
const char* fname, int lineno) const
|
||||
const char* fname, int lineno,
|
||||
const std::string&) const
|
||||
{
|
||||
switch(lvl)
|
||||
{
|
||||
@ -31,7 +32,11 @@ namespace llarp
|
||||
}
|
||||
|
||||
void
|
||||
AndroidLogStream::PostLog(std::stingstream&) const
|
||||
AndroidLogStream::PostLog(std::stringstream&) const
|
||||
{
|
||||
}
|
||||
|
||||
void AndroidLogStream::Tick(llarp_time_t)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef LLARP_UTIL_OSTREAM_LOGGER_HPP
|
||||
#define LLARP_UTIL_OSTREAM_LOGGER_HPP
|
||||
#ifndef LLARP_UTIL_ANDROID_LOGGER_HPP
|
||||
#define LLARP_UTIL_ANDROID_LOGGER_HPP
|
||||
|
||||
#include <util/logstream.hpp>
|
||||
#include <iostream>
|
||||
@ -9,14 +9,14 @@ namespace llarp
|
||||
struct AndroidLogStream : public ILogStream
|
||||
{
|
||||
void
|
||||
PreLog(std::stringstream& s, LogLevel lvl, const char* fname,
|
||||
int lineno) const override;
|
||||
PreLog(std::stringstream& s, LogLevel lvl, const char* fname, int lineno,
|
||||
const std::string& nodename) const override;
|
||||
|
||||
void
|
||||
Log(LogLevel lvl, const std::string& msg) override;
|
||||
Print(LogLevel lvl, const char* filename, const std::string& msg) override;
|
||||
|
||||
void
|
||||
PostLog(std::stringstream&) const override{};
|
||||
PostLog(std::stringstream&) const override;
|
||||
|
||||
void Tick(llarp_time_t) override;
|
||||
};
|
||||
|
@ -11,9 +11,7 @@ namespace llarp
|
||||
/// logger stream interface
|
||||
struct ILogStream
|
||||
{
|
||||
virtual ~ILogStream()
|
||||
{
|
||||
}
|
||||
virtual ~ILogStream() = default;
|
||||
|
||||
virtual void
|
||||
PreLog(std::stringstream& out, LogLevel lvl, const char* fname, int lineno,
|
||||
|
4
vendor/libtuntap-master/tuntap-unix-linux.c
vendored
4
vendor/libtuntap-master/tuntap-unix-linux.c
vendored
@ -187,13 +187,15 @@ tuntap_sys_set_ipv4(struct device *dev, t_tun_in_addr *s4, uint32_t bits)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#if defined(ANDROID)
|
||||
|
||||
#else
|
||||
struct in6_ifreq {
|
||||
struct in6_addr ifr6_addr;
|
||||
__u32 ifr6_prefixlen;
|
||||
unsigned int ifr6_ifindex;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
tuntap_sys_set_ipv6(struct device *dev, t_tun_in6_addr *s6, uint32_t bits)
|
||||
|
Loading…
Reference in New Issue
Block a user