https://github.com/matrix-org/dendrite fork for cross-compile for ARM
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
10 KiB

Send Application Service Events (#477) * Prevent sql scanning into nil value in accounts_table Signed-off-by: Andrew Morgan <andrewm@matrix.org> * Remove uneccessary logging, null checking * Don't forget to set the localpart * Simplify error checking * Store And Send Application Service Events * Modify INSTALL.md and dendrite-config.yaml for the new appservice database * Correct all instances of casing on 'application service' to align with spec * Store incoming events that an app service is interested in in the database to be later read by transaction workers. * Retrieve these events from transaction workers, one per AS. * Minimal transaction ID data is stored as well to recover after server failure. * Send events to AS and exponentially backoff on failure. Signed-off-by: Andrew Morgan <andrewm@matrix.org> * Finish my own sentences. * Fix up database interaction * Change to event-based AS sending * Reduce cyclomatic complexity * Appease the errcheck gods * Delete by int ID instead of string. This was causing some events to not be deleted, as < an eventID doesn't really make much sense. * Check if there are more events to send before sleeping * Send same transaction if last send attempt failed * Don't backoff on non-200s, tight send loop, 1 event query * Remove tight send loop. Fix events not being deleted * Additionally order by event id, track main.go * Return the last txnID, which our events are using * Remove old main.go file * Prevent duplicate events from being sent... * Strip event content if it doesn't contain anything Signed-off-by: Andrew Morgan <andrewm@matrix.org> * Update gomatrixserverlib and use Unsigned AS event prop * Fixes * Fix sync server comment * Remove unnecessary printlns * Use logrus Fields * Worker state methods * Remove sillyness * Fix up event filtering * Handle transaction event limit in loop * Switch to using a sequence for transaction IDs * Don't verify self-signed AS certificates * Fix logging * Use gmsl.Event instead of AS-only event in transactions Also clear up the logic on lookupStateEvents a little bit. * Change invalid_txn_id to global (for efficiency) * Use a bool for EventsReady instead of an int
3 years ago
Send Application Service Events (#477) * Prevent sql scanning into nil value in accounts_table Signed-off-by: Andrew Morgan <andrewm@matrix.org> * Remove uneccessary logging, null checking * Don't forget to set the localpart * Simplify error checking * Store And Send Application Service Events * Modify INSTALL.md and dendrite-config.yaml for the new appservice database * Correct all instances of casing on 'application service' to align with spec * Store incoming events that an app service is interested in in the database to be later read by transaction workers. * Retrieve these events from transaction workers, one per AS. * Minimal transaction ID data is stored as well to recover after server failure. * Send events to AS and exponentially backoff on failure. Signed-off-by: Andrew Morgan <andrewm@matrix.org> * Finish my own sentences. * Fix up database interaction * Change to event-based AS sending * Reduce cyclomatic complexity * Appease the errcheck gods * Delete by int ID instead of string. This was causing some events to not be deleted, as < an eventID doesn't really make much sense. * Check if there are more events to send before sleeping * Send same transaction if last send attempt failed * Don't backoff on non-200s, tight send loop, 1 event query * Remove tight send loop. Fix events not being deleted * Additionally order by event id, track main.go * Return the last txnID, which our events are using * Remove old main.go file * Prevent duplicate events from being sent... * Strip event content if it doesn't contain anything Signed-off-by: Andrew Morgan <andrewm@matrix.org> * Update gomatrixserverlib and use Unsigned AS event prop * Fixes * Fix sync server comment * Remove unnecessary printlns * Use logrus Fields * Worker state methods * Remove sillyness * Fix up event filtering * Handle transaction event limit in loop * Switch to using a sequence for transaction IDs * Don't verify self-signed AS certificates * Fix logging * Use gmsl.Event instead of AS-only event in transactions Also clear up the logic on lookupStateEvents a little bit. * Change invalid_txn_id to global (for efficiency) * Use a bool for EventsReady instead of an int
3 years ago
Send Application Service Events (#477) * Prevent sql scanning into nil value in accounts_table Signed-off-by: Andrew Morgan <andrewm@matrix.org> * Remove uneccessary logging, null checking * Don't forget to set the localpart * Simplify error checking * Store And Send Application Service Events * Modify INSTALL.md and dendrite-config.yaml for the new appservice database * Correct all instances of casing on 'application service' to align with spec * Store incoming events that an app service is interested in in the database to be later read by transaction workers. * Retrieve these events from transaction workers, one per AS. * Minimal transaction ID data is stored as well to recover after server failure. * Send events to AS and exponentially backoff on failure. Signed-off-by: Andrew Morgan <andrewm@matrix.org> * Finish my own sentences. * Fix up database interaction * Change to event-based AS sending * Reduce cyclomatic complexity * Appease the errcheck gods * Delete by int ID instead of string. This was causing some events to not be deleted, as < an eventID doesn't really make much sense. * Check if there are more events to send before sleeping * Send same transaction if last send attempt failed * Don't backoff on non-200s, tight send loop, 1 event query * Remove tight send loop. Fix events not being deleted * Additionally order by event id, track main.go * Return the last txnID, which our events are using * Remove old main.go file * Prevent duplicate events from being sent... * Strip event content if it doesn't contain anything Signed-off-by: Andrew Morgan <andrewm@matrix.org> * Update gomatrixserverlib and use Unsigned AS event prop * Fixes * Fix sync server comment * Remove unnecessary printlns * Use logrus Fields * Worker state methods * Remove sillyness * Fix up event filtering * Handle transaction event limit in loop * Switch to using a sequence for transaction IDs * Don't verify self-signed AS certificates * Fix logging * Use gmsl.Event instead of AS-only event in transactions Also clear up the logic on lookupStateEvents a little bit. * Change invalid_txn_id to global (for efficiency) * Use a bool for EventsReady instead of an int
3 years ago
  1. # Installing Dendrite
  2. Dendrite can be run in one of two configurations:
  3. * **Polylith mode**: A cluster of individual components, dealing with different
  4. aspects of the Matrix protocol (see [WIRING.md](WIRING-Current.md)). Components communicate
  5. with each other using internal HTTP APIs and [Apache Kafka](https://kafka.apache.org).
  6. This will almost certainly be the preferred model for large-scale deployments.
  7. * **Monolith mode**: All components run in the same process. In this mode,
  8. Kafka is completely optional and can instead be replaced with an in-process
  9. lightweight implementation called [Naffka](https://github.com/matrix-org/naffka). This
  10. will usually be the preferred model for low-volume, low-user or experimental deployments.
  11. For most deployments, it is **recommended to run in monolith mode with PostgreSQL databases**.
  12. Regardless of whether you are running in polylith or monolith mode, each Dendrite component that
  13. requires storage has its own database. Both Postgres and SQLite are supported and can be
  14. mixed-and-matched across components as needed in the configuration file.
  15. Be advised that Dendrite is still in development and it's not recommended for
  16. use in production environments just yet!
  17. ## Requirements
  18. Dendrite requires:
  19. * Go 1.14 or higher
  20. * Postgres 9.6 or higher (if using Postgres databases, not needed for SQLite)
  21. If you want to run a polylith deployment, you also need:
  22. * Apache Kafka 0.10.2+
  23. Please note that Kafka is **not required** for a monolith deployment.
  24. ## Building Dendrite
  25. Start by cloning the code:
  26. ```bash
  27. git clone https://github.com/matrix-org/dendrite
  28. cd dendrite
  29. ```
  30. Then build it:
  31. ```bash
  32. ./build.sh
  33. ```
  34. ## Install Kafka (polylith only)
  35. Install and start Kafka (c.f. [scripts/install-local-kafka.sh](scripts/install-local-kafka.sh)):
  36. ```bash
  37. KAFKA_URL=http://archive.apache.org/dist/kafka/2.1.0/kafka_2.11-2.1.0.tgz
  38. # Only download the kafka if it isn't already downloaded.
  39. test -f kafka.tgz || wget $KAFKA_URL -O kafka.tgz
  40. # Unpack the kafka over the top of any existing installation
  41. mkdir -p kafka && tar xzf kafka.tgz -C kafka --strip-components 1
  42. # Start the zookeeper running in the background.
  43. # By default the zookeeper listens on localhost:2181
  44. kafka/bin/zookeeper-server-start.sh -daemon kafka/config/zookeeper.properties
  45. # Start the kafka server running in the background.
  46. # By default the kafka listens on localhost:9092
  47. kafka/bin/kafka-server-start.sh -daemon kafka/config/server.properties
  48. ```
  49. On macOS, you can use [Homebrew](https://brew.sh/) for easier setup of Kafka:
  50. ```bash
  51. brew install kafka
  52. brew services start zookeeper
  53. brew services start kafka
  54. ```
  55. ## Configuration
  56. ### PostgreSQL database setup
  57. Assuming that PostgreSQL 9.6 (or later) is installed:
  58. * Create role, choosing a new password when prompted:
  59. ```bash
  60. sudo -u postgres createuser -P dendrite
  61. ```
  62. At this point you have a choice on whether to run all of the Dendrite
  63. components from a single database, or for each component to have its
  64. own database. For most deployments, running from a single database will
  65. be sufficient, although you may wish to separate them if you plan to
  66. split out the databases across multiple machines in the future.
  67. On macOS, omit `sudo -u postgres` from the below commands.
  68. * If you want to run all Dendrite components from a single database:
  69. ```bash
  70. sudo -u postgres createdb -O dendrite dendrite
  71. ```
  72. ... in which case your connection string will look like `postgres://user:pass@database/dendrite`.
  73. * If you want to run each Dendrite component with its own database:
  74. ```bash
  75. for i in mediaapi syncapi roomserver signingkeyserver federationsender appservice keyserver userapi_accounts userapi_devices naffka; do
  76. sudo -u postgres createdb -O dendrite dendrite_$i
  77. done
  78. ```
  79. ... in which case your connection string will look like `postgres://user:pass@database/dendrite_componentname`.
  80. ### SQLite database setup
  81. **WARNING:** SQLite is suitable for small experimental deployments only and should not be used in production - use PostgreSQL instead for any user-facing federating installation!
  82. Dendrite can use the built-in SQLite database engine for small setups.
  83. The SQLite databases do not need to be pre-built - Dendrite will
  84. create them automatically at startup.
  85. ### Server key generation
  86. Each Dendrite installation requires:
  87. * A unique Matrix signing private key
  88. * A valid and trusted TLS certificate and private key
  89. To generate a Matrix signing private key:
  90. ```bash
  91. ./bin/generate-keys --private-key matrix_key.pem
  92. ```
  93. **WARNING:** Make sure take a safe backup of this key! You will likely need it if you want to reinstall Dendrite, or
  94. any other Matrix homeserver, on the same domain name in the future. If you lose this key, you may have trouble joining
  95. federated rooms.
  96. For testing, you can generate a self-signed certificate and key, although this will not work for public federation:
  97. ```bash
  98. ./bin/generate-keys --tls-cert server.crt --tls-key server.key
  99. ```
  100. If you have server keys from an older Synapse instance,
  101. [convert them](serverkeyformat.md#converting-synapse-keys) to Dendrite's PEM
  102. format and configure them as `old_private_keys` in your config.
  103. ### Configuration file
  104. Create config file, based on `dendrite-config.yaml`. Call it `dendrite.yaml`. Things that will need editing include *at least*:
  105. * The `server_name` entry to reflect the hostname of your Dendrite server
  106. * The `database` lines with an updated connection string based on your
  107. desired setup, e.g. replacing `database` with the name of the database:
  108. * For Postgres: `postgres://dendrite:password@localhost/database`, e.g.
  109. * `postgres://dendrite:password@localhost/dendrite_userapi_account` to connect to PostgreSQL with SSL/TLS
  110. * `postgres://dendrite:password@localhost/dendrite_userapi_account?sslmode=disable` to connect to PostgreSQL without SSL/TLS
  111. * For SQLite on disk: `file:component.db` or `file:///path/to/component.db`, e.g. `file:userapi_account.db`
  112. * Postgres and SQLite can be mixed and matched on different components as desired.
  113. * The `use_naffka` option if using Naffka in a monolith deployment
  114. There are other options which may be useful so review them all. In particular,
  115. if you are trying to federate from your Dendrite instance into public rooms
  116. then configuring `key_perspectives` (like `matrix.org` in the sample) can
  117. help to improve reliability considerably by allowing your homeserver to fetch
  118. public keys for dead homeservers from somewhere else.
  119. **WARNING:** Dendrite supports running all components from the same database in
  120. PostgreSQL mode, but this is **NOT** a supported configuration with SQLite. When
  121. using SQLite, all components **MUST** use their own database file.
  122. ## Starting a monolith server
  123. It is possible to use Naffka as an in-process replacement to Kafka when using
  124. the monolith server. To do this, set `use_naffka: true` in your `dendrite.yaml`
  125. configuration and uncomment the relevant Naffka line in the `database` section.
  126. Be sure to update the database username and password if needed.
  127. The monolith server can be started as shown below. By default it listens for
  128. HTTP connections on port 8008, so you can configure your Matrix client to use
  129. `http://servername:8008` as the server:
  130. ```bash
  131. ./bin/dendrite-monolith-server
  132. ```
  133. If you set `--tls-cert` and `--tls-key` as shown below, it will also listen
  134. for HTTPS connections on port 8448:
  135. ```bash
  136. ./bin/dendrite-monolith-server --tls-cert=server.crt --tls-key=server.key
  137. ```
  138. ## Starting a polylith deployment
  139. The following contains scripts which will run all the required processes in order to point a Matrix client at Dendrite.
  140. ### nginx (or other reverse proxy)
  141. This is what your clients and federated hosts will talk to. It must forward
  142. requests onto the correct API server based on URL:
  143. * `/_matrix/client` to the client API server
  144. * `/_matrix/federation` to the federation API server
  145. * `/_matrix/key` to the federation API server
  146. * `/_matrix/media` to the media API server
  147. See `docs/nginx/polylith-sample.conf` for a sample configuration.
  148. ### Client API server
  149. This is what implements CS API endpoints. Clients talk to this via the proxy in
  150. order to send messages, create and join rooms, etc.
  151. ```bash
  152. ./bin/dendrite-polylith-multi --config=dendrite.yaml clientapi
  153. ```
  154. ### Sync server
  155. This is what implements `/sync` requests. Clients talk to this via the proxy
  156. in order to receive messages.
  157. ```bash
  158. ./bin/dendrite-polylith-multi --config=dendrite.yaml syncapi
  159. ```
  160. ### Media server
  161. This implements `/media` requests. Clients talk to this via the proxy in
  162. order to upload and retrieve media.
  163. ```bash
  164. ./bin/dendrite-polylith-multi --config=dendrite.yaml mediaapi
  165. ```
  166. ### Federation API server
  167. This implements the federation API. Servers talk to this via the proxy in
  168. order to send transactions. This is only required if you want to support
  169. federation.
  170. ```bash
  171. ./bin/dendrite-polylith-multi --config=dendrite.yaml federationapi
  172. ```
  173. ### Internal components
  174. This refers to components that are not directly spoken to by clients. They are only
  175. contacted by other components. This includes the following components.
  176. #### Room server
  177. This is what implements the room DAG. Clients do not talk to this.
  178. ```bash
  179. ./bin/dendrite-polylith-multi --config=dendrite.yaml roomserver
  180. ```
  181. #### Federation sender
  182. This sends events from our users to other servers. This is only required if
  183. you want to support federation.
  184. ```bash
  185. ./bin/dendrite-polylith-multi --config=dendrite.yaml federationsender
  186. ```
  187. #### Appservice server
  188. This sends events from the network to [application
  189. services](https://matrix.org/docs/spec/application_service/unstable.html)
  190. running locally. This is only required if you want to support running
  191. application services on your homeserver.
  192. ```bash
  193. ./bin/dendrite-polylith-multi --config=dendrite.yaml appservice
  194. ```
  195. #### Key server
  196. This manages end-to-end encryption keys for users.
  197. ```bash
  198. ./bin/dendrite-polylith-multi --config=dendrite.yaml keyserver
  199. ```
  200. #### Signing key server
  201. This manages signing keys for servers.
  202. ```bash
  203. ./bin/dendrite-polylith-multi --config=dendrite.yaml signingkeyserver
  204. ```
  205. #### EDU server
  206. This manages processing EDUs such as typing, send-to-device events and presence. Clients do not talk to
  207. ```bash
  208. ./bin/dendrite-polylith-multi --config=dendrite.yaml eduserver
  209. ```
  210. #### User server
  211. This manages user accounts, device access tokens and user account data,
  212. amongst other things.
  213. ```bash
  214. ./bin/dendrite-polylith-multi --config=dendrite.yaml userapi
  215. ```