2020-03-20 19:01:25 +01:00
|
|
|
module Main where
|
|
|
|
|
2020-05-19 12:29:15 +02:00
|
|
|
import Control.Concurrent
|
2020-05-29 17:39:35 +02:00
|
|
|
import Control.Concurrent.Async
|
2020-06-04 22:29:11 +02:00
|
|
|
import Control.Concurrent.STM
|
|
|
|
import Control.Concurrent.STM.TVar
|
2020-05-27 17:48:01 +02:00
|
|
|
import Control.Exception
|
2020-05-27 19:10:45 +02:00
|
|
|
import Data.Either
|
2020-06-04 22:29:11 +02:00
|
|
|
import Data.IP (IPv6, toHostAddress6)
|
2020-05-19 12:29:15 +02:00
|
|
|
import System.Environment
|
2020-05-12 11:30:55 +02:00
|
|
|
|
2020-05-19 12:29:15 +02:00
|
|
|
import Hash2Pub.FediChord
|
2020-07-30 01:21:56 +02:00
|
|
|
import Hash2Pub.FediChordTypes
|
|
|
|
import Hash2Pub.PostService (PostService (..))
|
2020-03-20 19:01:25 +01:00
|
|
|
|
|
|
|
main :: IO ()
|
2020-05-12 11:30:55 +02:00
|
|
|
main = do
|
|
|
|
-- ToDo: parse and pass config
|
|
|
|
-- probably use `tomland` for that
|
2020-07-30 01:21:56 +02:00
|
|
|
(fConf, sConf) <- readConfig
|
2020-05-12 11:30:55 +02:00
|
|
|
-- ToDo: load persisted caches, bootstrapping nodes …
|
2020-09-20 19:30:35 +02:00
|
|
|
(fediThreads, thisNode) <- fediChordInit fConf (runService sConf :: DHT d => d -> IO (PostService d))
|
|
|
|
-- wait for all DHT threads to terminate, this keeps the main thread running
|
|
|
|
wait fediThreads
|
2020-05-12 11:30:55 +02:00
|
|
|
|
2020-05-26 20:54:02 +02:00
|
|
|
|
2020-07-30 01:21:56 +02:00
|
|
|
readConfig :: IO (FediChordConf, ServiceConf)
|
2020-05-12 11:30:55 +02:00
|
|
|
readConfig = do
|
2020-09-22 23:12:07 +02:00
|
|
|
confDomainString : ipString : portString : servicePortString : speedupString : loadBalancingEnabled : remainingArgs <- getArgs
|
2020-09-03 11:20:38 +02:00
|
|
|
-- allow starting the initial node without bootstrapping info to avoid
|
|
|
|
-- waiting for timeout
|
2020-07-30 01:21:56 +02:00
|
|
|
let
|
2020-09-04 11:08:40 +02:00
|
|
|
speedup = read speedupString
|
2020-09-03 11:20:38 +02:00
|
|
|
confBootstrapNodes' = case remainingArgs of
|
|
|
|
bootstrapHost : bootstrapPortString : _ ->
|
|
|
|
[(bootstrapHost, read bootstrapPortString)]
|
|
|
|
_ -> []
|
2020-09-09 17:12:56 +02:00
|
|
|
fConf = FediChordConf
|
|
|
|
{ confDomain = confDomainString
|
2020-09-04 11:08:40 +02:00
|
|
|
, confIP = toHostAddress6 . read $ ipString
|
|
|
|
, confDhtPort = read portString
|
|
|
|
, confBootstrapNodes = confBootstrapNodes'
|
2020-09-16 01:54:40 +02:00
|
|
|
, confStabiliseInterval = 80 * 10^6
|
2020-09-04 11:08:40 +02:00
|
|
|
, confBootstrapSamplingInterval = 180 * 10^6 `div` speedup
|
|
|
|
, confMaxLookupCacheAge = 300 / fromIntegral speedup
|
|
|
|
, confJoinAttemptsInterval = 60 * 10^6 `div` speedup
|
|
|
|
, confMaxNodeCacheAge = 600 / fromIntegral speedup
|
|
|
|
, confResponsePurgeAge = 60 / fromIntegral speedup
|
2020-09-04 16:53:48 +02:00
|
|
|
, confRequestTimeout = 5 * 10^6 `div` speedup
|
|
|
|
, confRequestRetries = 3
|
2020-09-22 23:12:07 +02:00
|
|
|
, confEnableKChoices = loadBalancingEnabled /= "off"
|
2020-09-25 00:42:41 +02:00
|
|
|
, confKChoicesOverload = 0.9
|
|
|
|
, confKChoicesUnderload = 0.1
|
|
|
|
, confKChoicesMaxVS = 8
|
2020-09-09 17:12:56 +02:00
|
|
|
}
|
|
|
|
sConf = ServiceConf
|
2020-09-16 16:07:39 +02:00
|
|
|
{ confSubscriptionExpiryTime = 24*3600 / fromIntegral speedup
|
2020-09-04 11:08:40 +02:00
|
|
|
, confServicePort = read servicePortString
|
|
|
|
, confServiceHost = confDomainString
|
2020-09-09 17:12:56 +02:00
|
|
|
, confLogfilePath = "../simulationData/logs/" <> confDomainString <> ".log"
|
2020-09-10 21:23:21 +02:00
|
|
|
, confSpeedupFactor = speedup
|
2020-09-14 14:57:25 +02:00
|
|
|
, confStatsEvalDelay = 120 * 10^6 `div` speedup
|
2020-09-09 17:12:56 +02:00
|
|
|
}
|
2020-07-30 01:21:56 +02:00
|
|
|
pure (fConf, sConf)
|
|
|
|
|