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

@ -102,6 +102,7 @@ func parseChainSelector(cfg *config.SelectorConfig) chain.Selector[chain.Selecta
return chain.NewSelector(
strategy,
chain.FailFilter[chain.SelectableChainer](cfg.MaxFails, cfg.FailTimeout),
chain.BackupFilter[chain.SelectableChainer](),
)
}
@ -125,6 +126,7 @@ func parseNodeSelector(cfg *config.SelectorConfig) chain.Selector[*chain.Node] {
return chain.NewSelector(
strategy,
chain.FailFilter[*chain.Node](cfg.MaxFails, cfg.FailTimeout),
chain.BackupFilter[*chain.Node](),
)
}

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 {
@ -19,9 +19,9 @@ func (c *httpConnector) parseMetadata(md mdata.Metadata) (err error) {
header = "header"
)
c.md.connectTimeout = mdx.GetDuration(md, connectTimeout)
c.md.connectTimeout = mdutil.GetDuration(md, connectTimeout)
if mm := mdx.GetStringMapString(md, header); len(mm) > 0 {
if mm := mdutil.GetStringMapString(md, header); len(mm) > 0 {
hd := http.Header{}
for k, v := range mm {
hd.Add(k, v)

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 {
@ -19,8 +19,8 @@ func (c *http2Connector) parseMetadata(md mdata.Metadata) (err error) {
header = "header"
)
c.md.connectTimeout = mdx.GetDuration(md, connectTimeout)
if mm := mdx.GetStringMapString(md, header); len(mm) > 0 {
c.md.connectTimeout = mdutil.GetDuration(md, connectTimeout)
if mm := mdutil.GetStringMapString(md, header); len(mm) > 0 {
hd := http.Header{}
for k, v := range mm {
hd.Add(k, v)

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 (c *relayConnector) parseMetadata(md mdata.Metadata) (err error) {
noDelay = "nodelay"
)
c.md.connectTimeout = mdx.GetDuration(md, connectTimeout)
c.md.noDelay = mdx.GetBool(md, noDelay)
c.md.connectTimeout = mdutil.GetDuration(md, connectTimeout)
c.md.noDelay = mdutil.GetBool(md, noDelay)
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 {
@ -18,8 +18,8 @@ func (c *sniConnector) parseMetadata(md mdata.Metadata) (err error) {
connectTimeout = "timeout"
)
c.md.host = mdx.GetString(md, host)
c.md.connectTimeout = mdx.GetDuration(md, connectTimeout)
c.md.host = mdutil.GetString(md, host)
c.md.connectTimeout = mdutil.GetDuration(md, connectTimeout)
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 {
@ -18,8 +18,8 @@ func (c *socks4Connector) parseMetadata(md mdata.Metadata) (err error) {
disable4a = "disable4a"
)
c.md.connectTimeout = mdx.GetDuration(md, connectTimeout)
c.md.disable4a = mdx.GetBool(md, disable4a)
c.md.connectTimeout = mdutil.GetDuration(md, connectTimeout)
c.md.disable4a = mdutil.GetBool(md, disable4a)
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"
)
const (
@ -26,10 +26,10 @@ func (c *socks5Connector) parseMetadata(md mdata.Metadata) (err error) {
udpBufferSize = "udpBufferSize"
)
c.md.connectTimeout = mdx.GetDuration(md, connectTimeout)
c.md.noTLS = mdx.GetBool(md, noTLS)
c.md.relay = mdx.GetString(md, relay)
c.md.udpBufferSize = mdx.GetInt(md, udpBufferSize)
c.md.connectTimeout = mdutil.GetDuration(md, connectTimeout)
c.md.noTLS = mdutil.GetBool(md, noTLS)
c.md.relay = mdutil.GetString(md, relay)
c.md.udpBufferSize = mdutil.GetInt(md, udpBufferSize)
if c.md.udpBufferSize <= 0 {
c.md.udpBufferSize = defaultUDPBufferSize
}

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 {
@ -20,9 +20,9 @@ func (c *ssConnector) parseMetadata(md mdata.Metadata) (err error) {
noDelay = "nodelay"
)
c.md.key = mdx.GetString(md, key)
c.md.connectTimeout = mdx.GetDuration(md, connectTimeout)
c.md.noDelay = mdx.GetBool(md, noDelay)
c.md.key = mdutil.GetString(md, key)
c.md.connectTimeout = mdutil.GetDuration(md, connectTimeout)
c.md.noDelay = mdutil.GetBool(md, noDelay)
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 (c *ssuConnector) parseMetadata(md mdata.Metadata) (err error) {
bufferSize = "bufferSize" // udp buffer size
)
c.md.key = mdx.GetString(md, key)
c.md.connectTimeout = mdx.GetDuration(md, connectTimeout)
c.md.key = mdutil.GetString(md, key)
c.md.connectTimeout = mdutil.GetDuration(md, connectTimeout)
if bs := mdx.GetInt(md, bufferSize); bs > 0 {
if bs := mdutil.GetInt(md, bufferSize); bs > 0 {
c.md.bufferSize = int(math.Min(math.Max(float64(bs), 512), 64*1024))
} else {
c.md.bufferSize = 1500

View File

@ -2,7 +2,7 @@ package grpc
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 {
@ -18,9 +18,9 @@ func (d *grpcDialer) parseMetadata(md mdata.Metadata) (err error) {
path = "path"
)
d.md.insecure = mdx.GetBool(md, insecure)
d.md.host = mdx.GetString(md, host)
d.md.path = mdx.GetString(md, path)
d.md.insecure = mdutil.GetBool(md, insecure)
d.md.host = mdutil.GetString(md, host)
d.md.path = mdutil.GetString(md, path)
return
}

View File

@ -4,7 +4,7 @@ import (
"net/http"
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 {
@ -20,9 +20,9 @@ func (d *h2Dialer) parseMetadata(md mdata.Metadata) (err error) {
header = "header"
)
d.md.host = mdx.GetString(md, host)
d.md.path = mdx.GetString(md, path)
if m := mdx.GetStringMapString(md, header); len(m) > 0 {
d.md.host = mdutil.GetString(md, host)
d.md.path = mdutil.GetString(md, path)
if m := mdutil.GetStringMapString(md, header); len(m) > 0 {
h := http.Header{}
for k, v := range m {
h.Add(k, v)

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 (
@ -35,19 +35,19 @@ func (d *http3Dialer) parseMetadata(md mdata.Metadata) (err error) {
host = "host"
)
d.md.authorizePath = mdx.GetString(md, authorizePath)
d.md.authorizePath = mdutil.GetString(md, authorizePath)
if !strings.HasPrefix(d.md.authorizePath, "/") {
d.md.authorizePath = defaultAuthorizePath
}
d.md.pushPath = mdx.GetString(md, pushPath)
d.md.pushPath = mdutil.GetString(md, pushPath)
if !strings.HasPrefix(d.md.pushPath, "/") {
d.md.pushPath = defaultPushPath
}
d.md.pullPath = mdx.GetString(md, pullPath)
d.md.pullPath = mdutil.GetString(md, pullPath)
if !strings.HasPrefix(d.md.pullPath, "/") {
d.md.pullPath = defaultPullPath
}
d.md.host = mdx.GetString(md, host)
d.md.host = mdutil.GetString(md, host)
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 {
@ -21,14 +21,14 @@ func (d *icmpDialer) parseMetadata(md mdata.Metadata) (err error) {
maxIdleTimeout = "maxIdleTimeout"
)
if mdx.GetBool(md, keepAlive) {
d.md.keepAlivePeriod = mdx.GetDuration(md, keepAlivePeriod)
if mdutil.GetBool(md, keepAlive) {
d.md.keepAlivePeriod = mdutil.GetDuration(md, keepAlivePeriod)
if d.md.keepAlivePeriod <= 0 {
d.md.keepAlivePeriod = 10 * time.Second
}
}
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
d.md.maxIdleTimeout = mdx.GetDuration(md, maxIdleTimeout)
d.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
d.md.maxIdleTimeout = mdutil.GetDuration(md, maxIdleTimeout)
return
}

View File

@ -5,8 +5,8 @@ import (
"time"
mdata "github.com/go-gost/core/metadata"
mdutil "github.com/go-gost/core/metadata/util"
kcp_util "github.com/go-gost/x/internal/util/kcp"
mdx "github.com/go-gost/x/metadata"
)
type metadata struct {
@ -21,14 +21,14 @@ func (d *kcpDialer) parseMetadata(md mdata.Metadata) (err error) {
handshakeTimeout = "handshakeTimeout"
)
if file := mdx.GetString(md, configFile); file != "" {
if file := mdutil.GetString(md, configFile); file != "" {
d.md.config, err = kcp_util.ParseFromFile(file)
if err != nil {
return
}
}
if m := mdx.GetStringMap(md, config); len(m) > 0 {
if m := mdutil.GetStringMap(md, config); len(m) > 0 {
b, err := json.Marshal(m)
if err != nil {
return err
@ -43,6 +43,6 @@ func (d *kcpDialer) parseMetadata(md mdata.Metadata) (err error) {
d.md.config = kcp_util.DefaultConfig
}
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
d.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
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 {
@ -30,14 +30,14 @@ func (d *mtlsDialer) parseMetadata(md mdata.Metadata) (err error) {
muxMaxStreamBuffer = "muxMaxStreamBuffer"
)
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
d.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
d.md.muxKeepAliveDisabled = mdx.GetBool(md, muxKeepAliveDisabled)
d.md.muxKeepAliveInterval = mdx.GetDuration(md, muxKeepAliveInterval)
d.md.muxKeepAliveTimeout = mdx.GetDuration(md, muxKeepAliveTimeout)
d.md.muxMaxFrameSize = mdx.GetInt(md, muxMaxFrameSize)
d.md.muxMaxReceiveBuffer = mdx.GetInt(md, muxMaxReceiveBuffer)
d.md.muxMaxStreamBuffer = mdx.GetInt(md, muxMaxStreamBuffer)
d.md.muxKeepAliveDisabled = mdutil.GetBool(md, muxKeepAliveDisabled)
d.md.muxKeepAliveInterval = mdutil.GetDuration(md, muxKeepAliveInterval)
d.md.muxKeepAliveTimeout = mdutil.GetDuration(md, muxKeepAliveTimeout)
d.md.muxMaxFrameSize = mdutil.GetInt(md, muxMaxFrameSize)
d.md.muxMaxReceiveBuffer = mdutil.GetInt(md, muxMaxReceiveBuffer)
d.md.muxMaxStreamBuffer = mdutil.GetInt(md, muxMaxStreamBuffer)
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"
)
const (
@ -55,34 +55,34 @@ func (d *mwsDialer) parseMetadata(md mdata.Metadata) (err error) {
muxMaxStreamBuffer = "muxMaxStreamBuffer"
)
d.md.host = mdx.GetString(md, host)
d.md.host = mdutil.GetString(md, host)
d.md.path = mdx.GetString(md, path)
d.md.path = mdutil.GetString(md, path)
if d.md.path == "" {
d.md.path = defaultPath
}
d.md.muxKeepAliveDisabled = mdx.GetBool(md, muxKeepAliveDisabled)
d.md.muxKeepAliveInterval = mdx.GetDuration(md, muxKeepAliveInterval)
d.md.muxKeepAliveTimeout = mdx.GetDuration(md, muxKeepAliveTimeout)
d.md.muxMaxFrameSize = mdx.GetInt(md, muxMaxFrameSize)
d.md.muxMaxReceiveBuffer = mdx.GetInt(md, muxMaxReceiveBuffer)
d.md.muxMaxStreamBuffer = mdx.GetInt(md, muxMaxStreamBuffer)
d.md.muxKeepAliveDisabled = mdutil.GetBool(md, muxKeepAliveDisabled)
d.md.muxKeepAliveInterval = mdutil.GetDuration(md, muxKeepAliveInterval)
d.md.muxKeepAliveTimeout = mdutil.GetDuration(md, muxKeepAliveTimeout)
d.md.muxMaxFrameSize = mdutil.GetInt(md, muxMaxFrameSize)
d.md.muxMaxReceiveBuffer = mdutil.GetInt(md, muxMaxReceiveBuffer)
d.md.muxMaxStreamBuffer = mdutil.GetInt(md, muxMaxStreamBuffer)
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
d.md.readHeaderTimeout = mdx.GetDuration(md, readHeaderTimeout)
d.md.readBufferSize = mdx.GetInt(md, readBufferSize)
d.md.writeBufferSize = mdx.GetInt(md, writeBufferSize)
d.md.enableCompression = mdx.GetBool(md, enableCompression)
d.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
d.md.readHeaderTimeout = mdutil.GetDuration(md, readHeaderTimeout)
d.md.readBufferSize = mdutil.GetInt(md, readBufferSize)
d.md.writeBufferSize = mdutil.GetInt(md, writeBufferSize)
d.md.enableCompression = mdutil.GetBool(md, enableCompression)
if m := mdx.GetStringMapString(md, header); len(m) > 0 {
if m := mdutil.GetStringMapString(md, header); len(m) > 0 {
h := http.Header{}
for k, v := range m {
h.Add(k, v)
}
d.md.header = h
}
d.md.keepAlive = mdx.GetDuration(md, keepAlive)
d.md.keepAlive = mdutil.GetDuration(md, keepAlive)
return
}

View File

@ -4,7 +4,7 @@ import (
"net/http"
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,13 +18,13 @@ func (d *obfsHTTPDialer) parseMetadata(md mdata.Metadata) (err error) {
host = "host"
)
if m := mdx.GetStringMapString(md, header); len(m) > 0 {
if m := mdutil.GetStringMapString(md, header); len(m) > 0 {
h := http.Header{}
for k, v := range m {
h.Add(k, v)
}
d.md.header = h
}
d.md.host = mdx.GetString(md, host)
d.md.host = mdutil.GetString(md, host)
return
}

View File

@ -2,7 +2,7 @@ package tls
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 {
@ -14,6 +14,6 @@ func (d *obfsTLSDialer) parseMetadata(md mdata.Metadata) (err error) {
host = "host"
)
d.md.host = mdx.GetString(md, host)
d.md.host = mdutil.GetString(md, host)
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"
)
const (
@ -35,19 +35,19 @@ func (d *phtDialer) parseMetadata(md mdata.Metadata) (err error) {
host = "host"
)
d.md.authorizePath = mdx.GetString(md, authorizePath)
d.md.authorizePath = mdutil.GetString(md, authorizePath)
if !strings.HasPrefix(d.md.authorizePath, "/") {
d.md.authorizePath = defaultAuthorizePath
}
d.md.pushPath = mdx.GetString(md, pushPath)
d.md.pushPath = mdutil.GetString(md, pushPath)
if !strings.HasPrefix(d.md.pushPath, "/") {
d.md.pushPath = defaultPushPath
}
d.md.pullPath = mdx.GetString(md, pullPath)
d.md.pullPath = mdutil.GetString(md, pullPath)
if !strings.HasPrefix(d.md.pullPath, "/") {
d.md.pullPath = defaultPullPath
}
d.md.host = mdx.GetString(md, host)
d.md.host = mdutil.GetString(md, host)
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 {
@ -25,18 +25,18 @@ func (d *quicDialer) parseMetadata(md mdata.Metadata) (err error) {
cipherKey = "cipherKey"
)
if key := mdx.GetString(md, cipherKey); key != "" {
if key := mdutil.GetString(md, cipherKey); key != "" {
d.md.cipherKey = []byte(key)
}
if mdx.GetBool(md, keepAlive) {
d.md.keepAlivePeriod = mdx.GetDuration(md, keepAlivePeriod)
if mdutil.GetBool(md, keepAlive) {
d.md.keepAlivePeriod = mdutil.GetDuration(md, keepAlivePeriod)
if d.md.keepAlivePeriod <= 0 {
d.md.keepAlivePeriod = 10 * time.Second
}
}
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
d.md.maxIdleTimeout = mdx.GetDuration(md, maxIdleTimeout)
d.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
d.md.maxIdleTimeout = mdutil.GetDuration(md, maxIdleTimeout)
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"
"golang.org/x/crypto/ssh"
)
@ -21,13 +21,13 @@ func (d *sshDialer) parseMetadata(md mdata.Metadata) (err error) {
passphrase = "passphrase"
)
if key := mdx.GetString(md, privateKeyFile); key != "" {
if key := mdutil.GetString(md, privateKeyFile); key != "" {
data, err := ioutil.ReadFile(key)
if err != nil {
return err
}
pp := mdx.GetString(md, passphrase)
pp := mdutil.GetString(md, passphrase)
if pp == "" {
d.md.signer, err = ssh.ParsePrivateKey(data)
} else {
@ -38,7 +38,7 @@ func (d *sshDialer) parseMetadata(md mdata.Metadata) (err error) {
}
}
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
d.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
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"
"golang.org/x/crypto/ssh"
)
@ -21,13 +21,13 @@ func (d *sshdDialer) parseMetadata(md mdata.Metadata) (err error) {
passphrase = "passphrase"
)
if key := mdx.GetString(md, privateKeyFile); key != "" {
if key := mdutil.GetString(md, privateKeyFile); key != "" {
data, err := ioutil.ReadFile(key)
if err != nil {
return err
}
pp := mdx.GetString(md, passphrase)
pp := mdutil.GetString(md, passphrase)
if pp == "" {
d.md.signer, err = ssh.ParsePrivateKey(data)
} else {
@ -38,7 +38,7 @@ func (d *sshdDialer) parseMetadata(md mdata.Metadata) (err error) {
}
}
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
d.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
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,7 +16,7 @@ func (d *tlsDialer) parseMetadata(md mdata.Metadata) (err error) {
handshakeTimeout = "handshakeTimeout"
)
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
d.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
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"
)
const (
@ -43,20 +43,20 @@ func (d *wsDialer) parseMetadata(md mdata.Metadata) (err error) {
keepAlivePeriod = "ttl"
)
d.md.host = mdx.GetString(md, host)
d.md.host = mdutil.GetString(md, host)
d.md.path = mdx.GetString(md, path)
d.md.path = mdutil.GetString(md, path)
if d.md.path == "" {
d.md.path = defaultPath
}
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
d.md.readHeaderTimeout = mdx.GetDuration(md, readHeaderTimeout)
d.md.readBufferSize = mdx.GetInt(md, readBufferSize)
d.md.writeBufferSize = mdx.GetInt(md, writeBufferSize)
d.md.enableCompression = mdx.GetBool(md, enableCompression)
d.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
d.md.readHeaderTimeout = mdutil.GetDuration(md, readHeaderTimeout)
d.md.readBufferSize = mdutil.GetInt(md, readBufferSize)
d.md.writeBufferSize = mdutil.GetInt(md, writeBufferSize)
d.md.enableCompression = mdutil.GetBool(md, enableCompression)
if m := mdx.GetStringMapString(md, header); len(m) > 0 {
if m := mdutil.GetStringMapString(md, header); len(m) > 0 {
h := http.Header{}
for k, v := range m {
h.Add(k, v)
@ -64,8 +64,8 @@ func (d *wsDialer) parseMetadata(md mdata.Metadata) (err error) {
d.md.header = h
}
if mdx.GetBool(md, keepAlive) {
d.md.keepAlive = mdx.GetDuration(md, keepAlivePeriod)
if mdutil.GetBool(md, keepAlive) {
d.md.keepAlive = mdutil.GetDuration(md, keepAlivePeriod)
if d.md.keepAlive <= 0 {
d.md.keepAlive = defaultKeepAlivePeriod
}

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
}

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 (
@ -28,12 +28,12 @@ func (l *dnsListener) parseMetadata(md mdata.Metadata) (err error) {
writeTimeout = "writeTimeout"
)
l.md.mode = mdx.GetString(md, mode)
l.md.readBufferSize = mdx.GetInt(md, readBufferSize)
l.md.readTimeout = mdx.GetDuration(md, readTimeout)
l.md.writeTimeout = mdx.GetDuration(md, writeTimeout)
l.md.mode = mdutil.GetString(md, mode)
l.md.readBufferSize = mdutil.GetInt(md, readBufferSize)
l.md.readTimeout = mdutil.GetDuration(md, readTimeout)
l.md.writeTimeout = mdutil.GetDuration(md, writeTimeout)
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}

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 (
@ -30,21 +30,21 @@ func (l *ftcpListener) parseMetadata(md mdata.Metadata) (err error) {
backlog = "backlog"
)
l.md.ttl = mdx.GetDuration(md, ttl)
l.md.ttl = mdutil.GetDuration(md, ttl)
if l.md.ttl <= 0 {
l.md.ttl = defaultTTL
}
l.md.readBufferSize = mdx.GetInt(md, readBufferSize)
l.md.readBufferSize = mdutil.GetInt(md, readBufferSize)
if l.md.readBufferSize <= 0 {
l.md.readBufferSize = defaultReadBufferSize
}
l.md.readQueueSize = mdx.GetInt(md, readQueueSize)
l.md.readQueueSize = mdutil.GetInt(md, readQueueSize)
if l.md.readQueueSize <= 0 {
l.md.readQueueSize = defaultReadQueueSize
}
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}

View File

@ -2,7 +2,7 @@ package grpc
import (
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
const (
@ -22,12 +22,12 @@ func (l *grpcListener) parseMetadata(md mdata.Metadata) (err error) {
path = "path"
)
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}
l.md.insecure = mdx.GetBool(md, insecure)
l.md.path = mdx.GetString(md, path)
l.md.insecure = mdutil.GetBool(md, insecure)
l.md.path = mdutil.GetString(md, path)
return
}

View File

@ -2,7 +2,7 @@ package h2
import (
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
const (
@ -20,11 +20,11 @@ func (l *h2Listener) parseMetadata(md mdata.Metadata) (err error) {
backlog = "backlog"
)
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}
l.md.path = mdx.GetString(md, path)
l.md.path = mdutil.GetString(md, path)
return
}

View File

@ -2,7 +2,7 @@ package http2
import (
mdata "github.com/go-gost/core/metadata"
mdx "github.com/go-gost/x/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
const (
@ -18,7 +18,7 @@ func (l *http2Listener) parseMetadata(md mdata.Metadata) (err error) {
backlog = "backlog"
)
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}

View File

@ -4,7 +4,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"
)
const (
@ -30,20 +30,20 @@ func (l *http3Listener) parseMetadata(md mdata.Metadata) (err error) {
backlog = "backlog"
)
l.md.authorizePath = mdx.GetString(md, authorizePath)
l.md.authorizePath = mdutil.GetString(md, authorizePath)
if !strings.HasPrefix(l.md.authorizePath, "/") {
l.md.authorizePath = defaultAuthorizePath
}
l.md.pushPath = mdx.GetString(md, pushPath)
l.md.pushPath = mdutil.GetString(md, pushPath)
if !strings.HasPrefix(l.md.pushPath, "/") {
l.md.pushPath = defaultPushPath
}
l.md.pullPath = mdx.GetString(md, pullPath)
l.md.pullPath = mdutil.GetString(md, pullPath)
if !strings.HasPrefix(l.md.pullPath, "/") {
l.md.pullPath = defaultPullPath
}
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}

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 (
@ -29,19 +29,19 @@ func (l *icmpListener) parseMetadata(md mdata.Metadata) (err error) {
backlog = "backlog"
)
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}
if mdx.GetBool(md, keepAlive) {
l.md.keepAlivePeriod = mdx.GetDuration(md, keepAlivePeriod)
if mdutil.GetBool(md, keepAlive) {
l.md.keepAlivePeriod = mdutil.GetDuration(md, keepAlivePeriod)
if l.md.keepAlivePeriod <= 0 {
l.md.keepAlivePeriod = 10 * time.Second
}
}
l.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
l.md.maxIdleTimeout = mdx.GetDuration(md, maxIdleTimeout)
l.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
l.md.maxIdleTimeout = mdutil.GetDuration(md, maxIdleTimeout)
return
}

View File

@ -4,8 +4,8 @@ import (
"encoding/json"
mdata "github.com/go-gost/core/metadata"
mdutil "github.com/go-gost/core/metadata/util"
kcp_util "github.com/go-gost/x/internal/util/kcp"
mdx "github.com/go-gost/x/metadata"
)
const (
@ -24,14 +24,14 @@ func (l *kcpListener) parseMetadata(md mdata.Metadata) (err error) {
configFile = "c"
)
if file := mdx.GetString(md, configFile); file != "" {
if file := mdutil.GetString(md, configFile); file != "" {
l.md.config, err = kcp_util.ParseFromFile(file)
if err != nil {
return
}
}
if m := mdx.GetStringMap(md, config); len(m) > 0 {
if m := mdutil.GetStringMap(md, config); len(m) > 0 {
b, err := json.Marshal(m)
if err != nil {
return err
@ -47,7 +47,7 @@ func (l *kcpListener) parseMetadata(md mdata.Metadata) (err error) {
l.md.config = kcp_util.DefaultConfig
}
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}

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 (
@ -34,17 +34,17 @@ func (l *mtlsListener) parseMetadata(md mdata.Metadata) (err error) {
muxMaxStreamBuffer = "muxMaxStreamBuffer"
)
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}
l.md.muxKeepAliveDisabled = mdx.GetBool(md, muxKeepAliveDisabled)
l.md.muxKeepAliveInterval = mdx.GetDuration(md, muxKeepAliveInterval)
l.md.muxKeepAliveTimeout = mdx.GetDuration(md, muxKeepAliveTimeout)
l.md.muxMaxFrameSize = mdx.GetInt(md, muxMaxFrameSize)
l.md.muxMaxReceiveBuffer = mdx.GetInt(md, muxMaxReceiveBuffer)
l.md.muxMaxStreamBuffer = mdx.GetInt(md, muxMaxStreamBuffer)
l.md.muxKeepAliveDisabled = mdutil.GetBool(md, muxKeepAliveDisabled)
l.md.muxKeepAliveInterval = mdutil.GetDuration(md, muxKeepAliveInterval)
l.md.muxKeepAliveTimeout = mdutil.GetDuration(md, muxKeepAliveTimeout)
l.md.muxMaxFrameSize = mdutil.GetInt(md, muxMaxFrameSize)
l.md.muxMaxReceiveBuffer = mdutil.GetInt(md, muxMaxReceiveBuffer)
l.md.muxMaxStreamBuffer = mdutil.GetInt(md, muxMaxStreamBuffer)
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"
)
const (
@ -52,30 +52,30 @@ func (l *mwsListener) parseMetadata(md mdata.Metadata) (err error) {
muxMaxStreamBuffer = "muxMaxStreamBuffer"
)
l.md.path = mdx.GetString(md, path)
l.md.path = mdutil.GetString(md, path)
if l.md.path == "" {
l.md.path = defaultPath
}
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}
l.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
l.md.readHeaderTimeout = mdx.GetDuration(md, readHeaderTimeout)
l.md.readBufferSize = mdx.GetInt(md, readBufferSize)
l.md.writeBufferSize = mdx.GetInt(md, writeBufferSize)
l.md.enableCompression = mdx.GetBool(md, enableCompression)
l.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
l.md.readHeaderTimeout = mdutil.GetDuration(md, readHeaderTimeout)
l.md.readBufferSize = mdutil.GetInt(md, readBufferSize)
l.md.writeBufferSize = mdutil.GetInt(md, writeBufferSize)
l.md.enableCompression = mdutil.GetBool(md, enableCompression)
l.md.muxKeepAliveDisabled = mdx.GetBool(md, muxKeepAliveDisabled)
l.md.muxKeepAliveInterval = mdx.GetDuration(md, muxKeepAliveInterval)
l.md.muxKeepAliveTimeout = mdx.GetDuration(md, muxKeepAliveTimeout)
l.md.muxMaxFrameSize = mdx.GetInt(md, muxMaxFrameSize)
l.md.muxMaxReceiveBuffer = mdx.GetInt(md, muxMaxReceiveBuffer)
l.md.muxMaxStreamBuffer = mdx.GetInt(md, muxMaxStreamBuffer)
l.md.muxKeepAliveDisabled = mdutil.GetBool(md, muxKeepAliveDisabled)
l.md.muxKeepAliveInterval = mdutil.GetDuration(md, muxKeepAliveInterval)
l.md.muxKeepAliveTimeout = mdutil.GetDuration(md, muxKeepAliveTimeout)
l.md.muxMaxFrameSize = mdutil.GetInt(md, muxMaxFrameSize)
l.md.muxMaxReceiveBuffer = mdutil.GetInt(md, muxMaxReceiveBuffer)
l.md.muxMaxStreamBuffer = mdutil.GetInt(md, muxMaxStreamBuffer)
if mm := mdx.GetStringMapString(md, header); len(mm) > 0 {
if mm := mdutil.GetStringMapString(md, header); len(mm) > 0 {
hd := http.Header{}
for k, v := range mm {
hd.Add(k, v)

View File

@ -4,7 +4,7 @@ import (
"net/http"
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,7 +16,7 @@ func (l *obfsListener) parseMetadata(md mdata.Metadata) (err error) {
header = "header"
)
if mm := mdx.GetStringMapString(md, header); len(mm) > 0 {
if mm := mdutil.GetStringMapString(md, header); len(mm) > 0 {
hd := http.Header{}
for k, v := range mm {
hd.Add(k, v)

View File

@ -4,7 +4,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"
)
const (
@ -30,20 +30,20 @@ func (l *phtListener) parseMetadata(md mdata.Metadata) (err error) {
backlog = "backlog"
)
l.md.authorizePath = mdx.GetString(md, authorizePath)
l.md.authorizePath = mdutil.GetString(md, authorizePath)
if !strings.HasPrefix(l.md.authorizePath, "/") {
l.md.authorizePath = defaultAuthorizePath
}
l.md.pushPath = mdx.GetString(md, pushPath)
l.md.pushPath = mdutil.GetString(md, pushPath)
if !strings.HasPrefix(l.md.pushPath, "/") {
l.md.pushPath = defaultPushPath
}
l.md.pullPath = mdx.GetString(md, pullPath)
l.md.pullPath = mdutil.GetString(md, pullPath)
if !strings.HasPrefix(l.md.pullPath, "/") {
l.md.pullPath = defaultPullPath
}
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}

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 (
@ -32,23 +32,23 @@ func (l *quicListener) parseMetadata(md mdata.Metadata) (err error) {
cipherKey = "cipherKey"
)
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}
if key := mdx.GetString(md, cipherKey); key != "" {
if key := mdutil.GetString(md, cipherKey); key != "" {
l.md.cipherKey = []byte(key)
}
if mdx.GetBool(md, keepAlive) {
l.md.keepAlivePeriod = mdx.GetDuration(md, keepAlivePeriod)
if mdutil.GetBool(md, keepAlive) {
l.md.keepAlivePeriod = mdutil.GetDuration(md, keepAlivePeriod)
if l.md.keepAlivePeriod <= 0 {
l.md.keepAlivePeriod = 10 * time.Second
}
}
l.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
l.md.maxIdleTimeout = mdx.GetDuration(md, maxIdleTimeout)
l.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
l.md.maxIdleTimeout = mdutil.GetDuration(md, maxIdleTimeout)
return
}

View File

@ -2,7 +2,7 @@ package tcp
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 {
@ -13,6 +13,6 @@ func (l *redirectListener) parseMetadata(md mdata.Metadata) (err error) {
const (
tproxy = "tproxy"
)
l.md.tproxy = mdx.GetBool(md, tproxy)
l.md.tproxy = mdutil.GetBool(md, tproxy)
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"
)
const (
@ -23,12 +23,12 @@ func (l *redirectListener) parseMetadata(md mdata.Metadata) (err error) {
readBufferSize = "readBufferSize"
)
l.md.ttl = mdx.GetDuration(md, ttl)
l.md.ttl = mdutil.GetDuration(md, ttl)
if l.md.ttl <= 0 {
l.md.ttl = defaultTTL
}
l.md.readBufferSize = mdx.GetInt(md, readBufferSize)
l.md.readBufferSize = mdutil.GetInt(md, readBufferSize)
if l.md.readBufferSize <= 0 {
l.md.readBufferSize = defaultReadBufferSize
}

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 (
@ -29,21 +29,21 @@ func (l *rudpListener) parseMetadata(md mdata.Metadata) (err error) {
backlog = "backlog"
)
l.md.ttl = mdx.GetDuration(md, ttl)
l.md.ttl = mdutil.GetDuration(md, ttl)
if l.md.ttl <= 0 {
l.md.ttl = defaultTTL
}
l.md.readBufferSize = mdx.GetInt(md, readBufferSize)
l.md.readBufferSize = mdutil.GetInt(md, readBufferSize)
if l.md.readBufferSize <= 0 {
l.md.readBufferSize = defaultReadBufferSize
}
l.md.readQueueSize = mdx.GetInt(md, readQueueSize)
l.md.readQueueSize = mdutil.GetInt(md, readQueueSize)
if l.md.readQueueSize <= 0 {
l.md.readQueueSize = defaultReadQueueSize
}
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}

View File

@ -4,8 +4,8 @@ import (
"io/ioutil"
mdata "github.com/go-gost/core/metadata"
mdutil "github.com/go-gost/core/metadata/util"
ssh_util "github.com/go-gost/x/internal/util/ssh"
mdx "github.com/go-gost/x/metadata"
"golang.org/x/crypto/ssh"
)
@ -27,13 +27,13 @@ func (l *sshListener) parseMetadata(md mdata.Metadata) (err error) {
backlog = "backlog"
)
if key := mdx.GetString(md, privateKeyFile); key != "" {
if key := mdutil.GetString(md, privateKeyFile); key != "" {
data, err := ioutil.ReadFile(key)
if err != nil {
return err
}
pp := mdx.GetString(md, passphrase)
pp := mdutil.GetString(md, passphrase)
if pp == "" {
l.md.signer, err = ssh.ParsePrivateKey(data)
} else {
@ -51,7 +51,7 @@ func (l *sshListener) parseMetadata(md mdata.Metadata) (err error) {
l.md.signer = signer
}
if name := mdx.GetString(md, authorizedKeys); name != "" {
if name := mdutil.GetString(md, authorizedKeys); name != "" {
m, err := ssh_util.ParseAuthorizedKeysFile(name)
if err != nil {
return err
@ -59,7 +59,7 @@ func (l *sshListener) parseMetadata(md mdata.Metadata) (err error) {
l.md.authorizedKeys = m
}
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}

View File

@ -4,8 +4,8 @@ import (
"io/ioutil"
mdata "github.com/go-gost/core/metadata"
mdutil "github.com/go-gost/core/metadata/util"
ssh_util "github.com/go-gost/x/internal/util/ssh"
mdx "github.com/go-gost/x/metadata"
"golang.org/x/crypto/ssh"
)
@ -27,13 +27,13 @@ func (l *sshdListener) parseMetadata(md mdata.Metadata) (err error) {
backlog = "backlog"
)
if key := mdx.GetString(md, privateKeyFile); key != "" {
if key := mdutil.GetString(md, privateKeyFile); key != "" {
data, err := ioutil.ReadFile(key)
if err != nil {
return err
}
pp := mdx.GetString(md, passphrase)
pp := mdutil.GetString(md, passphrase)
if pp == "" {
l.md.signer, err = ssh.ParsePrivateKey(data)
} else {
@ -51,7 +51,7 @@ func (l *sshdListener) parseMetadata(md mdata.Metadata) (err error) {
l.md.signer = signer
}
if name := mdx.GetString(md, authorizedKeys); name != "" {
if name := mdutil.GetString(md, authorizedKeys); name != "" {
m, err := ssh_util.ParseAuthorizedKeysFile(name)
if err != nil {
return err
@ -59,7 +59,7 @@ func (l *sshdListener) parseMetadata(md mdata.Metadata) (err error) {
l.md.authorizedKeys = m
}
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}

View File

@ -2,8 +2,8 @@ package tap
import (
mdata "github.com/go-gost/core/metadata"
mdutil "github.com/go-gost/core/metadata/util"
tap_util "github.com/go-gost/x/internal/util/tap"
mdx "github.com/go-gost/x/metadata"
)
const (
@ -24,16 +24,16 @@ func (l *tapListener) parseMetadata(md mdata.Metadata) (err error) {
)
config := &tap_util.Config{
Name: mdx.GetString(md, name),
Net: mdx.GetString(md, netKey),
MTU: mdx.GetInt(md, mtu),
Gateway: mdx.GetString(md, gateway),
Name: mdutil.GetString(md, name),
Net: mdutil.GetString(md, netKey),
MTU: mdutil.GetInt(md, mtu),
Gateway: mdutil.GetString(md, gateway),
}
if config.MTU <= 0 {
config.MTU = DefaultMTU
}
for _, s := range mdx.GetStrings(md, routes) {
for _, s := range mdutil.GetStrings(md, routes) {
if s != "" {
config.Routes = append(config.Routes, s)
}

View File

@ -5,8 +5,8 @@ import (
"strings"
mdata "github.com/go-gost/core/metadata"
mdutil "github.com/go-gost/core/metadata/util"
tun_util "github.com/go-gost/x/internal/util/tun"
mdx "github.com/go-gost/x/metadata"
)
const (
@ -29,11 +29,11 @@ func (l *tunListener) parseMetadata(md mdata.Metadata) (err error) {
)
config := &tun_util.Config{
Name: mdx.GetString(md, name),
Net: mdx.GetString(md, netKey),
Peer: mdx.GetString(md, peer),
MTU: mdx.GetInt(md, mtu),
Gateway: mdx.GetString(md, gateway),
Name: mdutil.GetString(md, name),
Net: mdutil.GetString(md, netKey),
Peer: mdutil.GetString(md, peer),
MTU: mdutil.GetInt(md, mtu),
Gateway: mdutil.GetString(md, gateway),
}
if config.MTU <= 0 {
config.MTU = DefaultMTU
@ -41,7 +41,7 @@ func (l *tunListener) parseMetadata(md mdata.Metadata) (err error) {
gw := net.ParseIP(config.Gateway)
for _, s := range strings.Split(mdx.GetString(md, route), ",") {
for _, s := range strings.Split(mdutil.GetString(md, route), ",") {
var route tun_util.Route
_, ipNet, _ := net.ParseCIDR(strings.TrimSpace(s))
if ipNet == nil {
@ -53,7 +53,7 @@ func (l *tunListener) parseMetadata(md mdata.Metadata) (err error) {
config.Routes = append(config.Routes, route)
}
for _, s := range mdx.GetStrings(md, routes) {
for _, s := range mdutil.GetStrings(md, routes) {
ss := strings.SplitN(s, " ", 2)
if len(ss) == 2 {
var route tun_util.Route

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 (
@ -31,25 +31,25 @@ func (l *udpListener) parseMetadata(md mdata.Metadata) (err error) {
ttl = "ttl"
)
l.md.ttl = mdx.GetDuration(md, ttl)
l.md.ttl = mdutil.GetDuration(md, ttl)
if l.md.ttl <= 0 {
l.md.ttl = defaultTTL
}
l.md.readBufferSize = mdx.GetInt(md, readBufferSize)
l.md.readBufferSize = mdutil.GetInt(md, readBufferSize)
if l.md.readBufferSize <= 0 {
l.md.readBufferSize = defaultReadBufferSize
}
l.md.readQueueSize = mdx.GetInt(md, readQueueSize)
l.md.readQueueSize = mdutil.GetInt(md, readQueueSize)
if l.md.readQueueSize <= 0 {
l.md.readQueueSize = defaultReadQueueSize
}
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}
l.md.keepalive = mdx.GetBool(md, keepAlive)
l.md.keepalive = mdutil.GetBool(md, keepAlive)
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"
)
const (
@ -40,23 +40,23 @@ func (l *wsListener) parseMetadata(md mdata.Metadata) (err error) {
header = "header"
)
l.md.path = mdx.GetString(md, path)
l.md.path = mdutil.GetString(md, path)
if l.md.path == "" {
l.md.path = defaultPath
}
l.md.backlog = mdx.GetInt(md, backlog)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}
l.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
l.md.readHeaderTimeout = mdx.GetDuration(md, readHeaderTimeout)
l.md.readBufferSize = mdx.GetInt(md, readBufferSize)
l.md.writeBufferSize = mdx.GetInt(md, writeBufferSize)
l.md.enableCompression = mdx.GetBool(md, enableCompression)
l.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
l.md.readHeaderTimeout = mdutil.GetDuration(md, readHeaderTimeout)
l.md.readBufferSize = mdutil.GetInt(md, readBufferSize)
l.md.writeBufferSize = mdutil.GetInt(md, writeBufferSize)
l.md.enableCompression = mdutil.GetBool(md, enableCompression)
if mm := mdx.GetStringMapString(md, header); len(mm) > 0 {
if mm := mdutil.GetStringMapString(md, header); len(mm) > 0 {
hd := http.Header{}
for k, v := range mm {
hd.Add(k, v)

View File

@ -1,10 +1,6 @@
package metadata
import (
"fmt"
"strconv"
"time"
"github.com/go-gost/core/metadata"
)
@ -29,120 +25,3 @@ func (m mapMetadata) Get(key string) any {
}
return nil
}
func GetBool(md metadata.Metadata, key string) (v bool) {
if md == nil || !md.IsExists(key) {
return
}
switch vv := md.Get(key).(type) {
case bool:
return vv
case int:
return vv != 0
case string:
v, _ = strconv.ParseBool(vv)
return
}
return
}
func GetInt(md metadata.Metadata, key string) (v int) {
if md == nil {
return
}
switch vv := md.Get(key).(type) {
case bool:
if vv {
v = 1
}
case int:
return vv
case string:
v, _ = strconv.Atoi(vv)
return
}
return
}
func GetFloat(md metadata.Metadata, key string) (v float64) {
if md == nil {
return
}
switch vv := md.Get(key).(type) {
case int:
return float64(vv)
case string:
v, _ = strconv.ParseFloat(vv, 64)
return
}
return
}
func GetDuration(md metadata.Metadata, key string) (v time.Duration) {
if md == nil {
return
}
switch vv := md.Get(key).(type) {
case int:
return time.Duration(vv) * time.Second
case string:
v, _ = time.ParseDuration(vv)
if v == 0 {
n, _ := strconv.Atoi(vv)
v = time.Duration(n) * time.Second
}
}
return
}
func GetString(md metadata.Metadata, key string) (v string) {
if md != nil {
v, _ = md.Get(key).(string)
}
return
}
func GetStrings(md metadata.Metadata, key string) (ss []string) {
switch v := md.Get(key).(type) {
case []string:
ss = v
case []any:
for _, vv := range v {
if s, ok := vv.(string); ok {
ss = append(ss, s)
}
}
}
return
}
func GetStringMap(md metadata.Metadata, key string) (m map[string]any) {
switch vv := md.Get(key).(type) {
case map[string]any:
return vv
case map[any]any:
m = make(map[string]any)
for k, v := range vv {
m[fmt.Sprintf("%v", k)] = v
}
}
return
}
func GetStringMapString(md metadata.Metadata, key string) (m map[string]string) {
switch vv := md.Get(key).(type) {
case map[string]any:
m = make(map[string]string)
for k, v := range vv {
m[k] = fmt.Sprintf("%v", v)
}
case map[any]any:
m = make(map[string]string)
for k, v := range vv {
m[fmt.Sprintf("%v", k)] = fmt.Sprintf("%v", v)
}
}
return
}