store and initialise lookup cache

contributes to #24
This commit is contained in:
Trolli Schmittlauch 2020-07-15 01:44:47 +02:00
parent 42af6afb86
commit c37fe88b35
2 changed files with 7 additions and 0 deletions

View file

@ -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

View file

@ -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) }