2020-03-21 15:46:49 +00:00
|
|
|
package outboundgroup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
2022-04-19 17:52:51 +00:00
|
|
|
"net/netip"
|
2020-03-21 15:46:49 +00: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-04-19 17:52:51 +00:00
|
|
|
ip, err := netip.ParseAddr(host)
|
|
|
|
if err != nil {
|
2020-03-21 15:46:49 +00:00
|
|
|
addr = &C.Metadata{
|
|
|
|
AddrType: C.AtypDomainName,
|
|
|
|
Host: host,
|
2022-04-19 17:52:51 +00:00
|
|
|
DstIP: netip.Addr{},
|
2020-03-21 15:46:49 +00:00
|
|
|
DstPort: port,
|
|
|
|
}
|
2022-04-23 02:26:22 +00:00
|
|
|
err = nil
|
2020-03-21 15:46:49 +00:00
|
|
|
return
|
2022-04-19 17:52:51 +00:00
|
|
|
} else if ip.Is4() {
|
2021-03-23 17:00:21 +00:00
|
|
|
addr = &C.Metadata{
|
|
|
|
AddrType: C.AtypIPv4,
|
|
|
|
Host: "",
|
2022-04-19 17:52:51 +00:00
|
|
|
DstIP: ip,
|
2021-03-23 17:00:21 +00:00
|
|
|
DstPort: port,
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = &C.Metadata{
|
|
|
|
AddrType: C.AtypIPv6,
|
|
|
|
Host: "",
|
|
|
|
DstIP: ip,
|
|
|
|
DstPort: port,
|
2020-03-21 15:46:49 +00:00
|
|
|
}
|
2021-03-23 17:00:21 +00:00
|
|
|
return
|
2020-03-21 15:46:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2020-03-21 15:46:49 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-22 16:40:27 +00:00
|
|
|
|
|
|
|
type SelectAble interface {
|
|
|
|
Set(string) error
|
|
|
|
}
|