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