add backup filter

This commit is contained in:
ginuerzh
2022-09-02 11:52:44 +08:00
parent 9b695bc374
commit 09dbdbb03c
61 changed files with 289 additions and 408 deletions

View File

@ -5,7 +5,7 @@ import (
"time"
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
const (
@ -33,18 +33,18 @@ func (h *dnsHandler) parseMetadata(md mdata.Metadata) (err error) {
bufferSize = "bufferSize"
)
h.md.readTimeout = mdx.GetDuration(md, readTimeout)
h.md.ttl = mdx.GetDuration(md, ttl)
h.md.timeout = mdx.GetDuration(md, timeout)
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
h.md.ttl = mdutil.GetDuration(md, ttl)
h.md.timeout = mdutil.GetDuration(md, timeout)
if h.md.timeout <= 0 {
h.md.timeout = defaultTimeout
}
sip := mdx.GetString(md, clientIP)
sip := mdutil.GetString(md, clientIP)
if sip != "" {
h.md.clientIP = net.ParseIP(sip)
}
h.md.dns = mdx.GetStrings(md, dns)
h.md.bufferSize = mdx.GetInt(md, bufferSize)
h.md.dns = mdutil.GetStrings(md, dns)
h.md.bufferSize = mdutil.GetInt(md, bufferSize)
if h.md.bufferSize <= 0 {
h.md.bufferSize = defaultBufferSize
}

View File

@ -4,7 +4,7 @@ import (
"time"
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
type metadata struct {
@ -16,6 +16,6 @@ func (h *forwardHandler) parseMetadata(md mdata.Metadata) (err error) {
readTimeout = "readTimeout"
)
h.md.readTimeout = mdx.GetDuration(md, readTimeout)
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
return
}

View File

@ -4,7 +4,7 @@ import (
"time"
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
type metadata struct {
@ -16,6 +16,6 @@ func (h *forwardHandler) parseMetadata(md mdata.Metadata) (err error) {
readTimeout = "readTimeout"
)
h.md.readTimeout = mdx.GetDuration(md, readTimeout)
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
return
}

View File

@ -5,7 +5,7 @@ import (
"strings"
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
type metadata struct {
@ -23,7 +23,7 @@ func (h *httpHandler) parseMetadata(md mdata.Metadata) error {
enableUDP = "udp"
)
if m := mdx.GetStringMapString(md, header); len(m) > 0 {
if m := mdutil.GetStringMapString(md, header); len(m) > 0 {
hd := http.Header{}
for k, v := range m {
hd.Add(k, v)
@ -31,20 +31,20 @@ func (h *httpHandler) parseMetadata(md mdata.Metadata) error {
h.md.header = hd
}
pr := mdx.GetString(md, probeResistKey)
pr := mdutil.GetString(md, probeResistKey)
if pr == "" {
pr = mdx.GetString(md, probeResistKeyX)
pr = mdutil.GetString(md, probeResistKeyX)
}
if pr != "" {
if ss := strings.SplitN(pr, ":", 2); len(ss) == 2 {
h.md.probeResistance = &probeResistance{
Type: ss[0],
Value: ss[1],
Knock: mdx.GetString(md, knock),
Knock: mdutil.GetString(md, knock),
}
}
}
h.md.enableUDP = mdx.GetBool(md, enableUDP)
h.md.enableUDP = mdutil.GetBool(md, enableUDP)
return nil
}

View File

@ -5,7 +5,7 @@ import (
"strings"
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
type metadata struct {
@ -21,7 +21,7 @@ func (h *http2Handler) parseMetadata(md mdata.Metadata) error {
knock = "knock"
)
if m := mdx.GetStringMapString(md, header); len(m) > 0 {
if m := mdutil.GetStringMapString(md, header); len(m) > 0 {
hd := http.Header{}
for k, v := range m {
hd.Add(k, v)
@ -29,16 +29,16 @@ func (h *http2Handler) parseMetadata(md mdata.Metadata) error {
h.md.header = hd
}
pr := mdx.GetString(md, probeResistKey)
pr := mdutil.GetString(md, probeResistKey)
if pr == "" {
pr = mdx.GetString(md, probeResistKeyX)
pr = mdutil.GetString(md, probeResistKeyX)
}
if pr != "" {
if ss := strings.SplitN(pr, ":", 2); len(ss) == 2 {
h.md.probeResistance = &probeResistance{
Type: ss[0],
Value: ss[1],
Knock: mdx.GetString(md, knock),
Knock: mdutil.GetString(md, knock),
}
}
}

View File

@ -2,7 +2,7 @@ package redirect
import (
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
type metadata struct {
@ -15,7 +15,7 @@ func (h *redirectHandler) parseMetadata(md mdata.Metadata) (err error) {
sniffing = "sniffing"
tproxy = "tproxy"
)
h.md.sniffing = mdx.GetBool(md, sniffing)
h.md.tproxy = mdx.GetBool(md, tproxy)
h.md.sniffing = mdutil.GetBool(md, sniffing)
h.md.tproxy = mdutil.GetBool(md, tproxy)
return
}

View File

@ -5,7 +5,7 @@ import (
"time"
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
type metadata struct {
@ -23,11 +23,11 @@ func (h *relayHandler) parseMetadata(md mdata.Metadata) (err error) {
noDelay = "nodelay"
)
h.md.readTimeout = mdx.GetDuration(md, readTimeout)
h.md.enableBind = mdx.GetBool(md, enableBind)
h.md.noDelay = mdx.GetBool(md, noDelay)
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
h.md.enableBind = mdutil.GetBool(md, enableBind)
h.md.noDelay = mdutil.GetBool(md, noDelay)
if bs := mdx.GetInt(md, udpBufferSize); bs > 0 {
if bs := mdutil.GetInt(md, udpBufferSize); bs > 0 {
h.md.udpBufferSize = int(math.Min(math.Max(float64(bs), 512), 64*1024))
} else {
h.md.udpBufferSize = 1500

View File

@ -4,7 +4,7 @@ import (
"time"
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
type metadata struct {
@ -16,6 +16,6 @@ func (h *sniHandler) parseMetadata(md mdata.Metadata) (err error) {
readTimeout = "readTimeout"
)
h.md.readTimeout = mdx.GetDuration(md, readTimeout)
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
return
}

View File

@ -4,7 +4,7 @@ import (
"time"
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
type metadata struct {
@ -16,6 +16,6 @@ func (h *socks4Handler) parseMetadata(md mdata.Metadata) (err error) {
readTimeout = "readTimeout"
)
h.md.readTimeout = mdx.GetDuration(md, readTimeout)
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
return
}

View File

@ -5,7 +5,7 @@ import (
"time"
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
type metadata struct {
@ -27,18 +27,18 @@ func (h *socks5Handler) parseMetadata(md mdata.Metadata) (err error) {
compatibilityMode = "comp"
)
h.md.readTimeout = mdx.GetDuration(md, readTimeout)
h.md.noTLS = mdx.GetBool(md, noTLS)
h.md.enableBind = mdx.GetBool(md, enableBind)
h.md.enableUDP = mdx.GetBool(md, enableUDP)
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
h.md.noTLS = mdutil.GetBool(md, noTLS)
h.md.enableBind = mdutil.GetBool(md, enableBind)
h.md.enableUDP = mdutil.GetBool(md, enableUDP)
if bs := mdx.GetInt(md, udpBufferSize); bs > 0 {
if bs := mdutil.GetInt(md, udpBufferSize); bs > 0 {
h.md.udpBufferSize = int(math.Min(math.Max(float64(bs), 512), 64*1024))
} else {
h.md.udpBufferSize = 1500
}
h.md.compatibilityMode = mdx.GetBool(md, compatibilityMode)
h.md.compatibilityMode = mdutil.GetBool(md, compatibilityMode)
return nil
}

View File

@ -4,7 +4,7 @@ import (
"time"
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
type metadata struct {
@ -18,8 +18,8 @@ func (h *ssHandler) parseMetadata(md mdata.Metadata) (err error) {
readTimeout = "readTimeout"
)
h.md.key = mdx.GetString(md, key)
h.md.readTimeout = mdx.GetDuration(md, readTimeout)
h.md.key = mdutil.GetString(md, key)
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
return
}

View File

@ -5,7 +5,7 @@ import (
"time"
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
type metadata struct {
@ -21,10 +21,10 @@ func (h *ssuHandler) parseMetadata(md mdata.Metadata) (err error) {
bufferSize = "bufferSize"
)
h.md.key = mdx.GetString(md, key)
h.md.readTimeout = mdx.GetDuration(md, readTimeout)
h.md.key = mdutil.GetString(md, key)
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
if bs := mdx.GetInt(md, bufferSize); bs > 0 {
if bs := mdutil.GetInt(md, bufferSize); bs > 0 {
h.md.bufferSize = int(math.Min(math.Max(float64(bs), 512), 64*1024))
} else {
h.md.bufferSize = 1500

View File

@ -2,7 +2,7 @@ package tap
import (
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
type metadata struct {
@ -16,8 +16,8 @@ func (h *tapHandler) parseMetadata(md mdata.Metadata) (err error) {
bufferSize = "bufferSize"
)
h.md.key = mdx.GetString(md, key)
h.md.bufferSize = mdx.GetInt(md, bufferSize)
h.md.key = mdutil.GetString(md, key)
h.md.bufferSize = mdutil.GetInt(md, bufferSize)
if h.md.bufferSize <= 0 {
h.md.bufferSize = 1500
}

View File

@ -4,7 +4,7 @@ import (
"time"
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
const (
@ -23,13 +23,13 @@ func (h *tunHandler) parseMetadata(md mdata.Metadata) (err error) {
keepAlivePeriod = "ttl"
)
h.md.bufferSize = mdx.GetInt(md, bufferSize)
h.md.bufferSize = mdutil.GetInt(md, bufferSize)
if h.md.bufferSize <= 0 {
h.md.bufferSize = 1500
}
if mdx.GetBool(md, keepAlive) {
h.md.keepAlivePeriod = mdx.GetDuration(md, keepAlivePeriod)
if mdutil.GetBool(md, keepAlive) {
h.md.keepAlivePeriod = mdutil.GetDuration(md, keepAlivePeriod)
if h.md.keepAlivePeriod <= 0 {
h.md.keepAlivePeriod = defaultKeepAlivePeriod
}