chore: rebuild add adapter/inbound.Addition to simply Listener.New apis

This commit is contained in:
wwqgtxx
2022-12-05 00:20:50 +08:00
parent c7f83d3ff1
commit 2e22c712af
30 changed files with 290 additions and 225 deletions

View File

@ -71,20 +71,37 @@ func New(config string, tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter
return sl, nil
}
func (l *Listener) Close() {
l.closed = true
func (l *Listener) Close() error {
var retErr error
for _, lis := range l.listeners {
_ = lis.Close()
err := lis.Close()
if err != nil {
retErr = err
}
}
for _, lis := range l.udpListeners {
_ = lis.Close()
err := lis.Close()
if err != nil {
retErr = err
}
}
return retErr
}
func (l *Listener) Config() string {
return l.config
}
func (l *Listener) AddrList() (addrList []net.Addr) {
for _, lis := range l.listeners {
addrList = append(addrList, lis.Addr())
}
for _, lis := range l.udpListeners {
addrList = append(addrList, lis.LocalAddr())
}
return
}
func (l *Listener) HandleConn(conn net.Conn, in chan<- C.ConnContext) {
conn = l.pickCipher.StreamConn(conn)

View File

@ -53,6 +53,10 @@ func (l *UDPListener) Close() error {
return l.packetConn.Close()
}
func (l *UDPListener) LocalAddr() net.Addr {
return l.packetConn.LocalAddr()
}
func handleSocksUDP(pc net.PacketConn, in chan<- C.PacketAdapter, buf []byte, addr net.Addr) {
tgtAddr := socks5.SplitAddr(buf)
if tgtAddr == nil {