simplexmq-6.5.0.16: SimpleXMQ message broker
Copyright(c) simplex.chat
LicenseAGPL-3
Maintainerchat@simplex.chat
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe-Inferred
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

SMP transport parameters

data SMPVersion Source #

Instances

Instances details
VersionScope SMPVersion Source # 
Instance details

Defined in Simplex.Messaging.Transport

Protocol SMPVersion ErrorType BrokerMsg Source # 
Instance details

Defined in Simplex.Messaging.Protocol

Associated Types

type ProtoCommand BrokerMsg = (cmd :: Type) Source #

type ProtoType BrokerMsg = (sch :: ProtocolType) Source #

ProtocolEncoding SMPVersion ErrorType BrokerMsg Source # 
Instance details

Defined in Simplex.Messaging.Protocol

Associated Types

type Tag BrokerMsg Source #

ProtocolEncoding SMPVersion ErrorType Cmd Source # 
Instance details

Defined in Simplex.Messaging.Protocol

Associated Types

type Tag Cmd Source #

PartyI p => ProtocolEncoding SMPVersion ErrorType (Command p) Source # 
Instance details

Defined in Simplex.Messaging.Protocol

Associated Types

type Tag (Command p) Source #

data TransportConfig Source #

Constructors

TransportConfig 

Fields

Transport connection class

class Typeable c => Transport (c :: TransportPeer -> Type) where Source #

Methods

transport :: forall p. ATransport p Source #

transportName :: TProxy c p -> String Source #

transportConfig :: c p -> TransportConfig Source #

getTransportConnection :: TransportPeerI p => TransportConfig -> Bool -> CertificateChain -> Context -> IO (c p) Source #

Upgrade TLS context to connection

certificateSent :: c p -> Bool Source #

Whether TLS certificate chain was provided to peer It is always True for the server. It is True for the client when server requested it AND non-empty chain is sent.

getPeerCertChain :: c p -> CertificateChain Source #

TLS certificate chain, server's in the client, client's in the server (empty chain for non-service clients)

tlsUnique :: c p -> SessionId Source #

tls-unique channel binding per RFC5929

getSessionALPN :: c p -> Maybe ALPN Source #

ALPN value negotiated for the session

closeConnection :: c p -> IO () Source #

Close connection

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

Read fixed number of bytes from connection

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

Write bytes to connection

getLn :: c p -> IO ByteString Source #

Receive ByteString from connection, allowing LF or CRLF termination.

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

Send ByteString to connection terminating it with CRLF.

Instances

Instances details
Transport TLS Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

transport :: forall (p :: TransportPeer). ATransport p Source #

transportName :: forall (p :: TransportPeer). TProxy TLS p -> String Source #

transportConfig :: forall (p :: TransportPeer). TLS p -> TransportConfig Source #

getTransportConnection :: forall (p :: TransportPeer). TransportPeerI p => TransportConfig -> Bool -> CertificateChain -> Context -> IO (TLS p) Source #

certificateSent :: forall (p :: TransportPeer). TLS p -> Bool Source #

getPeerCertChain :: forall (p :: TransportPeer). TLS p -> CertificateChain Source #

tlsUnique :: forall (p :: TransportPeer). TLS p -> SessionId Source #

getSessionALPN :: forall (p :: TransportPeer). TLS p -> Maybe ALPN Source #

closeConnection :: forall (p :: TransportPeer). TLS p -> IO () Source #

cGet :: forall (p :: TransportPeer). TLS p -> Int -> IO ByteString Source #

cPut :: forall (p :: TransportPeer). TLS p -> ByteString -> IO () Source #

getLn :: forall (p :: TransportPeer). TLS p -> IO ByteString Source #

putLn :: forall (p :: TransportPeer). TLS p -> ByteString -> IO () Source #

Transport WS Source # 
Instance details

Defined in Simplex.Messaging.Transport.WebSockets

Methods

transport :: forall (p :: TransportPeer). ATransport p Source #

transportName :: forall (p :: TransportPeer). TProxy WS p -> String Source #

transportConfig :: forall (p :: TransportPeer). WS p -> TransportConfig Source #

getTransportConnection :: forall (p :: TransportPeer). TransportPeerI p => TransportConfig -> Bool -> CertificateChain -> Context -> IO (WS p) Source #

certificateSent :: forall (p :: TransportPeer). WS p -> Bool Source #

getPeerCertChain :: forall (p :: TransportPeer). WS p -> CertificateChain Source #

tlsUnique :: forall (p :: TransportPeer). WS p -> SessionId Source #

getSessionALPN :: forall (p :: TransportPeer). WS p -> Maybe ALPN Source #

closeConnection :: forall (p :: TransportPeer). WS p -> IO () Source #

