Initial commit (code only without large binaries)

This commit is contained in:
robin
2026-02-15 18:58:44 +08:00
commit 35df75498f
9442 changed files with 1495866 additions and 0 deletions

3
EdgeNode/build/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
bin/*
caches
upload.sh

View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
./build.sh linux amd64 plus
#./build.sh linux 386 plus
#./build.sh linux arm64 plus
#./build.sh linux mips64 plus
#./build.sh linux mips64le plus
#./build.sh darwin amd64 plus
#./build.sh darwin arm64 plus

View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
./build.sh linux amd64
#./build.sh linux 386
#./build.sh linux arm64
#./build.sh linux mips64
#./build.sh linux mips64le
#./build.sh darwin amd64
#./build.sh darwin arm64

260
EdgeNode/build/build.sh Normal file
View File

@@ -0,0 +1,260 @@
#!/usr/bin/env bash
function build() {
ROOT=$(dirname $0)
NAME="edge-node"
VERSION=$(lookup-version "$ROOT"/../internal/const/const.go)
DIST=$ROOT/"../dist/${NAME}"
MUSL_DIR="/usr/local/opt/musl-cross/bin"
SRCDIR=$(realpath "$ROOT/..")
# for macOS users: precompiled gcc can be downloaded from https://github.com/messense/homebrew-macos-cross-toolchains
GCC_X86_64_DIR="/usr/local/gcc/x86_64-unknown-linux-gnu/bin"
GCC_ARM64_DIR="/usr/local/gcc/aarch64-unknown-linux-gnu/bin"
OS=${1}
ARCH=${2}
TAG=${3}
if [ -z "$OS" ]; then
echo "usage: build.sh OS ARCH"
exit
fi
if [ -z "$ARCH" ]; then
echo "usage: build.sh OS ARCH"
exit
fi
if [ -z "$TAG" ]; then
TAG="community"
fi
echo "checking ..."
ZIP_PATH=$(which zip)
if [ -z "$ZIP_PATH" ]; then
echo "we need 'zip' command to compress files"
exit
fi
echo "building v${VERSION}/${OS}/${ARCH}/${TAG} ..."
# 生成 zip 文件名时不包含 plus 标记
if [ "${TAG}" = "plus" ]; then
ZIP="${NAME}-${OS}-${ARCH}-v${VERSION}.zip"
else
ZIP="${NAME}-${OS}-${ARCH}-${TAG}-v${VERSION}.zip"
fi
echo "copying ..."
if [ ! -d "$DIST" ]; then
mkdir "$DIST"
mkdir "$DIST"/bin
mkdir "$DIST"/configs
mkdir "$DIST"/logs
mkdir "$DIST"/data
if [ "$TAG" = "plus" ]; then
mkdir "$DIST"/scripts
mkdir "$DIST"/scripts/js
fi
fi
cp "$ROOT"/configs/api_node.template.yaml "$DIST"/configs
cp "$ROOT"/configs/cluster.template.yaml "$DIST"/configs
cp -R "$ROOT"/www "$DIST"/
cp -R "$ROOT"/pages "$DIST"/
copy_fluent_bit_assets "$ROOT" "$DIST" "$OS" "$ARCH" || exit 1
# we support TOA on linux only
if [ "$OS" == "linux" ] && [ -f "${ROOT}/edge-toa/edge-toa-${ARCH}" ]
then
if [ ! -d "$DIST/edge-toa" ]
then
mkdir "$DIST/edge-toa"
fi
cp "${ROOT}/edge-toa/edge-toa-${ARCH}" "$DIST/edge-toa/edge-toa"
fi
echo "building ..."
CC_PATH=""
CXX_PATH=""
CGO_LDFLAGS=""
CGO_CFLAGS=""
BUILD_TAG=$TAG
if [[ `uname -a` == *"Darwin"* && "${OS}" == "linux" ]]; then
if [ "${ARCH}" == "amd64" ]; then
# build with script support
if [ -d $GCC_X86_64_DIR ]; then
MUSL_DIR=$GCC_X86_64_DIR
CC_PATH="x86_64-unknown-linux-gnu-gcc"
CXX_PATH="x86_64-unknown-linux-gnu-g++"
if [ "$TAG" = "plus" ]; then
BUILD_TAG="plus,script,packet"
fi
else
CC_PATH="x86_64-linux-musl-gcc"
CXX_PATH="x86_64-linux-musl-g++"
fi
fi
if [ "${ARCH}" == "386" ]; then
CC_PATH="i486-linux-musl-gcc"
CXX_PATH="i486-linux-musl-g++"
fi
if [ "${ARCH}" == "arm64" ]; then
# build with script support
if [ -d $GCC_ARM64_DIR ]; then
MUSL_DIR=$GCC_ARM64_DIR
CC_PATH="aarch64-unknown-linux-gnu-gcc"
CXX_PATH="aarch64-unknown-linux-gnu-g++"
if [ "$TAG" = "plus" ]; then
BUILD_TAG="plus,script,packet"
fi
else
CC_PATH="aarch64-linux-musl-gcc"
CXX_PATH="aarch64-linux-musl-g++"
fi
fi
if [ "${ARCH}" == "arm" ]; then
CC_PATH="arm-linux-musleabi-gcc"
CXX_PATH="arm-linux-musleabi-g++"
fi
if [ "${ARCH}" == "mips64" ]; then
CC_PATH="mips64-linux-musl-gcc"
CXX_PATH="mips64-linux-musl-g++"
fi
if [ "${ARCH}" == "mips64le" ]; then
CC_PATH="mips64el-linux-musl-gcc"
CXX_PATH="mips64el-linux-musl-g++"
fi
fi
# libpcap
if [ "$OS" == "linux" ] && [[ "$ARCH" == "amd64" || "$ARCH" == "arm64" ]] && [ "$TAG" == "plus" ]; then
CGO_LDFLAGS="-L${SRCDIR}/libs/libpcap/${ARCH} -lpcap -L${SRCDIR}/libs/libbrotli/${ARCH} -lbrotlienc -lbrotlidec -lbrotlicommon"
CGO_CFLAGS="-I${SRCDIR}/libs/libpcap/src/libpcap -I${SRCDIR}/libs/libpcap/src/libpcap/pcap -I${SRCDIR}/libs/libbrotli/src/brotli/c/include -I${SRCDIR}/libs/libbrotli/src/brotli/c/include/brotli"
fi
if [ ! -z $CC_PATH ]; then
env CC=$MUSL_DIR/$CC_PATH \
CXX=$MUSL_DIR/$CXX_PATH GOOS="${OS}" \
GOARCH="${ARCH}" CGO_ENABLED=1 \
CGO_LDFLAGS="${CGO_LDFLAGS}" \
CGO_CFLAGS="${CGO_CFLAGS}" \
go build -trimpath -tags $BUILD_TAG -o "$DIST"/bin/${NAME} -ldflags "-linkmode external -extldflags -static -s -w" "$ROOT"/../cmd/edge-node/main.go
else
if [[ `uname` == *"Linux"* ]] && [ "$OS" == "linux" ] && [[ "$ARCH" == "amd64" || "$ARCH" == "arm64" ]] && [ "$TAG" == "plus" ]; then
BUILD_TAG="plus,script,packet"
fi
env GOOS="${OS}" GOARCH="${ARCH}" CGO_ENABLED=1 CGO_LDFLAGS="${CGO_LDFLAGS}" CGO_CFLAGS="${CGO_CFLAGS}" go build -trimpath -tags $BUILD_TAG -o "$DIST"/bin/${NAME} -ldflags="-s -w" "$ROOT"/../cmd/edge-node/main.go
fi
if [ ! -f "${DIST}/bin/${NAME}" ]; then
echo "build failed!"
exit
fi
# delete hidden files
find "$DIST" -name ".DS_Store" -delete
find "$DIST" -name ".gitignore" -delete
echo "zip files"
cd "${DIST}/../" || exit
if [ -f "${ZIP}" ]; then
rm -f "${ZIP}"
fi
zip -r -X -q "${ZIP}" ${NAME}/
rm -rf ${NAME}
cd - || exit
echo "OK"
}
function copy_fluent_bit_assets() {
ROOT=$1
DIST=$2
OS=$3
ARCH=$4
FLUENT_ROOT="$ROOT/../../deploy/fluent-bit"
FLUENT_DIST="$DIST/deploy/fluent-bit"
if [ ! -d "$FLUENT_ROOT" ]; then
echo "[error] fluent-bit source directory not found: $FLUENT_ROOT"
return 1
fi
verify_fluent_bit_package_matrix "$FLUENT_ROOT" "$ARCH" || return 1
rm -rf "$FLUENT_DIST"
mkdir -p "$FLUENT_DIST"
for file in fluent-bit.conf fluent-bit-dns.conf fluent-bit-https.conf fluent-bit-dns-https.conf fluent-bit-windows.conf fluent-bit-windows-https.conf parsers.conf clickhouse-upstream.conf clickhouse-upstream-windows.conf README.md; do
if [ -f "$FLUENT_ROOT/$file" ]; then
cp "$FLUENT_ROOT/$file" "$FLUENT_DIST/"
fi
done
if [ "$OS" = "linux" ]; then
PACKAGE_SRC="$FLUENT_ROOT/packages/linux-$ARCH"
PACKAGE_DST="$FLUENT_DIST/packages/linux-$ARCH"
if [ -d "$PACKAGE_SRC" ]; then
mkdir -p "$PACKAGE_DST"
cp -R "$PACKAGE_SRC/." "$PACKAGE_DST/"
else
echo "[error] fluent-bit package directory not found: $PACKAGE_SRC"
return 1
fi
fi
rm -f "$FLUENT_DIST/.gitignore"
rm -f "$FLUENT_DIST"/logs.db*
rm -rf "$FLUENT_DIST/storage"
return 0
}
function verify_fluent_bit_package_matrix() {
FLUENT_ROOT=$1
ARCH=$2
REQUIRED_FILES=()
if [ "$ARCH" = "amd64" ]; then
REQUIRED_FILES=(
"packages/linux-amd64/fluent-bit_4.2.2_amd64.deb"
"packages/linux-amd64/fluent-bit-4.2.2-1.x86_64.rpm"
)
elif [ "$ARCH" = "arm64" ]; then
REQUIRED_FILES=(
"packages/linux-arm64/fluent-bit_4.2.2_arm64.deb"
"packages/linux-arm64/fluent-bit-4.2.2-1.aarch64.rpm"
)
else
echo "[error] unsupported arch for fluent-bit package validation: $ARCH"
return 1
fi
MISSING=0
for FILE in "${REQUIRED_FILES[@]}"; do
if [ ! -f "$FLUENT_ROOT/$FILE" ]; then
echo "[error] fluent-bit matrix package missing: $FLUENT_ROOT/$FILE"
MISSING=1
fi
done
if [ "$MISSING" -ne 0 ]; then
return 1
fi
return 0
}
function lookup-version() {
FILE=$1
VERSION_DATA=$(cat "$FILE")
re="Version[ ]+=[ ]+\"([0-9.]+)\""
if [[ $VERSION_DATA =~ $re ]]; then
VERSION=${BASH_REMATCH[1]}
echo "$VERSION"
else
echo "could not match version"
exit
fi
}
build "$1" "$2" "$3"

6
EdgeNode/build/configs/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
node.json
api.yaml
api_node.yaml
cluster.yaml
api_cluster.yaml
*.cache

View File

@@ -0,0 +1,3 @@
* `api_node.template.yaml` - API相关配置模板
* `cluster.template.yaml` - 通过集群自动接入节点模板
* `cache.template.yaml` - 缓存优化配置模板TTL缓存和文件缓存优化参数

View File

@@ -0,0 +1,3 @@
rpc.endpoints: [ "" ]
nodeId: ""
secret: ""

View File

@@ -0,0 +1,70 @@
# GoEdge CDN 缓存优化配置文件模板
# 复制此文件为 cache.yaml 并根据实际情况修改配置
# TTL 缓存配置
ttl_cache:
# 分片配置
# pieces: 0 表示自动计算,> 0 表示手动指定分片数
# 自动计算规则:基础分片数 = CPU核心数 * 2根据系统内存调整
pieces: 0
min_pieces: 64 # 最小分片数
max_pieces: 1024 # 最大分片数
# GC 配置
gc:
base_interval: 2s # 基础 GC 间隔
min_interval: 1s # 最小 GC 间隔(过期率高时使用)
max_interval: 10s # 最大 GC 间隔(过期率低时使用)
adaptive: true # 是否启用自适应 GC根据过期率动态调整间隔
sample_size: 100 # 过期率采样大小(用于智能分片选择)
# 文件缓存配置
file_cache:
# SSD 检测配置
auto_detect_ssd: true # 是否自动检测 SSD通过 /sys/block/*/queue/rotational 或 lsblk
ssd_paths: [] # 手动指定 SSD 路径(可选,如:["/mnt/ssd1", "/mnt/ssd2"]
# 如果 auto_detect_ssd 为 false将使用此列表
# SSD 优化策略
# 热点数据将优先存储在 SSD 上
ssd:
hot_item_threshold: 100 # 访问次数超过此值视为热点数据
write_buffer_size: 128KB # 写入缓冲区大小SSD 随机写性能好,使用更大缓冲区)
read_ahead_size: 256KB # 预读大小SSD 使用更激进的预读策略)
sync_interval: 10s # 同步间隔SSD 不需要频繁同步,减少 fsync 频率)
open_file_cache_max: 10000 # 文件句柄缓存最大值SSD 可以缓存更多文件句柄)
# HDD 配置
# 传统机械硬盘的优化配置
hdd:
write_buffer_size: 64KB # 写入缓冲区大小
read_ahead_size: 128KB # 预读大小
sync_interval: 1s # 同步间隔HDD 需要更频繁的同步)
open_file_cache_max: 5000 # 文件句柄缓存最大值
# 内存缓存配置
# 内存缓存作为文件缓存的一级缓存,用于提升小文件访问性能
memory:
# 内存缓存容量(系统内存的百分比)
# 如果未设置,将根据系统内存自动计算:
# - 系统内存 < 32GB: 10%
# - 系统内存 >= 32GB: 15%
# - 系统内存 >= 64GB: 20%
# 限制范围:最小 512MB最大 32GB
capacity_percent: 15 # 默认 15%,可配置 10-30%
# 小文件阈值
small_file_threshold: 1MB # 1MB 以下视为小文件(强制使用内存缓存)
medium_file_threshold: 10MB # 10MB 以下视为中等文件(根据内存使用率决定)
# 小文件内存缓存策略
small_file_memory_cache: true # 小文件强制使用内存缓存(提升访问速度)
# 淘汰策略
eviction_policy: "lfu_lru" # 淘汰策略:
# - lfu: 最少使用频率Least Frequently Used
# - lru: 最近最少使用Least Recently Used
# - lfu_lru: 混合策略(保留热点和最近访问的数据)
preserve_hot_items: true # 保留热点数据(访问频率高的数据)
preserve_recent_items: true # 保留最近访问的数据(最近 1 小时内访问的数据)

