v2scar

package module
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2020 License: GPL-3.0 Imports: 17 Imported by: 0

README

v2scar

Sidecar For V2ray

go-releaser

原理介绍

该项目需要以sidecar的形式和v2ray部署在一台机器上

他通过grpc接口动态添加/删除V2ray的Vmess用户,并统计流量

通过接入django-sspanel的api,可以动态调节v2ray的Vmess用户

目前实现了以下几个接口:

  • AddInboundUser
  • RemoveInboundUser
  • GetAndResetUserTraffic

使用说明

  • 可以直接以cli的形式运行:

./v2scar --api-endpoint="xxx" --grpc-endpoint="127.0.0.1:8080" --sync-time=60

  • 或者通过配置环境变量来运行:
export V2SCAR_SYNC_TIME=60 # 和django-sspanel同步的时间间隔
export V2SCAR_API_ENDPOINT="xxxx" # 这个是django-sspanel的sync api 地址
export V2SCAR_GRPC_ENDPOINT="127.0.0.1:8080" # 这个是机器上v2ray开放的grpc地址

配置V2ray:

这只是一份参考的配置, 关键的部分在于stats/api/policy/routing 另外如果需要对接 django-sspanel的话,配置里的inbound的port/tag/level必须和面板后台里的配置相同

{
    "stats": {},
    "api": {
        "tag": "api",
        "services": [
            "HandlerService",
            "StatsService"
        ]
    },
    "log": {
        "loglevel": "warning"
    },
    "policy": {
        "levels": {
            "0": {
                "statsUserUplink": true,
                "statsUserDownlink": true
            }
        },
        "system": {
            "statsInboundUplink": true,
            "statsInboundDownlink": true
        }
    },
    "inbounds": [
        {
            "tag": "proxy",
            "port": 10086,
            "protocol": "vmess",
            "settings": {
                "clients": []
            }
        },
        {
            "listen": "127.0.0.1",
            "port": 8080,
            "protocol": "dokodemo-door",
            "settings": {
                "address": "127.0.0.1"
            },
            "tag": "api"
        }
    ],
    "outbounds": [
        {
            "protocol": "freedom",
            "settings": {}
        }
    ],
    "routing": {
        "settings": {
            "rules": [
                {
                    "inboundTag": [
                        "api"
                    ],
                    "outboundTag": "api",
                    "type": "field"
                }
            ]
        },
        "strategy": "rules"
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var API_ENDPOINT string
View Source
var GRPC_ENDPOINT string

Functions

func AddInboundUser

func AddInboundUser(c v2proxyman.HandlerServiceClient, tag string, user *User)

AddInboundUser add user to inbound by tag

func GetAndResetUserTraffic

func GetAndResetUserTraffic(c v2stats.StatsServiceClient, up *UserPool)

GetAndResetUserTraffic 统计所有user的上行下行流量 V2ray的stats的统计模块设计的非常奇怪,具体规则如下 上传流量:"user>>>" + user.Email + ">>>traffic>>>uplink" 下载流量:"user>>>" + user.Email + ">>>traffic>>>downlink"

func RemoveInboundUser

func RemoveInboundUser(c v2proxyman.HandlerServiceClient, tag string, user *User)

RemoveInboundUser remove user from inbound by tag

func SyncTask added in v0.0.5

func SyncTask(up *UserPool)

Types

type User

type User struct {
	UserId          int    `json:"user_id"`
	Email           string `json:"email"`
	UUID            string `json:"uuid"`
	AlterId         uint32 `json:"alter_id"`
	Level           uint32 `json:"level"`
	Enable          bool   `json:"enable"`
	UploadTraffic   int64  `json:"upload_traffic"`
	DownloadTraffic int64  `json:"download_traffic"`
	// contains filtered or unexported fields
}

User V2ray User

type UserConfig

type UserConfig struct {
	UserId  int    `json:"user_id"`
	Email   string `json:"email"`
	UUID    string `json:"uuid"`
	AlterId uint32 `json:"alter_id"`
	Level   uint32 `json:"level"`
	Enable  bool   `json:"enable"`
}

type UserPool

type UserPool struct {
	// contains filtered or unexported fields
}

UserPool user pool

func NewUserPool

func NewUserPool() *UserPool

NewUserPool New UserPool

func (*UserPool) CreateUser

func (up *UserPool) CreateUser(userId int, email, uuid string, level, alterId uint32, enable bool) (*User, error)

CreateUser get create user

func (*UserPool) GetAllUsers

func (up *UserPool) GetAllUsers() []*User

GetAllUsers GetAllUsers

func (*UserPool) GetUserByEmail

func (up *UserPool) GetUserByEmail(email string) (*User, error)

GetUserByEmail get user by email

func (*UserPool) GetUsersNum added in v0.0.5

func (up *UserPool) GetUsersNum() int

GetUsersNum GetUsersNum

func (*UserPool) RemoveUserByEmail added in v0.0.11

func (up *UserPool) RemoveUserByEmail(email string)

RemoveUserByEmail get user by email

type UserTraffic added in v0.0.5

type UserTraffic struct {
	UserId          int   `json:"user_id"`
	DownloadTraffic int64 `json:"dt"`
	UploadTraffic   int64 `json:"ut"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL