chore: listeners support tunnel
This commit is contained in:
@ -33,14 +33,14 @@ func (l *Listener) Close() error {
|
||||
return l.listener.Close()
|
||||
}
|
||||
|
||||
func (l *Listener) handleTCP(conn net.Conn, in chan<- C.ConnContext) {
|
||||
func (l *Listener) handleTCP(conn net.Conn, in chan<- C.ConnContext, additions ...inbound.Addition) {
|
||||
conn.(*net.TCPConn).SetKeepAlive(true)
|
||||
ctx := inbound.NewSocket(l.target, conn, C.TUNNEL)
|
||||
ctx := inbound.NewSocket(l.target, conn, C.TUNNEL, additions...)
|
||||
ctx.Metadata().SpecialProxy = l.proxy
|
||||
in <- ctx
|
||||
}
|
||||
|
||||
func New(addr, target, proxy string, in chan<- C.ConnContext) (*Listener, error) {
|
||||
func New(addr, target, proxy string, in chan<- C.ConnContext, additions ...inbound.Addition) (*Listener, error) {
|
||||
l, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -67,7 +67,7 @@ func New(addr, target, proxy string, in chan<- C.ConnContext) (*Listener, error)
|
||||
}
|
||||
continue
|
||||
}
|
||||
go rl.handleTCP(c, in)
|
||||
go rl.handleTCP(c, in, additions...)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -34,7 +34,7 @@ func (l *PacketConn) Close() error {
|
||||
return l.conn.Close()
|
||||
}
|
||||
|
||||
func NewUDP(addr, target, proxy string, in chan<- C.PacketAdapter) (*PacketConn, error) {
|
||||
func NewUDP(addr, target, proxy string, in chan<- C.PacketAdapter, additions ...inbound.Addition) (*PacketConn, error) {
|
||||
l, err := net.ListenPacket("udp", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -62,21 +62,21 @@ func NewUDP(addr, target, proxy string, in chan<- C.PacketAdapter) (*PacketConn,
|
||||
}
|
||||
continue
|
||||
}
|
||||
sl.handleUDP(l, in, buf[:n], remoteAddr)
|
||||
sl.handleUDP(l, in, buf[:n], remoteAddr, additions...)
|
||||
}
|
||||
}()
|
||||
|
||||
return sl, nil
|
||||
}
|
||||
|
||||
func (l *PacketConn) handleUDP(pc net.PacketConn, in chan<- C.PacketAdapter, buf []byte, addr net.Addr) {
|
||||
func (l *PacketConn) handleUDP(pc net.PacketConn, in chan<- C.PacketAdapter, buf []byte, addr net.Addr, additions ...inbound.Addition) {
|
||||
packet := &packet{
|
||||
pc: pc,
|
||||
rAddr: addr,
|
||||
payload: buf,
|
||||
}
|
||||
|
||||
ctx := inbound.NewPacket(l.target, packet, C.TUNNEL)
|
||||
ctx := inbound.NewPacket(l.target, packet, C.TUNNEL, additions...)
|
||||
ctx.Metadata().SpecialProxy = l.proxy
|
||||
select {
|
||||
case in <- ctx:
|
||||
|
Reference in New Issue
Block a user