clash/adapter/outboundgroup/util.go

45 lines
731 B
Go
Raw Normal View History

package outboundgroup
import (
"fmt"
"net"
2022-04-19 17:52:51 +00:00
"net/netip"
"time"
C "github.com/Dreamacro/clash/constant"
)
func addrToMetadata(rawAddress string) (addr *C.Metadata, err error) {
host, port, err := net.SplitHostPort(rawAddress)
if err != nil {
err = fmt.Errorf("addrToMetadata failed: %w", err)
return
}
2022-11-11 01:19:28 +00:00
if ip, err := netip.ParseAddr(host); err != nil {
addr = &C.Metadata{
2022-11-11 01:19:28 +00:00
Host: host,
DstPort: port,
}
2022-11-11 01:19:28 +00:00
} else {
2021-03-23 17:00:21 +00:00
addr = &C.Metadata{
2022-11-11 01:19:28 +00:00
Host: "",
DstIP: ip,
DstPort: port,
2021-03-23 17:00:21 +00:00
}
}
return
}
func tcpKeepAlive(c net.Conn) {
if tcp, ok := c.(*net.TCPConn); ok {
2022-04-19 17:52:51 +00:00
_ = tcp.SetKeepAlive(true)
_ = tcp.SetKeepAlivePeriod(30 * time.Second)
}
}
2022-05-22 16:40:27 +00:00
type SelectAble interface {
Set(string) error
}