View File

@@ -0,0 +1,58 @@
# GoEdge CDN 缓存优化配置文件
# 此文件用于配置 TTL 缓存和文件缓存的优化参数
# TTL 缓存配置
ttl_cache:
# 分片配置
# pieces: 0 表示自动计算,> 0 表示手动指定分片数
pieces: 0
min_pieces: 64 # 最小分片数
max_pieces: 1024 # 最大分片数
# GC 配置
gc:
base_interval: 2s # 基础 GC 间隔
min_interval: 1s # 最小 GC 间隔(过期率高时使用)
max_interval: 10s # 最大 GC 间隔(过期率低时使用)
adaptive: true # 是否启用自适应 GC
sample_size: 100 # 过期率采样大小
# 文件缓存配置
file_cache:
# SSD 检测配置
auto_detect_ssd: true # 是否自动检测 SSD
ssd_paths: [] # 手动指定 SSD 路径(可选,如:["/mnt/ssd1", "/mnt/ssd2"]
# SSD 优化策略
ssd:
hot_item_threshold: 100 # 访问次数超过此值视为热点数据
write_buffer_size: 128KB # 写入缓冲区大小SSD 随机写性能好)
read_ahead_size: 256KB # 预读大小
sync_interval: 10s # 同步间隔SSD 不需要频繁同步)
open_file_cache_max: 10000 # 文件句柄缓存最大值
# HDD 配置
hdd:
write_buffer_size: 64KB # 写入缓冲区大小
read_ahead_size: 128KB # 预读大小
sync_interval: 1s # 同步间隔
open_file_cache_max: 5000 # 文件句柄缓存最大值
# 内存缓存配置
memory:
# 内存缓存容量(系统内存的百分比)
# 如果未设置将根据系统内存自动计算10-20%
capacity_percent: 15 # 默认 15%,可配置 10-30%
# 小文件阈值
small_file_threshold: 1MB # 1MB 以下视为小文件
medium_file_threshold: 10MB # 10MB 以下视为中等文件
# 小文件内存缓存策略
small_file_memory_cache: true # 小文件强制使用内存缓存
# 淘汰策略
eviction_policy: "lfu_lru" # 淘汰策略lfu, lru, lfu_lru
preserve_hot_items: true # 保留热点数据
preserve_recent_items: true # 保留最近访问的数据

