clash/adapters/outbound/direct.go

35 lines
568 B
Go
Raw Normal View History

2018-06-10 14:50:03 +00:00
package adapters
import (
"net"
C "github.com/Dreamacro/clash/constant"
)
2018-12-22 15:56:42 +00:00
type Direct struct {
*Base
2018-06-10 14:50:03 +00:00
}
2018-12-22 15:56:42 +00:00
func (d *Direct) Generator(metadata *C.Metadata) (net.Conn, error) {
2018-12-05 13:13:29 +00:00
address := net.JoinHostPort(metadata.Host, metadata.Port)
if metadata.IP != nil {
address = net.JoinHostPort(metadata.IP.String(), metadata.Port)
}
c, err := net.DialTimeout("tcp", address, tcpTimeout)
2018-06-10 14:50:03 +00:00
if err != nil {
2018-12-22 15:56:42 +00:00
return nil, err
2018-06-10 14:50:03 +00:00
}
tcpKeepAlive(c)
2018-12-22 15:56:42 +00:00
return c, nil
2018-11-21 05:47:46 +00:00
}
func NewDirect() *Direct {
2018-12-22 15:56:42 +00:00
return &Direct{
Base: &Base{
name: "DIRECT",
tp: C.Direct,
},
}
2018-06-10 14:50:03 +00:00
}