mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-02 03:48:26 +00:00
lib/config, lib/connections: Configurables for KCP, disable by default
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4030
This commit is contained in:
parent
0da0774ce4
commit
81af29e3e2
@ -44,9 +44,12 @@ var (
|
|||||||
// config.
|
// config.
|
||||||
DefaultListenAddresses = []string{
|
DefaultListenAddresses = []string{
|
||||||
util.Address("tcp", net.JoinHostPort("0.0.0.0", strconv.Itoa(DefaultTCPPort))),
|
util.Address("tcp", net.JoinHostPort("0.0.0.0", strconv.Itoa(DefaultTCPPort))),
|
||||||
util.Address("kcp", net.JoinHostPort("0.0.0.0", strconv.Itoa(DefaultKCPPort))),
|
|
||||||
"dynamic+https://relays.syncthing.net/endpoint",
|
"dynamic+https://relays.syncthing.net/endpoint",
|
||||||
}
|
}
|
||||||
|
// DefaultKCPListenAddress gets added to the default listen address set
|
||||||
|
// when the appropriate feature flag is set. Feature flag stuff to be
|
||||||
|
// removed later.
|
||||||
|
DefaultKCPListenAddress = util.Address("kcp", net.JoinHostPort("0.0.0.0", strconv.Itoa(DefaultKCPPort)))
|
||||||
// DefaultDiscoveryServersV4 should be substituted when the configuration
|
// DefaultDiscoveryServersV4 should be substituted when the configuration
|
||||||
// contains <globalAnnounceServer>default-v4</globalAnnounceServer>.
|
// contains <globalAnnounceServer>default-v4</globalAnnounceServer>.
|
||||||
DefaultDiscoveryServersV4 = []string{
|
DefaultDiscoveryServersV4 = []string{
|
||||||
|
@ -67,6 +67,12 @@ func TestDefaultValues(t *testing.T) {
|
|||||||
WeakHashSelectionMethod: WeakHashAuto,
|
WeakHashSelectionMethod: WeakHashAuto,
|
||||||
StunKeepaliveS: 24,
|
StunKeepaliveS: 24,
|
||||||
StunServers: []string{"default"},
|
StunServers: []string{"default"},
|
||||||
|
DefaultKCPEnabled: false,
|
||||||
|
KCPCongestionControl: true,
|
||||||
|
KCPReceiveWindowSize: 128,
|
||||||
|
KCPSendWindowSize: 128,
|
||||||
|
KCPUpdateIntervalMs: 100,
|
||||||
|
KCPFastResend: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := New(device1)
|
cfg := New(device1)
|
||||||
@ -207,6 +213,12 @@ func TestOverriddenValues(t *testing.T) {
|
|||||||
WeakHashSelectionMethod: WeakHashNever,
|
WeakHashSelectionMethod: WeakHashNever,
|
||||||
StunKeepaliveS: 10,
|
StunKeepaliveS: 10,
|
||||||
StunServers: []string{"a.stun.com", "b.stun.com"},
|
StunServers: []string{"a.stun.com", "b.stun.com"},
|
||||||
|
DefaultKCPEnabled: true,
|
||||||
|
KCPCongestionControl: false,
|
||||||
|
KCPReceiveWindowSize: 1280,
|
||||||
|
KCPSendWindowSize: 1280,
|
||||||
|
KCPUpdateIntervalMs: 1000,
|
||||||
|
KCPFastResend: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Unsetenv("STNOUPGRADE")
|
os.Unsetenv("STNOUPGRADE")
|
||||||
|
@ -133,6 +133,13 @@ type OptionsConfiguration struct {
|
|||||||
WeakHashSelectionMethod WeakHashSelectionMethod `xml:"weakHashSelectionMethod" json:"weakHashSelectionMethod"`
|
WeakHashSelectionMethod WeakHashSelectionMethod `xml:"weakHashSelectionMethod" json:"weakHashSelectionMethod"`
|
||||||
StunServers []string `xml:"stunServer" json:"stunServers" default:"default"`
|
StunServers []string `xml:"stunServer" json:"stunServers" default:"default"`
|
||||||
StunKeepaliveS int `xml:"stunKeepaliveSeconds" json:"stunKeepaliveSeconds" default:"24"`
|
StunKeepaliveS int `xml:"stunKeepaliveSeconds" json:"stunKeepaliveSeconds" default:"24"`
|
||||||
|
DefaultKCPEnabled bool `xml:"defaultKCPEnabled" json:"defaultKCPEnabled" default:"false"`
|
||||||
|
KCPNoDelay bool `xml:"kcpNoDelay" json:"kcpNoDelay" default:"false"`
|
||||||
|
KCPUpdateIntervalMs int `xml:"kcpUpdateIntervalMs" json:"kcpUpdateIntervalMs" default:"100"`
|
||||||
|
KCPFastResend bool `xml:"kcpFastResend" json:"kcpFastResend" default:"false"`
|
||||||
|
KCPCongestionControl bool `xml:"kcpCongestionControl" json:"kcpCongestionControl" default:"true"`
|
||||||
|
KCPSendWindowSize int `xml:"kcpSendWindowSize" json:"kcpSendWindowSize" default:"128"`
|
||||||
|
KCPReceiveWindowSize int `xml:"kcpReceiveWindowSize" json:"kcpReceiveWindowSize" default:"128"`
|
||||||
|
|
||||||
DeprecatedUPnPEnabled bool `xml:"upnpEnabled,omitempty" json:"-"`
|
DeprecatedUPnPEnabled bool `xml:"upnpEnabled,omitempty" json:"-"`
|
||||||
DeprecatedUPnPLeaseM int `xml:"upnpLeaseMinutes,omitempty" json:"-"`
|
DeprecatedUPnPLeaseM int `xml:"upnpLeaseMinutes,omitempty" json:"-"`
|
||||||
|
6
lib/config/testdata/overridenvalues.xml
vendored
6
lib/config/testdata/overridenvalues.xml
vendored
@ -38,5 +38,11 @@
|
|||||||
<stunKeepaliveSeconds>10</stunKeepaliveSeconds>
|
<stunKeepaliveSeconds>10</stunKeepaliveSeconds>
|
||||||
<stunServer>a.stun.com</stunServer>
|
<stunServer>a.stun.com</stunServer>
|
||||||
<stunServer>b.stun.com</stunServer>
|
<stunServer>b.stun.com</stunServer>
|
||||||
|
<defaultKCPEnabled>true</defaultKCPEnabled>
|
||||||
|
<kcpCongestionControl>false</kcpCongestionControl>
|
||||||
|
<kcpReceiveWindowSize>1280</kcpReceiveWindowSize>
|
||||||
|
<kcpSendWindowSize>1280</kcpSendWindowSize>
|
||||||
|
<kcpUpdateIntervalMs>1000</kcpUpdateIntervalMs>
|
||||||
|
<kcpFastResend>true</kcpFastResend>
|
||||||
</options>
|
</options>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -391,6 +391,9 @@ func (w *Wrapper) ListenAddresses() []string {
|
|||||||
switch addr {
|
switch addr {
|
||||||
case "default":
|
case "default":
|
||||||
addresses = append(addresses, DefaultListenAddresses...)
|
addresses = append(addresses, DefaultListenAddresses...)
|
||||||
|
if w.cfg.Options.DefaultKCPEnabled { // temporary feature flag
|
||||||
|
addresses = append(addresses, DefaultKCPListenAddress)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
addresses = append(addresses, addr)
|
addresses = append(addresses, addr)
|
||||||
}
|
}
|
||||||
|
@ -22,23 +22,6 @@ const (
|
|||||||
kcpNoFilterPriority = 100
|
kcpNoFilterPriority = 100
|
||||||
kcpConversationFilterPriority = 20
|
kcpConversationFilterPriority = 20
|
||||||
kcpStunFilterPriority = 10
|
kcpStunFilterPriority = 10
|
||||||
|
|
||||||
// KCP SetNoDelay options
|
|
||||||
|
|
||||||
// 0 - disabled (default)
|
|
||||||
// 1 - enabled
|
|
||||||
kcpNoDelay = 0
|
|
||||||
kcpUpdateInterval = 100 // ms (default)
|
|
||||||
// 0 - disable (default)
|
|
||||||
// 1 - enabled
|
|
||||||
kcpFastResend = 0
|
|
||||||
// 0 - enabled (default)
|
|
||||||
// 1 - disabled
|
|
||||||
kcpCongestionControl = 0
|
|
||||||
|
|
||||||
// KCP window sizes
|
|
||||||
kcpSendWindowSize = 128
|
|
||||||
kcpReceiveWindowSize = 128
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -49,11 +49,13 @@ func (d *kcpDialer) Dial(id protocol.DeviceID, uri *url.URL) (internalConn, erro
|
|||||||
return internalConn{}, err
|
return internalConn{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opts := d.cfg.Options()
|
||||||
|
|
||||||
conn.SetKeepAlive(0) // yamux and stun service does keep-alives.
|
conn.SetKeepAlive(0) // yamux and stun service does keep-alives.
|
||||||
conn.SetStreamMode(true)
|
conn.SetStreamMode(true)
|
||||||
conn.SetACKNoDelay(false)
|
conn.SetACKNoDelay(false)
|
||||||
conn.SetWindowSize(kcpSendWindowSize, kcpReceiveWindowSize)
|
conn.SetWindowSize(opts.KCPSendWindowSize, opts.KCPReceiveWindowSize)
|
||||||
conn.SetNoDelay(kcpNoDelay, kcpUpdateInterval, kcpFastResend, kcpCongestionControl)
|
conn.SetNoDelay(boolInt(opts.KCPNoDelay), opts.KCPUpdateIntervalMs, boolInt(opts.KCPFastResend), boolInt(!opts.KCPCongestionControl))
|
||||||
|
|
||||||
ses, err := yamux.Client(conn, yamuxConfig)
|
ses, err := yamux.Client(conn, yamuxConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -107,12 +107,13 @@ func (t *kcpListener) Serve() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.SetStreamMode(true)
|
opts := t.cfg.Options()
|
||||||
conn.SetACKNoDelay(false)
|
|
||||||
conn.SetWindowSize(kcpSendWindowSize, kcpReceiveWindowSize)
|
|
||||||
conn.SetNoDelay(kcpNoDelay, kcpUpdateInterval, kcpFastResend, kcpCongestionControl)
|
|
||||||
|
|
||||||
conn.SetKeepAlive(0) // yamux and stun service does keep-alives.
|
conn.SetKeepAlive(0) // yamux and stun service does keep-alives.
|
||||||
|
conn.SetStreamMode(true)
|
||||||
|
conn.SetACKNoDelay(false)
|
||||||
|
conn.SetWindowSize(opts.KCPSendWindowSize, opts.KCPReceiveWindowSize)
|
||||||
|
conn.SetNoDelay(boolInt(opts.KCPNoDelay), opts.KCPUpdateIntervalMs, boolInt(opts.KCPFastResend), boolInt(!opts.KCPCongestionControl))
|
||||||
|
|
||||||
l.Debugln("connect from", conn.RemoteAddr())
|
l.Debugln("connect from", conn.RemoteAddr())
|
||||||
|
|
||||||
|
@ -180,3 +180,10 @@ func (w *sessionClosingStream) Close() error {
|
|||||||
}
|
}
|
||||||
return err2
|
return err2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func boolInt(b bool) int {
|
||||||
|
if b {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user