diff --git a/handshake/connection_parameters_manager.go b/handshake/connection_parameters_manager.go index cef9abdeb..697670f62 100644 --- a/handshake/connection_parameters_manager.go +++ b/handshake/connection_parameters_manager.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "errors" "sync" + "time" "github.com/lucas-clemente/quic-go/protocol" ) @@ -76,3 +77,16 @@ func (h *ConnectionParametersManager) GetStreamFlowControlWindow() (protocol.Byt return protocol.ByteCount(value), nil } + +// GetIdleConnectionStateLifetime gets the idle timeout +func (h *ConnectionParametersManager) GetIdleConnectionStateLifetime() (time.Duration, error) { + rawValue, err := h.GetRawValue(TagICSL) + if err != nil { + return 0, err + } + + if len(rawValue) != 4 { + return 0, errors.New("expected uint32 for ICSL") + } + return time.Duration(binary.LittleEndian.Uint32(rawValue)) * time.Second, nil +} diff --git a/handshake/connection_parameters_manager_test.go b/handshake/connection_parameters_manager_test.go index 2b8a44fbf..a1c7c6750 100644 --- a/handshake/connection_parameters_manager_test.go +++ b/handshake/connection_parameters_manager_test.go @@ -1,6 +1,8 @@ package handshake import ( + "time" + "github.com/lucas-clemente/quic-go/protocol" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -57,4 +59,11 @@ var _ = Describe("ConnectionsParameterManager", func() { Expect(val).To(Equal(protocol.ByteCount(0xEFBEADDE))) }) }) + + It("gets idle connection state lifetime", func() { + cpm.params[TagICSL] = []byte{0xad, 0xfb, 0xca, 0xde} + val, err := cpm.GetIdleConnectionStateLifetime() + Expect(err).ToNot(HaveOccurred()) + Expect(val).To(Equal(0xdecafbad * time.Second)) + }) })