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:
Jakob Borg
2017-03-07 12:55:50 +00:00
committed by Audrius Butkevicius
parent 0da0774ce4
commit 81af29e3e2
9 changed files with 48 additions and 24 deletions

View File

@@ -44,9 +44,12 @@ var (
// config.
DefaultListenAddresses = []string{
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",
}
// 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
// contains <globalAnnounceServer>default-v4</globalAnnounceServer>.
DefaultDiscoveryServersV4 = []string{

View File

@@ -67,6 +67,12 @@ func TestDefaultValues(t *testing.T) {
WeakHashSelectionMethod: WeakHashAuto,
StunKeepaliveS: 24,
StunServers: []string{"default"},
DefaultKCPEnabled: false,
KCPCongestionControl: true,
KCPReceiveWindowSize: 128,
KCPSendWindowSize: 128,
KCPUpdateIntervalMs: 100,
KCPFastResend: false,
}
cfg := New(device1)
@@ -207,6 +213,12 @@ func TestOverriddenValues(t *testing.T) {
WeakHashSelectionMethod: WeakHashNever,
StunKeepaliveS: 10,
StunServers: []string{"a.stun.com", "b.stun.com"},
DefaultKCPEnabled: true,
KCPCongestionControl: false,
KCPReceiveWindowSize: 1280,
KCPSendWindowSize: 1280,
KCPUpdateIntervalMs: 1000,
KCPFastResend: true,
}
os.Unsetenv("STNOUPGRADE")

View File

@@ -133,6 +133,13 @@ type OptionsConfiguration struct {
WeakHashSelectionMethod WeakHashSelectionMethod `xml:"weakHashSelectionMethod" json:"weakHashSelectionMethod"`
StunServers []string `xml:"stunServer" json:"stunServers" default:"default"`
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:"-"`
DeprecatedUPnPLeaseM int `xml:"upnpLeaseMinutes,omitempty" json:"-"`

View File

@@ -38,5 +38,11 @@
<stunKeepaliveSeconds>10</stunKeepaliveSeconds>
<stunServer>a.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>
</configuration>

View File

@@ -391,6 +391,9 @@ func (w *Wrapper) ListenAddresses() []string {
switch addr {
case "default":
addresses = append(addresses, DefaultListenAddresses...)
if w.cfg.Options.DefaultKCPEnabled { // temporary feature flag
addresses = append(addresses, DefaultKCPListenAddress)
}
default:
addresses = append(addresses, addr)
}