From 991b22a317ebb48fb02638e9ca06a8c9be416954 Mon Sep 17 00:00:00 2001 From: Yuzuki616 Date: Sun, 30 Jul 2023 19:49:42 +0800 Subject: [PATCH] support vless for sing --- core/imports/hy.go | 1 - core/sing/node.go | 19 ++++++++++++++----- core/sing/user.go | 30 +++++++++++++++++++++--------- go.mod | 2 +- go.sum | 4 ++-- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/core/imports/hy.go b/core/imports/hy.go index 9cc3e82..7a80f39 100644 --- a/core/imports/hy.go +++ b/core/imports/hy.go @@ -2,5 +2,4 @@ package imports -// not yet tested import _ "github.com/InazumaV/V2bX/core/hy" diff --git a/core/sing/node.go b/core/sing/node.go index a11c282..e43bf7c 100644 --- a/core/sing/node.go +++ b/core/sing/node.go @@ -46,7 +46,6 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio } switch info.Type { case "v2ray": - in.Type = "vmess" t := option.V2RayTransportOptions{ Type: info.Network, } @@ -83,10 +82,20 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err) } } - in.VMessOptions = option.VMessInboundOptions{ - ListenOptions: listen, - TLS: &tls, - Transport: &t, + if info.ExtraConfig.EnableVless == "true" { + in.Type = "vless" + in.VLESSOptions = option.VLESSInboundOptions{ + ListenOptions: listen, + TLS: &tls, + Transport: &t, + } + } else { + in.Type = "vmess" + in.VMessOptions = option.VMessInboundOptions{ + ListenOptions: listen, + TLS: &tls, + Transport: &t, + } } case "shadowsocks": in.Type = "shadowsocks" diff --git a/core/sing/user.go b/core/sing/user.go index 076c855..cfab779 100644 --- a/core/sing/user.go +++ b/core/sing/user.go @@ -13,16 +13,25 @@ import ( func (b *Box) AddUsers(p *core.AddUsersParams) (added int, err error) { switch p.NodeInfo.Type { case "v2ray": - us := make([]option.VMessUser, len(p.UserInfo)) - for i := range p.UserInfo { - us[i] = option.VMessUser{ - Name: p.UserInfo[i].Uuid, - UUID: p.UserInfo[i].Uuid, + if p.NodeInfo.ExtraConfig.EnableVless == "true" { + us := make([]option.VLESSUser, len(p.UserInfo)) + for i := range p.UserInfo { + us[i] = option.VLESSUser{ + Name: p.UserInfo[i].Uuid, + Flow: p.NodeInfo.ExtraConfig.VlessFlow, + UUID: p.UserInfo[i].Uuid, + } } - } - err = b.inbounds[p.Tag].(*inbound.VMess).AddUsers(us) - if err != nil { - return 0, err + err = b.inbounds[p.Tag].(*inbound.VLESS).AddUsers(us) + } else { + us := make([]option.VMessUser, len(p.UserInfo)) + for i := range p.UserInfo { + us[i] = option.VMessUser{ + Name: p.UserInfo[i].Uuid, + UUID: p.UserInfo[i].Uuid, + } + } + err = b.inbounds[p.Tag].(*inbound.VMess).AddUsers(us) } case "shadowsocks": us := make([]option.ShadowsocksUser, len(p.UserInfo)) @@ -33,6 +42,9 @@ func (b *Box) AddUsers(p *core.AddUsersParams) (added int, err error) { } } } + if err != nil { + return 0, err + } return len(p.UserInfo), err } diff --git a/go.mod b/go.mod index 4375d66..b03f89c 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/go-resty/resty/v2 v2.7.0 github.com/goccy/go-json v0.10.2 github.com/hashicorp/go-multierror v1.1.1 - github.com/inazumav/sing-box v0.0.0-20230728123002-eb2ba58e499a + github.com/inazumav/sing-box v0.0.0-20230730105931-e8479113c010 github.com/juju/ratelimit v1.0.2 github.com/oschwald/geoip2-golang v1.9.0 github.com/sagernet/sing v0.2.9 diff --git a/go.sum b/go.sum index 7e3407b..f40ffa0 100644 --- a/go.sum +++ b/go.sum @@ -379,8 +379,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df h1:MZf03xP9WdakyXhOWuAD5uPK3wHh96wCsqe3hCMKh8E= github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= -github.com/inazumav/sing-box v0.0.0-20230728123002-eb2ba58e499a h1:/FGmhOCu6LYt8zd6DpMEvuHlPnUPMr0zziyJkuU1wVI= -github.com/inazumav/sing-box v0.0.0-20230728123002-eb2ba58e499a/go.mod h1:W91us/coe3lvl5jCtw2n6acyagpRbOO16h1IV3/0nrc= +github.com/inazumav/sing-box v0.0.0-20230730105931-e8479113c010 h1:AbH2HERgLu8Jgi4vHi8aRvkds+biIqxw+Btz3L+XTJY= +github.com/inazumav/sing-box v0.0.0-20230730105931-e8479113c010/go.mod h1:W91us/coe3lvl5jCtw2n6acyagpRbOO16h1IV3/0nrc= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=