Clash.Meta/adapters/local/socks.go

38 lines
686 B
Go
Raw Normal View History

package adapters
import (
"net"
C "github.com/Dreamacro/clash/constant"
"github.com/riobard/go-shadowsocks2/socks"
)
2018-08-12 16:18:58 +08:00
// SocksAdapter is a adapter for socks and redir connection
type SocksAdapter struct {
conn net.Conn
addr *C.Addr
}
2018-08-12 16:18:58 +08:00
// Close socks and redir connection
func (s *SocksAdapter) Close() {
s.conn.Close()
}
2018-08-12 16:18:58 +08:00
// Addr return destination address
func (s *SocksAdapter) Addr() *C.Addr {
return s.addr
}
2018-08-12 16:18:58 +08:00
// Conn return raw net.Conn
func (s *SocksAdapter) Conn() net.Conn {
return s.conn
}
2018-08-12 16:18:58 +08:00
// NewSocks is SocksAdapter generator
func NewSocks(target socks.Addr, conn net.Conn) *SocksAdapter {
return &SocksAdapter{
conn: conn,
addr: parseSocksAddr(target),
}
}