respond to Stabilise requests

This commit is contained in:
Trolli Schmittlauch 2020-06-06 17:31:20 +02:00
parent 43d72128d2
commit 53308080db

View file

@ -195,22 +195,44 @@ handleIncomingRequest nsSTM sendQ msgSet sourceAddr = do
-- -- ToDo: figure out what happens if not joined
-- QueryID -> Just <$> respondQueryID nsSTM msgSet
-- -- only when joined
-- Leave -> if isJoined_ ns then Just <$> respondLeave nsSTM msgSet else Nothing
-- Leave -> if isJoined_ ns then Just <$> respondLeave nsSTM msgSet else pure Nothing
-- -- only when joined
-- Stabilise -> if isJoined_ ns then Just <$> respondStabilise nsSTM msgSet else Nothing
-- )
Stabilise -> if isJoined_ ns then Just <$> respondStabilise nsSTM msgSet else pure 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
) -- placeholder
-- ....... response sending .......
-- TODO: could all these respond* functions be in STM instead of IO?
-- | respond to stabilise requests by returning successor and predecessor list
respondStabilise :: LocalNodeStateSTM -> Set.Set FediChordMessage -> IO (Map.Map Integer BS.ByteString)
respondStabilise nsSTM msgSet = do
nsSnap <- readTVarIO nsSTM
let
aRequestPart = Set.elemAt 0 msgSet
responsePayload = StabiliseResponsePayload {
stabiliseSuccessors = successors nsSnap
, stabilisePredecessors = predecessors nsSnap
}
stabiliseResponse = Response {
responseTo = requestID aRequestPart
, senderID = getNid nsSnap
, part = if Set.size msgSet == 1 then 1 else fromIntegral $ Set.size msgSet + 1
, isFinalPart = False
, action = Stabilise
, payload = Just responsePayload
}
-- TODO: return service endpoint for copying over key data
pure $ serialiseMessage sendMessageSize stabiliseResponse
-- | respond to Ping request by returning all active vserver NodeStates
respondPing :: LocalNodeStateSTM -> Set.Set FediChordMessage -> IO (Map.Map Integer BS.ByteString)
respondPing nsSTM msgSet = do
-- TODO: respond with all active VS when implementing k-choices