add ttl option for quic

This commit is contained in:
ginuerzh
2022-08-21 21:47:07 +08:00
parent ca414f655d
commit dc36d50fb2
8 changed files with 38 additions and 18 deletions

View File

@ -103,7 +103,7 @@ func (d *quicDialer) Dial(ctx context.Context, addr string, opts ...dialer.DialO
func (d *quicDialer) initSession(ctx context.Context, addr net.Addr, conn net.PacketConn) (*quicSession, error) {
quicConfig := &quic.Config{
KeepAlivePeriod: d.md.keepAlive,
KeepAlivePeriod: d.md.keepAlivePeriod,
HandshakeIdleTimeout: d.md.handshakeTimeout,
MaxIdleTimeout: d.md.maxIdleTimeout,
Versions: []quic.VersionNumber{

View File

@ -8,7 +8,7 @@ import (
)
type metadata struct {
keepAlive time.Duration
keepAlivePeriod time.Duration
maxIdleTimeout time.Duration
handshakeTimeout time.Duration
@ -18,19 +18,23 @@ type metadata struct {
func (d *quicDialer) parseMetadata(md mdata.Metadata) (err error) {
const (
keepAlive = "keepAlive"
keepAlivePeriod = "ttl"
handshakeTimeout = "handshakeTimeout"
maxIdleTimeout = "maxIdleTimeout"
cipherKey = "cipherKey"
)
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
if key := mdx.GetString(md, cipherKey); key != "" {
d.md.cipherKey = []byte(key)
}
d.md.keepAlive = mdx.GetDuration(md, keepAlive)
if mdx.GetBool(md, keepAlive) {
d.md.keepAlivePeriod = mdx.GetDuration(md, keepAlivePeriod)
if d.md.keepAlivePeriod <= 0 {
d.md.keepAlivePeriod = 10 * time.Second
}
}
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
d.md.maxIdleTimeout = mdx.GetDuration(md, maxIdleTimeout)