> module DHSCore > where Global DHS datatypes and stuff that is needed in *any* module. #ifdef CONCDEBUG > import ConcurrentDebug as Concurrent #else > import Control.Concurrent #endif > import IO > import System > import Maybe #if __GLASGOW_HASKELL__ < 500 > import Word #endif > import Bits #if __GLASGOW_HASKELL__ >= 500 > wordToWord32 = id #endif > r # f = f r > type StringChan = Chan String The following newtypes are for sorting out nodes & hosts. > newtype Hostname = Hostname String deriving (Read,Show,Eq,Ord) > newtype Nodename = Nodename String deriving (Read,Show,Eq,Ord) > type Port = Int -- the TCP/IP-portnumber in Pid > type Node = (Hostname, Port) > type PNode = (String, Port) > nodeToPlain :: Node -> (String, Port) > nodeToPlain (Hostname h,p) = (h,p) > plainToNode :: (String, Port) -> Node > plainToNode (node, p) = (Hostname node, p) > type Servicename = String > type Magic = Int A Pid contains all the information necessary for sending a message to a (known) process on any host. However, note that a Pid obtained for remote hosts (for example from the dhd) are most likely to be invalid if the service is restarted. For now, there's no way of trapping this. 'Node' shall contain any data necessary to connect to the corresponding node > type PidInt = Integer > data Pid = Pid (String, Port) PidInt -- we donīt want the "Hostname" here > | PidName (Hostname,Nodename,String) > deriving (Show, Read, Eq) > distHaskellPortNr :: Int > distHaskellPortNr = 10008 Useful helpers: > myGetVar :: String -> IO (Maybe String) > myGetVar var = do > catch (getEnv var >>= (\x -> return (Just x))) -- can only be NoSuchThing > (\_ -> return Nothing) > myGetVarDefault :: String -> String -> IO String > myGetVarDefault var def = do > res <- myGetVar var > return (fromMaybe def res) > -- addressToIP :: Word -> String > addressToIP host = > let ip = (wordToWord32 host) > ip4 = (show (shiftR ip 24)) > ip3 = (show (shiftR (shiftL ip 8) 24)) > ip2 = (show (shiftR (shiftL ip 16) 24)) > ip1 = (show (shiftR (shiftL ip 24) 24)) in > (ip1 ++ "." ++ ip2 ++ "." ++ ip3 ++ "." ++ ip4)