simplexmq-0.3.1: 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

TCP transport

runTCPServer :: MonadUnliftIO m => TMVar Bool -> ServiceName -> (Handle -> m ()) -> m () Source #

Run TCP server on passed port and signal when server started and stopped via passed TMVar.

All accepted TCP connection handles are passed to the passed function.

runTCPClient :: MonadUnliftIO m => HostName -> ServiceName -> (Handle -> m a) -> m a Source #

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

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

Send ByteString to TCP connection handle terminating it with CRLF.

getLn :: Handle -> IO ByteString Source #

Receive ByteString from TCP connection handle, allowing LF or CRLF termination.

trimCR :: ByteString -> ByteString Source #

Trim trailing CR from ByteString.

SMP encrypted transport

data THandle Source #

The handle for SMP encrypted transport connection over TCP.

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 :: Handle -> FullKeyPair -> ExceptT TransportError IO THandle 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 :: Handle -> Maybe KeyHash -> ExceptT TransportError IO THandle 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 :: THandle -> ByteString -> IO (Either TransportError ()) Source #

Encrypt and send block to SMP encrypted transport.

tGetEncrypted :: THandle -> 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.