add mux config

This commit is contained in:
ginuerzh
2023-10-17 21:55:07 +08:00
parent bf5311ddc3
commit 1759c95e78
22 changed files with 805 additions and 23 deletions

View File

@ -50,7 +50,7 @@ func (c *relayConnector) bindTunnel(ctx context.Context, conn net.Conn, network,
}
log.Infof("create tunnel on %s/%s OK, tunnel=%s, connector=%s", addr, network, c.md.tunnelID.String(), cid)
session, err := mux.ServerSession(conn)
session, err := mux.ServerSession(conn, c.md.muxCfg)
if err != nil {
return nil, err
}
@ -130,7 +130,7 @@ func (c *relayConnector) bindTCP(ctx context.Context, conn net.Conn, network, ad
}
log.Debugf("bind on %s/%s OK", laddr, laddr.Network())
session, err := mux.ServerSession(conn)
session, err := mux.ServerSession(conn, c.md.muxCfg)
if err != nil {
return nil, err
}

View File

@ -6,13 +6,19 @@ import (
mdata "github.com/go-gost/core/metadata"
mdutil "github.com/go-gost/core/metadata/util"
"github.com/go-gost/relay"
"github.com/go-gost/x/internal/util/mux"
"github.com/google/uuid"
)
const (
defaultMuxVersion = 2
)
type metadata struct {
connectTimeout time.Duration
noDelay bool
tunnelID relay.TunnelID
muxCfg *mux.Config
}
func (c *relayConnector) parseMetadata(md mdata.Metadata) (err error) {
@ -32,5 +38,18 @@ func (c *relayConnector) parseMetadata(md mdata.Metadata) (err error) {
c.md.tunnelID = relay.NewTunnelID(uuid[:])
}
c.md.muxCfg = &mux.Config{
Version: mdutil.GetInt(md, "mux.version"),
KeepAliveInterval: mdutil.GetDuration(md, "mux.keepaliveInterval"),
KeepAliveDisabled: mdutil.GetBool(md, "mux.keepaliveDisabled"),
KeepAliveTimeout: mdutil.GetDuration(md, "mux.keepaliveTimeout"),
MaxFrameSize: mdutil.GetInt(md, "mux.maxFrameSize"),
MaxReceiveBuffer: mdutil.GetInt(md, "mux.maxReceiveBuffer"),
MaxStreamBuffer: mdutil.GetInt(md, "mux.maxStreamBuffer"),
}
if c.md.muxCfg.Version == 0 {
c.md.muxCfg.Version = defaultMuxVersion
}
return
}