make session timeout according to ICSL

fixes #54
This commit is contained in:
Lucas Clemente
2016-05-05 23:14:36 +02:00
parent b239b71bb4
commit 7e0d59a5e6
5 changed files with 23 additions and 11 deletions

View File

@@ -22,7 +22,7 @@ const (
QUIC_PEER_GOING_AWAY = protocol.ErrorCode(16) QUIC_PEER_GOING_AWAY = protocol.ErrorCode(16)
QUIC_INVALID_STREAM_ID = protocol.ErrorCode(17) QUIC_INVALID_STREAM_ID = protocol.ErrorCode(17)
QUIC_TOO_MANY_OPEN_STREAMS = protocol.ErrorCode(18) QUIC_TOO_MANY_OPEN_STREAMS = protocol.ErrorCode(18)
// QUIC_CONNECTION_TIMED_OUT= We hit our pre-negotiated (or default) timeout QUIC_NETWORK_IDLE_TIMEOUT = protocol.ErrorCode(25)
QUIC_CRYPTO_TAGS_OUT_OF_ORDER = protocol.ErrorCode(29) QUIC_CRYPTO_TAGS_OUT_OF_ORDER = protocol.ErrorCode(29)
QUIC_CRYPTO_TOO_MANY_ENTRIES = protocol.ErrorCode(30) QUIC_CRYPTO_TOO_MANY_ENTRIES = protocol.ErrorCode(30)
QUIC_CRYPTO_INVALID_VALUE_LENGTH = protocol.ErrorCode(31) QUIC_CRYPTO_INVALID_VALUE_LENGTH = protocol.ErrorCode(31)

View File

@@ -79,14 +79,13 @@ func (h *ConnectionParametersManager) GetStreamFlowControlWindow() (protocol.Byt
} }
// GetIdleConnectionStateLifetime gets the idle timeout // GetIdleConnectionStateLifetime gets the idle timeout
func (h *ConnectionParametersManager) GetIdleConnectionStateLifetime() (time.Duration, error) { func (h *ConnectionParametersManager) GetIdleConnectionStateLifetime() time.Duration {
rawValue, err := h.GetRawValue(TagICSL) rawValue, err := h.GetRawValue(TagICSL)
if err != nil { if err != nil {
return 0, err panic("ConnectionParameters: Could not find ICSL")
} }
if len(rawValue) != 4 { if len(rawValue) != 4 {
return 0, errors.New("expected uint32 for ICSL") panic("ConnectionParameters: ICSL has invalid value")
} }
return time.Duration(binary.LittleEndian.Uint32(rawValue)) * time.Second, nil return time.Duration(binary.LittleEndian.Uint32(rawValue)) * time.Second
} }

View File

@@ -62,8 +62,7 @@ var _ = Describe("ConnectionsParameterManager", func() {
It("gets idle connection state lifetime", func() { It("gets idle connection state lifetime", func() {
cpm.params[TagICSL] = []byte{0xad, 0xfb, 0xca, 0xde} cpm.params[TagICSL] = []byte{0xad, 0xfb, 0xca, 0xde}
val, err := cpm.GetIdleConnectionStateLifetime() val := cpm.GetIdleConnectionStateLifetime()
Expect(err).ToNot(HaveOccurred())
Expect(val).To(Equal(0xdecafbad * time.Second)) Expect(val).To(Equal(0xdecafbad * time.Second))
}) })
}) })

View File

@@ -119,6 +119,8 @@ func (s *Session) Run() {
s.scheduleSending() s.scheduleSending()
case <-s.sendingScheduled: case <-s.sendingScheduled:
err = s.sendPacket() err = s.sendPacket()
case <-time.After(s.connectionParametersManager.GetIdleConnectionStateLifetime()):
s.Close(protocol.NewQuicError(errorcodes.QUIC_NETWORK_IDLE_TIMEOUT, "No recent network activity."), true)
} }
if err != nil { if err != nil {

View File

@@ -45,6 +45,9 @@ var _ = Describe("Session", func() {
streams: make(map[protocol.StreamID]*stream), streams: make(map[protocol.StreamID]*stream),
streamCallback: func(*Session, utils.Stream) { callbackCalled = true }, streamCallback: func(*Session, utils.Stream) { callbackCalled = true },
connectionParametersManager: handshake.NewConnectionParamatersManager(), connectionParametersManager: handshake.NewConnectionParamatersManager(),
closeChan: make(chan struct{}, 1),
closeCallback: func(*Session) {},
packer: &packetPacker{aead: &crypto.NullAEAD{}},
} }
}) })
@@ -344,4 +347,13 @@ var _ = Describe("Session", func() {
Expect(conn.written).To(HaveLen(1)) Expect(conn.written).To(HaveLen(1))
Expect(conn.written[0]).To(ContainSubstring(string([]byte("PRST")))) Expect(conn.written[0]).To(ContainSubstring(string([]byte("PRST"))))
}) })
It("times out", func(done Done) {
session.connectionParametersManager.SetFromMap(map[handshake.Tag][]byte{
handshake.TagICSL: {0, 0, 0, 0},
})
session.Run() // Would normally not return
Expect(conn.written[0]).To(ContainSubstring("No recent network activity."))
close(done)
}, 0.5)
}) })