From d06aa29bc8d45f35aa067e03432f03d889e49ed3 Mon Sep 17 00:00:00 2001 From: Yuzuki616 Date: Wed, 9 Aug 2023 19:19:36 +0800 Subject: [PATCH 01/10] fix panic for sing --- core/sing/sing.go | 2 ++ go.mod | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core/sing/sing.go b/core/sing/sing.go index 1f5a814..9c6e6ff 100644 --- a/core/sing/sing.go +++ b/core/sing/sing.go @@ -20,6 +20,7 @@ import ( "github.com/sagernet/sing/common" E "github.com/sagernet/sing/common/exceptions" F "github.com/sagernet/sing/common/format" + "github.com/sagernet/sing/service/pause" ) var _ adapter.Service = (*Box)(nil) @@ -48,6 +49,7 @@ func New(c *conf.CoreConfig) (vCore.Core, error) { Output: c.SingConfig.LogConfig.Output, } ctx := context.Background() + ctx = pause.ContextWithDefaultManager(ctx) createdAt := time.Now() experimentalOptions := common.PtrValueOrDefault(options.Experimental) applyDebugOptions(common.PtrValueOrDefault(experimentalOptions.Debug)) diff --git a/go.mod b/go.mod index b03f89c..40073d0 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( 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 + github.com/sagernet/sing v0.2.10-0.20230807080248-4db0062caa0a github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 github.com/xtls/xray-core v1.8.3 From 877548921bc039391cb550eb716b8899fb86ad3a Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Mon, 25 Sep 2023 15:09:37 +0800 Subject: [PATCH 02/10] update example --- README.md | 3 --- example/config_full.json | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 21b140f..0afca58 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,7 @@ A V2board node server based on multi core, modified from XrayR. - [ ] 重新实现动态限速 - [ ] 重新实现在线IP同步(跨节点在线IP限制) -- [x] 集成基本操作Command(Start, Stop, Restart, Status, Uninstall) -- [ ] 完善Hysteria内核支持 - [ ] 完善使用文档 -- [ ] 尽可能统一日志输出格式 ## 软件安装 diff --git a/example/config_full.json b/example/config_full.json index cfc7643..a188bd7 100644 --- a/example/config_full.json +++ b/example/config_full.json @@ -185,7 +185,9 @@ { // xray内核 + "Name": "xray_node1", "Core": "xray", + "CoreName": "", "ApiHost": "http://127.0.0.1", "ApiKey": "test", "NodeID": 33, From 4ecbcf62f558d0c1acbbfb2daf9aa7a39fad2e74 Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Mon, 25 Sep 2023 15:31:26 +0800 Subject: [PATCH 03/10] fix bug --- core/sing/sing.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/sing/sing.go b/core/sing/sing.go index f230d49..4165684 100644 --- a/core/sing/sing.go +++ b/core/sing/sing.go @@ -3,14 +3,9 @@ package sing import ( "context" "fmt" - "github.com/goccy/go-json" - "io" - "os" - "runtime/debug" - "time" - "github.com/InazumaV/V2bX/conf" vCore "github.com/InazumaV/V2bX/core" + "github.com/goccy/go-json" "github.com/inazumav/sing-box/adapter" "github.com/inazumav/sing-box/inbound" "github.com/inazumav/sing-box/log" @@ -21,6 +16,11 @@ import ( E "github.com/sagernet/sing/common/exceptions" F "github.com/sagernet/sing/common/format" "github.com/sagernet/sing/service" + "github.com/sagernet/sing/service/pause" + "io" + "os" + "runtime/debug" + "time" ) var _ adapter.Service = (*Box)(nil) From 0fc91313898e820ca47b2172f7d8de6c9080344a Mon Sep 17 00:00:00 2001 From: Yuzuki <50410851+Yuzuki616@users.noreply.github.com> Date: Mon, 25 Sep 2023 15:36:33 +0800 Subject: [PATCH 04/10] Update release.yml --- .github/workflows/release.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 01b4295..5bb50bc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -142,11 +142,7 @@ jobs: run: | cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE - cp ${GITHUB_WORKSPACE}/example/dns.json ./build_assets/dns.json - cp ${GITHUB_WORKSPACE}/example/route.json ./build_assets/route.json - cp ${GITHUB_WORKSPACE}/example/custom_outbound.json ./build_assets/custom_outbound.json - cp ${GITHUB_WORKSPACE}/example/custom_inbound.json ./build_assets/custom_inbound.json - cp ${GITHUB_WORKSPACE}/example/config.yml.example ./build_assets/config.json + cp ${GITHUB_WORKSPACE}/example/*.json ./build_assets/ LIST=('geoip geoip geoip' 'domain-list-community dlc geosite') for i in "${LIST[@]}" do From cea6118ba6a7fae24b9676f46da1a0f5d1f23322 Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Mon, 25 Sep 2023 15:38:34 +0800 Subject: [PATCH 05/10] fix in out link bug --- core/xray/app/dispatcher/default.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/xray/app/dispatcher/default.go b/core/xray/app/dispatcher/default.go index 9995c7d..cb823df 100644 --- a/core/xray/app/dispatcher/default.go +++ b/core/xray/app/dispatcher/default.go @@ -492,6 +492,10 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport. } } + if handler == nil { + handler = d.ohm.GetHandler(inTag) + } + if handler == nil { handler = d.ohm.GetDefaultHandler() } From 94817e0f824b44a10e22a6193bf67e3f06b56abf Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Mon, 25 Sep 2023 15:56:27 +0800 Subject: [PATCH 06/10] fix routedDispatch --- core/xray/app/dispatcher/default.go | 37 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/core/xray/app/dispatcher/default.go b/core/xray/app/dispatcher/default.go index cb823df..18173bc 100644 --- a/core/xray/app/dispatcher/default.go +++ b/core/xray/app/dispatcher/default.go @@ -164,12 +164,12 @@ func (d *DefaultDispatcher) getLink(ctx context.Context, network net.Network) (* if user != nil && len(user.Email) > 0 { limit, err = limiter.GetLimiter(sessionInbound.Tag) if err != nil { - newError("Get limit info error: ", err).AtError().WriteToLog() + newError("get limiter ", sessionInbound.Tag, " error: ", err).AtError().WriteToLog() common.Close(outboundLink.Writer) common.Close(inboundLink.Writer) common.Interrupt(outboundLink.Reader) common.Interrupt(inboundLink.Reader) - return nil, nil, nil, newError("Get limit info error: ", err) + return nil, nil, nil, newError("get limiter ", sessionInbound.Tag, " error: ", err) } // Speed Limit and Device Limit w, reject := limit.CheckLimit(user.Email, @@ -427,10 +427,7 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport. var err error l, err = limiter.GetLimiter(sessionInbound.Tag) if err != nil { - newError("get limiter error: ", err).AtError().WriteToLog(session.ExportIDToError(ctx)) - common.Close(link.Writer) - common.Interrupt(link.Reader) - return + newError("get limiter ", sessionInbound.Tag, " error: ", err).AtWarning().WriteToLog(session.ExportIDToError(ctx)) } } var destStr string @@ -439,25 +436,27 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport. } else { destStr = destination.Address.IP().String() } - if l.CheckDomainRule(destStr) { - newError(fmt.Sprintf( - "User %s access domain %s reject by rule", - sessionInbound.User.Email, - destStr)).AtWarning().WriteToLog(session.ExportIDToError(ctx)) - common.Close(link.Writer) - common.Interrupt(link.Reader) - return - } - if len(protocol) != 0 { - if l.CheckProtocolRule(protocol) { + if l != nil { + if l.CheckDomainRule(destStr) { newError(fmt.Sprintf( - "User %s access protocol %s reject by rule", + "User %s access domain %s reject by rule", sessionInbound.User.Email, - protocol)).AtWarning().WriteToLog(session.ExportIDToError(ctx)) + destStr)).AtWarning().WriteToLog(session.ExportIDToError(ctx)) common.Close(link.Writer) common.Interrupt(link.Reader) return } + if len(protocol) != 0 { + if l.CheckProtocolRule(protocol) { + newError(fmt.Sprintf( + "User %s access protocol %s reject by rule", + sessionInbound.User.Email, + protocol)).AtWarning().WriteToLog(session.ExportIDToError(ctx)) + common.Close(link.Writer) + common.Interrupt(link.Reader) + return + } + } } var handler outbound.Handler From 2d44470f24bc2b965b16f48b98e225f1310bd097 Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Mon, 25 Sep 2023 16:20:12 +0800 Subject: [PATCH 07/10] fix routedDispatch --- core/xray/app/dispatcher/default.go | 60 ++++++++++++++--------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/core/xray/app/dispatcher/default.go b/core/xray/app/dispatcher/default.go index 18173bc..c4bf662 100644 --- a/core/xray/app/dispatcher/default.go +++ b/core/xray/app/dispatcher/default.go @@ -414,48 +414,48 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport. } sessionInbound := session.InboundFromContext(ctx) - if l != nil { - // del connect count - if sessionInbound.User != nil { + if sessionInbound.User != nil { + if l != nil { + // del connect count if destination.Network == net.Network_TCP { defer func() { l.ConnLimiter.DelConnCount(sessionInbound.User.Email, sessionInbound.Source.Address.IP().String()) }() } + } else { + var err error + l, err = limiter.GetLimiter(sessionInbound.Tag) + if err != nil { + newError("get limiter ", sessionInbound.Tag, " error: ", err).AtWarning().WriteToLog(session.ExportIDToError(ctx)) + } } - } else { - var err error - l, err = limiter.GetLimiter(sessionInbound.Tag) - if err != nil { - newError("get limiter ", sessionInbound.Tag, " error: ", err).AtWarning().WriteToLog(session.ExportIDToError(ctx)) - } - } - var destStr string - if destination.Address.Family().IsDomain() { - destStr = destination.Address.Domain() - } else { - destStr = destination.Address.IP().String() - } - if l != nil { - if l.CheckDomainRule(destStr) { - newError(fmt.Sprintf( - "User %s access domain %s reject by rule", - sessionInbound.User.Email, - destStr)).AtWarning().WriteToLog(session.ExportIDToError(ctx)) - common.Close(link.Writer) - common.Interrupt(link.Reader) - return - } - if len(protocol) != 0 { - if l.CheckProtocolRule(protocol) { + if l != nil { + var destStr string + if destination.Address.Family().IsDomain() { + destStr = destination.Address.Domain() + } else { + destStr = destination.Address.IP().String() + } + if l.CheckDomainRule(destStr) { newError(fmt.Sprintf( - "User %s access protocol %s reject by rule", + "User %s access domain %s reject by rule", sessionInbound.User.Email, - protocol)).AtWarning().WriteToLog(session.ExportIDToError(ctx)) + destStr)).AtWarning().WriteToLog(session.ExportIDToError(ctx)) common.Close(link.Writer) common.Interrupt(link.Reader) return } + if len(protocol) != 0 { + if l.CheckProtocolRule(protocol) { + newError(fmt.Sprintf( + "User %s access protocol %s reject by rule", + sessionInbound.User.Email, + protocol)).AtWarning().WriteToLog(session.ExportIDToError(ctx)) + common.Close(link.Writer) + common.Interrupt(link.Reader) + return + } + } } } From af9fb2084aa6c8f652fc9e78e95c32913bb055e2 Mon Sep 17 00:00:00 2001 From: Yuzuki <50410851+Yuzuki616@users.noreply.github.com> Date: Wed, 27 Sep 2023 12:29:49 +0800 Subject: [PATCH 08/10] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0afca58..12e1dc2 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,12 @@ A V2board node server based on multi core, modified from XrayR. 一个基于多种内核的V2board节点服务端,修改自XrayR,支持V2ay,Trojan,Shadowsocks协议。 -**注意:1.1.0将更换为V2board1.7.0之后新增的Api,原Api将被移除,请1.7.0之前的用户使用1.1.0之前的版本。** +**注意: 本项目需要V2board版本 >= 1.7.0** ## 特点 * 永久开源且免费。 -* 支持V2ray,Trojan, Shadowsocks多种协议。 +* 支持Vmess/Vless, Trojan, Shadowsocks, Hysteria多种协议。 * 支持Vless和XTLS等新特性。 * 支持单实例对接多节点,无需重复启动。 * 支持限制在线IP。 From 00ec5b2d4dc151985c2b8ac5f2cfb13363f6c8fd Mon Sep 17 00:00:00 2001 From: root Date: Fri, 29 Sep 2023 14:18:29 +0900 Subject: [PATCH 09/10] fix bug: func RouterFromContext return nil router --- core/sing/node.go | 4 ++-- core/sing/sing.go | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/sing/node.go b/core/sing/node.go index 6573503..5b9f73b 100644 --- a/core/sing/node.go +++ b/core/sing/node.go @@ -1,7 +1,6 @@ package sing import ( - "context" "crypto/rand" "encoding/base64" "fmt" @@ -215,8 +214,9 @@ func (b *Box) AddNode(tag string, info *panel.NodeInfo, config *conf.Options) er if err != nil { return err } + in, err := inbound.New( - context.Background(), + b.ctx, b.router, b.logFactory.NewLogger(F.ToString("inbound/", c.Type, "[", tag, "]")), c, diff --git a/core/sing/sing.go b/core/sing/sing.go index 4165684..ec76b7f 100644 --- a/core/sing/sing.go +++ b/core/sing/sing.go @@ -31,6 +31,7 @@ type DNSConfig struct { } type Box struct { + ctx context.Context createdAt time.Time router adapter.Router inbounds map[string]adapter.Inbound @@ -169,6 +170,7 @@ func New(c *conf.CoreConfig) (vCore.Core, error) { } router.SetClashServer(server) return &Box{ + ctx: ctx, router: router, inbounds: inMap, outbounds: outbounds, From db238f7fe513c5fc19065bce30a2fb2eccf64b24 Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Fri, 29 Sep 2023 18:16:47 +0800 Subject: [PATCH 10/10] clean log --- api/panel/user.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/api/panel/user.go b/api/panel/user.go index c54f83f..f56e5de 100644 --- a/api/panel/user.go +++ b/api/panel/user.go @@ -2,8 +2,6 @@ package panel import ( "fmt" - log "github.com/sirupsen/logrus" - "github.com/goccy/go-json" ) @@ -67,6 +65,5 @@ func (c *Client) ReportUserTraffic(userTraffic []UserTraffic) error { if err != nil { return err } - log.Println(r.String()) return nil }