From c37fe88b354644f4b497623d27a2b3e8cfa2f5f8 Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Wed, 15 Jul 2020 01:44:47 +0200 Subject: [PATCH] store and initialise lookup cache contributes to #24 --- src/Hash2Pub/FediChord.hs | 2 ++ src/Hash2Pub/FediChordTypes.hs | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/Hash2Pub/FediChord.hs b/src/Hash2Pub/FediChord.hs index 6f1be65..dc32c77 100644 --- a/src/Hash2Pub/FediChord.hs +++ b/src/Hash2Pub/FediChord.hs @@ -94,10 +94,12 @@ import Debug.Trace (trace) -- ToDo: load persisted state, thus this function already operates in IO fediChordInit :: FediChordConf -> IO (Socket, LocalNodeStateSTM) fediChordInit initConf = do + emptyLookupCache <- newTVarIO Map.empty let realNode = RealNode { vservers = [] , nodeConfig = initConf , bootstrapNodes = confBootstrapNodes initConf + , lookupCacheSTM = emptyLookupCache } realNodeSTM <- newTVarIO realNode initialState <- nodeStateInit realNodeSTM diff --git a/src/Hash2Pub/FediChordTypes.hs b/src/Hash2Pub/FediChordTypes.hs index b5df0d4..9366a3f 100644 --- a/src/Hash2Pub/FediChordTypes.hs +++ b/src/Hash2Pub/FediChordTypes.hs @@ -145,6 +145,8 @@ data RealNode = RealNode -- ^ holds the initial configuration read at program start , bootstrapNodes :: [(String, PortNumber)] -- ^ nodes to be used as bootstrapping points, new ones learned during operation + , lookupCacheSTM :: TVar LookupCache + -- ^ a global cache of looked up keys and their associated nodes } type RealNodeSTM = TVar RealNode @@ -294,6 +296,9 @@ instance HasKeyID NodeID where type NodeCacheEntry = CacheEntry RemoteNodeState type NodeCache = RingMap NodeCacheEntry +type LookupCacheEntry = CacheEntry (String, PortNumber) +type LookupCache = Map.Map NodeID LookupCacheEntry + -- | generic data structure for holding elements with a key and modular lookup newtype RingMap a = RingMap { getRingMap :: HasKeyID a => Map.Map NodeID (RingEntry a) }