initialise own node state, preliminary config passing

This commit is contained in:
Trolli Schmittlauch 2020-05-12 11:30:55 +02:00
parent 1e870d1b13
commit 906cdc67c3
3 changed files with 56 additions and 3 deletions

View file

@ -74,7 +74,7 @@ executable Hash2Pub
import: deps import: deps
-- adding the library as a dependency -- adding the library as a dependency
build-depends: Hash2Pub build-depends: Hash2Pub, iproute
-- .hs or .lhs file containing the Main module. -- .hs or .lhs file containing the Main module.
main-is: Main.hs main-is: Main.hs

View file

@ -2,7 +2,7 @@
{- | {- |
Module : FediChord Module : FediChord
Description : An opinionated implementation of the EpiChord DHT by Leong et al. Description : An opinionated implementation of the EpiChord DHT by Leong et al.
Copyright : (c) schmittlauch, 2019 Copyright : (c) schmittlauch, 2019-2020
License : AGPL-3 License : AGPL-3
Stability : experimental Stability : experimental
@ -36,6 +36,8 @@ module Hash2Pub.FediChord (
, byteStringToUInteger , byteStringToUInteger
, ipAddrAsBS , ipAddrAsBS
, bsAsIpAddr , bsAsIpAddr
, FediChordConf(..)
, fediChordInit
) where ) where
import qualified Data.Map.Strict as Map import qualified Data.Map.Strict as Map
@ -392,3 +394,35 @@ checkCacheSlices state = case getNodeCache state of
-- Todo: DHT backend can learn potential initial bootstrapping points through the instances mentioned in the received AP-relay messages -- Todo: DHT backend can learn potential initial bootstrapping points through the instances mentioned in the received AP-relay messages
-- needs to know its own domain anyways for ID generation -- needs to know its own domain anyways for ID generation
-- persist them on disk so they can be used for all following bootstraps -- persist them on disk so they can be used for all following bootstraps
-- | configuration values used for initialising the FediChord DHT
data FediChordConf = FediChordConf {
confDomain :: String
, confIP :: HostAddress6
, confDhtPort :: Int
} deriving (Show, Eq)
-- | initialise data structures, compute own IDs.
-- ToDo: load persisted state, thus this function already operates in IO
fediChordInit :: FediChordConf -> IO NodeState
fediChordInit conf = return $ NodeState {
domain = confDomain conf
, ipAddr = confIP conf
, nid = genNodeID (confIP conf) (confDomain conf) 0
, dhtPort = toEnum $ confDhtPort conf
, apPort = Nothing
, vServerID = 0
, internals = Just internalsInit
}
where
internalsInit = InternalNodeState {
nodeCache = initCache
, successors = []
, predecessors = []
, kNeighbours = 3
, lNumBestNodes = 3
, pNumParallelQueries = 2
, jEntriesPerSlice = 2
}

View file

@ -1,6 +1,25 @@
module Main where module Main where
import System.Environment
import Data.IP (IPv6, toHostAddress6) -- iproute, just for IPv6 string parsing
import Hash2Pub.FediChord import Hash2Pub.FediChord
main :: IO () main :: IO ()
main = putStrLn "placeholder until later" main = do
-- ToDo: parse and pass config
-- probably use `tomland` for that
conf <- readConfig
-- ToDo: load persisted caches, bootstrapping nodes …
thisNode <- fediChordInit conf
print thisNode
return ()
readConfig :: IO FediChordConf
readConfig = do
confDomainString : ipString : portString : _ <- getArgs
return $ FediChordConf {
confDomain = confDomainString
, confIP = toHostAddress6 . read $ ipString
, confDhtPort = read portString
}