Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chrome greasing #20

Merged
merged 2 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions Network/QUIC/Packet/Frame.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Network/QUIC/Receiver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/FrameSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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