diff --git a/.github/workflows/deploy.sh b/.github/workflows/deploy.sh index dc5f43d..e3579a5 100644 --- a/.github/workflows/deploy.sh +++ b/.github/workflows/deploy.sh @@ -3,7 +3,7 @@ echo "$SSH_KEY" > key.pem chmod 600 key.pem -scp -o StrictHostKeyChecking=no -i key.pem cmd/node/unchain cmd/node/unchain.service $SSH_USER@$SSH_HOST:~ +scp -o StrictHostKeyChecking=no -i key.pem unchain unchain.service $SSH_USER@$SSH_HOST:~ ssh -o StrictHostKeyChecking=no -i key.pem $SSH_USER@$SSH_HOST << EOF cd ~ && pwd sudo rm -rf /app && sudo mkdir /app diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0f07ba0..1f756db 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -41,7 +41,7 @@ jobs: GIT_REPO: ${{ github.repository }} run: | echo "Building Go application with gitHash=${{ env.gitHash }} and buildTime=${{ env.buildTime }}" - go build -ldflags="-X 'github.com/unchainese/unchain/internal/global.gitHash=${{ github.sha }}' -X 'github.com/unchainese/unchain/internal/global.buildTime=${{ env.buildTime }}'" -o cmd/node/unchain cmd/node/main.go + go build -ldflags="-X 'github.com/unchainese/unchain/internal/global.gitHash=${{ github.sha }}' -X 'github.com/unchainese/unchain/internal/global.buildTime=${{ env.buildTime }}'" -o unchain main.go - name: Deploy to AWS EC2 env: diff --git a/.gitignore b/.gitignore index 61acb19..612a69d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea -*.log \ No newline at end of file +*.log +*.exe \ No newline at end of file diff --git a/internal/global/config.go b/internal/global/config.go index bf99b37..d5e4dce 100644 --- a/internal/global/config.go +++ b/internal/global/config.go @@ -14,17 +14,28 @@ import ( ) type Config struct { - SubAddresses string `desc:"sub addresses" def:"node1.xxx.cn:80,node2.xxx.cn:443"` //这个信息会帮助你生成V2ray/Clash/ShadowRocket的订阅链接,同时这个是互联网浏览器访问的地址 - Port string `desc:"port" def:"8080"` //golang app 服务端口 - RegisterUrl string `desc:"register url" def:"https://admin.unchain.people.from.censorship"` //optional,流量,用户鉴权的主控服务器地址 - RegisterToken string `desc:"register token" def:"unchain people from censorship and surveillance"` //optional,流量,用户鉴权的主控服务器token - AllowUsers string `desc:"allow users UUID" def:"903bcd04-79e7-429c-bf0c-0456c7de9cdc,903bcd04-79e7-429c-bf0c-0456c7de9cd1"` //单机模式下,允许的用户UUID - LogFile string `desc:"log file path" def:""` //日志文件路径 - DebugLevel string `desc:"debug level" def:"DEBUG"` //日志级别 - IntervalSecond string `desc:"interval second" def:"360"` //seconds 向主控服务器推送,流量使用情况的间隔时间 - GitHash string `desc:"git hash" def:""` //optional git hash - BuildTime string `desc:"build time" def:""` //optional build time - RunAt string `desc:"run at" def:""` //optional run at + SubAddresses string `desc:"sub addresses" def:"node1.xxx.cn:80,node2.xxx.cn:443"` //这个信息会帮助你生成V2ray/Clash/ShadowRocket的订阅链接,同时这个是互联网浏览器访问的地址 + Port string `desc:"port" def:"8080"` //golang app 服务端口 + RegisterUrl string `desc:"register url" def:"https://admin.unchain.people.from.censorship"` //optional,流量,用户鉴权的主控服务器地址 + RegisterToken string `desc:"register token" def:"unchain people from censorship and surveillance"` //optional,流量,用户鉴权的主控服务器token + AllowUsers string `desc:"allow users UUID" def:"903bcd04-79e7-429c-bf0c-0456c7de9cdc,903bcd04-79e7-429c-bf0c-0456c7de9cd1"` //单机模式下,允许的用户UUID + LogFile string `desc:"log file path" def:""` //日志文件路径 + DebugLevel string `desc:"debug level" def:"DEBUG"` //日志级别 + IntervalSecond string `desc:"interval second" def:"360"` //seconds 向主控服务器推送,流量使用情况的间隔时间 + GitHash string `desc:"git hash" def:""` //optional git hash + BuildTime string `desc:"build time" def:""` //optional build time + RunAt string `desc:"run at" def:""` //optional run at + IsUserTrafficStat string `desc:"is user traffic stat" def:"false"` //是否开启用户流量统计 +} + +func (c Config) DisableUserTraffic() bool { + if c.IsUserTrafficStat == "" { + return false + } + if strings.ToLower(c.IsUserTrafficStat) == "true" { + return true + } + return false } func (c Config) SubHostWithPort() []string { diff --git a/internal/node/app.go b/internal/node/app.go index 1f6bba6..1a530ed 100644 --- a/internal/node/app.go +++ b/internal/node/app.go @@ -106,6 +106,10 @@ func (app *App) loopPush() { } func (app *App) trafficInc(uid string, byteN int64) { + if app.cfg.DisableUserTraffic() { + return + } + kb := byteN >> 10 value, ok := app.userUsedTrafficKb.Load(uid) if ok {