View File

@@ -0,0 +1,4 @@
rpc:
endpoints: [ "" ]
clusterId: ""
secret: ""

View File

@@ -0,0 +1 @@
{"speed":1,"speedMB":1400,"countTests":3}

View File

@@ -0,0 +1 @@
{"22":{"hour":22,"avg":3,"values":[2.95703125]}}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1 @@
MANIFEST-000010

View File

@@ -0,0 +1,48 @@
[Version]
pebble_version=0.1
[Options]
bytes_per_sync=1048576
cache_size=8388608
cleaner=delete
compaction_debt_concurrency=1073741824
comparer=leveldb.BytewiseComparator
disable_wal=false
flush_delay_delete_range=0s
flush_delay_range_key=0s
flush_split_bytes=4194304
format_major_version=1
l0_compaction_concurrency=10
l0_compaction_file_threshold=500
l0_compaction_threshold=4
l0_stop_writes_threshold=12
lbase_max_bytes=67108864
max_concurrent_compactions=1
max_manifest_file_size=134217728
max_open_files=1000
mem_table_size=67108864
mem_table_stop_writes_threshold=2
min_deletion_rate=0
merger=pebble.concatenate
read_compaction_rate=16000
read_sampling_multiplier=16
strict_wal_tail=true
table_cache_shards=16
table_property_collectors=[]
validate_on_ingest=false
wal_dir=
wal_bytes_per_sync=0
max_writer_concurrency=0
force_writer_parallelism=false
secondary_cache_size_bytes=0
create_on_shared=0
[Level "0"]
block_restart_interval=16
block_size=4096
block_size_threshold=90
compression=Snappy
filter_policy=none
filter_type=table
index_block_size=4096
target_file_size=2097152

