diff --git a/README.md b/README.md index 59bf4e5..ee58209 100644 --- a/README.md +++ b/README.md @@ -37,75 +37,67 @@ export V2SCAR_GRPC_ENDPOINT="127.0.0.1:8080" # 这个是机器上v2ray开放的g ```json { -"stats": {}, -"api": { - "services": [ - "HandlerService", - "StatsService" - ], - "tag": "api" -}, -"policy": { - "levels": { - "0": { - "handshake": 4, - "connIdle": 300, - "uplinkOnly": 2, - "downlinkOnly": 5, - "statsUserUplink": true, - "statsUserDownlink": true, - "bufferSize": 10240 - } - }, - "system": { - "statsInboundUplink": true, - "statsInboundDownlink": true - } -}, -"inbound": { - "port": 10086, - "protocol": "vmess", - "settings": { - "clients": [] + "stats": {}, + "api": { + "tag": "api", + "services": [ + "HandlerService", + "StatsService" + ] }, - "streamSettings": { - "network": "tcp" + "log": { + "loglevel": "warning" }, - "tag": "proxy" -}, -"inboundDetour": [ - { - "listen": "127.0.0.1", - "port": 8080, - "protocol": "dokodemo-door", - "settings": { - "address": "127.0.0.1" + "policy": { + "levels": { + "0": { + "statsUserUplink": true, + "statsUserDownlink": true + } + }, + "system": { + "statsInboundUplink": true, + "statsInboundDownlink": true + } }, - "tag": "api" - } -], -"log": { - "loglevel": "warning", - "access": "/var/log/v2ray/access.log", - "error": "/var/log/v2ray/error.log" -}, -"outbound": { - "protocol": "freedom", - "settings": {} -}, -"routing": { - "settings": { - "rules": [ + "inbounds": [ + { + "tag": "proxy", + "port": 10086, + "protocol": "vmess", + "settings": { + "clients": [] + } + }, { - "inboundTag": [ - "api" - ], - "outboundTag": "api", - "type": "field" + "listen": "127.0.0.1", + "port": 8080, + "protocol": "dokodemo-door", + "settings": { + "address": "127.0.0.1" + }, + "tag": "api" } - ] - }, - "strategy": "rules" -} + ], + "outbounds": [ + { + "protocol": "freedom", + "settings": {} + } + ], + "routing": { + "settings": { + "rules": [ + { + "inboundTag": [ + "api" + ], + "outboundTag": "api", + "type": "field" + } + ] + }, + "strategy": "rules" + } } ``` \ No newline at end of file diff --git a/cli/main.go b/cli/main.go index 4785279..993a1a2 100644 --- a/cli/main.go +++ b/cli/main.go @@ -17,13 +17,13 @@ func main() { app := cli.NewApp() app.Name = "v2scar" app.Usage = "sidecar for V2ray" - app.Version = "0.0.2" + app.Version = "0.0.3" app.Author = "Ehco1996" app.Flags = []cli.Flag{ cli.StringFlag{ Name: "grpc-endpoint, gp", - Value: "127.0.0.0.1:8080", + Value: "127.0.0.1:8080", Usage: "V2ray开放的GRPC地址", EnvVar: "V2SCAR_GRPC_ENDPOINT", Destination: &v2scar.GRPC_ENDPOINT, diff --git a/services.go b/services.go index a43dc6e..4e5016d 100644 --- a/services.go +++ b/services.go @@ -21,18 +21,22 @@ func GetAndResetUserTraffic(c v2stats.StatsServiceClient, up *UserPool) { Pattern: "user>>>", Reset_: true, } - resp, _ := c.QueryStats(context.Background(), req) - for _, stat := range resp.Stat { - email, trafficType := getEmailAndTrafficType(stat.Name) - user, err := up.GetUserByEmail(email) - if err != nil { - log.Println(err) - } else { - switch trafficType { - case "uplink": - user.setUploadTraffic(stat.Value) - case "downlink": - user.setDownloadTraffic(stat.Value) + resp, err := c.QueryStats(context.Background(), req) + if err != nil { + log.Println("[ERROR]:", err) + } else { + for _, stat := range resp.Stat { + email, trafficType := getEmailAndTrafficType(stat.Name) + user, err := up.GetUserByEmail(email) + if err != nil { + log.Println(err) + } else { + switch trafficType { + case "uplink": + user.setUploadTraffic(stat.Value) + case "downlink": + user.setDownloadTraffic(stat.Value) + } } } }