mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2026-09-22 15:29:03 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2c745c285 | ||
|
|
e5ecb28841 | ||
|
|
f176e2539e | ||
|
|
d6bfb8889a | ||
|
|
24fb1ced3c | ||
|
|
82b8a4f584 | ||
|
|
979bca57d5 | ||
|
|
93fd93da5c | ||
|
|
508527f7cd | ||
|
|
34cc26176c | ||
|
|
f9c6ee0181 | ||
|
|
f5cc7746b6 | ||
|
|
41a4690372 | ||
|
|
9d57ccd7b1 | ||
|
|
ad60d708e1 | ||
|
|
2f3ea8882b | ||
|
|
e32fecd16d | ||
|
|
dca77cb0d2 | ||
|
|
9ec6c2901c | ||
|
|
e915d10953 | ||
|
|
ddb2759a52 | ||
|
|
28cf1423c9 | ||
|
|
9de2b90528 | ||
|
|
8b44ac984c | ||
|
|
5533b82450 |
No files matched your search
+74
-75
@@ -1,21 +1,20 @@
|
||||
on: [ push ]
|
||||
|
||||
jobs:
|
||||
build_ubuntu:
|
||||
runs-on: ubuntu-latest
|
||||
build_ubuntu_x64:
|
||||
runs-on: gha-runner-x64
|
||||
steps:
|
||||
- name: gitconfig
|
||||
run: |
|
||||
git config --global core.autocrlf input
|
||||
# git config --global core.eol lf
|
||||
# - name: gitconfig
|
||||
# run: |
|
||||
# git config --global core.autocrlf input
|
||||
# # git config --global core.eol lf
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: stable
|
||||
target: x86_64-unknown-linux-gnu
|
||||
override: true
|
||||
target: x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu
|
||||
components: rustfmt, clippy
|
||||
|
||||
- name: Set up cargo cache
|
||||
@@ -34,72 +33,72 @@ jobs:
|
||||
make selftest
|
||||
./zerotier-selftest
|
||||
|
||||
build_macos:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- name: gitconfig
|
||||
run: |
|
||||
git config --global core.autocrlf input
|
||||
# git config --global core.eol lf
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Install Rust aarch64
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
target: aarch64-apple-darwin
|
||||
override: true
|
||||
components: rustfmt, clippy
|
||||
- name: Install Rust x86_64
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
target: x86_64-apple-darwin
|
||||
override: true
|
||||
components: rustfmt, clippy
|
||||
- name: Set up cargo cache
|
||||
uses: Swatinem/rust-cache@v2
|
||||
continue-on-error: false
|
||||
with:
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('rustybits//Cargo.lock') }}
|
||||
shared-key: ${{ runner.os }}-cargo-
|
||||
workspaces: |
|
||||
rustybits/
|
||||
# build_macos:
|
||||
# runs-on: macos-latest
|
||||
# steps:
|
||||
# - name: gitconfig
|
||||
# run: |
|
||||
# git config --global core.autocrlf input
|
||||
# # git config --global core.eol lf
|
||||
# - name: checkout
|
||||
# uses: actions/checkout@v3
|
||||
# - name: Install Rust aarch64
|
||||
# uses: actions-rs/toolchain@v1
|
||||
# with:
|
||||
# toolchain: stable
|
||||
# target: aarch64-apple-darwin
|
||||
# override: true
|
||||
# components: rustfmt, clippy
|
||||
# - name: Install Rust x86_64
|
||||
# uses: actions-rs/toolchain@v1
|
||||
# with:
|
||||
# toolchain: stable
|
||||
# target: x86_64-apple-darwin
|
||||
# override: true
|
||||
# components: rustfmt, clippy
|
||||
# - name: Set up cargo cache
|
||||
# uses: Swatinem/rust-cache@v2
|
||||
# continue-on-error: false
|
||||
# with:
|
||||
# key: ${{ runner.os }}-cargo-${{ hashFiles('rustybits//Cargo.lock') }}
|
||||
# shared-key: ${{ runner.os }}-cargo-
|
||||
# workspaces: |
|
||||
# rustybits/
|
||||
|
||||
- name: make
|
||||
run: make
|
||||
- name: selftest
|
||||
run: |
|
||||
make selftest
|
||||
./zerotier-selftest
|
||||
# - name: make
|
||||
# run: make
|
||||
# - name: selftest
|
||||
# run: |
|
||||
# make selftest
|
||||
# ./zerotier-selftest
|
||||
|
||||
build_windows:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: gitconfig
|
||||
run: |
|
||||
git config --global core.autocrlf true
|
||||
# git config --global core.eol lf
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
target: aarch64-apple-darwin
|
||||
override: true
|
||||
components: rustfmt, clippy
|
||||
- name: Set up cargo cache
|
||||
uses: Swatinem/rust-cache@v2
|
||||
continue-on-error: false
|
||||
with:
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('rustybits//Cargo.lock') }}
|
||||
shared-key: ${{ runner.os }}-cargo-
|
||||
workspaces: |
|
||||
rustybits/
|
||||
# build_windows:
|
||||
# runs-on: windows-latest
|
||||
# steps:
|
||||
# - name: gitconfig
|
||||
# run: |
|
||||
# git config --global core.autocrlf true
|
||||
# # git config --global core.eol lf
|
||||
# - name: checkout
|
||||
# uses: actions/checkout@v3
|
||||
# - name: Install Rust
|
||||
# uses: actions-rs/toolchain@v1
|
||||
# with:
|
||||
# toolchain: stable
|
||||
# target: aarch64-apple-darwin
|
||||
# override: true
|
||||
# components: rustfmt, clippy
|
||||
# - name: Set up cargo cache
|
||||
# uses: Swatinem/rust-cache@v2
|
||||
# continue-on-error: false
|
||||
# with:
|
||||
# key: ${{ runner.os }}-cargo-${{ hashFiles('rustybits//Cargo.lock') }}
|
||||
# shared-key: ${{ runner.os }}-cargo-
|
||||
# workspaces: |
|
||||
# rustybits/
|
||||
|
||||
- name: setup msbuild
|
||||
uses: microsoft/setup-msbuild@v1.1.3
|
||||
- name: msbuild
|
||||
run: |
|
||||
msbuild windows\ZeroTierOne.sln /m /p:Configuration=Release /property:Platform=x64 /t:ZeroTierOne
|
||||
# - name: setup msbuild
|
||||
# uses: microsoft/setup-msbuild@v1.1.3
|
||||
# - name: msbuild
|
||||
# run: |
|
||||
# msbuild windows\ZeroTierOne.sln /m /p:Configuration=Release /property:Platform=x64 /t:ZeroTierOne
|
||||
@@ -382,6 +382,24 @@ void DB::_networkChanged(nlohmann::json &old,nlohmann::json &networkConfig,bool
|
||||
const std::string ids = old["id"];
|
||||
const uint64_t networkId = Utils::hexStrToU64(ids.c_str());
|
||||
if (networkId) {
|
||||
try {
|
||||
// deauth all members on the network
|
||||
nlohmann::json network;
|
||||
std::vector<nlohmann::json> members;
|
||||
this->get(networkId, network, members);
|
||||
for(auto i=members.begin();i!=members.end();++i) {
|
||||
const std::string nodeID = (*i)["id"];
|
||||
const uint64_t memberId = Utils::hexStrToU64(nodeID.c_str());
|
||||
std::unique_lock<std::shared_mutex> ll(_changeListeners_l);
|
||||
for(auto j=_changeListeners.begin();j!=_changeListeners.end();++j) {
|
||||
(*j)->onNetworkMemberDeauthorize(this,networkId,memberId);
|
||||
}
|
||||
}
|
||||
} catch (std::exception &e) {
|
||||
std::cerr << "Error deauthorizing members on network delete: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
// delete the network
|
||||
std::unique_lock<std::shared_mutex> l(_networks_l);
|
||||
_networks.erase(networkId);
|
||||
}
|
||||
|
||||
@@ -780,11 +780,25 @@ void PostgreSQL::initializeNetworks()
|
||||
fprintf(stderr, "adding networks to redis...\n");
|
||||
if (_rc->clusterMode) {
|
||||
auto tx = _cluster->transaction(_myAddressStr, true, false);
|
||||
tx.sadd(setKey, networkSet.begin(), networkSet.end());
|
||||
uint64_t count = 0;
|
||||
for (std::string nwid : networkSet) {
|
||||
tx.sadd(setKey, nwid);
|
||||
if (++count % 30000 == 0) {
|
||||
tx.exec();
|
||||
tx = _cluster->transaction(_myAddressStr, true, false);
|
||||
}
|
||||
}
|
||||
tx.exec();
|
||||
} else {
|
||||
auto tx = _redis->transaction(true, false);
|
||||
tx.sadd(setKey, networkSet.begin(), networkSet.end());
|
||||
uint64_t count = 0;
|
||||
for (std::string nwid : networkSet) {
|
||||
tx.sadd(setKey, nwid);
|
||||
if (++count % 30000 == 0) {
|
||||
tx.exec();
|
||||
tx = _redis->transaction(true, false);
|
||||
}
|
||||
}
|
||||
tx.exec();
|
||||
}
|
||||
fprintf(stderr, "done.\n");
|
||||
@@ -1005,14 +1019,24 @@ void PostgreSQL::initializeMembers()
|
||||
fprintf(stderr, "Load member data into redis...\n");
|
||||
if (_rc->clusterMode) {
|
||||
auto tx = _cluster->transaction(_myAddressStr, true, false);
|
||||
uint64_t count = 0;
|
||||
for (auto it : networkMembers) {
|
||||
tx.sadd(it.first, it.second);
|
||||
if (++count % 30000 == 0) {
|
||||
tx.exec();
|
||||
tx = _cluster->transaction(_myAddressStr, true, false);
|
||||
}
|
||||
}
|
||||
tx.exec();
|
||||
} else {
|
||||
auto tx = _redis->transaction(true, false);
|
||||
uint64_t count = 0;
|
||||
for (auto it : networkMembers) {
|
||||
tx.sadd(it.first, it.second);
|
||||
if (++count % 30000 == 0) {
|
||||
tx.exec();
|
||||
tx = _redis->transaction(true, false);
|
||||
}
|
||||
}
|
||||
tx.exec();
|
||||
}
|
||||
@@ -1180,7 +1204,7 @@ void PostgreSQL::_membersWatcher_Redis() {
|
||||
_memberChanged(oldConfig,newConfig,(this->_ready >= 2));
|
||||
}
|
||||
} catch (...) {
|
||||
fprintf(stderr, "json parse error in networkWatcher_Redis\n");
|
||||
fprintf(stderr, "json parse error in _membersWatcher_Redis: %s\n", a.second.c_str());
|
||||
}
|
||||
}
|
||||
if (_rc->clusterMode) {
|
||||
@@ -1269,8 +1293,8 @@ void PostgreSQL::_networksWatcher_Redis() {
|
||||
if (oldConfig.is_object()||newConfig.is_object()) {
|
||||
_networkChanged(oldConfig,newConfig,(this->_ready >= 2));
|
||||
}
|
||||
} catch (...) {
|
||||
fprintf(stderr, "json parse error in networkWatcher_Redis\n");
|
||||
} catch (std::exception &e) {
|
||||
fprintf(stderr, "json parse error in networkWatcher_Redis: what: %s json: %s\n", e.what(), a.second.c_str());
|
||||
}
|
||||
}
|
||||
if (_rc->clusterMode) {
|
||||
|
||||
@@ -111,6 +111,44 @@ namespace {
|
||||
bool finishInitializing();
|
||||
};
|
||||
|
||||
//
|
||||
// RAII construct for calling AttachCurrentThread and DetachCurrent automatically
|
||||
//
|
||||
struct ScopedJNIThreadAttacher {
|
||||
|
||||
JavaVM *jvm;
|
||||
JNIEnv **env_p;
|
||||
jint getEnvRet;
|
||||
|
||||
ScopedJNIThreadAttacher(JavaVM *jvmIn, JNIEnv **env_pIn, jint getEnvRetIn) :
|
||||
jvm(jvmIn),
|
||||
env_p(env_pIn),
|
||||
getEnvRet(getEnvRetIn) {
|
||||
|
||||
if (getEnvRet != JNI_EDETACHED) {
|
||||
return;
|
||||
}
|
||||
|
||||
jint attachCurrentThreadRet;
|
||||
if ((attachCurrentThreadRet = jvm->AttachCurrentThread(env_p, NULL)) != JNI_OK) {
|
||||
LOGE("Error calling AttachCurrentThread: %d", attachCurrentThreadRet);
|
||||
assert(false && "Error calling AttachCurrentThread");
|
||||
}
|
||||
}
|
||||
|
||||
~ScopedJNIThreadAttacher() {
|
||||
|
||||
if (getEnvRet != JNI_EDETACHED) {
|
||||
return;
|
||||
}
|
||||
|
||||
jint detachCurrentThreadRet;
|
||||
if ((detachCurrentThreadRet = jvm->DetachCurrentThread()) != JNI_OK) {
|
||||
LOGE("Error calling DetachCurrentThread: %d", detachCurrentThreadRet);
|
||||
assert(false && "Error calling DetachCurrentThread");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* This must return 0 on success. It can return any OS-dependent error code
|
||||
@@ -194,7 +232,25 @@ namespace {
|
||||
assert(ref);
|
||||
assert(ref->node == node);
|
||||
JNIEnv *env;
|
||||
GETENV(env, ref->jvm);
|
||||
|
||||
jint getEnvRet;
|
||||
assert(ref->jvm);
|
||||
getEnvRet = ref->jvm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
|
||||
|
||||
if (!(getEnvRet == JNI_OK || getEnvRet == JNI_EDETACHED)) {
|
||||
LOGE("Error calling GetEnv: %d", getEnvRet);
|
||||
assert(false && "Error calling GetEnv");
|
||||
}
|
||||
|
||||
//
|
||||
// Thread might actually be detached.
|
||||
//
|
||||
// e.g:
|
||||
// https://github.com/zerotier/ZeroTierOne/blob/91e7ce87f09ac1cfdeaf6ff22c3cedcd93574c86/node/Switch.cpp#L519
|
||||
//
|
||||
// Make sure to attach if needed
|
||||
//
|
||||
ScopedJNIThreadAttacher attacher{ref->jvm, &env, getEnvRet};
|
||||
|
||||
if (env->ExceptionCheck()) {
|
||||
LOGE("Unhandled pending exception");
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ else
|
||||
override CFLAGS+=-Wall -Wno-deprecated -pthread $(INCLUDES) -DNDEBUG $(DEFS)
|
||||
CXXFLAGS?=-O3 -fstack-protector
|
||||
override CXXFLAGS+=-Wall -Wno-deprecated -std=c++17 -pthread $(INCLUDES) -DNDEBUG $(DEFS)
|
||||
LDFLAGS=-pie -Wl,-z,relro,-z,now
|
||||
LDFLAGS?=-pie -Wl,-z,relro,-z,now
|
||||
ZT_CARGO_FLAGS=--release
|
||||
endif
|
||||
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
CC=clang
|
||||
CXX=clang++
|
||||
TOPDIR=$(shell PWD)
|
||||
TOPDIR=$(shell pwd)
|
||||
|
||||
INCLUDES=-I$(shell PWD)/rustybits/target -isystem $(TOPDIR)/ext -I$(TOPDIR)/ext/prometheus-cpp-lite-1.0/core/include -I$(TOPDIR)/ext-prometheus-cpp-lite-1.0/3rdparty/http-client-lite/include -I$(TOPDIR)/ext/prometheus-cpp-lite-1.0/simpleapi/include
|
||||
INCLUDES=-I$(shell pwd)/rustybits/target -isystem $(TOPDIR)/ext -I$(TOPDIR)/ext/prometheus-cpp-lite-1.0/core/include -I$(TOPDIR)/ext-prometheus-cpp-lite-1.0/3rdparty/http-client-lite/include -I$(TOPDIR)/ext/prometheus-cpp-lite-1.0/simpleapi/include
|
||||
DEFS=
|
||||
LIBS=
|
||||
ARCH_FLAGS=-arch x86_64 -arch arm64
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
## Docker image for Synology's DSM7
|
||||
|
||||
Documentation: [docs.zerotier.com/devices/synology](https://docs.zerotier.com/devices/synology)
|
||||
|
||||
### Build & Push changes to DockerHub
|
||||
```shell
|
||||
./build.sh build
|
||||
```
|
||||
@@ -3,19 +3,17 @@
|
||||
ZTO_VER=$(git describe --tags $(git rev-list --tags --max-count=1))
|
||||
ZTO_COMMIT=$(git rev-parse HEAD)
|
||||
|
||||
build()
|
||||
{
|
||||
sudo docker build --load --rm -t zerotier-synology . --build-arg ZTO_COMMIT=${ZTO_COMMIT} --build-arg ZTO_VER=${ZTO_VER}
|
||||
LATEST_DOCKER_IMAGE_HASH=$(sudo docker images -q zerotier-synology)
|
||||
sudo docker tag ${LATEST_DOCKER_IMAGE_HASH} zerotier/zerotier-synology:${ZTO_VER}
|
||||
sudo docker tag ${LATEST_DOCKER_IMAGE_HASH} zerotier/zerotier-synology:latest
|
||||
}
|
||||
|
||||
push()
|
||||
{
|
||||
build() {
|
||||
sudo docker login --username=${DOCKERHUB_USERNAME}
|
||||
sudo docker push zerotier/zerotier-synology:${ZTO_VER}
|
||||
sudo docker push zerotier/zerotier-synology:latest
|
||||
|
||||
sudo docker buildx build \
|
||||
--push \
|
||||
--platform linux/arm/v7,linux/arm64/v8,linux/amd64 \
|
||||
--tag zerotier/zerotier-synology:${ZTO_VER} \
|
||||
--tag zerotier/zerotier-synology:latest \
|
||||
--build-arg ZTO_COMMIT=${ZTO_COMMIT} \
|
||||
--build-arg ZTO_VER=${ZTO_VER} \
|
||||
.
|
||||
}
|
||||
|
||||
"$@"
|
||||
Generated
+263
-280
File diff suppressed because it is too large.
Load diff
@@ -91,7 +91,7 @@
|
||||
<NMakeOutput>
|
||||
</NMakeOutput>
|
||||
<NMakeCleanCommandLine>cargo clean</NMakeCleanCommandLine>
|
||||
<NMakeReBuildCommandLine>cargo clean & cargo build --release --target=x86_64-pc-windows-msvc</NMakeReBuildCommandLine>
|
||||
<NMakeReBuildCommandLine>cargo clean & cargo build -p zeroidc --release --target=x86_64-pc-windows-msvc</NMakeReBuildCommandLine>
|
||||
<NMakePreprocessorDefinitions>NDEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
|
||||
|
||||
+4
-10
@@ -1,15 +1,9 @@
|
||||
CXX=$(shell which clang++ g++ c++ 2>/dev/null | head -n 1)
|
||||
|
||||
INCLUDES?=-isystem ../ext/prometheus-cpp-lite-1.0/core/include -isystem ../ext/prometheus-cpp-lite-1.0/simpleapi/include -isystem ../ext/
|
||||
INCLUDES?=-I../ext/prometheus-cpp-lite-1.0/core/include -I../ext/prometheus-cpp-lite-1.0/simpleapi/include
|
||||
|
||||
OBJS=Metrics.o \
|
||||
../node/Metrics.o \
|
||||
../osdep/OSUtils.o
|
||||
|
||||
CXXFLAGS=-O3 -fno-rtti $(INCLUDES) -std=c++17 -pthread -frtti
|
||||
|
||||
all: $(OBJS) tcp-proxy.o
|
||||
$(CXX) -O3 -fno-rtti $(INCLUDES) -std=c++17 -pthread -frtti -o tcp-proxy tcp-proxy.o $(OBJS)
|
||||
all:
|
||||
$(CXX) -O3 -fno-rtti $(INCLUDES) -std=c++11 -pthread -frtti -o tcp-proxy tcp-proxy.cpp ../node/Metrics.cpp
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) tcp-proxy.o tcp-proxy *.dSYM
|
||||
rm -f *.o tcp-proxy *.dSYM
|
||||
@@ -1,27 +0,0 @@
|
||||
#include <prometheus/simpleapi.h>
|
||||
|
||||
|
||||
namespace ZeroTier {
|
||||
namespace Metrics {
|
||||
// prometheus::simpleapi::gauge_metric_t tcp_connections
|
||||
// {"tcp_connections", "TCP connections"};
|
||||
|
||||
// prometheus::simpleapi::counter_metric_t udp_open_failed
|
||||
// {"udp_open_failed", "UDP open failed"};
|
||||
|
||||
// prometheus::simpleapi::counter_metric_t tcp_opened
|
||||
// {"tcp_opened", "TCP opened"};
|
||||
// prometheus::simpleapi::counter_metric_t tcp_closed
|
||||
// {"tcp_closed", "TCP closed"};
|
||||
|
||||
// prometheus::simpleapi::counter_metric_t tcp_bytes_in
|
||||
// {"tcp_byes_in", "TCP bytes in"};
|
||||
// prometheus::simpleapi::counter_metric_t tcp_bytes_out
|
||||
// {"tcp_byes_out", "TCP bytes out"};
|
||||
|
||||
// prometheus::simpleapi::counter_metric_t udp_bytes_in
|
||||
// {"udp_bytes_in", "UDP bytes in"};
|
||||
// prometheus::simpleapi::counter_metric_t udp_bytes_out
|
||||
// {"udp_bytes_out", "UDP bytes out"};
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
#ifndef _TCP_PROXY_METRICS_H_
|
||||
#define _TCP_PROXY_METRICS_H_
|
||||
|
||||
#include "../node/Metrics.hpp"
|
||||
|
||||
namespace ZeroTier {
|
||||
namespace Metrics {
|
||||
// extern prometheus::simpleapi::gauge_metric_t tcp_connections;
|
||||
|
||||
// extern prometheus::simpleapi::counter_metric_t udp_open_failed;
|
||||
|
||||
// extern prometheus::simpleapi::counter_metric_t tcp_opened;
|
||||
// extern prometheus::simpleapi::counter_metric_t tcp_closed;
|
||||
|
||||
// extern prometheus::simpleapi::counter_metric_t tcp_bytes_in;
|
||||
// extern prometheus::simpleapi::counter_metric_t tcp_bytes_out;
|
||||
|
||||
// extern prometheus::simpleapi::counter_metric_t udp_bytes_in;
|
||||
// extern prometheus::simpleapi::counter_metric_t udp_bytes_out;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _TCP_PROXY_METRICS_H_
|
||||
+3
-40
@@ -42,15 +42,12 @@
|
||||
#include <vector>
|
||||
|
||||
#include "../osdep/Phy.hpp"
|
||||
#include "../osdep/OSUtils.hpp"
|
||||
|
||||
#include "Metrics.hpp"
|
||||
#include "../node/Metrics.hpp"
|
||||
|
||||
#define ZT_TCP_PROXY_CONNECTION_TIMEOUT_SECONDS 300
|
||||
#define ZT_TCP_PROXY_TCP_PORT 443
|
||||
|
||||
#define HOMEDIR "/var/lib/zt-tcp-proxy"
|
||||
|
||||
using namespace ZeroTier;
|
||||
|
||||
/*
|
||||
@@ -130,8 +127,6 @@ struct TcpProxyService
|
||||
if (!*uptr)
|
||||
return;
|
||||
if ((from->sa_family == AF_INET)&&(len >= 16)&&(len < 2048)) {
|
||||
// Metrics::udp_bytes_in += len;
|
||||
|
||||
Client &c = *((Client *)*uptr);
|
||||
c.lastActivity = time((time_t *)0);
|
||||
|
||||
@@ -176,7 +171,6 @@ struct TcpProxyService
|
||||
Client &c = clients[sockN];
|
||||
PhySocket *udp = getUnusedUdp((void *)&c);
|
||||
if (!udp) {
|
||||
// Metrics::udp_open_failed++;
|
||||
phy->close(sockN);
|
||||
clients.erase(sockN);
|
||||
printf("** TCP rejected, no more UDP ports to assign\n");
|
||||
@@ -190,8 +184,6 @@ struct TcpProxyService
|
||||
c.newVersion = false;
|
||||
*uptrN = (void *)&c;
|
||||
printf("<< TCP from %s -> %.16llx\n",inet_ntoa(reinterpret_cast<const struct sockaddr_in *>(from)->sin_addr),(unsigned long long)&c);
|
||||
// Metrics::tcp_opened++;
|
||||
// Metrics::tcp_connections++;
|
||||
}
|
||||
|
||||
void phyOnTcpClose(PhySocket *sock,void **uptr)
|
||||
@@ -202,7 +194,6 @@ struct TcpProxyService
|
||||
phy->close(c.udp);
|
||||
clients.erase(sock);
|
||||
printf("** TCP %.16llx closed\n",(unsigned long long)*uptr);
|
||||
// Metrics::tcp_closed++;
|
||||
}
|
||||
|
||||
void phyOnTcpData(PhySocket *sock,void **uptr,void *data,unsigned long len)
|
||||
@@ -210,8 +201,6 @@ struct TcpProxyService
|
||||
Client &c = *((Client *)*uptr);
|
||||
c.lastActivity = time((time_t *)0);
|
||||
|
||||
// Metrics::tcp_bytes_in += len;
|
||||
|
||||
for(unsigned long i=0;i<len;++i) {
|
||||
if (c.tcpReadPtr >= sizeof(c.tcpReadBuf)) {
|
||||
phy->close(sock);
|
||||
@@ -257,7 +246,6 @@ struct TcpProxyService
|
||||
if ((ntohs(dest.sin_port) > 1024)&&(payloadLen >= 16)) {
|
||||
phy->udpSend(c.udp,(const struct sockaddr *)&dest,payload,payloadLen);
|
||||
printf(">> TCP %.16llx to %s:%d\n",(unsigned long long)*uptr,inet_ntoa(dest.sin_addr),(int)ntohs(dest.sin_port));
|
||||
// Metrics::udp_bytes_out += payloadLen;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,7 +261,6 @@ struct TcpProxyService
|
||||
if (c.tcpWritePtr) {
|
||||
long n = phy->streamSend(sock,c.tcpWriteBuf,c.tcpWritePtr);
|
||||
if (n > 0) {
|
||||
// Metrics::tcp_bytes_out += n;
|
||||
memmove(c.tcpWriteBuf,c.tcpWriteBuf + n,c.tcpWritePtr -= (unsigned long)n);
|
||||
if (!c.tcpWritePtr)
|
||||
phy->setNotifyWritable(sock,false);
|
||||
@@ -291,11 +278,8 @@ struct TcpProxyService
|
||||
toClose.push_back(c->second.udp);
|
||||
}
|
||||
}
|
||||
for(std::vector<PhySocket *>::iterator s(toClose.begin());s!=toClose.end();++s) {
|
||||
for(std::vector<PhySocket *>::iterator s(toClose.begin());s!=toClose.end();++s)
|
||||
phy->close(*s);
|
||||
// Metrics::tcp_closed++;
|
||||
// Metrics::tcp_connections--;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -305,37 +289,16 @@ int main(int argc,char **argv)
|
||||
signal(SIGHUP,SIG_IGN);
|
||||
srand(time((time_t *)0));
|
||||
|
||||
// if (!OSUtils::fileExists(HOMEDIR)) {
|
||||
// if (!OSUtils::mkdir(HOMEDIR)) {
|
||||
// fprintf(stderr,"%s: fatal error: unable to create %s\n",argv[0],HOMEDIR);
|
||||
// return 1;
|
||||
// }
|
||||
// }
|
||||
|
||||
// prometheus::simpleapi::saver.set_registry(prometheus::simpleapi::registry_ptr);
|
||||
// prometheus::simpleapi::saver.set_delay(std::chrono::seconds(5));
|
||||
// prometheus::simpleapi::saver.set_out_file(HOMEDIR "/metrics.json");
|
||||
|
||||
TcpProxyService svc;
|
||||
Phy<TcpProxyService *> phy(&svc,false,true);
|
||||
svc.phy = &phy;
|
||||
svc.udpPortCounter = 1023;
|
||||
|
||||
uint16_t listenPort = ZT_TCP_PROXY_TCP_PORT;
|
||||
if (argc > 1) {
|
||||
listenPort = (uint16_t)atoi(argv[1]);
|
||||
}
|
||||
|
||||
if (listenPort == 0) {
|
||||
fprintf(stderr,"%s: fatal error: invalid port number\n",argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
{
|
||||
struct sockaddr_in laddr;
|
||||
memset(&laddr,0,sizeof(laddr));
|
||||
laddr.sin_family = AF_INET;
|
||||
laddr.sin_port = htons(listenPort);
|
||||
laddr.sin_port = htons(ZT_TCP_PROXY_TCP_PORT);
|
||||
if (!phy.tcpListen((const struct sockaddr *)&laddr)) {
|
||||
fprintf(stderr,"%s: fatal error: unable to bind TCP port %d\n",argv[0],ZT_TCP_PROXY_TCP_PORT);
|
||||
return 1;
|
||||
|
||||
Reference in new issue
Block a user