dp wiz avatar dp wiz committed c3b7825

Fork peer controller and run a useful process instead.

Comments (0)

Files changed (1)

src/Control/Distributed/Backend/P2P.hs

 makeNodeId addr = DPT.NodeId . EndPointAddress . BS.concat $ [BS.pack addr, ":0"]
 
 -- | Start a peerController process and aquire connections to a swarm.
-bootstrap :: String -> String -> [DPT.NodeId] -> IO ()
-bootstrap host port seeds = do
+bootstrap :: String -> String -> [DPT.NodeId] -> (DPN.LocalNode -> DPT.ProcessId -> DP.Process ()) -> IO ()
+bootstrap host port seeds proc = do
     transport <- either (error . show) id `fmap` createTransport host port defaultTCPParameters
     node <- DPN.newLocalNode transport DPN.initRemoteTable
 
-    DPN.runProcess node $ do
+    pcPid <- DPN.forkProcess node $ do
         pid <- getSelfPid
         register "peerController" pid
         peerSet <- liftIO $ newMVar (S.singleton pid)
 
         forM_ seeds $ flip whereisRemoteAsync "peerController"
 
-        forever $ do
-            receiveTimeout 5000000 [ match $ onPeerMsg peerSet
-                                   , match $ onMonitor peerSet
-                                   , match $ onDiscover pid
-                                   ]
-            liftIO $ readMVar peerSet >>= print
+        forever $ receiveWait [ match $ onPeerMsg peerSet
+                              , match $ onMonitor peerSet
+                              , match $ onDiscover pid
+                              ]
+
+    DPN.runProcess node $ proc node pcPid
 
 data PeerMessage = PeerPing
                  | PeerExchange [DPT.ProcessId]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.