summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Announcer.hs19
1 files changed, 10 insertions, 9 deletions
diff --git a/Announcer.hs b/Announcer.hs
index 9558e3eb..e9d83e65 100644
--- a/Announcer.hs
+++ b/Announcer.hs
@@ -57,9 +57,10 @@ unpackAnnounceKey _ (AnnounceKey bs) = return $ Char8.unpack bs
57-- 'Announce'. 57-- 'Announce'.
58data ScheduledItem 58data ScheduledItem
59 = DeleteAnnouncement 59 = DeleteAnnouncement
60 -- NewAnnouncement searchAgain search announce aInterval
60 | NewAnnouncement (STM (IO ())) (IO ()) (IO ()) POSIXTime 61 | NewAnnouncement (STM (IO ())) (IO ()) (IO ()) POSIXTime
61 | Announce (STM (IO ())) (IO ()) POSIXTime 62 | Announce (STM (IO ())) (IO ()) POSIXTime
62 | SearchResult (STM (IO ())) 63 | ScheduledItem (Announcer -> AnnounceKey -> POSIXTime -> STM (IO ()))
63 | StopAnnouncer 64 | StopAnnouncer
64 -- Can't use Data because STM and IO. :( 65 -- Can't use Data because STM and IO. :(
65 -- deriving Data {- itemStatusNum sch = constrIndex $ toConstr sch -} 66 -- deriving Data {- itemStatusNum sch = constrIndex $ toConstr sch -}
@@ -73,7 +74,7 @@ itemStatusNum :: ScheduledItem -> Int
73itemStatusNum (DeleteAnnouncement ) = 0 74itemStatusNum (DeleteAnnouncement ) = 0
74itemStatusNum (NewAnnouncement {}) = 1 75itemStatusNum (NewAnnouncement {}) = 1
75itemStatusNum (Announce {}) = 2 76itemStatusNum (Announce {}) = 2
76itemStatusNum (SearchResult {}) = 3 77itemStatusNum (ScheduledItem {}) = 3
77itemStatusNum (StopAnnouncer ) = 4 78itemStatusNum (StopAnnouncer ) = 4
78itemStatusNum _ = error "itemStatusNum not in sync with ScheduledItem declaration." 79itemStatusNum _ = error "itemStatusNum not in sync with ScheduledItem declaration."
79 80
@@ -182,7 +183,7 @@ schedule announcer k AnnounceMethod{aSearch,aPublish,aBuckets,aTarget,aInterval}
182 onResult sr 183 onResult sr
183 | Right _ <- aPublish = return True 184 | Right _ <- aPublish = return True
184 | Left sendit <- aPublish = do 185 | Left sendit <- aPublish = do
185 scheduleImmediately announcer k $ SearchResult $ return $ do 186 scheduleImmediately announcer k $ ScheduledItem $ \_ _ _ -> return $ do
186 got <- sendit r sr 187 got <- sendit r sr
187 -- If we had a way to get the source of a search result, we might want to 188 -- If we had a way to get the source of a search result, we might want to
188 -- treat it similarly to an announcing node and remember it in the 'aStoringNodes' 189 -- treat it similarly to an announcing node and remember it in the 'aStoringNodes'
@@ -269,7 +270,12 @@ announceThread announcer = do
269performScheduledItem :: Announcer -> POSIXTime -> Binding' AnnounceKey POSIXTime ScheduledItem -> STM (Maybe (IO ())) 270performScheduledItem :: Announcer -> POSIXTime -> Binding' AnnounceKey POSIXTime ScheduledItem -> STM (Maybe (IO ()))
270performScheduledItem announcer now = \case 271performScheduledItem announcer now = \case
271 272
272 (Binding _ StopAnnouncer _) -> return Nothing 273 (Binding _ StopAnnouncer _) -> return Nothing
274
275 -- announcement removed:
276 (Binding _ DeleteAnnouncement _) -> return $ Just $ return ()
277
278 (Binding k (ScheduledItem action) _) -> Just <$> action announcer k now
273 279
274 -- announcement started: 280 -- announcement started:
275 (Binding k (NewAnnouncement checkFin search announce interval) _) -> do 281 (Binding k (NewAnnouncement checkFin search announce interval) _) -> do
@@ -277,9 +283,6 @@ performScheduledItem announcer now = \case
277 (PSQ.insert' k (Announce checkFin announce interval) (now + interval)) 283 (PSQ.insert' k (Announce checkFin announce interval) (now + interval))
278 return $ Just $ void $ fork search 284 return $ Just $ void $ fork search
279 285
280 -- announcement removed:
281 (Binding k DeleteAnnouncement _) -> return $ Just $ return ()
282
283 -- time for periodic announce: 286 -- time for periodic announce:
284 -- (re-)announce to the current known set of storing-nodes. 287 -- (re-)announce to the current known set of storing-nodes.
285 -- TODO: If the search is finished, restart the search. 288 -- TODO: If the search is finished, restart the search.
@@ -292,6 +295,4 @@ performScheduledItem announcer now = \case
292 hPutStrLn stderr $ "This print avoids negative-time future scheduling. Weird bug. TODO: fix it. "++show now 295 hPutStrLn stderr $ "This print avoids negative-time future scheduling. Weird bug. TODO: fix it. "++show now
293 announce 296 announce
294 297
295 (Binding _ (SearchResult action) _) -> Just <$> action
296
297 298