2020-03-21 23:46:49 +08:00
|
|
|
package outboundgroup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
2022-04-20 01:52:51 +08:00
|
|
|
"net/netip"
|
2020-03-21 23:46:49 +08:00
|
|
|
"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 09:19:28 +08:00
|
|
|
if ip, err := netip.ParseAddr(host); err != nil {
|
2020-03-21 23:46:49 +08:00
|
|
|
addr = &C.Metadata{
|
2022-11-11 09:19:28 +08:00
|
|
|
Host: host,
|
|
|
|
DstPort: port,
|
2020-03-21 23:46:49 +08:00
|
|
|
}
|
2022-11-11 09:19:28 +08:00
|
|
|
} else {
|
2021-03-24 01:00:21 +08:00
|
|
|
addr = &C.Metadata{
|
2022-11-11 09:19:28 +08:00
|
|
|
Host: "",
|
2022-12-19 21:34:07 +08:00
|
|
|
DstIP: ip.Unmap(),
|
2022-11-11 09:19:28 +08:00
|
|
|
DstPort: port,
|
2021-03-24 01:00:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
2020-03-21 23:46:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func tcpKeepAlive(c net.Conn) {
|
|
|
|
if tcp, ok := c.(*net.TCPConn); ok {
|
2022-04-20 01:52:51 +08:00
|
|
|
_ = tcp.SetKeepAlive(true)
|
|
|
|
_ = tcp.SetKeepAlivePeriod(30 * time.Second)
|
2020-03-21 23:46:49 +08:00
|
|
|
}
|
|
|
|
}
|
2022-05-23 00:40:27 +08:00
|
|
|
|
|
|
|
type SelectAble interface {
|
|
|
|
Set(string) error
|
|
|
|
}
|