ContentsIndex
Barracuda.ServerState
MaintainerHenning Guenther, Martin Wegner, Stephan Friedrichs
Contents
Types
Monadic operations
Running the ServerMonad
Retrieving IDs
Sending messages
Accessing attributes
General accessors
Shortcuts
Other accessors
Auxiliary functions
Logging and debugging
Description
This module contains a monad encapsulating the entire status of the distributor, so that it is completely free of side-effects. As a consequence, dumping the ServerState gives all information about why the distributor has made any decision.
Synopsis
data ServerMonad a
data ServerState = ServST {
routingTable :: SimpleRT
chanList :: ChannelMap
localUserInfo :: LocalUserInfo
certificates :: CertificateList
certificateRequests :: [CertificateRequest]
userTimeOffsets :: (Map UserID (UTCTime, UTCTime))
randGen :: StdGen
pendingAck :: (PendingAck InternalSignature)
pendingAnonymous :: PendingAnonymous
pendingKey :: PendingKey
pendingRoute :: (PendingRoute InternalSignature)
msgIds :: [MessageID]
channelIdCounter :: Integer
infrastructure :: (Maybe (Set SockAddr))
floodBuffer :: [(UserID, MessageID)]
nextRouting :: UTCTime
verbose :: Bool
localhost :: String
localhostAddr :: SockAddr
wantsShutdown :: Bool
}
type CertificateCallback = Map UserID Certificate -> ServerMonad ()
type CertificateRequest = (Set UserID, Map UserID Certificate, CertificateCallback)
type Accessor a b = (a -> (a, b)) -> ServerMonad b
type SendCB = [MessageID] -> SockAddr -> InternalMessage -> IO [MessageID]
runServerMonad :: SendCB -> Bool -> HostAddress -> Certificate -> PortNumber -> [(UTCTime, ServerMonad ())] -> IO ()
newMessageId :: ServerMonad MessageID
newChannelId :: ServerMonad ChannelID
sendMessage :: SockAddr -> InternalMessage -> ServerMonad ()
sendMessageBroadcast :: InternalMessage -> ServerMonad ()
sendUser :: UserID -> ControlResponse -> ServerMonad ()
sendUserBroadcast :: ControlResponse -> ServerMonad ()
with :: (ServerState -> a) -> (a -> ServerState -> ServerState) -> Accessor a b
query :: (a -> b) -> a -> (a, b)
manipulate :: (a -> a) -> a -> (a, ())
withCertificateRequests :: Accessor [CertificateRequest] b
withCertificates :: Accessor CertificateList b
withTimeOffsets :: Accessor (Map UserID (UTCTime, UTCTime)) b
withChannelList :: Accessor ChannelMap b
withLocalUserInfo :: Accessor LocalUserInfo b
withPendingAck :: Accessor (PendingAck InternalSignature) b
withPendingAnonymous :: Accessor PendingAnonymous b
withPendingKey :: Accessor PendingKey b
withPendingRoute :: Accessor (PendingRoute InternalSignature) b
withRandom :: Accessor StdGen b
newRandom :: ServerMonad StdGen
withRoutingTable :: Accessor SimpleRT b
rootCertificate :: ServerMonad Certificate
curTime :: ServerMonad UTCTime
shutdown :: ServerMonad ()
floodAgain :: UserID -> MessageID -> ServerMonad Bool
isLocal :: UserID -> ServerMonad Bool
partitionLocals :: Set UserID -> ServerMonad (Set UserID, Set UserID)
btrace :: String -> ServerMonad ()
berror :: String -> ServerMonad ()
Types
data ServerMonad a
A Monad (MonadState) wrapping the ServerState and queues for output.
show/hide Instances
data ServerState
The state of the server. It holds all relevant data structures that store on the one hand information about the network and on the other hand the internal state of certain data such as open certificate requests and different structures waiting for different events (Pending*).
Constructors
ServST
routingTable :: SimpleRTThe currently known routing table to be used to route messages.
chanList :: ChannelMapThe list of currently known public and private channels.
localUserInfo :: LocalUserInfoStores information (UserID, PrivateKey, joined channels and a handle to send messages to the GUI of the user) about all locally connected users.
certificates :: CertificateListStores all known certificates.
certificateRequests :: [CertificateRequest]Stores a list of CertificateRequests waiting for certain certificates.
userTimeOffsets :: (Map UserID (UTCTime, UTCTime))The time offsets to remote users.
randGen :: StdGenStores a random number generator.
pendingAck :: (PendingAck InternalSignature)Stores messages that an ACK is awaited for.
pendingAnonymous :: PendingAnonymousStores anonymous messages to be monitored to be actually posted to the anonymous channel.
pendingKey :: PendingKeyStores messages to be de- or encrypted that are waiting for a shared key of a channel.
pendingRoute :: (PendingRoute InternalSignature)Stores messages that are waiting for a route to their destinations.
msgIds :: [MessageID]An infinite list of unused MessageIDs.
channelIdCounter :: IntegerCounter for the ChannelIDs we use.
infrastructure :: (Maybe (Set SockAddr))Maybe stores a set of peers we are (only) connected with.
floodBuffer :: [(UserID, MessageID)]Stores information about last received flood messages.
nextRouting :: UTCTimeTimestamp when routing messages have to be sent the next time.
verbose :: BoolWhether to be verbose or not in output.
localhost :: StringLocal hostname.
localhostAddr :: SockAddrThe local ip and port.
wantsShutdown :: BoolThe server wants to be shut down. Access this flag by shutdown rather than directly.
show/hide Instances
type CertificateCallback = Map UserID Certificate -> ServerMonad ()
Required callback type for functions that want to be called when open certificate requests have been answered.
type CertificateRequest = (Set UserID, Map UserID Certificate, CertificateCallback)
Holds one certificate request. The first set holds all UserIDs we wait for a certificate from, the second map holds the already satisfied certificates and the third element is the callback to be called when all requests are satisfied.
type Accessor a b = (a -> (a, b)) -> ServerMonad b
Type specification for accessor functions (i. e. functions that work on the data structures in the ServerState).
type SendCB
 = [MessageID]An infinite list of unused MessageIDs.
