Clash.Meta/adapters/inbound/socket.go

33 lines
709 B
Go
Raw Normal View History

package adapters
import (
"net"
2019-04-25 13:48:47 +08:00
"github.com/Dreamacro/clash/component/socks5"
C "github.com/Dreamacro/clash/constant"
)
2018-08-27 00:06:40 +08:00
// SocketAdapter is a adapter for socks and redir connection
type SocketAdapter struct {
2019-04-23 23:29:36 +08:00
net.Conn
2018-09-30 12:25:52 +08:00
metadata *C.Metadata
}
2018-09-30 12:25:52 +08:00
// Metadata return destination metadata
func (s *SocketAdapter) Metadata() *C.Metadata {
return s.metadata
}
2018-08-27 00:06:40 +08:00
// NewSocket is SocketAdapter generator
2019-04-25 13:48:47 +08:00
func NewSocket(target socks5.Addr, conn net.Conn, source C.SourceType, netType C.NetWork) *SocketAdapter {
2018-12-05 21:13:29 +08:00
metadata := parseSocksAddr(target)
2019-04-23 23:29:36 +08:00
metadata.NetWork = netType
2018-12-05 21:13:29 +08:00
metadata.Source = source
metadata.SourceIP = parseSourceIP(conn)
2018-12-05 21:13:29 +08:00
2018-08-27 00:06:40 +08:00
return &SocketAdapter{
2019-04-23 23:29:36 +08:00
Conn: conn,
2018-12-05 21:13:29 +08:00
metadata: metadata,
}
}