View File

@@ -0,0 +1 @@
[]

1
EdgeNode/build/logs/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.log

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Error</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<h3>403 Forbidden</h3>
<p>Sorry, your access to the page has been denied. Please try again later.</p>
<footer>Powered by GoEdge.</footer>
</body>
</html>

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Error</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<h3>404 Not Found</h3>
<p>Sorry, the page you are looking for is not found. Please try again later.</p>
<footer>Powered by GoEdge.</footer>
</body>
</html>

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Error</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<h3>An error occurred.</h3>
<p>Sorry, the page you are looking for is currently unavailable. Please try again later.</p>
<footer>Powered by GoEdge.</footer>
</body>
</html>

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Shutdown Notice</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<h3>The website is shutdown.</h3>
<p>Sorry, the page you are looking for is currently unavailable. Please try again later.</p>
<footer>Powered by GoEdge.</footer>
</body>
</html>

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>升级中</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<h3>网站升级中</h3>
<p>为了给您提供更好的服务,我们正在升级网站,请稍后重新访问。</p>
<footer>Powered by GoEdge.</footer>
</body>
</html>

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>临时关闭提醒</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<h3>网站暂时关闭</h3>
<p>网站已被暂时关闭,请耐心等待我们的重新开通通知。</p>
<footer>Powered by GoEdge.</footer>
</body>
</html>

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
sudo go run -tags="plus script packet" ../cmd/edge-node/main.go

14
EdgeNode/build/test.sh Normal file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash
TAG=${1}
if [ -z "$TAG" ]; then
TAG="community"
fi
# stop node
go run -tags=${TAG} ../cmd/edge-node/main.go stop
# reference: https://pkg.go.dev/cmd/go/internal/test
go clean -testcache
go test -timeout 60s -tags="${TAG}" -cover ../...

0
EdgeNode/build/www/.gitignore vendored Normal file
View File

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome</title>
</head>
<body>
I am index.
</body>
</html>