forked from schmittlauch/Hash2Pub
dispatch incoming requests to their response functions
- contributes to #28
This commit is contained in:
parent
0660bce299
commit
f42dfb2137
|
@ -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' ->
|
||||||
|
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: 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
|
-- TODO: test case: mixed message types of parts
|
||||||
-- PLACEHOLDER
|
|
||||||
pure ()
|
|
||||||
|
|
||||||
-- ....... response sending .......
|
-- ....... response sending .......
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue