add tun/tap
This commit is contained in:
@ -2,12 +2,13 @@ package v5
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-gost/gost/pkg/auth"
|
||||
tls_util "github.com/go-gost/gost/pkg/common/util/tls"
|
||||
md "github.com/go-gost/gost/pkg/metadata"
|
||||
mdata "github.com/go-gost/gost/pkg/metadata"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
@ -23,7 +24,7 @@ type metadata struct {
|
||||
compatibilityMode bool
|
||||
}
|
||||
|
||||
func (h *socks5Handler) parseMetadata(md md.Metadata) (err error) {
|
||||
func (h *socks5Handler) parseMetadata(md mdata.Metadata) (err error) {
|
||||
const (
|
||||
certFile = "certFile"
|
||||
keyFile = "keyFile"
|
||||
@ -40,49 +41,41 @@ func (h *socks5Handler) parseMetadata(md md.Metadata) (err error) {
|
||||
)
|
||||
|
||||
h.md.tlsConfig, err = tls_util.LoadServerConfig(
|
||||
md.GetString(certFile),
|
||||
md.GetString(keyFile),
|
||||
md.GetString(caFile),
|
||||
mdata.GetString(md, certFile),
|
||||
mdata.GetString(md, keyFile),
|
||||
mdata.GetString(md, caFile),
|
||||
)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if v, _ := md.Get(users).([]interface{}); len(v) > 0 {
|
||||
if auths := mdata.GetStrings(md, users); len(auths) > 0 {
|
||||
authenticator := auth.NewLocalAuthenticator(nil)
|
||||
for _, auth := range v {
|
||||
if s, _ := auth.(string); s != "" {
|
||||
ss := strings.SplitN(s, ":", 2)
|
||||
if len(ss) == 1 {
|
||||
authenticator.Add(ss[0], "")
|
||||
} else {
|
||||
authenticator.Add(ss[0], ss[1])
|
||||
}
|
||||
for _, auth := range auths {
|
||||
ss := strings.SplitN(auth, ":", 2)
|
||||
if len(ss) == 1 {
|
||||
authenticator.Add(ss[0], "")
|
||||
} else {
|
||||
authenticator.Add(ss[0], ss[1])
|
||||
}
|
||||
}
|
||||
h.md.authenticator = authenticator
|
||||
}
|
||||
|
||||
h.md.readTimeout = md.GetDuration(readTimeout)
|
||||
h.md.timeout = md.GetDuration(timeout)
|
||||
h.md.retryCount = md.GetInt(retryCount)
|
||||
h.md.noTLS = md.GetBool(noTLS)
|
||||
h.md.enableBind = md.GetBool(enableBind)
|
||||
h.md.enableUDP = md.GetBool(enableUDP)
|
||||
h.md.readTimeout = mdata.GetDuration(md, readTimeout)
|
||||
h.md.timeout = mdata.GetDuration(md, timeout)
|
||||
h.md.retryCount = mdata.GetInt(md, retryCount)
|
||||
h.md.noTLS = mdata.GetBool(md, noTLS)
|
||||
h.md.enableBind = mdata.GetBool(md, enableBind)
|
||||
h.md.enableUDP = mdata.GetBool(md, enableUDP)
|
||||
|
||||
h.md.udpBufferSize = md.GetInt(udpBufferSize)
|
||||
if h.md.udpBufferSize > 0 {
|
||||
if h.md.udpBufferSize < 512 {
|
||||
h.md.udpBufferSize = 512 // min buffer size
|
||||
}
|
||||
if h.md.udpBufferSize > 65*1024 {
|
||||
h.md.udpBufferSize = 65 * 1024 // max buffer size
|
||||
}
|
||||
if bs := mdata.GetInt(md, udpBufferSize); bs > 0 {
|
||||
h.md.udpBufferSize = int(math.Min(math.Max(float64(bs), 512), 64*1024))
|
||||
} else {
|
||||
h.md.udpBufferSize = 1024 // default buffer size
|
||||
h.md.udpBufferSize = 1024
|
||||
}
|
||||
|
||||
h.md.compatibilityMode = md.GetBool(compatibilityMode)
|
||||
h.md.compatibilityMode = mdata.GetBool(md, compatibilityMode)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user