-> SockAddrThe target network address.
-> InternalMessageThis message has to be sent.
-> IO [MessageID]Another infinite list of unused MessageIDs. The ones used must be removed.
Such a function has to be provided to runServerMonad in order to enable it to perform necessary network output.
Monadic operations
Running the ServerMonad
runServerMonad
:: SendCBA send callback that performs pending network operations.
-> BoolIndicates weather we're verbosed or not.
-> HostAddressThe broadcast address to use
-> CertificateThe root certificate for the network.
-> PortNumberThe portnumber, used for hostname generation
-> [(UTCTime, ServerMonad ())]The actual list of timestamped operations to perform.
-> IO ()
This function actually runs the entire ServerMonad structure. Given some configurational parameters and a callback to perform network output, it takes a list of timestamped instructions and performs the resulting IO.
Retrieving IDs
newMessageId :: ServerMonad MessageID
Generates a new unique MessageID.
newChannelId :: ServerMonad ChannelID
Generates a new unique ChannelID.
Sending messages
sendMessage :: SockAddr -> InternalMessage -> ServerMonad ()
Queues a message to be sent to the network.
sendMessageBroadcast :: InternalMessage -> ServerMonad ()
Takes a message to be broadcastet to the network and sends it.
sendUser :: UserID -> ControlResponse -> ServerMonad ()
Sends the given ControlResponse to the given user's GUI.
sendUserBroadcast :: ControlResponse -> ServerMonad ()
Sends the given ControlResponse to the GUIs of all connected users.
Accessing attributes
General accessors
with
:: (ServerState -> a)A getter function.
-> (a -> ServerState -> ServerState)The setter function.
-> Accessor a bAllows monadic access according to the callbacks above.
The general accessor for The ServerState, that makes its attributs available in a monadic calculation. See also: query and manipulate, they make things easier.
query :: (a -> b) -> a -> (a, b)
Helper to wrap querying "non-monad functions" to work with the ServerMonad.
manipulate :: (a -> a) -> a -> (a, ())
Helper to wrap modifying "non-monad functions" to work with the ServerMonad.
Shortcuts
withCertificateRequests :: Accessor [CertificateRequest] b
Gives access for querying and manipulating the certificate request list.
withCertificates :: Accessor CertificateList b
Gives access for querying and manipulating the certificate list.
withTimeOffsets :: Accessor (Map UserID (UTCTime, UTCTime)) b
Gives access for querying and manipulating the user time offset list.
withChannelList :: Accessor ChannelMap b
Gives access for querying and manipulating the channel list.
withLocalUserInfo :: Accessor LocalUserInfo b
Gives access for querying and manipulating the local user info.
withPendingAck :: Accessor (PendingAck InternalSignature) b
Gives access for querying and manipulating the pending ack data structure.
withPendingAnonymous :: Accessor PendingAnonymous b
Gives access for querying and manipulating the pending anonymous data structure.
withPendingKey :: Accessor PendingKey b
Gives access for querying and manipulating the pending key data structure.
withPendingRoute :: Accessor (PendingRoute InternalSignature) b
Gives access for querying and manipulating the pending route data structure.
withRandom :: Accessor StdGen b
Gives access for querying and manipulating the random generator.
newRandom :: ServerMonad StdGen
Returns a new random generator
withRoutingTable :: Accessor SimpleRT b
Gives access for querying and manipulating the routing table.
Other accessors
rootCertificate :: ServerMonad Certificate
Returns the root certificate used to verify all other certificates.
curTime :: ServerMonad UTCTime
Returns the current time.
shutdown :: ServerMonad ()
Shut down the server. This is not rather done after processing the current DistributorMsg than immediately.
Auxiliary functions
floodAgain :: UserID -> MessageID -> ServerMonad Bool
Checks whether a flood message identified by the given UserID and MessageID was already received before.
isLocal :: UserID -> ServerMonad Bool
Checks whether the given UserID identifies a locally connected user or not.
partitionLocals :: Set UserID -> ServerMonad (Set UserID, Set UserID)
Splits a given set of users into (locals,non-locals)
Logging and debugging
btrace :: String -> ServerMonad ()
Used for rather verbosed output, for example for keeping track of an attribute. It only performs the output, if verbose is activated. For error messages use berror, to be sure it's printed!
berror :: String -> ServerMonad ()
Used for error output. This functions also performs output if verbose is deactivated. See also: btrace.
Produced by Haddock version 0.8