forked from schmittlauch/Hash2Pub
respond to Ping requests
This commit is contained in:
parent
cb769e088f
commit
43d72128d2
|
@ -190,7 +190,7 @@ handleIncomingRequest nsSTM sendQ msgSet sourceAddr = do
|
||||||
mapM_ (\resp -> atomically $ writeTQueue sendQ (resp, sourceAddr))
|
mapM_ (\resp -> atomically $ writeTQueue sendQ (resp, sourceAddr))
|
||||||
)
|
)
|
||||||
=<< (case action aPart of
|
=<< (case action aPart of
|
||||||
-- Ping -> Just <$> respondPing nsSTM msgSet
|
Ping -> Just <$> respondPing nsSTM msgSet
|
||||||
Join -> Just <$> respondJoin nsSTM msgSet
|
Join -> Just <$> respondJoin nsSTM msgSet
|
||||||
-- -- ToDo: figure out what happens if not joined
|
-- -- ToDo: figure out what happens if not joined
|
||||||
-- QueryID -> Just <$> respondQueryID nsSTM msgSet
|
-- QueryID -> Just <$> respondQueryID nsSTM msgSet
|
||||||
|
@ -209,6 +209,25 @@ handleIncomingRequest nsSTM sendQ msgSet sourceAddr = do
|
||||||
|
|
||||||
-- ....... response sending .......
|
-- ....... response sending .......
|
||||||
|
|
||||||
|
-- TODO: could all these respond* functions be in STM instead of IO?
|
||||||
|
|
||||||
|
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
|
||||||
|
nsSnap <- readTVarIO nsSTM
|
||||||
|
let
|
||||||
|
aRequestPart = Set.elemAt 0 msgSet
|
||||||
|
responsePayload = PingResponsePayload { pingNodeStates = [ toRemoteNodeState nsSnap ] }
|
||||||
|
pingResponse = Response {
|
||||||
|
responseTo = requestID aRequestPart
|
||||||
|
, senderID = getNid nsSnap
|
||||||
|
, part = if Set.size msgSet == 1 then 1 else fromIntegral $ Set.size msgSet + 1
|
||||||
|
, isFinalPart = False
|
||||||
|
, action = Ping
|
||||||
|
, payload = Just responsePayload
|
||||||
|
}
|
||||||
|
pure $ serialiseMessage sendMessageSize pingResponse
|
||||||
|
|
||||||
-- this modifies node state, so locking and IO seems to be necessary.
|
-- this modifies node state, so locking and IO seems to be necessary.
|
||||||
-- Still try to keep as much code as possible pure
|
-- Still try to keep as much code as possible pure
|
||||||
respondJoin :: LocalNodeStateSTM -> Set.Set FediChordMessage -> IO (Map.Map Integer BS.ByteString)
|
respondJoin :: LocalNodeStateSTM -> Set.Set FediChordMessage -> IO (Map.Map Integer BS.ByteString)
|
||||||
|
|
Loading…
Reference in a new issue