add knock option for probe resistance
This commit is contained in:
parent
6f0bf7da03
commit
86e9772f08
@ -438,6 +438,7 @@ func (r *route) GenRouters() ([]router, error) {
|
||||
gost.RetryHandlerOption(node.GetInt("retry")), // override the global retry option.
|
||||
gost.TimeoutHandlerOption(time.Duration(node.GetInt("timeout"))*time.Second),
|
||||
gost.ProbeResistHandlerOption(node.Get("probe_resist")),
|
||||
gost.KnockingHandlerOption(node.Get("knock")),
|
||||
gost.NodeHandlerOption(node),
|
||||
gost.IPsHandlerOption(ips),
|
||||
)
|
||||
|
@ -34,6 +34,7 @@ type HandlerOptions struct {
|
||||
Resolver Resolver
|
||||
Hosts *Hosts
|
||||
ProbeResist string
|
||||
KnockingHost string
|
||||
Node Node
|
||||
Host string
|
||||
IPs []string
|
||||
@ -150,6 +151,13 @@ func ProbeResistHandlerOption(pr string) HandlerOption {
|
||||
}
|
||||
}
|
||||
|
||||
// KnockingHandlerOption adds the knocking host for probe resistance.
|
||||
func KnockingHandlerOption(host string) HandlerOption {
|
||||
return func(opts *HandlerOptions) {
|
||||
opts.KnockingHost = host
|
||||
}
|
||||
}
|
||||
|
||||
// NodeHandlerOption set the server node for server handler.
|
||||
func NodeHandlerOption(node Node) HandlerOption {
|
||||
return func(opts *HandlerOptions) {
|
||||
|
5
http.go
5
http.go
@ -302,8 +302,9 @@ func (h *httpHandler) authenticate(conn net.Conn, req *http.Request, resp *http.
|
||||
return true
|
||||
}
|
||||
|
||||
// probing resistance is enabled
|
||||
if ss := strings.SplitN(h.options.ProbeResist, ":", 2); len(ss) == 2 {
|
||||
// probing resistance is enabled, and knocking host is mismatch.
|
||||
if ss := strings.SplitN(h.options.ProbeResist, ":", 2); len(ss) == 2 &&
|
||||
(h.options.KnockingHost == "" || !strings.EqualFold(req.URL.Hostname(), h.options.KnockingHost)) {
|
||||
resp.StatusCode = http.StatusServiceUnavailable // default status code
|
||||
|
||||
switch ss[0] {
|
||||
|
5
http2.go
5
http2.go
@ -461,8 +461,9 @@ func (h *http2Handler) authenticate(w http.ResponseWriter, r *http.Request, resp
|
||||
return true
|
||||
}
|
||||
|
||||
// probing resistance is enabled
|
||||
if ss := strings.SplitN(h.options.ProbeResist, ":", 2); len(ss) == 2 {
|
||||
// probing resistance is enabled, and knocking host is mismatch.
|
||||
if ss := strings.SplitN(h.options.ProbeResist, ":", 2); len(ss) == 2 &&
|
||||
(h.options.KnockingHost == "" || !strings.EqualFold(r.URL.Hostname(), h.options.KnockingHost)) {
|
||||
resp.StatusCode = http.StatusServiceUnavailable // default status code
|
||||
w.Header().Del("Proxy-Agent")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user