Skip to content

Commit

Permalink
fix typo && update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehco1996 committed Oct 1, 2019
1 parent 175b040 commit ff2ccf2
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 79 deletions.
122 changes: 57 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
```
4 changes: 2 additions & 2 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 16 additions & 12 deletions services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down

0 comments on commit ff2ccf2

Please # to comment.