This makes the various protocol priorities configurable among the other options. With this, it's possible to prefer QUIC over TCP for WAN connections, for example. Both sides need to be similarly configured for this to work properly. The default priority order remains the same as previously (TCP, QUIC, Relay, with LAN better than WAN). To make this happen I made each dialer & listener more priority aware, and moved the check for whether a connection is LAN or not into the dialer / listener -- this is the new "lanChecker" type that's passed around.
This commit is contained in:
@@ -25,8 +25,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
quicPriority = 100
|
||||
|
||||
// The timeout for connecting, accepting and creating the various
|
||||
// streams.
|
||||
quicOperationTimeout = 10 * time.Second
|
||||
@@ -92,12 +90,17 @@ func (d *quicDialer) Dial(ctx context.Context, _ protocol.DeviceID, uri *url.URL
|
||||
return internalConn{}, fmt.Errorf("open stream: %w", err)
|
||||
}
|
||||
|
||||
return newInternalConn(&quicTlsConn{session, stream, createdConn}, connTypeQUICClient, quicPriority), nil
|
||||
priority := d.wanPriority
|
||||
isLocal := d.lanChecker.isLAN(session.RemoteAddr())
|
||||
if isLocal {
|
||||
priority = d.lanPriority
|
||||
}
|
||||
return newInternalConn(&quicTlsConn{session, stream, createdConn}, connTypeQUICClient, isLocal, priority), nil
|
||||
}
|
||||
|
||||
type quicDialerFactory struct{}
|
||||
|
||||
func (quicDialerFactory) New(opts config.OptionsConfiguration, tlsCfg *tls.Config, registry *registry.Registry) genericDialer {
|
||||
func (quicDialerFactory) New(opts config.OptionsConfiguration, tlsCfg *tls.Config, registry *registry.Registry, lanChecker *lanChecker) genericDialer {
|
||||
// So the idea is that we should probably try dialing every 20 seconds.
|
||||
// However it would still be nice if this was adjustable/proportional to ReconnectIntervalS
|
||||
// But prevent something silly like 1/3 = 0 etc.
|
||||
@@ -109,15 +112,14 @@ func (quicDialerFactory) New(opts config.OptionsConfiguration, tlsCfg *tls.Confi
|
||||
commonDialer: commonDialer{
|
||||
reconnectInterval: time.Duration(quicInterval) * time.Second,
|
||||
tlsCfg: tlsCfg,
|
||||
lanPriority: opts.ConnectionPriorityQUICLAN,
|
||||
wanPriority: opts.ConnectionPriorityQUICWAN,
|
||||
lanChecker: lanChecker,
|
||||
},
|
||||
registry: registry,
|
||||
}
|
||||
}
|
||||
|
||||
func (quicDialerFactory) Priority() int {
|
||||
return quicPriority
|
||||
}
|
||||
|
||||
func (quicDialerFactory) AlwaysWAN() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user