This commit is contained in:
ginuerzh
2021-11-15 12:55:05 +08:00
parent 3fe5084629
commit ce3d62759a
38 changed files with 788 additions and 291 deletions

View File

@ -4,12 +4,7 @@ import (
"time"
"github.com/go-gost/gost/pkg/auth"
)
const (
authsKey = "auths"
readTimeout = "readTimeout"
retryCount = "retry"
md "github.com/go-gost/gost/pkg/metadata"
)
type metadata struct {
@ -17,3 +12,25 @@ type metadata struct {
readTimeout time.Duration
retryCount int
}
func (h *socks4Handler) parseMetadata(md md.Metadata) (err error) {
const (
authsKey = "auths"
readTimeout = "readTimeout"
retryCount = "retry"
)
if v, _ := md.Get(authsKey).([]interface{}); len(v) > 0 {
authenticator := auth.NewLocalAuthenticator(nil)
for _, auth := range v {
if v, _ := auth.(string); v != "" {
authenticator.Add(v, "")
}
}
h.md.authenticator = authenticator
}
h.md.readTimeout = md.GetDuration(readTimeout)
h.md.retryCount = md.GetInt(retryCount)
return
}