Copyright | (c) simplex.chat |
---|---|
License | AGPL-3 |
Maintainer | chat@simplex.chat |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
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
- runTCPServer :: MonadUnliftIO m => TMVar Bool -> ServiceName -> (Handle -> m ()) -> m ()
- runTCPClient :: MonadUnliftIO m => HostName -> ServiceName -> (Handle -> m a) -> m a
- putLn :: Handle -> ByteString -> IO ()
- getLn :: Handle -> IO ByteString
- trimCR :: ByteString -> ByteString
- data THandle = THandle {}
- data TransportError
- = TEBadBlock
- | TEEncrypt
- | TEDecrypt
- | TEHandshake HandshakeError
- serverHandshake :: Handle -> FullKeyPair -> ExceptT TransportError IO THandle
- clientHandshake :: Handle -> Maybe KeyHash -> ExceptT TransportError IO THandle
- tPutEncrypted :: THandle -> ByteString -> IO (Either TransportError ())
- tGetEncrypted :: THandle -> IO (Either TransportError ByteString)
- serializeTransportError :: TransportError -> ByteString
- transportErrorP :: Parser TransportError
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
The handle for SMP encrypted transport connection over TCP.
data TransportError Source #
Error of SMP encrypted transport over TCP.
TEBadBlock | error parsing transport block |
TEEncrypt | block encryption error |
TEDecrypt | block decryption error |
TEHandshake HandshakeError | transport handshake error |
Instances
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.