dispatch incoming requests to their response functions

- contributes to #28
This commit is contained in:
Trolli Schmittlauch 2020-06-03 23:46:05 +02:00
parent 0660bce299
commit f42dfb2137

View file

@ -177,14 +177,28 @@ handleIncomingRequest :: LocalNodeState -- ^ the handling no
handleIncomingRequest ns sendQ msgSet sourceAddr = do handleIncomingRequest ns sendQ msgSet sourceAddr = do
-- add nodestate to cache -- add nodestate to cache
now <- getPOSIXTime now <- getPOSIXTime
queueAddEntries (Identity . RemoteCacheEntry (sender . head . Set.elems $ msgSet) $ now) ns aPart <- headMay . Set.elems $ msgSet
-- distinguish on whether and how to respond case aPart of
-- create and enqueue ACK Nothing -> pure ()
-- Idea: only respond with payload on last part (part == parts), problem: need to know partnumber of response from first part on Just aPart' ->
-- TODO: determine request type only from first part, but catch RecSelError on each record access when folding, because otherwise different request type parts can make this crash queueAddEntries (Identity . RemoteCacheEntry (sender aPart') $ now) ns
-- TODO: test case: mixed message types of parts -- distinguish on whether and how to respond. If responding, pass message to response generating function and write responses to send queue
-- PLACEHOLDER maybe (pure ()) (\respSet ->
pure () forM_ (\resp -> atomically $ writeTQueue sendQ (resp, sourceAddr)))
(case action aPart' of
Ping -> Just respondPing ns msgSet
Join -> Just respondJoin ns msgSet
-- ToDo: figure out what happens if not joined
QueryID -> Just respondQueryID ns msgSet
-- only when joined
Leave -> if isJoined_ ns then Just respondLeave ns msgSet else Nothing
-- only when joined
Stabilise -> if isJoined_ ns then Just respondStabilise ns msgSet else Nothing
)
-- for single part request, response starts with part number 1. For multipart requests, response starts with part number n+1.
-- TODO: determine request type only from first part, but catch RecSelError on each record access when folding, because otherwise different request type parts can make this crash
-- TODO: test case: mixed message types of parts
-- ....... response sending ....... -- ....... response sending .......