Skip to content

Commit

Permalink
introducing streamNotCreatedYet
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Aug 18, 2024
1 parent 2fb1b37 commit 9cd4bb8
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions Network/QUIC/Receiver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,21 @@ isInitiated conn sid
| otherwise = isServerInitiated sid

guardStream :: Connection -> StreamId -> Maybe Stream -> IO ()
guardStream conn sid Nothing
guardStream conn sid Nothing =
streamNotCreatedYet
conn
sid
"a locally-initiated stream that has not yet been created"
guardStream _ _ _ = return ()

-- fixme: what about unidirection stream?
streamNotCreatedYet :: Connection -> StreamId -> ReasonPhrase -> IO ()
streamNotCreatedYet conn sid emsg
| isInitiated conn sid = do
curSid <- getMyStreamId conn
when (sid > curSid) $
closeConnection
StreamStateError
"a locally-initiated stream that has not yet been created"
guardStream _ _ _ = return ()
closeConnection StreamStateError emsg
streamNotCreatedYet _ _ _ = return ()

processFrame :: Connection -> EncryptionLevel -> Frame -> IO ()
processFrame _ _ Padding{} = return ()
Expand Down Expand Up @@ -247,9 +254,7 @@ processFrame conn lvl (StopSending sid err) = do
closeConnection StreamStateError "Receive-only stream"
mstrm <- findStream conn sid
case mstrm of
Nothing -> do
when (isInitiated conn sid) $
closeConnection StreamStateError "No such stream for STOP_SENDING"
Nothing -> streamNotCreatedYet conn sid "No such stream for STOP_SENDING"
Just _strm -> sendFramesLim conn lvl [ResetStream sid err 0]
processFrame _ _ (CryptoF _ "") = return ()
processFrame conn lvl (CryptoF off cdat) = do
Expand Down Expand Up @@ -338,11 +343,7 @@ processFrame conn lvl (MaxStreamData sid n) = do
closeConnection StreamStateError "Receive-only stream"
mstrm <- findStream conn sid
case mstrm of
Nothing ->
when (isInitiated conn sid) $ do
curSid <- getMyStreamId conn
when (sid > curSid) $
closeConnection StreamStateError "No such stream for MAX_STREAM_DATA"
Nothing -> streamNotCreatedYet conn sid "No such stream for MAX_STREAM_DATA"
Just strm -> setTxMaxStreamData strm n
processFrame conn lvl (MaxStreams dir n) = do
when (lvl == InitialLevel || lvl == HandshakeLevel) $
Expand Down

0 comments on commit 9cd4bb8

Please sign in to comment.