diff --git a/src/Hash2Pub/FediChord.hs b/src/Hash2Pub/FediChord.hs index 914ea57..858b38e 100644 --- a/src/Hash2Pub/FediChord.hs +++ b/src/Hash2Pub/FediChord.hs @@ -105,20 +105,23 @@ fediChordInit initConf serviceRunner = do , nodeConfig = initConf , bootstrapNodes = confBootstrapNodes initConf , lookupCacheSTM = emptyLookupCache - --, service = undefined + , nodeService = undefined } realNodeSTM <- newTVarIO realNode -- launch service and set the reference in the RealNode serv <- serviceRunner realNodeSTM - --atomically . writeTVar $ realNode { service = serv } + atomically . modifyTVar' realNodeSTM $ \rn -> rn { nodeService = serv } + -- initialise a single vserver initialState <- nodeStateInit realNodeSTM initialStateSTM <- newTVarIO initialState + -- add vserver to list at RealNode + atomically . modifyTVar' realNodeSTM $ \rn -> rn { vservers = initialStateSTM:vservers rn } serverSock <- mkServerSocket (getIpAddr initialState) (getDhtPort initialState) pure (serverSock, initialStateSTM) -- | initialises the 'NodeState' for this local node. -- Separated from 'fediChordInit' to be usable in tests. -nodeStateInit :: RealNodeSTM s -> IO (LocalNodeState s) +nodeStateInit :: Service s (RealNodeSTM s) => RealNodeSTM s -> IO (LocalNodeState s) nodeStateInit realNodeSTM = do realNode <- readTVarIO realNodeSTM cacheSTM <- newTVarIO initCache @@ -131,7 +134,7 @@ nodeStateInit realNodeSTM = do , ipAddr = confIP conf , nid = genNodeID (confIP conf) (confDomain conf) $ fromInteger vsID , dhtPort = toEnum $ confDhtPort conf - , servicePort = 0 + , servicePort = getListeningPortFromService $ nodeService realNode , vServerID = vsID } initialState = LocalNodeState { @@ -543,7 +546,7 @@ sendThread sock sendQ = forever $ do fediMainThreads :: Socket -> LocalNodeStateSTM s -> IO () fediMainThreads sock nsSTM = do ns <- readTVarIO nsSTM - putStrLn $ "launching threads" + putStrLn "launching threads" sendQ <- newTQueueIO recvQ <- newTQueueIO -- concurrently launch all handler threads, if one of them throws an exception diff --git a/src/Hash2Pub/FediChordTypes.hs b/src/Hash2Pub/FediChordTypes.hs index 5b8ef17..e73e7f5 100644 --- a/src/Hash2Pub/FediChordTypes.hs +++ b/src/Hash2Pub/FediChordTypes.hs @@ -423,7 +423,7 @@ data FediChordConf = FediChordConf class Service s d where -- | run the service runService :: ServiceConf -> d -> IO (s d) - getServicePort' :: (Integral i) => s d -> i + getListeningPortFromService :: (Integral i) => s d -> i instance Hashable.Hashable NodeID where hashWithSalt salt = Hashable.hashWithSalt salt . getNodeID diff --git a/src/Hash2Pub/PostService.hs b/src/Hash2Pub/PostService.hs index d5dd30d..ae122e2 100644 --- a/src/Hash2Pub/PostService.hs +++ b/src/Hash2Pub/PostService.hs @@ -97,7 +97,7 @@ instance DHT d => Service PostService d where atomically $ writeTVar threadVar servThreadID pure thisService - getServicePort' = fromIntegral . confServicePort . serviceConf + getListeningPortFromService = fromIntegral . confServicePort . serviceConf -- | return a WAI application