diff options
Diffstat (limited to 'docs')
-rw-r--r-- | docs/client-server/specification.rst | 14 | ||||
-rw-r--r-- | docs/server-server/specification.rst | 90 |
2 files changed, 80 insertions, 24 deletions
diff --git a/docs/client-server/specification.rst b/docs/client-server/specification.rst index 7df2bb14c5..3367884ad4 100644 --- a/docs/client-server/specification.rst +++ b/docs/client-server/specification.rst @@ -1,6 +1,6 @@ -========================= -Synapse Client-Server API -========================= +======================== +Matrix Client-Server API +======================== The following specification outlines how a client can send and receive data from a home server. @@ -262,7 +262,10 @@ the error, but the keys 'error' and 'errcode' will always be present. Some standard error codes are below: M_FORBIDDEN: -Forbidden access, e.g. bad access token, failed login. +Forbidden access, e.g. joining a room without permission, failed login. + +M_UNKNOWN_TOKEN: +The access token specified was not recognised. M_BAD_JSON: Request contained valid JSON, but it was malformed in some way, e.g. missing @@ -411,6 +414,9 @@ The server checks this, finds it is valid, and returns: { "access_token": "abcdef0123456789" } +The server may optionally return "user_id" to confirm or change the user's ID. +This is particularly useful if the home server wishes to support localpart entry +of usernames (e.g. "bob" rather than "@bob:matrix.org"). OAuth2-based ------------ diff --git a/docs/server-server/specification.rst b/docs/server-server/specification.rst index f3c571aa86..a9ab9bff66 100644 --- a/docs/server-server/specification.rst +++ b/docs/server-server/specification.rst @@ -1,8 +1,8 @@ -============================ -Synapse Server-to-Server API -============================ +=========================== +Matrix Server-to-Server API +=========================== -A description of the protocol used to communicate between Synapse home servers; +A description of the protocol used to communicate between Matrix home servers; also known as Federation. @@ -10,7 +10,7 @@ Overview ======== The server-server API is a mechanism by which two home servers can exchange -Synapse event messages, both as a real-time push of current events, and as a +Matrix event messages, both as a real-time push of current events, and as a historic fetching mechanism to synchronise past history for clients to view. It uses HTTP connections between each pair of servers involved as the underlying transport. Messages are exchanged between servers in real-time by active pushing @@ -19,7 +19,7 @@ historic data for the purpose of back-filling scrollback buffers and the like can also be performed. - { Synapse entities } { Synapse entities } + { Matrix clients } { Matrix clients } ^ | ^ | | events | | events | | V | V @@ -29,27 +29,53 @@ can also be performed. | |<--------( HTTP )-----------| | +------------------+ +------------------+ +There are three main kinds of communication that occur between home servers: -Transactions and PDUs -===================== + * Queries + These are single request/response interactions between a given pair of + servers, initiated by one side sending an HTTP request to obtain some + information, and responded by the other. They are not persisted and contain + no long-term significant history. They simply request a snapshot state at the + instant the query is made. -The communication between home servers is performed by a bidirectional exchange -of messages. These messages are called Transactions, and are encoded as JSON -objects with a dict as the top-level element, passed over HTTP. A Transaction is -meaningful only to the pair of home servers that exchanged it; they are not -globally-meaningful. + * EDUs - Ephemeral Data Units + These are notifications of events that are pushed from one home server to + another. They are not persisted and contain no long-term significant history, + nor does the receiving home server have to reply to them. -Each transaction has an opaque ID and timestamp (UNIX epoch time in miliseconds) -generated by its origin server, an origin and destination server name, a list of -"previous IDs", and a list of PDUs - the actual message payload that the -Transaction carries. + * PDUs - Persisted Data Units + These are notifications of events that are broadcast from one home server to + any others that are interested in the same "context" (namely, a Room ID). + They are persisted to long-term storage and form the record of history for + that context. + +Where Queries are presented directly across the HTTP connection as GET requests +to specific URLs, EDUs and PDUs are further wrapped in an envelope called a +Transaction, which is transferred from the origin to the destination home server +using a PUT request. + + +Transactions and EDUs/PDUs +========================== + +The transfer of EDUs and PDUs between home servers is performed by an exchange +of Transaction messages, which are encoded as JSON objects with a dict as the +top-level element, passed over an HTTP PUT request. A Transaction is meaningful +only to the pair of home servers that exchanged it; they are not globally- +meaningful. + +Each transaction has an opaque ID and timestamp (UNIX epoch time in +milliseconds) generated by its origin server, an origin and destination server +name, a list of "previous IDs", and a list of PDUs - the actual message payload +that the Transaction carries. {"transaction_id":"916d630ea616342b42e98a3be0b74113", "ts":1404835423000, "origin":"red", "destination":"blue", "prev_ids":["e1da392e61898be4d2009b9fecce5325"], - "pdus":[...]} + "pdus":[...], + "edus":[...]} The "previous IDs" field will contain a list of previous transaction IDs that the origin server has sent to this destination. Its purpose is to act as a @@ -58,7 +84,9 @@ successfully received that Transaction, or ask for a retransmission if not. The "pdus" field of a transaction is a list, containing zero or more PDUs.[*] Each PDU is itself a dict containing a number of keys, the exact details of -which will vary depending on the type of PDU. +which will vary depending on the type of PDU. Similarly, the "edus" field is +another list containing the EDUs. This key may be entirely absent if there are +no EDUs to transfer. (* Normally the PDU list will be non-empty, but the server should cope with receiving an "empty" transaction, as this is useful for informing peers of other @@ -86,7 +114,7 @@ field of a PDU refers to PDUs that any origin server has sent, rather than previous IDs that this origin has sent. This list may refer to other PDUs sent by the same origin as the current one, or other origins. -Because of the distributed nature of participants in a Synapse conversation, it +Because of the distributed nature of participants in a Matrix conversation, it is impossible to establish a globally-consistent total ordering on the events. However, by annotating each outbound PDU at its origin with IDs of other PDUs it has received, a partial ordering can be constructed allowing causallity @@ -112,6 +140,15 @@ so on. This part needs refining. And writing in its own document as the details relate to the server/system as a whole, not specifically to server-server federation.]] +EDUs, by comparison to PDUs, do not have an ID, a context, or a list of +"previous" IDs. The only mandatory fields for these are the type, origin and +destination home server names, and the actual nested content. + + {"edu_type":"m.presence", + "origin":"blue", + "destination":"orange", + "content":...} + Protocol URLs ============= @@ -179,3 +216,16 @@ To stream events all the events: Retrieves all of the transactions later than any version given by the "v" arguments. [[TODO(paul): I'm not sure what the "origin" argument does because I think at some point in the code it's got swapped around.]] + + +To make a query: + + GET .../query/:query_type + Query args: as specified by the individual query types + + Response: JSON encoding of a response object + + Performs a single query request on the receiving home server. The Query Type + part of the path specifies the kind of query being made, and its query + arguments have a meaning specific to that kind of query. The response is a + JSON-encoded object whose meaning also depends on the kind of query. |