add GetIdleConnectionStateLifetime to connection params

This commit is contained in:
Lucas Clemente
2016-05-05 22:58:59 +02:00
parent 76d279ed8f
commit b239b71bb4
2 changed files with 23 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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))
})
})