update handler options

This commit is contained in:
ginuerzh
2022-01-04 21:56:58 +08:00
parent 566e930010
commit c428b37a36
36 changed files with 468 additions and 524 deletions

View File

@ -1,41 +1,21 @@
package tun
import (
"strings"
"github.com/go-gost/gost/pkg/common/util/ss"
mdata "github.com/go-gost/gost/pkg/metadata"
"github.com/shadowsocks/go-shadowsocks2/core"
)
type metadata struct {
cipher core.Cipher
key string
bufferSize int
}
func (h *tunHandler) parseMetadata(md mdata.Metadata) (err error) {
const (
users = "users"
key = "key"
readTimeout = "readTimeout"
bufferSize = "bufferSize"
key = "key"
bufferSize = "bufferSize"
)
var method, password string
if auths := mdata.GetStrings(md, users); len(auths) > 0 {
auth := auths[0]
ss := strings.SplitN(auth, ":", 2)
if len(ss) == 1 {
method = ss[0]
} else {
method, password = ss[0], ss[1]
}
}
h.md.cipher, err = ss.ShadowCipher(method, password, mdata.GetString(md, key))
if err != nil {
return
}
h.md.key = mdata.GetString(md, key)
h.md.bufferSize = mdata.GetInt(md, bufferSize)
if h.md.bufferSize <= 0 {
h.md.bufferSize = 1024