update config

This commit is contained in:
ginuerzh
2022-01-03 23:45:49 +08:00
parent 14537d16ea
commit 566e930010
42 changed files with 412 additions and 521 deletions

View File

@ -6,6 +6,7 @@ import (
"strconv"
"time"
"github.com/go-gost/gost/pkg/auth"
"github.com/go-gost/gost/pkg/bypass"
"github.com/go-gost/gost/pkg/chain"
"github.com/go-gost/gost/pkg/handler"
@ -20,11 +21,12 @@ func init() {
}
type relayHandler struct {
group *chain.NodeGroup
bypass bypass.Bypass
router *chain.Router
logger logger.Logger
md metadata
group *chain.NodeGroup
bypass bypass.Bypass
router *chain.Router
authenticator auth.Authenticator
logger logger.Logger
md metadata
}
func NewHandler(opts ...handler.Option) handler.Handler {
@ -107,7 +109,7 @@ func (h *relayHandler) Handle(ctx context.Context, conn net.Conn) {
Version: relay.Version1,
Status: relay.StatusOK,
}
if h.md.authenticator != nil && !h.md.authenticator.Authenticate(user, pass) {
if h.authenticator != nil && !h.authenticator.Authenticate(user, pass) {
resp.Status = relay.StatusUnauthorized
resp.WriteTo(conn)
h.logger.Error("unauthorized")

View File

@ -2,15 +2,12 @@ package relay
import (
"math"
"strings"
"time"
"github.com/go-gost/gost/pkg/auth"
mdata "github.com/go-gost/gost/pkg/metadata"
)
type metadata struct {
authenticator auth.Authenticator
readTimeout time.Duration
enableBind bool
udpBufferSize int
@ -19,26 +16,12 @@ type metadata struct {
func (h *relayHandler) parseMetadata(md mdata.Metadata) (err error) {
const (
users = "users"
readTimeout = "readTimeout"
enableBind = "bind"
udpBufferSize = "udpBufferSize"
noDelay = "nodelay"
)
if auths := mdata.GetStrings(md, users); len(auths) > 0 {
authenticator := auth.NewLocalAuthenticator(nil)
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 = mdata.GetDuration(md, readTimeout)
h.md.enableBind = mdata.GetBool(md, enableBind)
h.md.noDelay = mdata.GetBool(md, noDelay)