修订代码;

上一个commit认知错误,400和403并没有写反逻辑,已经改回
This commit is contained in:
e1732a364fed
2000-01-01 00:00:00 +00:00
parent fe843a1280
commit 538e0e9de7
4 changed files with 66 additions and 67 deletions

View File

@@ -1,6 +1,13 @@
[[listen]]
tag = "myreject"
protocol = "reject"
ip = "0.0.0.0"
port = 4433
extra = { type = "nginx"}
extra = { type = "nginx"} # type 可为 "", "http", "nginx", 推荐使用 nginx类型 来模拟。
# 本 reject 的listen 可以用于 最终回落, 比如下面代码。 当然本示例 只列了 一个listen。你可以在 listen其它协议的 配置文件中 放置一个 reject 的 listen 来作为回落。
# 换句话说,你直接把本文件 所有内容复制粘贴 到 其它 文件到末尾 即可 实现默认回落 到 reject 的用法。
[[fallback]]
dest = "@myreject"

View File

@@ -25,9 +25,9 @@ func tryRejectWithHttpRespAndClose(rejectType string, underlay net.Conn) {
bs = bs[:n]
_, _, _, _, failreason := httpLayer.ParseH1Request(bs, false)
if failreason == 0 {
underlay.Write([]byte(httpLayer.GetReal400Response()))
underlay.Write([]byte(httpLayer.GetReal403Response())) //forbiden
} else {
underlay.Write([]byte(httpLayer.GetReal403Response()))
underlay.Write([]byte(httpLayer.GetReal400Response())) //bad request, for non-http (illegal) request
}
}
@@ -41,10 +41,7 @@ type RejectCreator struct{}
func (RejectCreator) NewClientFromURL(url *url.URL) (Client, error) {
r := &RejectClient{}
nStr := url.Query().Get("type")
if nStr != "" {
r.theType = nStr
}
r.initWithUrl(url)
return r, nil
}
@@ -52,15 +49,51 @@ func (RejectCreator) NewClientFromURL(url *url.URL) (Client, error) {
func (RejectCreator) NewClient(dc *DialConf) (Client, error) {
r := &RejectClient{}
if dc.Extra != nil {
if thing := dc.Extra["type"]; thing != nil {
r.initWithCommonConf(&dc.CommonConf)
return r, nil
}
func (RejectCreator) NewServerFromURL(url *url.URL) (Server, error) {
r := &RejectServer{}
r.initWithUrl(url)
return r, nil
}
func (RejectCreator) NewServer(lc *ListenConf) (Server, error) {
r := &RejectServer{}
r.initWithCommonConf(&lc.CommonConf)
return r, nil
}
type rejectCommon struct {
Base
theType string
}
func (*rejectCommon) Name() string { return RejectName }
func (rc *rejectCommon) initWithUrl(url *url.URL) {
nStr := url.Query().Get("type")
if nStr != "" {
rc.theType = nStr
}
}
func (rc *rejectCommon) initWithCommonConf(cc *CommonConf) {
if cc.Extra != nil {
if thing := cc.Extra["type"]; thing != nil {
if t, ok := thing.(string); ok && t != "" {
r.theType = t
rc.theType = t
}
}
}
return r, nil
}
/*RejectClient implements Client, optionally response a 403 and close the underlay immediately.
@@ -77,14 +110,10 @@ func (RejectCreator) NewClient(dc *DialConf) (Client, error) {
默认为 "" 空类型直接 close不反回任何信息 若设为 http则返回一个403错误若设为nginx则分类返回400/403错误
*/
type RejectClient struct {
Base
theType string
rejectCommon
}
func (*RejectClient) Name() string { return RejectName }
//optionally response a 403 and close the underlay.
//optionally response 403 and close the underlay, return io.EOF.
func (c *RejectClient) Handshake(underlay net.Conn, _ []byte, _ netLayer.Addr) (result io.ReadWriteCloser, err error) {
tryRejectWithHttpRespAndClose(c.theType, underlay)
return nil, io.EOF
@@ -95,3 +124,16 @@ func (c *RejectClient) EstablishUDPChannel(underlay net.Conn, _ []byte, _ netLay
tryRejectWithHttpRespAndClose(c.theType, underlay)
return nil, io.EOF
}
//mimic the behavior of RejectClient
type RejectServer struct {
rejectCommon
}
//return utils.ErrHandled
func (s *RejectServer) Handshake(underlay net.Conn) (_ net.Conn, _ netLayer.MsgConn, _ netLayer.Addr, e error) {
tryRejectWithHttpRespAndClose(s.theType, underlay)
e = utils.ErrHandled
return
}

View File

@@ -1,50 +0,0 @@
package proxy
import (
"net"
"net/url"
"github.com/e1732a364fed/v2ray_simple/netLayer"
"github.com/e1732a364fed/v2ray_simple/utils"
)
func (RejectCreator) NewServerFromURL(url *url.URL) (Server, error) {
r := &RejectServer{}
nStr := url.Query().Get("type")
if nStr != "" {
r.theType = nStr
}
return r, nil
}
func (RejectCreator) NewServer(dc *ListenConf) (Server, error) {
r := &RejectServer{}
if dc.Extra != nil {
if thing := dc.Extra["type"]; thing != nil {
if t, ok := thing.(string); ok && t != "" {
r.theType = t
}
}
}
return r, nil
}
//mimic the behavior of RejectClient
type RejectServer struct {
Base
theType string
}
func (*RejectServer) Name() string { return RejectName }
//return utils.ErrHandled
func (s *RejectServer) Handshake(underlay net.Conn) (_ net.Conn, _ netLayer.MsgConn, _ netLayer.Addr, e error) {
tryRejectWithHttpRespAndClose(s.theType, underlay)
e = utils.ErrHandled
return
}