Feature: add reject proxy

This commit is contained in:
xjasonlyu
2021-07-15 19:54:56 +08:00
parent 67cc84d1d0
commit 842920c39b
3 changed files with 37 additions and 0 deletions

View File

@@ -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():

View File

@@ -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:

32
proxy/reject.go Normal file
View File

@@ -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")
}