From 43e4ab184e51a4632e92860b628155ceb3b6a4f7 Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Wed, 17 Jun 2020 14:53:36 +0200 Subject: [PATCH] adjust cache entry insertion to usage of RingMap #48 --- src/Hash2Pub/DHTProtocol.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Hash2Pub/DHTProtocol.hs b/src/Hash2Pub/DHTProtocol.hs index 2fe41eb..3c6cd6c 100644 --- a/src/Hash2Pub/DHTProtocol.hs +++ b/src/Hash2Pub/DHTProtocol.hs @@ -60,6 +60,7 @@ import Hash2Pub.FediChordTypes (CacheEntry (..), NodeID, NodeState (..), RemoteNodeState (..), RingEntry (..), RingMap (..), + addRMapEntryWith, cacheGetNodeStateUnvalidated, cacheLookup, cacheLookupPred, cacheLookupSucc, localCompare, @@ -114,14 +115,14 @@ addCacheEntry entry cache = do -- | pure version of 'addCacheEntry' with current time explicitly specified as argument addCacheEntryPure :: POSIXTime -- ^ current time - -> RemoteCacheEntry -- ^ a remote cache entry received from network - -> NodeCache -- ^ node cache to insert to - -> NodeCache -- ^ new node cache with the element inserted + -> RemoteCacheEntry -- ^ a remote cache entry received from network + -> NodeCache -- ^ node cache to insert to + -> NodeCache -- ^ new node cache with the element inserted addCacheEntryPure now (RemoteCacheEntry ns ts) cache = let -- TODO: limit diffSeconds to some maximum value to prevent malicious nodes from inserting entries valid nearly until eternity timestamp' = if ts <= now then ts else now - newCache = addRMapEntryWith insertCombineFunction (KeyEntry (CacheEntry False ns timestamp')) cache + newCache = addRMapEntryWith insertCombineFunction (CacheEntry False ns timestamp') cache insertCombineFunction newVal@(KeyEntry (CacheEntry newValidationState newNode newTimestamp)) oldVal = case oldVal of ProxyEntry n _ -> ProxyEntry n (Just newVal)