mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-07 01:33:15 +08:00
Change: use nop for reject
This commit is contained in:
@@ -2,8 +2,9 @@ package proxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
M "github.com/xjasonlyu/tun2socks/constant"
|
||||
"github.com/xjasonlyu/tun2socks/proxy/proto"
|
||||
@@ -24,9 +25,30 @@ func NewReject() *Reject {
|
||||
}
|
||||
|
||||
func (r *Reject) DialContext(context.Context, *M.Metadata) (net.Conn, error) {
|
||||
return nil, errors.New("TCP rejected")
|
||||
return &nopConn{}, nil
|
||||
}
|
||||
|
||||
func (r *Reject) DialUDP(*M.Metadata) (net.PacketConn, error) {
|
||||
return nil, errors.New("UDP rejected")
|
||||
return &nopPacketConn{}, nil
|
||||
}
|
||||
|
||||
type nopConn struct{}
|
||||
|
||||
func (rw *nopConn) Read([]byte) (int, error) { return 0, io.EOF }
|
||||
func (rw *nopConn) Write([]byte) (int, error) { return 0, io.EOF }
|
||||
func (rw *nopConn) Close() error { return nil }
|
||||
func (rw *nopConn) LocalAddr() net.Addr { return nil }
|
||||
func (rw *nopConn) RemoteAddr() net.Addr { return nil }
|
||||
func (rw *nopConn) SetDeadline(time.Time) error { return nil }
|
||||
func (rw *nopConn) SetReadDeadline(time.Time) error { return nil }
|
||||
func (rw *nopConn) SetWriteDeadline(time.Time) error { return nil }
|
||||
|
||||
type nopPacketConn struct{}
|
||||
|
||||
func (npc *nopPacketConn) WriteTo(b []byte, _ net.Addr) (n int, err error) { return len(b), nil }
|
||||
func (npc *nopPacketConn) ReadFrom([]byte) (int, net.Addr, error) { return 0, nil, io.EOF }
|
||||
func (npc *nopPacketConn) Close() error { return nil }
|
||||
func (npc *nopPacketConn) LocalAddr() net.Addr { return &net.UDPAddr{IP: net.IPv4zero, Port: 0} }
|
||||
func (npc *nopPacketConn) SetDeadline(time.Time) error { return nil }
|
||||
func (npc *nopPacketConn) SetReadDeadline(time.Time) error { return nil }
|
||||
func (npc *nopPacketConn) SetWriteDeadline(time.Time) error { return nil }
|
||||
|
Reference in New Issue
Block a user