57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package tunnel
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
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"
|
|
)
|
|
|
|
var (
|
|
ErrInvalidTunnelID = errors.New("tunnel: invalid tunnel ID")
|
|
)
|
|
|
|
type metadata struct {
|
|
connectTimeout time.Duration
|
|
tunnelID relay.TunnelID
|
|
noDelay bool
|
|
muxCfg *mux.Config
|
|
}
|
|
|
|
func (c *tunnelConnector) parseMetadata(md mdata.Metadata) (err error) {
|
|
c.md.connectTimeout = mdutil.GetDuration(md, "connectTimeout")
|
|
c.md.noDelay = mdutil.GetBool(md, "nodelay")
|
|
|
|
if s := mdutil.GetString(md, "tunnelID", "tunnel.id"); s != "" {
|
|
uuid, err := uuid.Parse(s)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c.md.tunnelID = relay.NewTunnelID(uuid[:])
|
|
}
|
|
|
|
if c.md.tunnelID.IsZero() {
|
|
uuid, err := uuid.NewUUID()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
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"),
|
|
}
|
|
|
|
return
|
|
}
|