merge ss and ssu
This commit is contained in:
@ -90,13 +90,29 @@ func (h *socks5Handler) Handle(ctx context.Context, conn net.Conn) {
|
||||
case gosocks5.CmdConnect:
|
||||
h.handleConnect(ctx, conn, req.Addr.String())
|
||||
case gosocks5.CmdBind:
|
||||
h.handleBind(ctx, conn, req)
|
||||
if h.md.enableBind {
|
||||
h.handleBind(ctx, conn, req)
|
||||
} else {
|
||||
h.logger.Error("BIND is diabled")
|
||||
}
|
||||
case socks.CmdMuxBind:
|
||||
h.handleMuxBind(ctx, conn, req)
|
||||
if h.md.enableBind {
|
||||
h.handleMuxBind(ctx, conn, req)
|
||||
} else {
|
||||
h.logger.Error("BIND is diabled")
|
||||
}
|
||||
case gosocks5.CmdUdp:
|
||||
h.handleUDP(ctx, conn, req)
|
||||
if h.md.enableUDP {
|
||||
h.handleUDP(ctx, conn, req)
|
||||
} else {
|
||||
h.logger.Error("UDP relay is diabled")
|
||||
}
|
||||
case socks.CmdUDPTun:
|
||||
h.handleUDPTun(ctx, conn, req)
|
||||
if h.md.enableUDP {
|
||||
h.handleUDPTun(ctx, conn, req)
|
||||
} else {
|
||||
h.logger.Error("UDP relay is diabled")
|
||||
}
|
||||
default:
|
||||
h.logger.Errorf("unknown cmd: %d", req.Cmd)
|
||||
resp := gosocks5.NewReply(gosocks5.CmdUnsupported, nil)
|
||||
|
@ -10,18 +10,6 @@ import (
|
||||
md "github.com/go-gost/gost/pkg/metadata"
|
||||
)
|
||||
|
||||
const (
|
||||
certFile = "certFile"
|
||||
keyFile = "keyFile"
|
||||
caFile = "caFile"
|
||||
authsKey = "auths"
|
||||
readTimeout = "readTimeout"
|
||||
timeout = "timeout"
|
||||
retryCount = "retry"
|
||||
noTLS = "notls"
|
||||
udpBufferSize = "udpBufferSize"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
tlsConfig *tls.Config
|
||||
authenticator auth.Authenticator
|
||||
@ -29,10 +17,26 @@ type metadata struct {
|
||||
readTimeout time.Duration
|
||||
retryCount int
|
||||
noTLS bool
|
||||
enableBind bool
|
||||
enableUDP bool
|
||||
udpBufferSize int
|
||||
}
|
||||
|
||||
func (h *socks5Handler) parseMetadata(md md.Metadata) error {
|
||||
const (
|
||||
certFile = "certFile"
|
||||
keyFile = "keyFile"
|
||||
caFile = "caFile"
|
||||
authsKey = "auths"
|
||||
readTimeout = "readTimeout"
|
||||
timeout = "timeout"
|
||||
retryCount = "retry"
|
||||
noTLS = "notls"
|
||||
enableBind = "bind"
|
||||
enableUDP = "udp"
|
||||
udpBufferSize = "udpBufferSize"
|
||||
)
|
||||
|
||||
var err error
|
||||
h.md.tlsConfig, err = util_tls.LoadTLSConfig(
|
||||
md.GetString(certFile),
|
||||
@ -62,6 +66,8 @@ func (h *socks5Handler) parseMetadata(md md.Metadata) error {
|
||||
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.udpBufferSize = md.GetInt(udpBufferSize)
|
||||
if h.md.udpBufferSize > 0 {
|
||||
|
Reference in New Issue
Block a user