Safe Haskell | None |
---|---|
Language | Haskell2010 |
Peer-to-peer node discovery backend for Cloud Haskell based on the TCP transport. Provided with a known node address it discovers and maintains the knowledge of it's peers.
import qualified Control.Distributed.Backend.P2P as P2P import Control.Monad.Trans (liftIO) import Control.Concurrent (threadDelay) main = P2P.bootstrap "myhostname" "9001" [P2P.makeNodeId "seedhost:9000"] $ do liftIO $ threadDelay 1000000 -- give dispatcher a second to discover other nodes P2P.nsendPeers "myService" ("some", "message")
- bootstrap :: HostName -> ServiceName -> (ServiceName -> (HostName, ServiceName)) -> RemoteTable -> [NodeId] -> Process () -> IO ()
- bootstrapNonBlocking :: HostName -> ServiceName -> (ServiceName -> (HostName, ServiceName)) -> RemoteTable -> [NodeId] -> Process () -> IO (LocalNode, ProcessId)
- peerController :: [NodeId] -> Process ()
- makeNodeId :: String -> NodeId
- getPeers :: Process [NodeId]
- getCapable :: String -> Process [ProcessId]
- nsendPeers :: Serializable a => String -> a -> Process ()
- nsendCapable :: Serializable a => String -> a -> Process ()
- createLocalNode :: HostName -> ServiceName -> (ServiceName -> (HostName, ServiceName)) -> RemoteTable -> IO LocalNode
- waitController :: Process a -> Process a
Starting peer controller
bootstrap :: HostName -> ServiceName -> (ServiceName -> (HostName, ServiceName)) -> RemoteTable -> [NodeId] -> Process () -> IO () Source #
Start a controller service process and aquire connections to a swarm.
bootstrapNonBlocking :: HostName -> ServiceName -> (ServiceName -> (HostName, ServiceName)) -> RemoteTable -> [NodeId] -> Process () -> IO (LocalNode, ProcessId) Source #
Like bootstrap
but use forkProcess
instead of runProcess
. Returns local node and pid of given process
peerController :: [NodeId] -> Process () Source #
A P2P controller service process.
Nodes manipulation
makeNodeId :: String -> NodeId Source #
Make a NodeId from "host:port" string.
getCapable :: String -> Process [ProcessId] Source #
Poll a network for a list of specific service providers.
nsendPeers :: Serializable a => String -> a -> Process () Source #
Broadcast a message to a specific service on all peers.
nsendCapable :: Serializable a => String -> a -> Process () Source #
Broadcast a message to a service of on nodes currently running it.
Auxiliary
createLocalNode :: HostName -> ServiceName -> (ServiceName -> (HostName, ServiceName)) -> RemoteTable -> IO LocalNode Source #
Creates tcp local node which used by bootstrap
waitController :: Process a -> Process a Source #
Waits for controller to start, then runs given process