From 256c493e82025916fb2d2eea8feae5261dc01fb9 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Sat, 23 Sep 2023 19:25:15 -0500 Subject: [PATCH] N2N and Godot runtime with embedded edge now building for Linux and Windows. --- .gitignore | 2 + N2NCMakeLists.txt | 85 +++++++++++++++++++++++++++++++++++ N2Nconfig.h | 44 ++++++++++++++++++ build-godot.sh | 2 + build-n2n.sh | 33 +++++++------- modules/embedded/embedded.cpp | 4 +- 6 files changed, 151 insertions(+), 19 deletions(-) create mode 100644 N2NCMakeLists.txt create mode 100644 N2Nconfig.h diff --git a/.gitignore b/.gitignore index 2f9af32..d84752a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ *~ output.log bin/ +n2n/CMakeLists.txt +n2n/include/config.h modules/embedded/embeds/ hamncheese/export_presets.cfg temp/ diff --git a/N2NCMakeLists.txt b/N2NCMakeLists.txt new file mode 100644 index 0000000..1d4b42b --- /dev/null +++ b/N2NCMakeLists.txt @@ -0,0 +1,85 @@ +cmake_minimum_required(VERSION 3.22) + +project(n2n VERSION 3.1.1) + +set(N2N_SOURCE + src/aes.c + src/auth.c + src/cc20.c + src/curve25519.c + src/edge_management.c + src/edge_utils.c + src/header_encryption.c + src/hexdump.c + src/json.c + src/management.c + src/minilzo.c + src/n2n.c + src/n2n_port_mapping.c + src/n2n_regex.c + src/network_traffic_filter.c + src/pearson.c + src/random_numbers.c + src/sn_management.c + src/sn_selection.c + src/sn_utils.c + src/speck.c + src/tf.c + src/transform_aes.c + src/transform_cc20.c + src/transform_lzo.c + src/transform_null.c + src/transform_speck.c + src/transform_tf.c + src/transform_zstd.c + src/tuntap_freebsd.c + src/tuntap_linux.c + src/tuntap_netbsd.c + src/tuntap_osx.c + src/wire.c +) + +if(DEFINED WIN32) +set(WIN_IS_DUMB "lib") +endif() + +set(N2N_LIBS + n2n + ${CMAKE_SOURCE_DIR}/thirdparty/libnatpmp/build/libnatpmp.a + ${CMAKE_SOURCE_DIR}/thirdparty/miniupnp/miniupnpc/build/${WIN_IS_DUMB}libminiupnpc.a +) + +if(DEFINED WIN32) +set(N2N_SOURCE + ${N2N_SOURCE} + src/win32/edge_utils_win32.c + src/win32/getopt1.c + src/win32/getopt.c + src/win32/wintap.c +) +set(N2N_LIBS + ${N2N_LIBS} + netapi32 + ws2_32 + iphlpapi +) +endif() + +include_directories( + include + ${CMAKE_SOURCE_DIR}/thirdparty/libnatpmp/build + ${CMAKE_SOURCE_DIR}/thirdparty/miniupnp/miniupnpc/build +) + +add_definitions( + -O2 + -DNDEBUG +) + +add_library(n2n ${N2N_SOURCE}) + +add_executable(edge src/edge.c) +target_link_libraries(edge ${N2N_LIBS}) + +add_executable(supernode src/supernode.c) +target_link_libraries(supernode ${N2N_LIBS}) diff --git a/N2Nconfig.h b/N2Nconfig.h new file mode 100644 index 0000000..27552c1 --- /dev/null +++ b/N2Nconfig.h @@ -0,0 +1,44 @@ +/* include/config.h. Generated from config.h.in by configure. */ +/* include/config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the `cap' library (-lcap). */ +/* #undef HAVE_LIBCAP */ + +/* Define to 1 if you have the `crypto' library (-lcrypto). */ +/* #undef HAVE_LIBCRYPTO */ + +/* Define to 1 if you have the `miniupnpc' library (-lminiupnpc). */ +#define HAVE_LIBMINIUPNPC 1 + +/* Define to 1 if you have the `natpmp' library (-lnatpmp). */ +#define HAVE_LIBNATPMP 1 + +/* Define to 1 if you have the `pcap' library (-lpcap). */ +/* #undef HAVE_LIBPCAP */ + +/* Define to 1 if you have the `pthread' library (-lpthread). */ +//#define HAVE_LIBPTHREAD 1 + +/* Define to 1 if you have the `zstd' library (-lzstd). */ +/* #undef HAVE_LIBZSTD */ + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Last change date */ +#define PACKAGE_BUILDDATE "Sat Sep 23 18:31:22 CDT 2023" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "edge" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "edge 3.1.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "edge" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "3.1.1" diff --git a/build-godot.sh b/build-godot.sh index 7a4d3de..246eaaa 100755 --- a/build-godot.sh +++ b/build-godot.sh @@ -67,6 +67,7 @@ LTO="lto=none" # Use "lto=full" for releases. pushd bin mkdir -p ../modules/embedded/embeds createEmbeddedBinary x86_64-linux-gnu-edge ../modules/embedded/embeds/linux_x86_64.h EDGE_H +createEmbeddedBinary x86_64-w64-mingw32-edge.exe ../modules/embedded/embeds/windows_x86_64.h EDGE_H popd pushd godot @@ -85,6 +86,7 @@ scons compiledb=yes # Build Templates. scons platform=linuxbsd target=template_release arch=x86_64 ${TEMPLATE} ${LTO} +scons platform=windows target=template_release arch=x86_64 ${TEMPLATE} ${LTO} popd diff --git a/build-n2n.sh b/build-n2n.sh index bc9b196..c6fb4fb 100755 --- a/build-n2n.sh +++ b/build-n2n.sh @@ -10,6 +10,7 @@ mkdir -p bin function buildn2n() { TRIPLE=$1 + SUFFIX=$2 TOOLCHAIN=${BUILDROOT}/cmake/${TRIPLE}.cmake pushd n2n/thirdparty/libnatpmp @@ -24,30 +25,28 @@ function buildn2n() { pushd n2n/thirdparty/miniupnp/miniupnpc [[ -d build ]] && rm -rf build mkdir -p build + cd build cmake -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN} .. make popd pushd n2n - ./autogen.sh - CFLAGS="-I ${BUILDROOT}/n2n/thirdparty/libnatpmp -I ${BUILDROOT}/n2n/thirdparty/miniupnp/miniupnpc/include" \ - LDFLAGS="-L ${BUILDROOT}/n2n/thirdparty/libnatpmp/build -L ${BUILDROOT}/n2n/thirdparty/miniupnp/miniupnpc/build" \ - ./configure \ - --target=${TRIPLE} \ - --host=${TRIPLE} \ - --build=x86_64-linux \ - --enable-pthread \ - --enable-natpmp \ - --enable-miniupnp - make edge - make supernode - upx -9 edge - upx -9 supernode - mv edge ../bin/${TRIPLE}-edge - mv supernode ../bin/${TRIPLE}-supernode + cd include + ln -f -s ../../N2Nconfig.h config.h + cd .. + ln -f -s ../N2NCMakeLists.txt CMakeLists.txt + [[ -d build ]] && rm -rf build + mkdir -p build + cd build + cmake -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN} .. + make + upx -9 edge${SUFFIX} + upx -9 supernode${SUFFIX} + mv edge${SUFFIX} ../../bin/${TRIPLE}-edge${SUFFIX} + mv supernode${SUFFIX} ../../bin/${TRIPLE}-supernode${SUFFIX} popd } buildn2n "x86_64-linux-gnu" -buildn2n "x86_64-w64-mingw32" +buildn2n "x86_64-w64-mingw32" ".exe" diff --git a/modules/embedded/embedded.cpp b/modules/embedded/embedded.cpp index 4b31355..12a5f49 100644 --- a/modules/embedded/embedded.cpp +++ b/modules/embedded/embedded.cpp @@ -16,8 +16,8 @@ extern "C" { #endif #elif _WIN32 #include "embeds/windows_x86_64.h" - unsigned char *data = x86_64_w64_mingw32_edge; - size_t length = (size_t)x86_64_w64_mingw32_edge_len; + unsigned char *data = x86_64_w64_mingw32_edge_exe; + size_t length = (size_t)x86_64_w64_mingw32_edge_exe_len; #elif __APPLE__ #ifdef __arm__ #include "embeds/macos_arm64.h"