|
| 1 | +# SaltyRTC Relayed Data Task |
| 2 | + |
| 3 | +This task uses the end-to-end encrypted WebSocket connection set up by |
| 4 | +the SaltyRTC protocol to send user defined messages. |
| 5 | + |
| 6 | +# Conventions |
| 7 | + |
| 8 | +The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", |
| 9 | +"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this |
| 10 | +document are to be interpreted as described in |
| 11 | +[RFC 2119](https://tools.ietf.org/html/rfc2119). |
| 12 | + |
| 13 | +# Terminology |
| 14 | + |
| 15 | +All terms from the [SaltyRTC protocol |
| 16 | +specification](./Protocol.md#terminology) are valid in this document. |
| 17 | + |
| 18 | +# Task Protocol Name |
| 19 | + |
| 20 | +The following protocol name SHALL be used for task negotiation: |
| 21 | + |
| 22 | +`v0.relayed-data.tasks.saltyrtc.org` |
| 23 | + |
| 24 | +# Task Data |
| 25 | + |
| 26 | +This task does not currently make use of the *data* field of the 'auth' |
| 27 | +messages described in the [SaltyRTC protocol |
| 28 | +specification](./Protocol.md#auth-message). The task data sent by the |
| 29 | +peers should be `Nil`. |
| 30 | + |
| 31 | +# Message Structure |
| 32 | + |
| 33 | +The same message structure as defined in the [SaltyRTC protocol |
| 34 | +specification](./Protocol.md#message-structure) SHALL be used. |
| 35 | + |
| 36 | +# Client-to-Client Messages |
| 37 | + |
| 38 | +Once the task has taken over, user data MAY be sent using 'data' |
| 39 | +messages. |
| 40 | + |
| 41 | +If one of the sides wants to terminate the connection, the 'close' |
| 42 | +Message SHALL be sent as described in the [SaltyRTC protocol |
| 43 | +specification](./Protocol.md#close-message). |
| 44 | + |
| 45 | +Other message types (including the |
| 46 | +['application' message](./Protocol.md#application-message)) |
| 47 | +SHALL NOT be used in the Relayed Data task. |
| 48 | + |
| 49 | +## Message States (Beyond 'auth') |
| 50 | + |
| 51 | + +--+ |
| 52 | + | v |
| 53 | + +-+----+ +-------+ |
| 54 | + -+->+ data +--->+ close | |
| 55 | + | +------+ +-------+ |
| 56 | + | ^ |
| 57 | + +------------------+ |
| 58 | + |
| 59 | +## 'data' messages |
| 60 | + |
| 61 | +Once the task has taken over, the user application of a client MAY |
| 62 | +trigger sending this message. |
| 63 | + |
| 64 | +This message MAY contain any MessagePack value type. If the user does |
| 65 | +not wish to encode messages with MessagePack, they can be transmitted |
| 66 | +using MessagePack binary or string value types. |
| 67 | + |
| 68 | +A task who sends a 'data' message SHALL set the *p* field to whatever |
| 69 | +data the user application provided. The name is an abbreviation that |
| 70 | +stands for "payload" and has been chosen to reduce the message overhead. |
| 71 | + |
| 72 | +A receiving task SHALL validate that the *p* field is set. It MUST pass |
| 73 | +the payload inside that field to the user application. |
| 74 | + |
| 75 | +``` |
| 76 | +{ |
| 77 | + "type": "data", |
| 78 | + "p": ... |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +# Sending a Message |
| 83 | + |
| 84 | +The task must provide a way for the user application to send 'data' |
| 85 | +messages. It MUST validate the messages as described in the section on |
| 86 | +['data' messages](#data-messages). |
| 87 | + |
| 88 | +The same procedure as described in the [SaltyRTC protocol |
| 89 | +specification](./Protocol.md#sending-a-signalling-message) SHALL be |
| 90 | +followed to send 'data' messages. |
| 91 | + |
| 92 | +# Receiving a Message |
| 93 | + |
| 94 | +Incoming task messages shall be processed as follows: |
| 95 | + |
| 96 | +* The client SHALL validate and decrypt the message according to the |
| 97 | + [SaltyRTC protocol specification](./Protocol.md#receiving-a-signalling-message) |
| 98 | +* If the message type is 'close', the message MUST be handled as |
| 99 | + described in the |
| 100 | + [SaltyRTC protocol specification](./Protocol.md#close-message) |
| 101 | +* Otherwise, if the message type is 'data', the payload MUST be passed |
| 102 | + to the user application. |
| 103 | +* For all other message types, the connection MUST be closed with a |
| 104 | + close code of `3001` (*Protocol Error*) |
0 commit comments