# SOLEC protocol specification ## Data format * Payload can contain multiple numeric types or binary data in a single frame * Numeric types are big endian * See [test payload](#Test) for an example of complex data structure ### Frame structure | Type | Description | |----------|----------------| | `uint8` | Payload type | | `uint16` | Payload length | | `any` | Payload | ### Special types #### Strings and binary Strings and binary data are prefixed wtith 2 bytes denoting their length. Strings are UTF-8 encoded. #### Timestamps Timestamps are stored as `uint64` in [Unix format](https://en.wikipedia.org/wiki/Unix_time). Timezone is always set to UTC. ### Payloads All payload types are described in following files: * [Kaitai Struct](https://git.sr.ht/~rctt/solec/blob/main/solec.ksy) * [SVG graph](https://git.sr.ht/~rctt/solec/blob/main/solec.svg) ## Client-server connection initialization 1. Initialize TCP connection 2. Receive `handshake` 3. Send `hadnshake` 4. Send `auth` 5. Receive `success` or `error` ## Client-server messaging After successfull auth server will listen for payloads of `message` type. Sending different payload will result in error and connection will be closed by the server. Message consist of following fields: * Source - address of the user sending a message * Target - address of channel or user receiving a message * Timestamp - set by user sending a message, UTC timezone * Content - UTF-8 string ## Addresses Source and target addresses are similair to e-mail addresses. There are two parts separated by `@` where second part is address of the server where specific user or channel is registered on. Target addresses is set to user that created specific message. Messaegs can be relayed between servers so it's necessary to keep that info as part of the message. Channel addresses always starts from `#` to distinct them from user addresses. Because of that user address cannot start from this character. Channels can be grouped in a hierarchy. Levels of channels hierarchy are separated by `.`. `*` is special address reserved for broadcast messages send by the server administrator. | Type | Address | |-----------|----------------------| | user | user@example.org | | channel | #channel@example.org | | broadcast | *@example.org | ## Channels hierarchy Channels can be groupped into a hierarchy. Channels hierarchy can be used to simplify moderation and management.