46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package quic
|
|
|
|
import (
|
|
"time"
|
|
|
|
mdata "github.com/go-gost/core/metadata"
|
|
mdutil "github.com/go-gost/core/metadata/util"
|
|
)
|
|
|
|
type metadata struct {
|
|
keepAlivePeriod time.Duration
|
|
maxIdleTimeout time.Duration
|
|
handshakeTimeout time.Duration
|
|
maxStreams int
|
|
|
|
cipherKey []byte
|
|
}
|
|
|
|
func (d *quicDialer) parseMetadata(md mdata.Metadata) (err error) {
|
|
const (
|
|
keepAlive = "keepAlive"
|
|
keepAlivePeriod = "ttl"
|
|
handshakeTimeout = "handshakeTimeout"
|
|
maxIdleTimeout = "maxIdleTimeout"
|
|
maxStreams = "maxStreams"
|
|
|
|
cipherKey = "cipherKey"
|
|
)
|
|
|
|
if key := mdutil.GetString(md, cipherKey); key != "" {
|
|
d.md.cipherKey = []byte(key)
|
|
}
|
|
|
|
if md == nil || !md.IsExists(keepAlive) || mdutil.GetBool(md, keepAlive) {
|
|
d.md.keepAlivePeriod = mdutil.GetDuration(md, keepAlivePeriod)
|
|
if d.md.keepAlivePeriod <= 0 {
|
|
d.md.keepAlivePeriod = 10 * time.Second
|
|
}
|
|
}
|
|
d.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
|
|
d.md.maxIdleTimeout = mdutil.GetDuration(md, maxIdleTimeout)
|
|
d.md.maxStreams = mdutil.GetInt(md, maxStreams)
|
|
|
|
return
|
|
}
|