distributed-process-p2p 0.1.3.0 → 0.1.3.1
raw patch · 3 files changed
+42/−16 lines, 3 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Control.Distributed.Backend.P2P: bootstrapNonBlocking :: HostName -> ServiceName -> [NodeId] -> RemoteTable -> Process () -> IO (LocalNode, ProcessId)
+ Control.Distributed.Backend.P2P: createLocalNode :: HostName -> ServiceName -> RemoteTable -> IO LocalNode
+ Control.Distributed.Backend.P2P: waitController :: Process a -> Process a
Files
- CHANGELOG +4/−0
- distributed-process-p2p.cabal +2/−2
- src/Control/Distributed/Backend/P2P.hs +36/−14
CHANGELOG view
@@ -1,3 +1,7 @@+0.1.3.1:++ * Unpack and export more bootstrapping functions.+ 0.1.3.0: * Update dependencies to Cloud Haskell release.
distributed-process-p2p.cabal view
@@ -1,5 +1,5 @@ name: distributed-process-p2p-version: 0.1.3.0+version: 0.1.3.1 synopsis: Peer-to-peer node discovery for Cloud Haskell description: Bootstraps a peer-to-peer connection network from a set of known hosts. homepage: https://bitbucket.org/dpwiz/distributed-process-p2p/@@ -20,7 +20,7 @@ library exposed-modules: Control.Distributed.Backend.P2P- -- other-modules: + -- other-modules: hs-source-dirs: src ghc-options: -Wall build-depends:
src/Control/Distributed/Backend/P2P.hs view
@@ -13,26 +13,32 @@ -- > P2P.nsendPeers "myService" ("some", "message") module Control.Distributed.Backend.P2P (+ -- * Starting peer controller bootstrap,+ bootstrapNonBlocking, peerController,+ -- * Nodes manipulation makeNodeId, getPeers, getCapable, nsendPeers,- nsendCapable+ nsendCapable,+ -- * Auxiliary+ createLocalNode,+ waitController ) where import Control.Distributed.Process as DP import Control.Distributed.Process.Node as DPN-import Control.Distributed.Process.Internal.Types as DPT import Control.Distributed.Process.Serializable (Serializable) import Network.Transport (EndPointAddress(..)) import Network.Socket (HostName, ServiceName) import Network.Transport.TCP (createTransport, defaultTCPParameters) -import Control.Monad-import Control.Concurrent.MVar+import Control.Applicative import Control.Concurrent (threadDelay)+import Control.Concurrent.MVar+import Control.Monad import qualified Data.ByteString.Char8 as BS import qualified Data.Set as S@@ -58,18 +64,35 @@ -- | Start a controller service process and aquire connections to a swarm. bootstrap :: HostName -> ServiceName -> [NodeId] -> RemoteTable -> Process () -> IO ()-bootstrap host port seeds rTable proc = do- transport <- either (error . show) id `fmap` createTransport host port defaultTCPParameters- node <- newLocalNode transport rTable+bootstrap host port seeds rTable prc = do+ node <- createLocalNode host port rTable+ _ <- forkProcess node $ peerController seeds+ runProcess node $ waitController prc +-- | Like 'bootstrap' but use 'forkProcess' instead of 'runProcess'. Returns local node and pid of given process+bootstrapNonBlocking :: HostName -> ServiceName -> [NodeId] -> RemoteTable -> Process () -> IO (LocalNode, ProcessId)+bootstrapNonBlocking host port seeds rTable prc = do+ node <- createLocalNode host port rTable _ <- forkProcess node $ peerController seeds- let waitController = do- res <- whereis peerControllerService- case res of- Nothing -> (liftIO $ threadDelay 100000) >> waitController- Just _ -> say "Bootstrap complete." >> proc- runProcess node waitController+ pid <- forkProcess node $ waitController prc+ return (node, pid) +-- | Waits for controller to start, then runs given process+waitController :: Process a -> Process a+waitController prc = do+ res <- whereis peerControllerService+ case res of+ Nothing -> (liftIO $ threadDelay 100000) >> waitController prc+ Just _ -> say "Bootstrap complete." >> prc++-- | Creates tcp local node which used by 'bootstrap'+createLocalNode :: HostName -> ServiceName -> RemoteTable -> IO LocalNode+createLocalNode host port rTable = do+ transport <- either (error . show) id+ <$> createTransport host port defaultTCPParameters+ newLocalNode transport rTable++ peerControllerService :: String peerControllerService = "P2P:Controller" @@ -195,4 +218,3 @@ -- | Broadcast a message to a service of on nodes currently running it. nsendCapable :: Serializable a => String -> a -> Process () nsendCapable service msg = getCapable service >>= mapM_ (\pid -> send pid msg)-