x/listener/quic/metadata.go
2022-09-02 11:52:44 +08:00

55 lines
1.1 KiB
Go

package quic
import (
"time"
mdata "github.com/go-gost/core/metadata"
mdutil "github.com/go-gost/core/metadata/util"
)
const (
defaultBacklog = 128
)
type metadata struct {
// keepAlive bool
keepAlivePeriod time.Duration
handshakeTimeout time.Duration
maxIdleTimeout time.Duration
cipherKey []byte
backlog int
}
func (l *quicListener) parseMetadata(md mdata.Metadata) (err error) {
const (
keepAlive = "keepAlive"
keepAlivePeriod = "ttl"
handshakeTimeout = "handshakeTimeout"
maxIdleTimeout = "maxIdleTimeout"
backlog = "backlog"
cipherKey = "cipherKey"
)
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}
if key := mdutil.GetString(md, cipherKey); key != "" {
l.md.cipherKey = []byte(key)
}
if mdutil.GetBool(md, keepAlive) {
l.md.keepAlivePeriod = mdutil.GetDuration(md, keepAlivePeriod)
if l.md.keepAlivePeriod <= 0 {
l.md.keepAlivePeriod = 10 * time.Second
}
}
l.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
l.md.maxIdleTimeout = mdutil.GetDuration(md, maxIdleTimeout)
return
}