Hermes 0.0.3 → 0.0.4
raw patch · 2 files changed
+15/−13 lines, 2 filesdep +random-shufflePVP ok
version bump matches the API change (PVP)
Dependencies added: random-shuffle
API changes (from Hackage documentation)
Files
- Hermes.cabal +3/−2
- Network/Hermes/Gossip.hs +12/−11
Hermes.cabal view
@@ -3,7 +3,7 @@ Description: A middleware providing best-effort unicast, remote procedure calls, probabilistic (and slow!) broadcast and automatic membership management, meant for small to medium networks-Version: 0.0.3+Version: 0.0.4 License: BSD3 Author: Svein Ove Aas <svein.ove@aas.no> Maintainer: Svein Ove Aas <svein.ove@aas.no>@@ -19,7 +19,8 @@ Build-Depends: base == 4.*, bytestring, cereal >= 0.2, stm, hslogger >= 1.0.7, old-time, containers, AES >= 0.2.4, SHA2 >= 0.1.1, RSA >= 1.0.2, network, yjtools >= 0.9.7, random, monads-tf == 0.1.*,- syb == 0.1.*, unamb >= 0.2.2, time >= 1.1.4, transformers >= 0.1.4.0+ syb == 0.1.*, unamb >= 0.2.2, time >= 1.1.4, transformers >= 0.1.4.0,+ random-shuffle ghc-options:
Network/Hermes/Gossip.hs view
@@ -33,6 +33,7 @@ import Data.Maybe import System.Log.Logger import System.Random+import System.Random.Shuffle import Network.Hermes.Core import Network.Hermes.Misc@@ -208,15 +209,14 @@ -- (or we run out of peers). limitedGossip :: CoreContext -> Factoid -> FactoidKey -> IO () limitedGossip core factoid key = do- return () -- FIXME: THIS ENTIRE FUNCTION- -fooasdhu core factoid key = do -- HACK: Let the system bootstrap before we start looking for peers threadDelay 100000- -- Get a list of every peer we know the address of- -- FIXME: SHUFFLE THE LIST, FILTER OUT MYSELF- peers <- (fmap . fmap) fst $ atomically $ M.toList <$> readTVar (peerAddress core)- -- Then contact them, one by one. Instead of doing it serially, + -- Get a list of every peer we know the address of, shuffled+ rndgen <- newStdGen+ peers' <- (fmap . fmap) fst $ atomically $ M.toList <$> readTVar (peerAddress core)+ let peers = shuffle' peers' (length peers') rndgen+ -- Then contact them, one by one. Instead of doing it serially, we start a new contact+ -- every half-second. mvar <- newEmptyMVar acceptType core (undefined :: FactoidMessage) key timerThread <- forkIO $ forever $ do putMVar mvar Nothing; threadDelay 500000@@ -289,7 +289,8 @@ => GossipContext -> tag -> HermesID -> IO (Maybe factoid) readFactoid GossipContext{factoids} tag source = do let key = FactoidKey (showType (undefined :: factoid)) (showType tag) (encode tag)- factoid <- atomically $ fmap (decode . factoidData) . M.lookup source . M.findWithDefault M.empty key <$> readTVar factoids+ factoid' <- atomically $ M.lookup source . M.findWithDefault M.empty key <$> readTVar factoids+ let factoid = fmap (decode . factoidData) factoid' case factoid of Nothing -> return Nothing Just (Left err) -> alertM "hermes.gossip.readFactoid" ("Factoid decode error: " ++ err) >> return Nothing@@ -302,10 +303,10 @@ readFactoids GossipContext{factoids} tag = do let key = FactoidKey (showType (undefined :: factoid)) (showType tag) (encode tag) facts <- M.toList . M.findWithDefault M.empty key <$> atomically (readTVar factoids)- fmap catMaybes $ forM facts $ \(source, decode . factoidData -> factoid) -> do- case factoid of+ fmap catMaybes $ forM facts $ \(source, factoid) -> do+ case decode . factoidData $ factoid of Left err -> alertM "hermes.gossip.readFactoids" ("Factoid decode error: " ++ err) >> return Nothing- Right f -> return $ Just f+ Right f -> return $ Just (source,f) -- | Creates a gossiper from scratch