metarhia / metacom

RPC communication protocol for Metarhia stack 🔌
https://metarhia.com
MIT License
80 stars 40 forks source link

Protocol parser #3

Closed tshemsedinov closed 4 years ago

tshemsedinov commented 6 years ago

Network transmission structures:

Handshake

- version: 2b
- status: 1b
  - 0 = new connection (from client)
  - 1 = restore connection (from client)
  - 2 = accept connection (from server)
  - 3 = reject connection (from server)
- reserved: 1b
- token: 32b (optional), token contains id (bit prefix)

Parcel

- structType: 1b
  - parcel = 0
- parcelId: 4b
  - client++, server--
- parcelType: 1b
  - ping = 0, pong = 1, call = 2, callback = 3,
  - event = 4, stream = 5
- compression: 1b
  - no = 0, gzip = 1
- encoding: 1b
  - binary = 0, jstp = 1, json = 2, bson = 3, v8 = 4
- length: 8b

Chunk

- structType: 1b
  - chunk = 1
- parcelId: 4b
- chunkId: 4b
  - client++, server--
- flags: 1b
  - more = 1
  - stop = 2
  - pause = 4
  - resume = 8
- length: 2b
- payload: length

Client/Server dialog example

C: 0001 00 (handshake, new session request)
S: 0001 00 D16A...2A75 (handshake, token)
C: 00 00000000 00 00 00 (ping parcel)
S: 00 00000000 01 00 00 (pong parcel)
C: 00 00000001 02 00 02 0000000000000035 (call parcel)
C: 01 00000001 00000000 01 001C ["applicationName","methodNa (chunk)
C: 01 00000001 00000001 00 0019 me","par1","par2","par3"] (chunk)
S: 00 00000001 03 00 02 000000000000000A (callback parcel)
S: 01 00000001 00000002 00 00 0A ["result"] (chunk)

Parsed from chunks ["applicationName","methodName","par1","par2","par3"]

tshemsedinov commented 4 years ago

Closed in favour of new version 0.1.x implementing new specification