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

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

View File

@ -8,7 +8,7 @@ import (
) )
type metadata struct { type metadata struct {
keepAlive time.Duration keepAlivePeriod time.Duration
maxIdleTimeout time.Duration maxIdleTimeout time.Duration
handshakeTimeout time.Duration handshakeTimeout time.Duration
} }
@ -16,13 +16,17 @@ type metadata struct {
func (d *icmpDialer) parseMetadata(md mdata.Metadata) (err error) { func (d *icmpDialer) parseMetadata(md mdata.Metadata) (err error) {
const ( const (
keepAlive = "keepAlive" keepAlive = "keepAlive"
keepAlivePeriod = "ttl"
handshakeTimeout = "handshakeTimeout" handshakeTimeout = "handshakeTimeout"
maxIdleTimeout = "maxIdleTimeout" maxIdleTimeout = "maxIdleTimeout"
) )
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout) if mdx.GetBool(md, keepAlive) {
d.md.keepAlivePeriod = mdx.GetDuration(md, keepAlivePeriod)
d.md.keepAlive = mdx.GetDuration(md, keepAlive) if d.md.keepAlivePeriod <= 0 {
d.md.keepAlivePeriod = 10 * time.Second
}
}
d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout) d.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
d.md.maxIdleTimeout = mdx.GetDuration(md, maxIdleTimeout) d.md.maxIdleTimeout = mdx.GetDuration(md, maxIdleTimeout)

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) { func (d *quicDialer) initSession(ctx context.Context, addr net.Addr, conn net.PacketConn) (*quicSession, error) {
quicConfig := &quic.Config{ quicConfig := &quic.Config{
KeepAlivePeriod: d.md.keepAlive, KeepAlivePeriod: d.md.keepAlivePeriod,
HandshakeIdleTimeout: d.md.handshakeTimeout, HandshakeIdleTimeout: d.md.handshakeTimeout,
MaxIdleTimeout: d.md.maxIdleTimeout, MaxIdleTimeout: d.md.maxIdleTimeout,
Versions: []quic.VersionNumber{ Versions: []quic.VersionNumber{

View File

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

View File

@ -59,7 +59,7 @@ func (l *icmpListener) Init(md md.Metadata) (err error) {
conn = admission.WrapPacketConn(l.options.Admission, conn) conn = admission.WrapPacketConn(l.options.Admission, conn)
config := &quic.Config{ config := &quic.Config{
KeepAlivePeriod: l.md.keepAlive, KeepAlivePeriod: l.md.keepAlivePeriod,
HandshakeIdleTimeout: l.md.handshakeTimeout, HandshakeIdleTimeout: l.md.handshakeTimeout,
MaxIdleTimeout: l.md.maxIdleTimeout, MaxIdleTimeout: l.md.maxIdleTimeout,
Versions: []quic.VersionNumber{ Versions: []quic.VersionNumber{

View File

@ -12,17 +12,17 @@ const (
) )
type metadata struct { type metadata struct {
keepAlive time.Duration keepAlivePeriod time.Duration
handshakeTimeout time.Duration handshakeTimeout time.Duration
maxIdleTimeout time.Duration maxIdleTimeout time.Duration
cipherKey []byte backlog int
backlog int
} }
func (l *icmpListener) parseMetadata(md mdata.Metadata) (err error) { func (l *icmpListener) parseMetadata(md mdata.Metadata) (err error) {
const ( const (
keepAlive = "keepAlive" keepAlive = "keepAlive"
keepAlivePeriod = "ttl"
handshakeTimeout = "handshakeTimeout" handshakeTimeout = "handshakeTimeout"
maxIdleTimeout = "maxIdleTimeout" maxIdleTimeout = "maxIdleTimeout"
@ -34,7 +34,12 @@ func (l *icmpListener) parseMetadata(md mdata.Metadata) (err error) {
l.md.backlog = defaultBacklog l.md.backlog = defaultBacklog
} }
l.md.keepAlive = mdx.GetDuration(md, keepAlive) if mdx.GetBool(md, keepAlive) {
l.md.keepAlivePeriod = mdx.GetDuration(md, keepAlivePeriod)
if l.md.keepAlivePeriod <= 0 {
l.md.keepAlivePeriod = 10 * time.Second
}
}
l.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout) l.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
l.md.maxIdleTimeout = mdx.GetDuration(md, maxIdleTimeout) l.md.maxIdleTimeout = mdx.GetDuration(md, maxIdleTimeout)

View File

@ -68,7 +68,7 @@ func (l *quicListener) Init(md md.Metadata) (err error) {
} }
config := &quic.Config{ config := &quic.Config{
KeepAlivePeriod: l.md.keepAlive, KeepAlivePeriod: l.md.keepAlivePeriod,
HandshakeIdleTimeout: l.md.handshakeTimeout, HandshakeIdleTimeout: l.md.handshakeTimeout,
MaxIdleTimeout: l.md.maxIdleTimeout, MaxIdleTimeout: l.md.maxIdleTimeout,
Versions: []quic.VersionNumber{ Versions: []quic.VersionNumber{

View File

@ -12,7 +12,8 @@ const (
) )
type metadata struct { type metadata struct {
keepAlive time.Duration // keepAlive bool
keepAlivePeriod time.Duration
handshakeTimeout time.Duration handshakeTimeout time.Duration
maxIdleTimeout time.Duration maxIdleTimeout time.Duration
@ -23,6 +24,7 @@ type metadata struct {
func (l *quicListener) parseMetadata(md mdata.Metadata) (err error) { func (l *quicListener) parseMetadata(md mdata.Metadata) (err error) {
const ( const (
keepAlive = "keepAlive" keepAlive = "keepAlive"
keepAlivePeriod = "ttl"
handshakeTimeout = "handshakeTimeout" handshakeTimeout = "handshakeTimeout"
maxIdleTimeout = "maxIdleTimeout" maxIdleTimeout = "maxIdleTimeout"
@ -39,7 +41,12 @@ func (l *quicListener) parseMetadata(md mdata.Metadata) (err error) {
l.md.cipherKey = []byte(key) l.md.cipherKey = []byte(key)
} }
l.md.keepAlive = mdx.GetDuration(md, keepAlive) if mdx.GetBool(md, keepAlive) {
l.md.keepAlivePeriod = mdx.GetDuration(md, keepAlivePeriod)
if l.md.keepAlivePeriod <= 0 {
l.md.keepAlivePeriod = 10 * time.Second
}
}
l.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout) l.md.handshakeTimeout = mdx.GetDuration(md, handshakeTimeout)
l.md.maxIdleTimeout = mdx.GetDuration(md, maxIdleTimeout) l.md.maxIdleTimeout = mdx.GetDuration(md, maxIdleTimeout)