nav_exclude | permalink |
---|---|
true |
/RS-004 |
{: .no_toc }
- Id: RS-004.
- Status: Abandoned.
- Type: Implementation.
- Proof of concept: https://github.com/AwalaApp/poc/tree/master/CoSocket
{: .no_toc }
This document describes CoSocket, a cargo relay binding on top of TCP or Unix sockets. As a purpose-built Application Layer protocol, this is the most efficient binding to relay cargo.
{: .no_toc }
- TOC {:toc}
As a cargo relay binding, CoSocket's objective is to provide the basis for a gateway to exchange cargo with a courier or another gateway.
Gateways and couriers can act as client and servers. One of them has to be the server so that the other can connect to it via TCP or a Unix socket, but once communication has been established, they become peers and can send packets to each other indistinctively.
CoSocket is a binary protocol with little-endian byte order.
The packets in this protocol use the following primitives:
- Varchar: A UTF-8 string, length-prefixed with a 8-bit unsigned integer (1 octet). Consequently, the string can have a length of up to 255 octets.
- Payload length: A 32-bit unsigned integer (4 octets), used as a length-prefix for a payload.
Each packet starts with a tag that identifies the type of packet. The tag itself is serialized as a 16-bit unsigned integer (2 octets).
Per Awala Core, the handshake involves three steps:
- The courier challenges the gateway to sign a nonce with its key(s).
- The gateway signs the nonce with each of its keys and sends the signatures to the courier.
- The courier verifies the signatures and confirms the end of the handshake.
This packet contains the nonce that the gateway has to sign. The packet comprises the following sequence:
- Tag:
0xf0
. - The nonce, as a random sequence of exactly 32 octets.
This packet contains the signatures for the nonce and comprises the following sequence:
- Tag:
0xf1
. - The total payload length for all the signatures and their length prefixes included in the packet.
- The payload with the sequence of signatures, where each is prefixed with its payload length.
This packet is sent by the courier when the signatures were successfully verified. This packet is empty -- It only contains its tag (0xf2
).
This packet encapsulates a Cargo Collection Authorization (CCA) and represents a request to collect cargo for a specific gateway.
A courier MUST send this packet to a gateway to indicate it is ready to receive cargo and to prove it is authorized to receive cargo for the gateway in the CCA.
The packet comprises the following sequence:
- Tag:
0x00
. - The payload length for the CCA.
- The CCA.
This packet encapsulates a cargo and has the following sequence:
- Tag:
0x01
. - A string that uniquely identifies this cargo delivery, serialized as a varchar. This MAY be different from the cargo id, so it could be a UUID4 value, for example.
- The payload length for the cargo.
- The cargo.
This is an alternative to Cargo Delivery using file descriptors, so this is only available on Unix sockets. The sequence is as follows:
- Tag:
0x02
. - The string that uniquely identifies this cargo delivery, serialized as a varchar.
- (TODO: Define how the file descriptor is actually passed)
This packet represents an acknowledgement that a cargo delivery was successfully received and has the following sequence:
- Tag:
0x03
. - The cargo delivery id, serialized as varchar.
Used to signal that there are no further cargoes for the specified gateway. It has the following sequence:
- Tag:
0x04
. - The address of the gateway for which there are no further cargoes, serialized as varchar.
The sender of this packet MUST also quit if its peer has already confirmed that it will not send any further cargoes.
Used by a peer to indicate that it is about to close the connection. The sender MUST close the connection immediately after sending this packet.
The packet has the following sequence:
- Tag:
0xff
. - Reason: A 16-bit unsigned integer representing the reason why the connection was terminated:
0x00
: Operation completed without errors.0x01
: Invalid packet.0x02
: Handshake error.0x03
: Quota reached.0x04
: Internal error.
Two gateways MAY maintain a persistent connection to exchange cargo in near-real time. This could be necessary when the target gateway is not a server that can be reached by the other gateway (e.g., the target is behind a NAT gateway).
Couriers MUST always quit the connection as soon as no further cargoes are expected in either direction.
TODO: Upload sequence diagram.
TODO: Upload sequence diagram.
TODO: Upload sequence diagram.
Awala Core (RS-000) defines the requirements for message transport bindings in general and cargo relay bindings specifically, all of which apply to CoSocket. Amongst other things, it defines the use Transport Layer Security (TLS).