From 842920c39b19c0f51be92f160af3d0ff4d830d06 Mon Sep 17 00:00:00 2001 From: xjasonlyu Date: Thu, 15 Jul 2021 19:54:56 +0800 Subject: [PATCH] Feature: add reject proxy --- engine/parse.go | 2 ++ proxy/proto/proto.go | 3 +++ proxy/reject.go | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 proxy/reject.go diff --git a/engine/parse.go b/engine/parse.go index ad390d8..a86fd9a 100644 --- a/engine/parse.go +++ b/engine/parse.go @@ -48,6 +48,8 @@ func parseProxy(s string) (proxy.Proxy, error) { switch protocol { case proto.Direct.String(): return proxy.NewDirect(), nil + case proto.Reject.String(): + return proxy.NewReject(), nil case proto.Socks5.String(): return proxy.NewSocks5(parseSocks(u)) case proto.Shadowsocks.String(): diff --git a/proxy/proto/proto.go b/proxy/proto/proto.go index 4f7286d..07770e7 100644 --- a/proxy/proto/proto.go +++ b/proxy/proto/proto.go @@ -4,6 +4,7 @@ import "fmt" const ( Direct Proto = iota + Reject Shadowsocks Socks5 ) @@ -14,6 +15,8 @@ func (proto Proto) String() string { switch proto { case Direct: return "direct" + case Reject: + return "reject" case Shadowsocks: return "ss" case Socks5: diff --git a/proxy/reject.go b/proxy/reject.go new file mode 100644 index 0000000..bc00b5c --- /dev/null +++ b/proxy/reject.go @@ -0,0 +1,32 @@ +package proxy + +import ( + "context" + "errors" + "net" + + M "github.com/xjasonlyu/tun2socks/constant" + "github.com/xjasonlyu/tun2socks/proxy/proto" +) + +var _ Proxy = (*Reject)(nil) + +type Reject struct { + *Base +} + +func NewReject() *Reject { + return &Reject{ + Base: &Base{ + proto: proto.Reject, + }, + } +} + +func (r *Reject) DialContext(context.Context, *M.Metadata) (net.Conn, error) { + return nil, errors.New("TCP rejected") +} + +func (r *Reject) DialUDP(*M.Metadata) (net.PacketConn, error) { + return nil, errors.New("UDP rejected") +}