|
| Barracuda.ServerState | | Maintainer | Henning Guenther, Martin Wegner, Stephan Friedrichs |
|
|
|
|
|
| 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 |
|
|
|
|
| Types
|
|
| data ServerMonad a |
| A Monad (MonadState) wrapping the ServerState and queues for output.
| 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 :: SimpleRT | The currently known routing table to be used to route messages.
| | chanList :: ChannelMap | The list of currently known public and private channels.
| | localUserInfo :: LocalUserInfo | Stores information (UserID, PrivateKey, joined channels and a handle to send messages to the GUI of the user) about all locally connected users.
| | certificates :: CertificateList | Stores 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 :: StdGen | Stores a random number generator.
| | pendingAck :: (PendingAck InternalSignature) | Stores messages that an ACK is awaited for.
| | pendingAnonymous :: PendingAnonymous | Stores anonymous messages to be monitored to be actually posted to the anonymous channel.
| | pendingKey :: PendingKey | Stores 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 :: Integer | Counter 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 :: UTCTime | Timestamp when routing messages have to be sent the next time.
| | verbose :: Bool | Whether to be verbose or not in output.
| | localhost :: String | Local hostname.
| | localhostAddr :: SockAddr | The local ip and port.
| | wantsShutdown :: Bool | The server wants to be shut down. Access this flag by shutdown rather than directly.
|
|
| 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.
| | -> SockAddr | The target network address.
| | -> InternalMessage | This 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 |
| :: SendCB | A send callback that performs pending network operations.
| | -> Bool | Indicates weather we're verbosed or not.
| | -> HostAddress | The broadcast address to use
| | -> Certificate | The root certificate for the network.
| | -> PortNumber | The 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 |
|
|
| 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 |