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
-- add nodestate to cache
now <- getPOSIXTime
queueAddEntries (Identity . RemoteCacheEntry (sender . head . Set.elems $ msgSet) $ now) ns
-- distinguish on whether and how to respond
-- create and enqueue ACK
-- Idea: only respond with payload on last part (part == parts), problem: need to know partnumber of response from first part on
-- 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
-- PLACEHOLDER
pure ()
aPart <- headMay . Set.elems $ msgSet
case aPart of
Nothing -> pure ()
Just aPart' ->
queueAddEntries (Identity . RemoteCacheEntry (sender aPart') $ now) ns
-- distinguish on whether and how to respond. If responding, pass message to response generating function and write responses to send queue
maybe (pure ()) (\respSet ->
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 .......