From 51d8d06fbdea938ff60efb6f8e94d35b4f00d5fe Mon Sep 17 00:00:00 2001 From: injoyai <1113655791@qq.com> Date: Tue, 18 Mar 2025 14:47:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0NewRangeDial=E5=87=BD?= =?UTF-8?q?=E6=95=B0,=E6=9B=B4=E6=96=B9=E4=BE=BF=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dial.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/dial.go b/dial.go index 562cf39..affc034 100644 --- a/dial.go +++ b/dial.go @@ -3,6 +3,7 @@ package tdx import ( "context" "github.com/injoyai/ios" + "github.com/injoyai/logs" "math/rand" "net" "strings" @@ -43,3 +44,25 @@ func NewRandomDial(hosts []string) ios.DialFunc { return c, addr, err } } + +func NewRangeDial(hosts []string) ios.DialFunc { + if len(hosts) == 0 { + hosts = Hosts + } + return func(ctx context.Context) (c ios.ReadWriteCloser, _ string, err error) { + for i, addr := range hosts { + if !strings.Contains(addr, ":") { + addr += ":7709" + } + c, err = net.Dial("tcp", addr) + if err == nil { + return c, addr, nil + } + if i < len(hosts)-1 { + //最后一个错误返回出去 + logs.Err(err) + } + } + return + } +}