Compare commits

..

No commits in common. "916ea87537e2a46950160a69d90ebd2dedafc060" and "f6a1b5200a96ad808698eb52593915a78683e3e1" have entirely different histories.

2 changed files with 13 additions and 45 deletions

View File

@ -1,7 +1,5 @@
# Trinitrix Backend API (TriBA) # Trinitrix Backend API (TriBA)
**Disclaimer:** These docs are WIP and going to receive a lot of improvement.
## Basic concept ## Basic concept
The core starts a CBS as its child process and gives it as first Arg a base64 encoded UUID. The core starts a CBS as its child process and gives it as first Arg a base64 encoded UUID.
@ -18,29 +16,12 @@ Post-Handshake communication is structured in packets, which have the following
| 4 | uint32 | The size of the payload. | | 4 | uint32 | The size of the payload. |
| - | encrypted payload | The AES-GCM-SIV encrypted MessagePack serialization of the packet. | | - | encrypted payload | The AES-GCM-SIV encrypted MessagePack serialization of the packet. |
A decrypted and deserialized payload contains either a response or a request. A decrypted and deserialized packet looks like this:
A request looks as follows:
| Size | Name | Type | Content | | Size | Name | Type | Content |
|------|--------|--------|-------------------------------------------------------------------------------------------------------------------| |------|--------|--------|-------------------------------------------------------------------------------------------------------------------|
| 8 | `id` | uint64 | The ID of _this_ packet. | | 8 | `id` | uint64 | The ID of _this_ packet. Is expected to be an incrementing counter. |
| - | `body` | enum | The actual packet data. (this will be better documented, as soon, as I dive into the mPack serialization details) | | - | `body` | enum | The actual packet date. (this will be better documented, as soon, as I dive into the mPack serialization details) |
A response looks like this:
| Size | Name | Type | Content |
|------|--------|--------|-------------------------------------------------------|
| 8 | `id` | uint64 | The ID of _this_ packet. |
| 8 | `req` | uint64 | The ID of the request packet this response refers to. |
| - | `body` | enum | The actual packet data. |
**Every request packet, that is sent over the socket, has to get a linked response packet.**
### IDs
Packet IDs are expected to be an incremental counter.
There is no difference between requests and responses originating from the same socket side when it comes to IDs.
So both - requests and responses - should share the same counter.
## Handshake ## Handshake
@ -54,8 +35,6 @@ The handshaking process after connecting to the socket looks as follows:
6. __Connection Upgrade:__ From this point on, all communication is structured by packets. 6. __Connection Upgrade:__ From this point on, all communication is structured by packets.
The packet encryption key is calculated using x25519 Diffie-Hellman and the previously exchanged keys. The packet encryption key is calculated using x25519 Diffie-Hellman and the previously exchanged keys.
The nonce from step 5 will be used as nonce for all packets. The nonce from step 5 will be used as nonce for all packets.
7. The CBS sends the `Request::HandshakeUpgradeConnection` packet. 7. The CBS sends the `HandshakeUpgradeConnection` packet.
8. The core responds with `Response::Success`. 8. (In here there is going to happen API version information exchange etc.)
9. (In here there is going to happen API version information exchange etc.) 9. The Core responds with `HandshakeSuccess`
10. The Core sends a `Request::HandshakeSuccess`
11. The CBS responds with `Response::Succcess`

View File

@ -56,21 +56,14 @@ impl UnstableConnection {
let packet = Packet::recv(&mut sock_rx, &cipher, &nonce).await?; let packet = Packet::recv(&mut sock_rx, &cipher, &nonce).await?;
match packet { match packet {
Packet::Request { id, body } => { Packet::Request { id, body } => {
match body { Packet::response(id_pool.acquire(), id, Response::Success)
Request::HandshakeUpgradeConnection => { .send(&mut sock_tx, &cipher, &nonce)
Packet::response(id_pool.acquire(), id, Response::Success) .await?;
.send(&mut sock_tx, &cipher, &nonce)
.await?;
cli_log::info!( cli_log::info!(
"CBS {id}: upgraded connection to encrypted messagepack", "CBS {id}: upgraded connection to encrypted messagepack",
id = self.id id = self.id
); );
}
req => return Err(anyhow!(
"expected cbs to send: Request::HandshakeUpgradeConnection, but got: Request::{req}"
))
}
} }
body => { body => {
return Err(anyhow!( return Err(anyhow!(
@ -79,10 +72,6 @@ impl UnstableConnection {
} }
} }
Packet::request(id_pool.acquire(), Request::HandshakeSuccess)
.send(&mut sock_tx, &cipher, &nonce)
.await?;
// Poll packets from socket // Poll packets from socket
{ {
let cipher = cipher.clone(); let cipher = cipher.clone();