diff --git a/Network/QUIC/Packet/Frame.hs b/Network/QUIC/Packet/Frame.hs index c7e62255..e350b345 100644 --- a/Network/QUIC/Packet/Frame.hs +++ b/Network/QUIC/Packet/Frame.hs @@ -196,27 +196,30 @@ decodePadding rbuf = do countZero :: Ptr Word8 -> Ptr Word8 -> IO Int countZero beg0 end0 - | (end0 `minusPtr` beg0) <= ali = countBy1 beg0 end0 0 + | (end0 `minusPtr` beg0) <= ali = fst <$> countBy1 beg0 end0 0 | otherwise = do let beg1 = alignPtr beg0 ali end1' = alignPtr end0 ali end1 | end0 == end1' = end1' | otherwise = end1' `plusPtr` negate ali - n1 <- countBy1 beg0 beg1 0 - (n2,beg2) <- countBy8 (castPtr beg1) (castPtr end1) 0 - n3 <- countBy1 (castPtr beg2) end0 0 - return (n1 + n2 + n3) + (n1,cont1) <- countBy1 beg0 beg1 0 + if not cont1 then + return n1 + else do + (n2,beg2) <- countBy8 (castPtr beg1) (castPtr end1) 0 + (n3,_) <- countBy1 (castPtr beg2) end0 0 + return (n1 + n2 + n3) where ali = alignment (0 :: Word64) - countBy1 :: Ptr Word8 -> Ptr Word8 -> Int -> IO Int + countBy1 :: Ptr Word8 -> Ptr Word8 -> Int -> IO (Int,Bool) countBy1 beg end n | beg < end = do ftyp <- peek beg if ftyp == 0 then countBy1 (beg `plusPtr` 1) end (n + 1) else - return n - | otherwise = return n + return (n, False) + | otherwise = return (n, True) countBy8 :: Ptr Word64 -> Ptr Word64 -> Int -> IO (Int, Ptr Word64) countBy8 beg end n | beg < end = do diff --git a/Network/QUIC/Receiver.hs b/Network/QUIC/Receiver.hs index 25da7332..6d0366f4 100644 --- a/Network/QUIC/Receiver.hs +++ b/Network/QUIC/Receiver.hs @@ -183,7 +183,7 @@ processFrame :: Connection -> EncryptionLevel -> Frame -> IO () processFrame _ _ Padding{} = return () processFrame conn lvl Ping = do -- see ackEli above - when (lvl /= RTT1Level) $ sendFrames conn lvl [] + when (lvl /= InitialLevel && lvl /= RTT1Level) $ sendFrames conn lvl [] processFrame conn lvl (Ack ackInfo ackDelay) = do when (lvl == RTT0Level) $ closeConnection ProtocolViolation "ACK" onAckReceived (connLDCC conn) lvl ackInfo $ milliToMicro ackDelay diff --git a/test/FrameSpec.hs b/test/FrameSpec.hs index f0a3f616..914a2e8b 100644 --- a/test/FrameSpec.hs +++ b/test/FrameSpec.hs @@ -46,3 +46,8 @@ spec = do countZero (beg +. 1) (beg +. 10) `shouldReturn` 9 countZero (beg +. 1) (beg +. 11) `shouldReturn` 10 countZero (beg +. 2) (beg +. 3) `shouldReturn` 1 + poke (beg +. 10) (1 :: Word8) + countZero beg end `shouldReturn` 10 + countZero (beg +. 1) end `shouldReturn` 9 + countZero (beg +. 2) end `shouldReturn` 8 + countZero (beg +. 3) end `shouldReturn` 7