cGet :: forall (p :: TransportPeer). WS p -> Int -> IO ByteString Source #

cPut :: forall (p :: TransportPeer). WS p -> ByteString -> IO () Source #

getLn :: forall (p :: TransportPeer). WS p -> IO ByteString Source #

putLn :: forall (p :: TransportPeer). WS p -> ByteString -> IO () Source #

data TProxy (c :: TransportPeer -> Type) (p :: TransportPeer) Source #

Constructors

TProxy 

data ATransport p Source #

Constructors

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

data TransportPeer Source #

Constructors

TClient 
TServer 

Instances

Instances details
Show TransportPeer Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

showsPrec :: Int -> TransportPeer -> ShowS

show :: TransportPeer -> String

showList :: [TransportPeer] -> ShowS

Eq TransportPeer Source # 
Instance details

Defined in Simplex.Messaging.Transport

TLS Transport

data TLS (p :: TransportPeer) Source #

Constructors

TLS 

Fields

Instances

Instances details
Transport TLS Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

transport :: forall (p :: TransportPeer). ATransport p Source #

transportName :: forall (p :: TransportPeer). TProxy TLS p -> String Source #

transportConfig :: forall (p :: TransportPeer). TLS p -> TransportConfig Source #

getTransportConnection :: forall (p :: TransportPeer). TransportPeerI p => TransportConfig -> Bool -> CertificateChain -> Context -> IO (TLS p) Source #

certificateSent :: forall (p :: TransportPeer). TLS p -> Bool Source #

getPeerCertChain :: forall (p :: TransportPeer). TLS p -> CertificateChain Source #

tlsUnique :: forall (p :: TransportPeer). TLS p -> SessionId Source #

getSessionALPN :: forall (p :: TransportPeer). TLS p -> Maybe ALPN Source #

closeConnection :: forall (p :: TransportPeer). TLS p -> IO () Source #

cGet :: forall (p :: TransportPeer). TLS p -> Int -> IO ByteString Source #

cPut :: forall (p :: TransportPeer). TLS p -> ByteString -> IO () Source #

getLn :: forall (p :: TransportPeer). TLS p -> IO ByteString Source #

putLn :: forall (p :: TransportPeer). TLS p -> ByteString -> IO () Source #

type SessionId = ByteString Source #

TLS-unique channel binding

newtype EntityId Source #

Constructors

EntityId 

Fields

Instances

Instances details
Show EntityId Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

showsPrec :: Int -> EntityId -> ShowS

show :: EntityId -> String

showList :: [EntityId] -> ShowS

Eq EntityId Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

(==) :: EntityId -> EntityId -> Bool

(/=) :: EntityId -> EntityId -> Bool

Ord EntityId Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

compare :: EntityId -> EntityId -> Ordering

(<) :: EntityId -> EntityId -> Bool

(<=) :: EntityId -> EntityId -> Bool

(>) :: EntityId -> EntityId -> Bool

(>=) :: EntityId -> EntityId -> Bool

max :: EntityId -> EntityId -> EntityId

min :: EntityId -> EntityId -> EntityId

Encoding EntityId Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

smpEncode :: EntityId -> ByteString Source #

smpDecode :: ByteString -> Either String EntityId Source #

smpP :: Parser EntityId Source #

StrEncoding EntityId Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

strEncode :: EntityId -> ByteString Source #

strDecode :: ByteString -> Either String EntityId Source #

strP :: Parser EntityId Source #

FromField EntityId Source # 
Instance details

Defined in Simplex.Messaging.Agent.Store.AgentStore

Methods

fromField :: FieldParser EntityId #

ToField EntityId Source # 
Instance details

Defined in Simplex.Messaging.Agent.Store.AgentStore

Methods

toField :: EntityId -> SQLData #

type ALPN = ByteString Source #

connectTLS :: TLSParams p => Maybe HostName -> TransportConfig -> p -> Socket -> IO Context Source #

closeTLS :: Context -> IO () Source #

defaultSupportedParamsHTTPS :: Supported Source #

A selection of extra parameters to accomodate browser chains

withTlsUnique :: forall c p. TransportPeerI p => Context -> (ByteString -> IO (c p)) -> IO (c p) Source #

SMP transport

data THandle v c p Source #

The handle for SMP encrypted transport connection over Transport.

Constructors

THandle 

Fields

data THandleParams v p Source #

Constructors

THandleParams 

Fields

data CertChainPubKey Source #

Constructors

CertChainPubKey 

Fields

Instances

Instances details
Show CertChainPubKey Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

showsPrec :: Int -> CertChainPubKey -> ShowS

show :: CertChainPubKey -> String

showList :: [CertChainPubKey] -> ShowS

Eq CertChainPubKey Source # 
Instance details

Defined in Simplex.Messaging.Transport

Encoding CertChainPubKey Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

