From ff1e530a26e39352250fefac032c31e759248121 Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Thu, 14 May 2020 12:26:05 +0200 Subject: [PATCH] function for updating CacheEntry timestamp and mark as verified --- Hash2Pub/src/Hash2Pub/DHTProtocol.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Hash2Pub/src/Hash2Pub/DHTProtocol.hs b/Hash2Pub/src/Hash2Pub/DHTProtocol.hs index 3defeac..a71b953 100644 --- a/Hash2Pub/src/Hash2Pub/DHTProtocol.hs +++ b/Hash2Pub/src/Hash2Pub/DHTProtocol.hs @@ -196,3 +196,14 @@ deleteCacheEntry = Map.update modifier modifier (ProxyEntry idPointer _) = Just (ProxyEntry idPointer Nothing) modifier NodeEntry {} = Nothing +-- | Mark a cache entry as verified after pinging it, possibly bumping its timestamp. +markCacheEntryAsVerified :: Maybe POSIXTime -- ^ the (current) timestamp to be + -- given to the entry, or Nothing + -> NodeID -- ^ which node to mark + -> NodeCache -- ^ current node cache + -> NodeCache -- ^ new NodeCache with the updated entry +markCacheEntryAsVerified timestamp = Map.adjust adjustFunc + where + adjustFunc (NodeEntry _ ns ts) = NodeEntry True ns $ fromMaybe ts timestamp + adjustFunc (ProxyEntry _ (Just entry)) = adjustFunc entry + adjustFunc entry = entry