mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 16:00:25 +08:00 
			
		
		
		
	实现网络数据包相关统计(商业版本)
This commit is contained in:
		@@ -6,6 +6,7 @@ function build() {
 | 
			
		||||
	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"
 | 
			
		||||
@@ -70,6 +71,8 @@ function build() {
 | 
			
		||||
 | 
			
		||||
	CC_PATH=""
 | 
			
		||||
	CXX_PATH=""
 | 
			
		||||
	CGO_LDFLAGS=""
 | 
			
		||||
	CGO_CFLAGS=""
 | 
			
		||||
	BUILD_TAG=$TAG
 | 
			
		||||
	if [[ `uname -a` == *"Darwin"* && "${OS}" == "linux" ]]; then
 | 
			
		||||
		if [ "${ARCH}" == "amd64" ]; then
 | 
			
		||||
@@ -79,7 +82,7 @@ function build() {
 | 
			
		||||
				CC_PATH="x86_64-unknown-linux-gnu-gcc"
 | 
			
		||||
				CXX_PATH="x86_64-unknown-linux-gnu-g++"
 | 
			
		||||
				if [ "$TAG" = "plus" ]; then
 | 
			
		||||
					BUILD_TAG="plus,script"
 | 
			
		||||
					BUILD_TAG="plus,script,packet"
 | 
			
		||||
				fi
 | 
			
		||||
			else
 | 
			
		||||
				CC_PATH="x86_64-linux-musl-gcc"
 | 
			
		||||
@@ -97,7 +100,7 @@ function build() {
 | 
			
		||||
				CC_PATH="aarch64-unknown-linux-gnu-gcc"
 | 
			
		||||
				CXX_PATH="aarch64-unknown-linux-gnu-g++"
 | 
			
		||||
				if [ "$TAG" = "plus" ]; then
 | 
			
		||||
					BUILD_TAG="plus,script"
 | 
			
		||||
					BUILD_TAG="plus,script,packet"
 | 
			
		||||
				fi
 | 
			
		||||
			else
 | 
			
		||||
				CC_PATH="aarch64-linux-musl-gcc"
 | 
			
		||||
@@ -117,13 +120,26 @@ function build() {
 | 
			
		||||
			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"
 | 
			
		||||
		CGO_CFLAGS="-I${SRCDIR}/libs/libpcap/src/libpcap -I${SRCDIR}/libs/libpcap/src/libpcap/pcap"
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	if [ ! -z $CC_PATH ]; then
 | 
			
		||||
		env CC=$MUSL_DIR/$CC_PATH CXX=$MUSL_DIR/$CXX_PATH GOOS="${OS}" GOARCH="${ARCH}" CGO_ENABLED=1 go build -trimpath -tags $BUILD_TAG -o "$DIST"/bin/${NAME} -ldflags "-linkmode external -extldflags -static -s -w" "$ROOT"/../cmd/edge-node/main.go
 | 
			
		||||
		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"
 | 
			
		||||
			BUILD_TAG="plus,script,packet"
 | 
			
		||||
		fi
 | 
			
		||||
		env GOOS="${OS}" GOARCH="${ARCH}" CGO_ENABLED=1 go build -trimpath -tags $BUILD_TAG -o "$DIST"/bin/${NAME} -ldflags="-s -w" "$ROOT"/../cmd/edge-node/main.go
 | 
			
		||||
 | 
			
		||||
		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
 | 
			
		||||
 
 | 
			
		||||
@@ -146,12 +146,12 @@ func (this *Node) Start() {
 | 
			
		||||
	remotelogs.Println("NODE", "init config ...")
 | 
			
		||||
	err = this.syncConfig(0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		_, err := nodeconfigs.SharedNodeConfig()
 | 
			
		||||
		_, err = nodeconfigs.SharedNodeConfig()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			// 无本地数据时,会尝试多次读取
 | 
			
		||||
			tryTimes := 0
 | 
			
		||||
			for {
 | 
			
		||||
				err := this.syncConfig(0)
 | 
			
		||||
				err = this.syncConfig(0)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					tryTimes++
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -97,6 +97,8 @@ func (this *Node) execTask(rpcClient *rpc.RPCClient, task *pb.NodeTask) error {
 | 
			
		||||
		err = this.notifyPlusChange()
 | 
			
		||||
	case "toaChanged":
 | 
			
		||||
		err = this.execTOAChangedTask()
 | 
			
		||||
	case "networkSecurityPolicyChanged":
 | 
			
		||||
		err = this.execNetworkSecurityPolicyChangedTask(rpcClient)
 | 
			
		||||
	default:
 | 
			
		||||
		// 特殊任务
 | 
			
		||||
		if strings.HasPrefix(task.Type, "ipListDeleted") { // 删除IP名单
 | 
			
		||||
 
 | 
			
		||||
@@ -29,3 +29,8 @@ func (this *Node) execHTTPPagesPolicyChangedTask(rpcClient *rpc.RPCClient) error
 | 
			
		||||
	// stub
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *Node) execNetworkSecurityPolicyChangedTask(rpcClient *rpc.RPCClient) error {
 | 
			
		||||
	// stub
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user