chore: code cleanup

This commit is contained in:
wwqgtxx
2023-10-11 22:54:19 +08:00
parent 0dc6a726c1
commit 129283066f
14 changed files with 97 additions and 106 deletions

View File

@ -36,9 +36,7 @@ func (l *Listener) Close() error {
func (l *Listener) handleTCP(conn net.Conn, tunnel C.Tunnel, additions ...inbound.Addition) {
N.TCPKeepAlive(conn)
conn, metadata := inbound.NewSocket(l.target, conn, C.TUNNEL, additions...)
metadata.SpecialProxy = l.proxy
tunnel.HandleTCPConn(conn, metadata)
tunnel.HandleTCPConn(inbound.NewSocket(l.target, conn, C.TUNNEL, additions...))
}
func New(addr, target, proxy string, tunnel C.Tunnel, additions ...inbound.Addition) (*Listener, error) {
@ -59,6 +57,10 @@ func New(addr, target, proxy string, tunnel C.Tunnel, additions ...inbound.Addit
addr: addr,
}
if proxy != "" {
additions = append([]inbound.Addition{inbound.WithSpecialProxy(proxy)}, additions...)
}
go func() {
for {
c, err := l.Accept()

View File

@ -51,6 +51,11 @@ func NewUDP(addr, target, proxy string, tunnel C.Tunnel, additions ...inbound.Ad
proxy: proxy,
addr: addr,
}
if proxy != "" {
additions = append([]inbound.Addition{inbound.WithSpecialProxy(proxy)}, additions...)
}
go func() {
for {
buf := pool.Get(pool.UDPBufferSize)
@ -76,7 +81,5 @@ func (l *PacketConn) handleUDP(pc net.PacketConn, tunnel C.Tunnel, buf []byte, a
payload: buf,
}
packet, metadata := inbound.NewPacket(l.target, cPacket, C.TUNNEL, additions...)
metadata.SpecialProxy = l.proxy
tunnel.HandleUDPPacket(packet, metadata)
tunnel.HandleUDPPacket(inbound.NewPacket(l.target, cPacket, C.TUNNEL, additions...))
}