From 90475134a82fcda180ca99ab8b25fec3d38e63f3 Mon Sep 17 00:00:00 2001 From: injoyai <1113655791@qq.com> Date: Thu, 14 Nov 2024 15:00:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=87=8D=E8=AF=95=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E7=9A=84=E6=9C=8D=E5=8A=A1=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dial.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 dial.go diff --git a/dial.go b/dial.go new file mode 100644 index 0000000..2c5e712 --- /dev/null +++ b/dial.go @@ -0,0 +1,29 @@ +package tdx + +import ( + "context" + "github.com/injoyai/ios" + "net" + "strings" + "time" +) + +func NewHostDial(hosts []string, timeout time.Duration) ios.DialFunc { + if len(hosts) == 0 { + hosts = Hosts + } + index := 0 + + return func(ctx context.Context) (ios.ReadWriteCloser, string, error) { + defer func() { index++ }() + if index >= len(hosts) { + index = 0 + } + addr := hosts[index] + if !strings.Contains(addr, ":") { + addr += ":7709" + } + c, err := net.DialTimeout("tcp", addr, timeout) + return c, hosts[index], err + } +}