diff --git a/Hash2Pub/Hash2Pub.cabal b/Hash2Pub/Hash2Pub.cabal index d487de4..2774a4b 100644 --- a/Hash2Pub/Hash2Pub.cabal +++ b/Hash2Pub/Hash2Pub.cabal @@ -74,7 +74,7 @@ executable Hash2Pub import: deps -- adding the library as a dependency - build-depends: Hash2Pub + build-depends: Hash2Pub, iproute -- .hs or .lhs file containing the Main module. main-is: Main.hs diff --git a/Hash2Pub/src/Hash2Pub/FediChord.hs b/Hash2Pub/src/Hash2Pub/FediChord.hs index e0ba99a..ea2be14 100644 --- a/Hash2Pub/src/Hash2Pub/FediChord.hs +++ b/Hash2Pub/src/Hash2Pub/FediChord.hs @@ -2,7 +2,7 @@ {- | Module : FediChord Description : An opinionated implementation of the EpiChord DHT by Leong et al. -Copyright : (c) schmittlauch, 2019 +Copyright : (c) schmittlauch, 2019-2020 License : AGPL-3 Stability : experimental @@ -36,6 +36,8 @@ module Hash2Pub.FediChord ( , byteStringToUInteger , ipAddrAsBS , bsAsIpAddr + , FediChordConf(..) + , fediChordInit ) where 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 -- needs to know its own domain anyways for ID generation -- 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 + } + + diff --git a/Hash2Pub/src/Hash2Pub/Main.hs b/Hash2Pub/src/Hash2Pub/Main.hs index 5160894..3f6e9ff 100644 --- a/Hash2Pub/src/Hash2Pub/Main.hs +++ b/Hash2Pub/src/Hash2Pub/Main.hs @@ -1,6 +1,25 @@ module Main where +import System.Environment +import Data.IP (IPv6, toHostAddress6) -- iproute, just for IPv6 string parsing + import Hash2Pub.FediChord 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 + }