simplexmq-0.5.2: SimpleXMQ message broker
Copyright(c) simplex.chat
LicenseAGPL-3
Maintainerchat@simplex.chat
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Simplex.Messaging.Transport

Description

This module defines basic TCP server and client and SMP protocol encrypted transport over TCP.

See https://github.com/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md#appendix-a

Synopsis

Transport connection class

class Transport c where Source #

Methods

transport :: ATransport Source #

transportName :: TProxy c -> String Source #

getServerConnection :: Socket -> IO c Source #

Upgrade client socket to connection (used in the server)

getClientConnection :: Socket -> IO c Source #

Upgrade server socket to connection (used in the client)

closeConnection :: c -> IO () Source #

Close connection

cGet :: c -> Int -> IO ByteString Source #

Read fixed number of bytes from connection

cPut :: c -> ByteString -> IO () Source #

Write bytes to connection

getLn :: c -> IO ByteString Source #

Receive ByteString from connection, allowing LF or CRLF termination.

putLn :: c -> ByteString -> IO () Source #

Send ByteString to connection terminating it with CRLF.

data TProxy c Source #

Constructors

TProxy 

data ATransport Source #

Constructors

forall c.Transport c => ATransport (TProxy c) 

Transport over TCP

runTransportServer :: (Transport c, MonadUnliftIO m) => TMVar Bool -> ServiceName -> (c -> m ()) -> m () Source #

Run transport server (plain TCP or WebSockets) on passed TCP port and signal when server started and stopped via passed TMVar.

All accepted connections are passed to the passed function.

runTransportClient :: Transport c => MonadUnliftIO m => HostName -> ServiceName -> (c -> m a) -> m a Source #

Connect to passed TCP host:port and pass handle to the client.

TCP transport

SMP encrypted transport

data THandle c Source #

The handle for SMP encrypted transport connection over Transport .

Constructors

THandle 

Fields

data TransportError Source #

Error of SMP encrypted transport over TCP.

Constructors

TEBadBlock

error parsing transport block

TEEncrypt

block encryption error

TEDecrypt

block decryption error

TEHandshake HandshakeError

transport handshake error

serverHandshake :: forall c. Transport c => c -> Int -> FullKeyPair -> ExceptT TransportError IO (THandle c) Source #

Server SMP encrypted transport handshake.

See https://github.com/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md#appendix-a

The numbers in function names refer to the steps in the document.

clientHandshake :: forall c. Transport c => c -> Maybe Int -> Maybe KeyHash -> ExceptT TransportError IO (THandle c) Source #

Client SMP encrypted transport handshake.

See https://github.com/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md#appendix-a

The numbers in function names refer to the steps in the document.

tPutEncrypted :: Transport c => THandle c -> ByteString -> IO (Either TransportError ()) Source #

Encrypt and send block to SMP encrypted transport.

tGetEncrypted :: Transport c => THandle c -> IO (Either TransportError ByteString) Source #

Receive and decrypt block from SMP encrypted transport.

serializeTransportError :: TransportError -> ByteString Source #

Serialize SMP encrypted transport error.

transportErrorP :: Parser TransportError Source #

SMP encrypted transport error parser.

Trim trailing CR

trimCR :: ByteString -> ByteString Source #

Trim trailing CR from ByteString.