From 634a0eb78cfe959327c0b829f1f05d2adbc16a29 Mon Sep 17 00:00:00 2001 From: Lucas Clemente Date: Thu, 8 Sep 2016 13:28:44 +0200 Subject: [PATCH] add new timeout consts ref #320 --- handshake/connection_parameters_manager.go | 5 ++--- handshake/connection_parameters_manager_test.go | 8 ++++---- protocol/protocol.go | 3 --- protocol/server_parameters.go | 16 ++++++++++++---- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/handshake/connection_parameters_manager.go b/handshake/connection_parameters_manager.go index f1e775f7f..df2611925 100644 --- a/handshake/connection_parameters_manager.go +++ b/handshake/connection_parameters_manager.go @@ -41,7 +41,7 @@ var ( func NewConnectionParamatersManager() *ConnectionParametersManager { return &ConnectionParametersManager{ params: make(map[Tag][]byte), - idleConnectionStateLifetime: protocol.InitialIdleConnectionStateLifetime, + idleConnectionStateLifetime: protocol.DefaultIdleTimeout, sendStreamFlowControlWindow: protocol.InitialStreamFlowControlWindow, // can only be changed by the client sendConnectionFlowControlWindow: protocol.InitialConnectionFlowControlWindow, // can only be changed by the client receiveStreamFlowControlWindow: protocol.ReceiveStreamFlowControlWindow, @@ -106,8 +106,7 @@ func (h *ConnectionParametersManager) negotiateMaxStreamsPerConnection(clientVal } func (h *ConnectionParametersManager) negotiateIdleConnectionStateLifetime(clientValue time.Duration) time.Duration { - // TODO: what happens if the clients sets 0 seconds? - return utils.MinDuration(clientValue, protocol.MaxIdleConnectionStateLifetime) + return utils.MinDuration(clientValue, protocol.MaxIdleTimeout) } // getRawValue gets the byte-slice for a tag diff --git a/handshake/connection_parameters_manager_test.go b/handshake/connection_parameters_manager_test.go index 3f76b2124..3f5139242 100644 --- a/handshake/connection_parameters_manager_test.go +++ b/handshake/connection_parameters_manager_test.go @@ -162,15 +162,15 @@ var _ = Describe("ConnectionsParameterManager", func() { Context("idle connection state lifetime", func() { It("has initial idle connection state lifetime", func() { - Expect(cpm.GetIdleConnectionStateLifetime()).To(Equal(protocol.InitialIdleConnectionStateLifetime)) + Expect(cpm.GetIdleConnectionStateLifetime()).To(Equal(protocol.DefaultIdleTimeout)) }) It("negotiates correctly when the client wants a longer lifetime", func() { - Expect(cpm.negotiateIdleConnectionStateLifetime(protocol.MaxIdleConnectionStateLifetime + 10*time.Second)).To(Equal(protocol.MaxIdleConnectionStateLifetime)) + Expect(cpm.negotiateIdleConnectionStateLifetime(protocol.MaxIdleTimeout + 10*time.Second)).To(Equal(protocol.MaxIdleTimeout)) }) It("negotiates correctly when the client wants a shorter lifetime", func() { - Expect(cpm.negotiateIdleConnectionStateLifetime(protocol.MaxIdleConnectionStateLifetime - 1*time.Second)).To(Equal(protocol.MaxIdleConnectionStateLifetime - 1*time.Second)) + Expect(cpm.negotiateIdleConnectionStateLifetime(protocol.MaxIdleTimeout - 1*time.Second)).To(Equal(protocol.MaxIdleTimeout - 1*time.Second)) }) It("sets the negotiated lifetime", func() { @@ -189,7 +189,7 @@ var _ = Describe("ConnectionsParameterManager", func() { } err := cpm.SetFromMap(values) Expect(err).To(MatchError(ErrMalformedTag)) - Expect(cpm.GetIdleConnectionStateLifetime()).To(Equal(protocol.InitialIdleConnectionStateLifetime)) + Expect(cpm.GetIdleConnectionStateLifetime()).To(Equal(protocol.DefaultIdleTimeout)) }) It("gets idle connection state lifetime", func() { diff --git a/protocol/protocol.go b/protocol/protocol.go index 90f50642a..bd912452d 100644 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -53,9 +53,6 @@ const InitialStreamFlowControlWindow ByteCount = (1 << 14) // 16 kB // InitialConnectionFlowControlWindow is the initial connection-level flow control window for sending const InitialConnectionFlowControlWindow ByteCount = (1 << 14) // 16 kB -// InitialIdleConnectionStateLifetime is the initial idle connection state lifetime -const InitialIdleConnectionStateLifetime = 30 * time.Second - // DefaultRetransmissionTime is the RTO time on new connections const DefaultRetransmissionTime = 500 * time.Millisecond diff --git a/protocol/server_parameters.go b/protocol/server_parameters.go index 8db73a3e6..661e03196 100644 --- a/protocol/server_parameters.go +++ b/protocol/server_parameters.go @@ -39,10 +39,6 @@ const MaxStreamsMinimumIncrement = 10 // note that the number of streams is half this value, since the client can only open streams with open StreamID const MaxNewStreamIDDelta = 4 * MaxStreamsPerConnection -// MaxIdleConnectionStateLifetime is the maximum value accepted for the idle connection state lifetime -// TODO: set a reasonable value here -const MaxIdleConnectionStateLifetime = 60 * time.Second - // MaxSessionUnprocessedPackets is the max number of packets stored in each session that are not yet processed. const MaxSessionUnprocessedPackets = DefaultMaxCongestionWindow @@ -77,3 +73,15 @@ const CryptoParameterMaxLength = 2000 // EphermalKeyLifetime is the lifetime of the ephermal key during the handshake, see handshake.getEphermalKEX. const EphermalKeyLifetime = time.Minute + +// InitialIdleTimeout is the timeout before the handshake succeeds. +const InitialIdleTimeout = 5 * time.Second + +// DefaultIdleTimeout is the default idle timeout. +const DefaultIdleTimeout = 30 * time.Second + +// MaxIdleTimeout is the maximum idle timeout that can be negotiated. +const MaxIdleTimeout = 1 * time.Minute + +// MaxTimeForCryptoHandshake is the default timeout for a connection until the crypto handshake succeeds. +const MaxTimeForCryptoHandshake = 10 * time.Second