diff options
Diffstat (limited to 'internal/packet')
| -rw-r--r-- | internal/packet/packet.go | 2 | ||||
| -rw-r--r-- | internal/packet/protocol.txt | 59 |
2 files changed, 60 insertions, 1 deletions
diff --git a/internal/packet/packet.go b/internal/packet/packet.go index f38ad14..9365d93 100644 --- a/internal/packet/packet.go +++ b/internal/packet/packet.go @@ -239,7 +239,7 @@ func (f *PacketFramer) parse() (*Packet, error) { } if f.buffer[VERSION_OFFSET] != VERSION { - return nil, fmt.Errorf("%w version=%v", PacketUnsupportedVersion, f.buffer[VERSION_OFFSET]) + return nil, PacketUnsupportedVersion } encoding := Encoding(f.buffer[ENCODING_OFFSET] >> 6) diff --git a/internal/packet/protocol.txt b/internal/packet/protocol.txt new file mode 100644 index 0000000..9a0070d --- /dev/null +++ b/internal/packet/protocol.txt @@ -0,0 +1,59 @@ +# Eko Protocol V1 + +## Packet Structure + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Version |En.| Type | Payload Length | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Payload... Payload Length bytes ... | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +Order of bytes is from left to right, top to bottom. +The first byte is always the version, any bytes after it +depend on the specific value of the first byte. + +- Encoding: 0-3, determines the way the payload was encoded + - 0: JSON + - 1: MsgPack + - 2: Reserved for future use + - 3: Reserved for future use +- Type: 0-63, determines the type ("schema"), of the payload +- Payload Length: 0-65531, determines how long the payload is in bytes +- Payload: 0 to 65531 bytes long, depending on the payload size (~64kb) + +## Handshake + +The first time a connection is established, the following packets are exchanged. + +- Server sends a special 1-byte for version then 32-byte the challenge nonce packet +- Client sends a Challenge Response packet with: + * version (1-byte long) + - the client's ed25519 public key (32-bytes long) + - the client's ed25519 signature for the server-given nonce (64-bytes long) + +After the handshake the server may close the connection, +for example due to an invalid signature. + +## Error handling + +The server may abruptly close a connection in these cases: + +- After the initial handshake +- After any response + A server may not close the connection if it received a request, it must first response then close. + +The client may abruptly close a connection at any time + +### Malformed Packets + +- unsupported/invalid version: connection can be closed immediately +- unsupported encoding: server must respond with an error type, may use any encoding, client may close the connection +- unknown type: server must respond with an error, client may close the connection +- malformed paylod: server must respond with an error, client may close the connection + +For application errors such as a client asking to send a message in a non-existent Frequency, +the server must respond with an error packet. +For internal errors such as database failure, the server must respond, it may choose to +disclose as much information as it wants, or just say "internal server error". |
