Exposes mechanisms for a program built on the Remote.Process framework to discover nodes on the current network. Programs can perform node discovery manually, or they can use Remote.Task, which does it automatically.
Documentation
type PeerInfo = Map String [NodeId]Source
Created by Remote.Peer.getPeers
, this maps
each role to a list of nodes that have that role.
It can be examined directly or queried with
findPeerByRole
.
startDiscoveryService :: ProcessM ()Source
Starts the discovery process, allowing this node to respond to
queries from getPeersDynamic. You don't want to call this yourself,
as it's called for you in Remote.Init.remoteInit
getPeers :: ProcessM PeerInfoSource
Returns information about all nodes on the current network
that this node knows about. This function combines dynamic
and static mechanisms. See documentation on getPeersStatic
and getPeersDynamic
for more info. This function depends
on the configuration values cfgKnownHosts
and cfgPeerDiscoveryPort
.
getPeersStatic :: ProcessM PeerInfoSource
Returns a PeerInfo, containing a list of known nodes ordered by role. This information is acquired by querying the local node registry on each of the hosts in the cfgKnownHosts entry in this node's config. Hostnames that don't respond are assumed to be down and nodes running on them won't be included in the results.
getPeersDynamic :: Int -> ProcessM PeerInfoSource
Returns a PeerInfo, containing a list of known nodes ordered by role. This information is acquired by sending out a UDP broadcast on the local network; active nodes running the discovery service should respond with their information. If nodes are running outside of the local network, or if UDP broadcasts are disabled by firewall configuration, this won't return useful information; in that case, use getPeersStatic. This function takes a parameter indicating how long in microseconds to wait for hosts to respond. A number like 50000 is usually good enough, unless your network is highly congested or with high latency.
findPeerByRole :: PeerInfo -> String -> [NodeId]Source
Given a PeerInfo returned by getPeersDynamic or getPeersStatic, give a list of nodes registered as a particular role. If no nodes of that role are found, the empty list is returned.