Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ancient_architecture_notes.md 2.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. > **Warning**
  2. > These architecture notes are spectacularly old, and date back
  3. > to when Synapse was just federation code in isolation. This should be
  4. > merged into the main spec.
  5. # Server to Server
  6. ## Server to Server Stack
  7. To use the server to server stack, homeservers should only need to
  8. interact with the Messaging layer.
  9. The server to server side of things is designed into 4 distinct layers:
  10. 1. Messaging Layer
  11. 2. Pdu Layer
  12. 3. Transaction Layer
  13. 4. Transport Layer
  14. Where the bottom (the transport layer) is what talks to the internet via
  15. HTTP, and the top (the messaging layer) talks to the rest of the Home
  16. Server with a domain specific API.
  17. 1. **Messaging Layer**
  18. This is what the rest of the homeserver hits to send messages, join rooms,
  19. etc. It also allows you to register callbacks for when it gets notified by
  20. lower levels that e.g. a new message has been received.
  21. It is responsible for serializing requests to send to the data
  22. layer, and to parse requests received from the data layer.
  23. 2. **PDU Layer**
  24. This layer handles:
  25. - duplicate `pdu_id`'s - i.e., it makes sure we ignore them.
  26. - responding to requests for a given `pdu_id`
  27. - responding to requests for all metadata for a given context (i.e. room)
  28. - handling incoming backfill requests
  29. So it has to parse incoming messages to discover which are metadata and
  30. which aren't, and has to correctly clobber existing metadata where
  31. appropriate.
  32. For incoming PDUs, it has to check the PDUs it references to see
  33. if we have missed any. If we have go and ask someone (another
  34. homeserver) for it.
  35. 3. **Transaction Layer**
  36. This layer makes incoming requests idempotent. i.e., it stores
  37. which transaction id's we have seen and what our response were.
  38. If we have already seen a message with the given transaction id,
  39. we do not notify higher levels but simply respond with the
  40. previous response.
  41. `transaction_id` is from "`GET /send/<tx_id>/`"
  42. It's also responsible for batching PDUs into single transaction for
  43. sending to remote destinations, so that we only ever have one
  44. transaction in flight to a given destination at any one time.
  45. This is also responsible for answering requests for things after a
  46. given set of transactions, i.e., ask for everything after 'ver' X.
  47. 4. **Transport Layer**
  48. This is responsible for starting a HTTP server and hitting the
  49. correct callbacks on the Transaction layer, as well as sending
  50. both data and requests for data.
  51. ## Persistence
  52. We persist things in a single sqlite3 database. All database queries get
  53. run on a separate, dedicated thread. This that we only ever have one
  54. query running at a time, making it a lot easier to do things in a safe
  55. manner.
  56. The queries are located in the `synapse.persistence.transactions` module,
  57. and the table information in the `synapse.persistence.tables` module.