如何使用Windows运行N2N-编译篇

按照N2N官方网站Building说明,Windows编译需要的软件有
Visual Studio,Cmake,OpenSSL

看到Visual Studio我就头大,这个软件安装起来可不得了。
于是我选择了交叉编译,即使用Linux环境编译Windows的exe和dll文件。

已编译好的文件

编译环境:
Ubuntu 20.04.1 LTS
Linux vm-n2n-cc2 5.4.0-59-generic #65-Ubuntu SMP Thu Dec 10 12:01:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

一键打包下载
edge,supernode,openssl链接库(n2n运行必备),tap-windows安装包(n2n运行必备,Win7&Win10)

wget https://download.margrop.net/d/oneindex/network/n2n_2.8_stable/Windows/edge.exe -O edge
wget https://download.margrop.net/d/oneindex/network/n2n_2.8_stable/Windows/supernode.exe -O supernode
wget https://download.margrop.net/d/oneindex/network/n2n_2.8_stable/Windows/libcrypto-1_1-x64.dll -O libcrypto-1_1-x64.dll
wget https://download.margrop.net/d/oneindex/network/n2n_2.8_stable/Windows/libssl-1_1-x64.dll -O libssl-1_1-x64.dll

准备编译环境

apt-get install mingw-w64
apt-get install cmake
apt-get install openssl
apt-get install libssl-dev
apt-get install build-essential git bison flex libxml2-dev libpcap-dev libtool libtool-bin rrdtool librrd-dev autoconf pkg-config automake autogen redis-server wget libsqlite3-dev libhiredis-dev libmaxminddb-dev libcurl4-openssl-dev libpango1.0-dev libcairo2-dev libnetfilter-queue-dev zlib1g-dev libssl-dev libcap-dev libnetfilter-conntrack-dev libreadline-dev libjson-c-dev libldap2-dev rename libsnmp-dev

OpenSSL交叉编译

wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz
tar -xvzf openssl-1.1.1i.tar.gz
cd openssl-1.1.1i
CROSS_COMPILE="x86_64-w64-mingw32-"  ./Configure mingw64 no-asm -shared --prefix=/opt/toolchain/openssl/install-x86_64
make
make install

下载N2N源代码

cd ~
git clone https://github.com/ntop/n2n
cd n2n
git checkout 2.8-stable

N2N交叉编译准备

cd ~/n2n
vim toolChain.cmake

n2n的目录下新建toolChain.cmake文件,并输入下面的配置内容

SET(CMAKE_SYSTEM_NAME Windows)
SET(CMAKE_CROSSCOMPILING TRUE)
SET(CMAKE_CROSSCOMPILER "x86_64-w64-mingw32-")
SET(CMAKE_C_COMPILER "${CMAKE_CROSSCOMPILER}gcc")
SET(CMAKE_CXX_COMPILER "${CMAKE_CROSSCOMPILER}g++")
SET(CMAKE_FIND_ROOT_PATH /opt/toolchain/openssl/install-x86_64)
SET(CMAKE_VERBOSE_MAKEFILE on)

N2N交叉编译

使用CMaken2n进行交叉编译

mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=../toolChain.cmake ..
make

安装TapWindows 9.24.2

官方下载 For Win7
官方下载 For Win10
本站下载 For Win7
本站下载 For Win10

可选,同一机器如何启动多个edge节点

  • 访问Windows机器的Tap-Windows安装目录,默认为C:\Program Files\TAP-Windows\bin,该目录下面有个addtap.bat文件,反复执行这个addtap.bat文件,即可在Windowsv中添加多个虚拟网卡。在网络和共享中心里面的更改适配器设置里面可以看到多个虚拟网卡。
  • 如果虚拟网卡太多了,也可以删除,进入设备管理器 ,删除不需要的虚拟网卡即可。