HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

Moduleacid-state-0.16.1.4Haskell2010

Data.Acid.Remote

This module provides the ability perform update and query calls from a remote process.

On the server-side you:

  1. open your AcidState normally

  2. then use acidServer to share the state

On the client-side you:

  1. use openRemoteState to connect to the remote state

  2. use the returned AcidState like any other AcidState handle

openRemoteState and acidServer communicate over an unencrypted socket. If you need an encrypted connection, see acid-state-tls.

On Unix®-like systems you can use SockAddrUnix to create a socket file for local communication between the client and server. Access can be controlled by setting the permissions of the parent directory containing the socket file.

It is also possible to perform some simple authentication using sharedSecretCheck and sharedSecretPerform. Keep in mind that secrets will be sent in plain-text if you do not use acid-state-tls. If you are using a SockAddrUnix additional authentication may not be required, so you can use skipAuthenticationCheck and skipAuthenticationPerform.

Working with a remote AcidState is nearly identical to working with a local AcidState with a few important differences.

The connection to the remote AcidState can be lost. The client will automatically attempt to reconnect every second. Because query events do not affect the state, an aborted query will be retried automatically after the server is reconnected.

If the connection was lost during an update event, the event will not be retried. Instead RemoteConnectionError will be raised. This is because it is impossible for the client to know if the aborted update completed on the server-side or not.

When using a local AcidState, an update event in one thread does not block query events taking place in other threads. With a remote connection, all queries and requests are channeled over a single connection. As a result, updates and queries are performed in the order they are executed and do block each other. In the rare case where this is an issue, you could create one remote connection per thread.

When working with local state, a query or update which returns the whole state is not usually a problem due to memory sharing. The update/query event basically just needs to return a pointer to the data already in memory. But, when working remotely, the entire result will be serialized and sent to the remote client. Hence, it is good practice to create queries and updates that will only return the required data.

This module is designed to be extenible. You can easily add your own authentication methods by creating a suitable pair of functions and passing them to acidServer and openRemoteState.

It is also possible to create alternative communication layers using CommChannel, process, and processRemoteState.

  • 2 types
  • 11 values
  • Packageacid-state-0.16.1.4
  • Exports13
  • LanguageHaskell2010
  • LicenceLicenseRef-PublicDomain
  • SourceRemote.hs

Server/Client

5 declarations
valueacidServer'
  1. :: (CommChannel -> IO Bool)

    check authentication, see sharedSecretPerform

  2. -> Socket

    binded socket to accept connections from

  3. -> AcidState st

    state to serve

  4. -> IO ()
#

Works the same way as acidServer, but uses pre-binded socket listenSocket.

Can be useful when fine-tuning of socket binding parameters is needed (for example, listening on a particular network interface, IPv4/IPv6 options).

Authentication

4 declarations
valuesharedSecretCheck
  1. :: Set ByteString

    set of shared secrets

  2. -> CommChannel
  3. -> IO Bool
#

check that the client knows a shared secret.

The function takes a Set of shared secrets. If a client knows any of them, it is considered to be trusted.

The shared secret is any ByteString of your choice.

If you give each client a different shared secret then you can revoke access individually.

see also: sharedSecretPerform

Exception type

1 declaration

Low-Level functions needed to implement additional communication channels

3 declarations
valueprocess
  1. :: CommChannel

    a connected, authenticated communication channel

  2. -> AcidState st

    state to share

  3. -> IO ()
#

Server inner-loop

This function is generally only needed if you are adding a new communication channel.