smpEncode :: CertChainPubKey -> ByteString Source #

smpDecode :: ByteString -> Either String CertChainPubKey Source #

smpP :: Parser CertChainPubKey Source #

data SMPServiceRole Source #

Instances

Instances details
Show SMPServiceRole Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

showsPrec :: Int -> SMPServiceRole -> ShowS

show :: SMPServiceRole -> String

showList :: [SMPServiceRole] -> ShowS

Eq SMPServiceRole Source # 
Instance details

Defined in Simplex.Messaging.Transport

Encoding SMPServiceRole Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

smpEncode :: SMPServiceRole -> ByteString Source #

smpDecode :: ByteString -> Either String SMPServiceRole Source #

smpP :: Parser SMPServiceRole Source #

data TSbChainKeys Source #

Constructors

TSbChainKeys 

Fields

data TransportError Source #

Error of SMP encrypted transport over TCP.

Constructors

TEBadBlock

error parsing transport block

TEVersion

incompatible client or server version

TELargeMsg

message does not fit in transport block

TEBadSession

incorrect session ID

TENoServerAuth

absent server key for v7 entity This error happens when the server did not provide a DH key to authorize commands for the queue that should be authorized with a DH key.

TEHandshake

transport handshake error

Instances

Instances details
FromJSON TransportError Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

parseJSON :: Value -> Parser TransportError

parseJSONList :: Value -> Parser [TransportError]

omittedField :: Maybe TransportError

ToJSON TransportError Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

toJSON :: TransportError -> Value

toEncoding :: TransportError -> Encoding

toJSONList :: [TransportError] -> Value

toEncodingList :: [TransportError] -> Encoding

omitField :: TransportError -> Bool

Exception TransportError Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

toException :: TransportError -> SomeException

fromException :: SomeException -> Maybe TransportError

displayException :: TransportError -> String

Read TransportError Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

readsPrec :: Int -> ReadS TransportError

readList :: ReadS [TransportError]

readPrec :: ReadPrec TransportError

readListPrec :: ReadPrec [TransportError]

Show TransportError Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

showsPrec :: Int -> TransportError -> ShowS

show :: TransportError -> String

showList :: [TransportError] -> ShowS

Eq TransportError Source # 
Instance details

Defined in Simplex.Messaging.Transport

Encoding TransportError Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

smpEncode :: TransportError -> ByteString Source #

smpDecode :: ByteString -> Either String TransportError Source #

smpP :: Parser TransportError Source #

data HandshakeError Source #

Transport handshake error.

Constructors

PARSE

parsing error

IDENTITY

incorrect server identity

BAD_AUTH

v7 authentication failed

BAD_SERVICE

error reading/creating service record

Instances

Instances details
FromJSON HandshakeError Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

parseJSON :: Value -> Parser HandshakeError

parseJSONList :: Value -> Parser [HandshakeError]

omittedField :: Maybe HandshakeError

ToJSON HandshakeError Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

toJSON :: HandshakeError -> Value

toEncoding :: HandshakeError -> Encoding

toJSONList :: [HandshakeError] -> Value

toEncodingList :: [HandshakeError] -> Encoding

omitField :: HandshakeError -> Bool

Exception HandshakeError Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

toException :: HandshakeError -> SomeException

fromException :: SomeException -> Maybe HandshakeError

displayException :: HandshakeError -> String

Read HandshakeError Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

readsPrec :: Int -> ReadS HandshakeError

readList :: ReadS [HandshakeError]

readPrec :: ReadPrec HandshakeError

readListPrec :: ReadPrec [HandshakeError]

Show HandshakeError Source # 
Instance details

Defined in Simplex.Messaging.Transport

Methods

showsPrec :: Int -> HandshakeError -> ShowS

show :: HandshakeError -> String

showList :: [HandshakeError] -> ShowS

Eq HandshakeError Source # 
Instance details

Defined in Simplex.Messaging.Transport

smpServerHandshake :: forall c. Transport c => CertificateChain -> APrivateSignKey -> c 'TServer -> KeyPairX25519 -> KeyHash -> VersionRangeSMP -> (SMPServiceRole -> CertificateChain -> Fingerprint -> ExceptT TransportError IO ServiceId) -> ExceptT TransportError IO (THandleSMP c 'TServer) Source #

tPutBlock :: Transport c => THandle v c p -> ByteString -> IO (Either TransportError ()) Source #

Pad and send block to SMP transport.

tGetBlock :: Transport c => THandle v c p -> IO (Either TransportError ByteString) Source #

Receive block from SMP transport.

sendHandshake :: (Transport c, Encoding smp) => THandle v c p -> smp -> ExceptT TransportError IO () Source #

getHandshake :: (Transport c, Encoding smp) => THandle v c p -> ExceptT TransportError IO smp Source #