mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 21:51:23 +08:00
46 lines
790 B
Go
46 lines
790 B
Go
package adapters
|
|
|
|
import (
|
|
"net"
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
)
|
|
|
|
// DirectAdapter is a directly connected adapter
|
|
type DirectAdapter struct {
|
|
conn net.Conn
|
|
}
|
|
|
|
// Close is used to close connection
|
|
func (d *DirectAdapter) Close() {
|
|
d.conn.Close()
|
|
}
|
|
|
|
// Conn is used to http request
|
|
func (d *DirectAdapter) Conn() net.Conn {
|
|
return d.conn
|
|
}
|
|
|
|
type Direct struct{}
|
|
|
|
func (d *Direct) Name() string {
|
|
return "Direct"
|
|
}
|
|
|
|
func (d *Direct) Type() C.AdapterType {
|
|
return C.Direct
|
|
}
|
|
|
|
func (d *Direct) Generator(metadata *C.Metadata) (adapter C.ProxyAdapter, err error) {
|
|
c, err := net.Dial("tcp", net.JoinHostPort(metadata.String(), metadata.Port))
|
|
if err != nil {
|
|
return
|
|
}
|
|
tcpKeepAlive(c)
|
|
return &DirectAdapter{conn: c}, nil
|
|
}
|
|
|
|
func NewDirect() *Direct {
|
|
return &Direct{}
|
|
}
|