@@ -29,9 +29,16 @@ import qualified Data.Map as Map
29 , partitionWithKey
29 , partitionWithKey
31 , filterWithKey
31 , filterWithKey
33import Data.Set (Set)
34import Data.Set (Set)
34−import qualified Data.Set as Set (empty, insert, delete, member)
35+import qualified Data.Set as Set
35import Data.Foldable (forM_)
42import Data.Foldable (forM_)
36import Data.Maybe (isJust, isNothing, catMaybes)
43import Data.Maybe (isJust, isNothing, catMaybes)
37import Data.Typeable (Typeable)
44import Data.Typeable (Typeable)
@@ -118,6 +125,8 @@ import Control.Distributed.Process.Internal.Types
118 , TypedChannel(..)
125 , TypedChannel(..)
119 , Identifier(..)
126 , Identifier(..)
129+ , ProcessInfoNone(..)
121 , SendPortId(..)
130 , SendPortId(..)
122 , typedChannelWithId
131 , typedChannelWithId
123 , RegisterReply(..)
132 , RegisterReply(..)
@@ -517,6 +526,8 @@ nodeController = do
517 ncEffectKill from to reason
526 ncEffectKill from to reason
518 NCMsg (ProcessIdentifier from) (Exit to reason) ->
527 NCMsg (ProcessIdentifier from) (Exit to reason) ->
519 ncEffectExit from to reason
528 ncEffectExit from to reason
529+ NCMsg (ProcessIdentifier from) (GetInfo pid) ->
530+ ncEffectGetInfo from pid
520 unexpected ->
531 unexpected ->
521 error $ "nodeController: unexpected message " ++ show unexpected
532 error $ "nodeController: unexpected message " ++ show unexpected
@@ -737,6 +748,53 @@ ncEffectExit from to reason = do
737 when (isLocal node (ProcessIdentifier to)) $
748 when (isLocal node (ProcessIdentifier to)) $
738 throwException to $ ProcessExitException from reason
749 throwException to $ ProcessExitException from reason
752+ncEffectGetInfo :: ProcessId -> ProcessId -> NC ()
753+ncEffectGetInfo from pid =
754+ let lpid = processLocalId pid
755+ them = (ProcessIdentifier pid)
759+ withMVar (localState node) $ return . (^. localProcessWithId lpid)
761+ Nothing -> dispatch (isLocal node (ProcessIdentifier from))
762+ from node (ProcessInfoNone DiedUnknownId)
764+ itsLinks <- gets (^. linksFor them)
765+ itsMons <- gets (^. monitorsFor them)
766+ registered <- gets (^. registeredHere)
768+ let reg = registeredNames registered
769+ dispatch (isLocal node (ProcessIdentifier from))
773+ infoNode = (processNodeId pid)
774+ , infoRegisteredNames = reg
775+ -- we cannot populate this field
776+ , infoMessageQueueLength = Nothing
777+ , infoMonitors = Set.toList itsMons
778+ , infoLinks = Set.toList itsLinks
780+ where dispatch :: (Serializable a, Show a)
786+ dispatch True dest _ pInfo = postAsMessage dest $ pInfo
787+ dispatch False dest node pInfo = do
788+ liftIO $ sendMessage node
789+ (NodeIdentifier (localNodeId node))
790+ (ProcessIdentifier dest)
791+ WithImplicitReconnect
794+ registeredNames = Map.foldlWithKey (\ks k v -> if v == pid
740--------------------------------------------------------------------------------
798--------------------------------------------------------------------------------
741-- Auxiliary --
799-- Auxiliary --
742--------------------------------------------------------------------------------
800--------------------------------------------------------------------------------
@@ -788,6 +846,7 @@ destNid (NamedSend _ _) = Nothing
788destNid (Died _ _) = Nothing
846destNid (Died _ _) = Nothing
789destNid (Kill pid _) = Just $ processNodeId pid
847destNid (Kill pid _) = Just $ processNodeId pid
790destNid (Exit pid _) = Just $ processNodeId pid
848destNid (Exit pid _) = Just $ processNodeId pid
849+destNid (GetInfo pid) = Just $ processNodeId pid
792-- | Check if a process is local to our own node
851-- | Check if a process is local to our own node
793isLocal :: LocalNode -> Identifier -> Bool
852isLocal :: LocalNode -> Identifier -> Bool
@@ -827,7 +886,8 @@ postAsMessage :: Serializable a => ProcessId -> a -> NC ()
827postAsMessage pid = postMessage pid . createMessage
886postAsMessage pid = postMessage pid . createMessage
829postMessage :: ProcessId -> Message -> NC ()
888postMessage :: ProcessId -> Message -> NC ()
889+postMessage pid msg = do
830−postMessage pid msg = withLocalProc pid $ \p -> enqueue (processQueue p) msg
890+ withLocalProc pid $ \p -> enqueue (processQueue p) msg
832throwException :: Exception e => ProcessId -> e -> NC ()
892throwException :: Exception e => ProcessId -> e -> NC ()
833throwException pid e = withLocalProc pid $ \p ->
893throwException pid e = withLocalProc pid $ \p ->