From 48b204b1ec8d922b2bcbe88c53d89d140e69740a Mon Sep 17 00:00:00 2001 From: squahtx Date: Tue, 15 Feb 2022 10:40:34 +0000 Subject: deploy: c4c98c75188015b7ee921ee0adc2c428fbb9b6b4 --- v1.53/development/cas.html | 317 +++++++++++ v1.53/development/contributing_guide.html | 620 +++++++++++++++++++++ v1.53/development/database_schema.html | 417 ++++++++++++++ v1.53/development/experimental_features.html | 288 ++++++++++ v1.53/development/git.html | 376 +++++++++++++ v1.53/development/img/git/branches.jpg | Bin 0 -> 72228 bytes v1.53/development/img/git/clean.png | Bin 0 -> 110840 bytes v1.53/development/img/git/squash.png | Bin 0 -> 29667 bytes .../development/internal_documentation/index.html | 264 +++++++++ v1.53/development/releases.html | 285 ++++++++++ v1.53/development/room-dag-concepts.html | 305 ++++++++++ v1.53/development/saml.html | 293 ++++++++++ v1.53/development/url_previews.html | 339 +++++++++++ 13 files changed, 3504 insertions(+) create mode 100644 v1.53/development/cas.html create mode 100644 v1.53/development/contributing_guide.html create mode 100644 v1.53/development/database_schema.html create mode 100644 v1.53/development/experimental_features.html create mode 100644 v1.53/development/git.html create mode 100644 v1.53/development/img/git/branches.jpg create mode 100644 v1.53/development/img/git/clean.png create mode 100644 v1.53/development/img/git/squash.png create mode 100644 v1.53/development/internal_documentation/index.html create mode 100644 v1.53/development/releases.html create mode 100644 v1.53/development/room-dag-concepts.html create mode 100644 v1.53/development/saml.html create mode 100644 v1.53/development/url_previews.html (limited to 'v1.53/development') diff --git a/v1.53/development/cas.html b/v1.53/development/cas.html new file mode 100644 index 0000000000..c5a0d9973a --- /dev/null +++ b/v1.53/development/cas.html @@ -0,0 +1,317 @@ + + + + + + CAS - Synapse + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + +
+
+ +
+ +
+ +

How to test CAS as a developer without a server

+

The django-mama-cas project is an +easy to run CAS implementation built on top of Django.

+

Prerequisites

+
    +
  1. Create a new virtualenv: python3 -m venv <your virtualenv>
  2. +
  3. Activate your virtualenv: source /path/to/your/virtualenv/bin/activate
  4. +
  5. Install Django and django-mama-cas: +
    python -m pip install "django<3" "django-mama-cas==2.4.0"
    +
    +
  6. +
  7. Create a Django project in the current directory: +
    django-admin startproject cas_test .
    +
    +
  8. +
  9. Follow the install directions for django-mama-cas
  10. +
  11. Setup the SQLite database: python manage.py migrate
  12. +
  13. Create a user: +
    python manage.py createsuperuser
    +
    +
      +
    1. Use whatever you want as the username and password.
    2. +
    3. Leave the other fields blank.
    4. +
    +
  14. +
  15. Use the built-in Django test server to serve the CAS endpoints on port 8000: +
    python manage.py runserver
    +
    +
  16. +
+

You should now have a Django project configured to serve CAS authentication with +a single user created.

+

Configure Synapse (and Element) to use CAS

+
    +
  1. Modify your homeserver.yaml to enable CAS and point it to your locally +running Django test server: +
    cas_config:
    +  enabled: true
    +  server_url: "http://localhost:8000"
    +  service_url: "http://localhost:8081"
    +  #displayname_attribute: name
    +  #required_attributes:
    +  #    name: value
    +
    +
  2. +
  3. Restart Synapse.
  4. +
+

Note that the above configuration assumes the homeserver is running on port 8081 +and that the CAS server is on port 8000, both on localhost.

+

Testing the configuration

+

Then in Element:

+
    +
  1. Visit the login page with a Element pointing at your homeserver.
  2. +
  3. Click the Single Sign-On button.
  4. +
  5. Login using the credentials created with createsuperuser.
  6. +
  7. You should be logged in.
  8. +
+

If you want to repeat this process you'll need to manually logout first:

+
    +
  1. http://localhost:8000/admin/
  2. +
  3. Click "logout" in the top right.
  4. +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/v1.53/development/contributing_guide.html b/v1.53/development/contributing_guide.html new file mode 100644 index 0000000000..f7420d9bd4 --- /dev/null +++ b/v1.53/development/contributing_guide.html @@ -0,0 +1,620 @@ + + + + + + Contributing Guide - Synapse + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + +
+
+ +
+ +
+ +

Contributing

+

This document aims to get you started with contributing to Synapse!

+

1. Who can contribute to Synapse?

+

Everyone is welcome to contribute code to matrix.org +projects, provided that they are willing to +license their contributions under the same license as the project itself. We +follow a simple 'inbound=outbound' model for contributions: the act of +submitting an 'inbound' contribution means that the contributor agrees to +license the code under the same terms as the project's overall 'outbound' +license - in our case, this is almost always Apache Software License v2 (see +LICENSE).

+

2. What do I need?

+

If you are running Windows, the Windows Subsystem for Linux (WSL) is strongly +recommended for development. More information about WSL can be found at +https://docs.microsoft.com/en-us/windows/wsl/install. Running Synapse natively +on Windows is not officially supported.

+

The code of Synapse is written in Python 3. To do pretty much anything, you'll need a recent version of Python 3. Your Python also needs support for virtual environments. This is usually built-in, but some Linux distributions like Debian and Ubuntu split it out into its own package. Running sudo apt install python3-venv should be enough.

+

Synapse can connect to PostgreSQL via the psycopg2 Python library. Building this library from source requires access to PostgreSQL's C header files. On Debian or Ubuntu Linux, these can be installed with sudo apt install libpq-dev.

+

The source code of Synapse is hosted on GitHub. You will also need a recent version of git.

+

For some tests, you will need a recent version of Docker.

+

3. Get the source.

+

The preferred and easiest way to contribute changes is to fork the relevant +project on GitHub, and then create a pull request to ask us to pull your +changes into our repo.

+

Please base your changes on the develop branch.

+
git clone git@github.com:YOUR_GITHUB_USER_NAME/synapse.git
+git checkout develop
+
+

If you need help getting started with git, this is beyond the scope of the document, but you +can find many good git tutorials on the web.

+

4. Install the dependencies

+

Once you have installed Python 3 and added the source, please open a terminal and +setup a virtualenv, as follows:

+
cd path/where/you/have/cloned/the/repository
+python3 -m venv ./env
+source ./env/bin/activate
+pip install wheel
+pip install -e ".[all,dev]"
+pip install tox
+
+

This will install the developer dependencies for the project.

+

5. Get in touch.

+

Join our developer community on Matrix: #synapse-dev:matrix.org!

+

6. Pick an issue.

+

Fix your favorite problem or perhaps find a Good First Issue +to work on.

+

7. Turn coffee into code and documentation!

+

There is a growing amount of documentation located in the +docs +directory, with a rendered version available online. +This documentation is intended primarily for sysadmins running their +own Synapse instance, as well as developers interacting externally with +Synapse. +docs/development +exists primarily to house documentation for +Synapse developers. +docs/admin_api houses documentation +regarding Synapse's Admin API, which is used mostly by sysadmins and external +service developers.

+

Synapse's code style is documented here. Please follow +it, including the conventions for the sample configuration +file.

+

We welcome improvements and additions to our documentation itself! When +writing new pages, please +build docs to a book +to check that your contributions render correctly. The docs are written in +GitHub-Flavoured Markdown.

+

Some documentation also exists in Synapse's GitHub +Wiki, although this is primarily +contributed to by community authors.

+

8. Test, test, test!

+

+

While you're developing and before submitting a patch, you'll +want to test your code.

+

Run the linters.

+

The linters look at your code and do two things:

+
    +
  • ensure that your code follows the coding style adopted by the project;
  • +
  • catch a number of errors in your code.
  • +
+

The linter takes no time at all to run as soon as you've downloaded the dependencies into your python virtual environment.

+
source ./env/bin/activate
+./scripts-dev/lint.sh
+
+

Note that this script will modify your files to fix styling errors. +Make sure that you have saved all your files.

+

If you wish to restrict the linters to only the files changed since the last commit +(much faster!), you can instead run:

+
source ./env/bin/activate
+./scripts-dev/lint.sh -d
+
+

Or if you know exactly which files you wish to lint, you can instead run:

+
source ./env/bin/activate
+./scripts-dev/lint.sh path/to/file1.py path/to/file2.py path/to/folder
+
+

Run the unit tests (Twisted trial).

+

The unit tests run parts of Synapse, including your changes, to see if anything +was broken. They are slower than the linters but will typically catch more errors.

+
source ./env/bin/activate
+trial tests
+
+

If you wish to only run some unit tests, you may specify +another module instead of tests - or a test class or a method:

+
source ./env/bin/activate
+trial tests.rest.admin.test_room tests.handlers.test_admin.ExfiltrateData.test_invite
+
+

If your tests fail, you may wish to look at the logs (the default log level is ERROR):

+
less _trial_temp/test.log
+
+

To increase the log level for the tests, set SYNAPSE_TEST_LOG_LEVEL:

+
SYNAPSE_TEST_LOG_LEVEL=DEBUG trial tests
+
+

By default, tests will use an in-memory SQLite database for test data. For additional +help with debugging, one can use an on-disk SQLite database file instead, in order to +review database state during and after running tests. This can be done by setting +the SYNAPSE_TEST_PERSIST_SQLITE_DB environment variable. Doing so will cause the +database state to be stored in a file named test.db under the trial process' +working directory. Typically, this ends up being _trial_temp/test.db. For example:

+
SYNAPSE_TEST_PERSIST_SQLITE_DB=1 trial tests
+
+

The database file can then be inspected with:

+
sqlite3 _trial_temp/test.db
+
+

Note that the database file is cleared at the beginning of each test run. Thus it +will always only contain the data generated by the last run test. Though generally +when debugging, one is only running a single test anyway.

+

Running tests under PostgreSQL

+

Invoking trial as above will use an in-memory SQLite database. This is great for +quick development and testing. However, we recommend using a PostgreSQL database +in production (and indeed, we have some code paths specific to each database). +This means that we need to run our unit tests against PostgreSQL too. Our CI does +this automatically for pull requests and release candidates, but it's sometimes +useful to reproduce this locally.

+

To do so, configure Postgres and run trial with the +following environment variables matching your configuration:

+
    +
  • SYNAPSE_POSTGRES to anything nonempty
  • +
  • SYNAPSE_POSTGRES_HOST
  • +
  • SYNAPSE_POSTGRES_USER
  • +
  • SYNAPSE_POSTGRES_PASSWORD
  • +
+

For example:

+
export SYNAPSE_POSTGRES=1
+export SYNAPSE_POSTGRES_HOST=localhost
+export SYNAPSE_POSTGRES_USER=postgres
+export SYNAPSE_POSTGRES_PASSWORD=mydevenvpassword
+trial
+
+

Prebuilt container

+

Since configuring PostgreSQL can be fiddly, we can make use of a pre-made +Docker container to set up PostgreSQL and run our tests for us. To do so, run

+
scripts-dev/test_postgresql.sh
+
+

Any extra arguments to the script will be passed to tox and then to trial, +so we can run a specific test in this container with e.g.

+
scripts-dev/test_postgresql.sh tests.replication.test_sharded_event_persister.EventPersisterShardTestCase
+
+

The container creates a folder in your Synapse checkout called +.tox-pg-container and uses this as a tox environment. The output of any +trial runs goes into _trial_temp in your synapse source directory — the same +as running trial directly on your host machine.

+

Run the integration tests (Sytest).

+

The integration tests are a more comprehensive suite of tests. They +run a full version of Synapse, including your changes, to check if +anything was broken. They are slower than the unit tests but will +typically catch more errors.

+

The following command will let you run the integration test with the most common +configuration:

+
$ docker run --rm -it -v /path/where/you/have/cloned/the/repository\:/src:ro -v /path/to/where/you/want/logs\:/logs matrixdotorg/sytest-synapse:buster
+
+

This configuration should generally cover your needs. For more details about other configurations, see documentation in the SyTest repo.

+

Run the integration tests (Complement).

+

Complement is a suite of black box tests that can be run on any homeserver implementation. It can also be thought of as end-to-end (e2e) tests.

+

It's often nice to develop on Synapse and write Complement tests at the same time. +Here is how to run your local Synapse checkout against your local Complement checkout.

+

(checkout complement alongside your synapse checkout)

+
COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh
+
+

To run a specific test file, you can pass the test name at the end of the command. The name passed comes from the naming structure in your Complement tests. If you're unsure of the name, you can do a full run and copy it from the test output:

+
COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestBackfillingHistory
+
+

To run a specific test, you can specify the whole name structure:

+
COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestBackfillingHistory/parallel/Backfilled_historical_events_resolve_with_proper_state_in_correct_order
+
+

Access database for homeserver after Complement test runs.

+

If you're curious what the database looks like after you run some tests, here are some steps to get you going in Synapse:

+
    +
  1. In your Complement test comment out defer deployment.Destroy(t) and replace with defer time.Sleep(2 * time.Hour) to keep the homeserver running after the tests complete
  2. +
  3. Start the Complement tests
  4. +
  5. Find the name of the container, docker ps -f name=complement_ (this will filter for just the Compelement related Docker containers)
  6. +
  7. Access the container replacing the name with what you found in the previous step: docker exec -it complement_1_hs_with_application_service.hs1_2 /bin/bash
  8. +
  9. Install sqlite (database driver), apt-get update && apt-get install -y sqlite3
  10. +
  11. Then run sqlite3 and open the database .open /conf/homeserver.db (this db path comes from the Synapse homeserver.yaml)
  12. +
+

9. Submit your patch.

+

Once you're happy with your patch, it's time to prepare a Pull Request.

+

To prepare a Pull Request, please:

+
    +
  1. verify that all the tests pass, including the coding style;
  2. +
  3. sign off your contribution;
  4. +
  5. git push your commit to your fork of Synapse;
  6. +
  7. on GitHub, create the Pull Request;
  8. +
  9. add a changelog entry and push it to your Pull Request;
  10. +
  11. for most contributors, that's all - however, if you are a member of the organization matrix-org, on GitHub, please request a review from matrix.org / Synapse Core.
  12. +
  13. if you need to update your PR, please avoid rebasing and just add new commits to your branch.
  14. +
+

Changelog

+

All changes, even minor ones, need a corresponding changelog / newsfragment +entry. These are managed by Towncrier.

+

To create a changelog entry, make a new file in the changelog.d directory named +in the format of PRnumber.type. The type can be one of the following:

+
    +
  • feature
  • +
  • bugfix
  • +
  • docker (for updates to the Docker image)
  • +
  • doc (for updates to the documentation)
  • +
  • removal (also used for deprecations)
  • +
  • misc (for internal-only changes)
  • +
+

This file will become part of our changelog at the next +release, so the content of the file should be a short description of your +change in the same style as the rest of the changelog. The file can contain Markdown +formatting, and should end with a full stop (.) or an exclamation mark (!) for +consistency.

+

Adding credits to the changelog is encouraged, we value your +contributions and would like to have you shouted out in the release notes!

+

For example, a fix in PR #1234 would have its changelog entry in +changelog.d/1234.bugfix, and contain content like:

+
+

The security levels of Florbs are now validated when received +via the /federation/florb endpoint. Contributed by Jane Matrix.

+
+

If there are multiple pull requests involved in a single bugfix/feature/etc, +then the content for each changelog.d file should be the same. Towncrier will +merge the matching files together into a single changelog entry when we come to +release.

+

How do I know what to call the changelog file before I create the PR?

+

Obviously, you don't know if you should call your newsfile +1234.bugfix or 5678.bugfix until you create the PR, which leads to a +chicken-and-egg problem.

+

There are two options for solving this:

+
    +
  1. +

    Open the PR without a changelog file, see what number you got, and then +add the changelog file to your branch (see Updating your pull +request), or:

    +
  2. +
  3. +

    Look at the list of all +issues/PRs, add one to the +highest number you see, and quickly open the PR before somebody else claims +your number.

    +

    This +script +might be helpful if you find yourself doing this a lot.

    +
  4. +
+

Sorry, we know it's a bit fiddly, but it's really helpful for us when we come +to put together a release!

+

Debian changelog

+

Changes which affect the debian packaging files (in debian) are an +exception to the rule that all changes require a changelog.d file.

+

In this case, you will need to add an entry to the debian changelog for the +next release. For this, run the following command:

+
dch
+
+

This will make up a new version number (if there isn't already an unreleased +version in flight), and open an editor where you can add a new changelog entry. +(Our release process will ensure that the version number and maintainer name is +corrected for the release.)

+

If your change affects both the debian packaging and files outside the debian +directory, you will need both a regular newsfragment and an entry in the +debian changelog. (Though typically such changes should be submitted as two +separate pull requests.)

+

Sign off

+

In order to have a concrete record that your contribution is intentional +and you agree to license it under the same terms as the project's license, we've adopted the +same lightweight approach that the Linux Kernel +submitting patches process, +Docker, and many other +projects use: the DCO (Developer Certificate of Origin: +http://developercertificate.org/). This is a simple declaration that you wrote +the contribution or otherwise have the right to contribute it to Matrix:

+
Developer Certificate of Origin
+Version 1.1
+
+Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
+660 York Street, Suite 102,
+San Francisco, CA 94110 USA
+
+Everyone is permitted to copy and distribute verbatim copies of this
+license document, but changing it is not allowed.
+
+Developer's Certificate of Origin 1.1
+
+By making a contribution to this project, I certify that:
+
+(a) The contribution was created in whole or in part by me and I
+    have the right to submit it under the open source license
+    indicated in the file; or
+
+(b) The contribution is based upon previous work that, to the best
+    of my knowledge, is covered under an appropriate open source
+    license and I have the right under that license to submit that
+    work with modifications, whether created in whole or in part
+    by me, under the same open source license (unless I am
+    permitted to submit under a different license), as indicated
+    in the file; or
+
+(c) The contribution was provided directly to me by some other
+    person who certified (a), (b) or (c) and I have not modified
+    it.
+
+(d) I understand and agree that this project and the contribution
+    are public and that a record of the contribution (including all
+    personal information I submit with it, including my sign-off) is
+    maintained indefinitely and may be redistributed consistent with
+    this project or the open source license(s) involved.
+
+

If you agree to this for your contribution, then all that's needed is to +include the line in your commit or pull request comment:

+
Signed-off-by: Your Name <your@email.example.org>
+
+

We accept contributions under a legally identifiable name, such as +your name on government documentation or common-law names (names +claimed by legitimate usage or repute). Unfortunately, we cannot +accept anonymous contributions at this time.

+

Git allows you to add this signoff automatically when using the -s +flag to git commit, which uses the name and email set in your +user.name and user.email git configs.

+

10. Turn feedback into better code.

+

Once the Pull Request is opened, you will see a few things:

+
    +
  1. our automated CI (Continuous Integration) pipeline will run (again) the linters, the unit tests, the integration tests and more;
  2. +
  3. one or more of the developers will take a look at your Pull Request and offer feedback.
  4. +
+

From this point, you should:

+
    +
  1. Look at the results of the CI pipeline. +
      +
    • If there is any error, fix the error.
    • +
    +
  2. +
  3. If a developer has requested changes, make these changes and let us know if it is ready for a developer to review again.
  4. +
  5. Create a new commit with the changes. +
      +
    • Please do NOT overwrite the history. New commits make the reviewer's life easier.
    • +
    • Push this commits to your Pull Request.
    • +
    +
  6. +
  7. Back to 1.
  8. +
+

Once both the CI and the developers are happy, the patch will be merged into Synapse and released shortly!

+

11. Find a new issue.

+

By now, you know the drill!

+

Notes for maintainers on merging PRs etc

+

There are some notes for those with commit access to the project on how we +manage git here.

+

Conclusion

+

That's it! Matrix is a very open and collaborative project as you might expect +given our obsession with open communication. If we're going to successfully +matrix together all the fragmented communication technologies out there we are +reliant on contributions and collaboration from the community to do so. So +please get involved - and we hope you have as much fun hacking on Matrix as we +do!

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/v1.53/development/database_schema.html b/v1.53/development/database_schema.html new file mode 100644 index 0000000000..a521a4ec3f --- /dev/null +++ b/v1.53/development/database_schema.html @@ -0,0 +1,417 @@ + + + + + + Database Schemas - Synapse + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + +
+
+ +
+ +
+ +

Synapse database schema files

+

Synapse's database schema is stored in the synapse.storage.schema module.

+

Logical databases

+

Synapse supports splitting its datastore across multiple physical databases (which can +be useful for large installations), and the schema files are therefore split according +to the logical database they apply to.

+

At the time of writing, the following "logical" databases are supported:

+
    +
  • state - used to store Matrix room state (more specifically, state_groups, +their relationships and contents).
  • +
  • main - stores everything else.
  • +
+

Additionally, the common directory contains schema files for tables which must be +present on all physical databases.

+

Synapse schema versions

+

Synapse manages its database schema via "schema versions". These are mainly used to +help avoid confusion if the Synapse codebase is rolled back after the database is +updated. They work as follows:

+
    +
  • +

    The Synapse codebase defines a constant synapse.storage.schema.SCHEMA_VERSION +which represents the expectations made about the database by that version. For +example, as of Synapse v1.36, this is 59.

    +
  • +
  • +

    The database stores a "compatibility version" in +schema_compat_version.compat_version which defines the SCHEMA_VERSION of the +oldest version of Synapse which will work with the database. On startup, if +compat_version is found to be newer than SCHEMA_VERSION, Synapse will refuse to +start.

    +

    Synapse automatically updates this field from +synapse.storage.schema.SCHEMA_COMPAT_VERSION.

    +
  • +
  • +

    Whenever a backwards-incompatible change is made to the database format (normally +via a delta file), synapse.storage.schema.SCHEMA_COMPAT_VERSION is also updated +so that administrators can not accidentally roll back to a too-old version of Synapse.

    +
  • +
+

Generally, the goal is to maintain compatibility with at least one or two previous +releases of Synapse, so any substantial change tends to require multiple releases and a +bit of forward-planning to get right.

+

As a worked example: we want to remove the room_stats_historical table. Here is how it +might pan out.

+
    +
  1. +

    Replace any code that reads from room_stats_historical with alternative +implementations, but keep writing to it in case of rollback to an earlier version. +Also, increase synapse.storage.schema.SCHEMA_VERSION. In this +instance, there is no existing code which reads from room_stats_historical, so +our starting point is:

    +

    v1.36.0: SCHEMA_VERSION=59, SCHEMA_COMPAT_VERSION=59

    +
  2. +
  3. +

    Next (say in Synapse v1.37.0): remove the code that writes to +room_stats_historical, but don’t yet remove the table in case of rollback to +v1.36.0. Again, we increase synapse.storage.schema.SCHEMA_VERSION, but +because we have not broken compatibility with v1.36, we do not yet update +SCHEMA_COMPAT_VERSION. We now have:

    +

    v1.37.0: SCHEMA_VERSION=60, SCHEMA_COMPAT_VERSION=59.

    +
  4. +
  5. +

    Later (say in Synapse v1.38.0): we can remove the table altogether. This will +break compatibility with v1.36.0, so we must update SCHEMA_COMPAT_VERSION accordingly. +There is no need to update synapse.storage.schema.SCHEMA_VERSION, since there is no +change to the Synapse codebase here. So we end up with:

    +

    v1.38.0: SCHEMA_VERSION=60, SCHEMA_COMPAT_VERSION=60.

    +
  6. +
+

If in doubt about whether to update SCHEMA_VERSION or not, it is generally best to +lean towards doing so.

+

Full schema dumps

+

In the full_schemas directories, only the most recently-numbered snapshot is used +(54 at the time of writing). Older snapshots (eg, 16) are present for historical +reference only.

+

Building full schema dumps

+

If you want to recreate these schemas, they need to be made from a database that +has had all background updates run.

+

To do so, use scripts-dev/make_full_schema.sh. This will produce new +full.sql.postgres and full.sql.sqlite files.

+

Ensure postgres is installed, then run:

+
./scripts-dev/make_full_schema.sh -p postgres_username -o output_dir/
+
+

NB at the time of writing, this script predates the split into separate state/main +databases so will require updates to handle that correctly.

+

Delta files

+

Delta files define the steps required to upgrade the database from an earlier version. +They can be written as either a file containing a series of SQL statements, or a Python +module.

+

Synapse remembers which delta files it has applied to a database (they are stored in the +applied_schema_deltas table) and will not re-apply them (even if a given file is +subsequently updated).

+

Delta files should be placed in a directory named synapse/storage/schema/<database>/delta/<version>/. +They are applied in alphanumeric order, so by convention the first two characters +of the filename should be an integer such as 01, to put the file in the right order.

+

SQL delta files

+

These should be named *.sql, or — for changes which should only be applied for a +given database engine — *.sql.posgres or *.sql.sqlite. For example, a delta which +adds a new column to the foo table might be called 01add_bar_to_foo.sql.

+

Note that our SQL parser is a bit simple - it understands comments (-- and /*...*/), +but complex statements which require a ; in the middle of them (such as CREATE TRIGGER) are beyond it and you'll have to use a Python delta file.

+

Python delta files

+

For more flexibility, a delta file can take the form of a python module. These should +be named *.py. Note that database-engine-specific modules are not supported here – +instead you can write if isinstance(database_engine, PostgresEngine) or similar.

+

A Python delta module should define either or both of the following functions:

+
import synapse.config.homeserver
+import synapse.storage.engines
+import synapse.storage.types
+
+
+def run_create(
+    cur: synapse.storage.types.Cursor,
+    database_engine: synapse.storage.engines.BaseDatabaseEngine,
+) -> None:
+    """Called whenever an existing or new database is to be upgraded"""
+    ...
+
+def run_upgrade(
+    cur: synapse.storage.types.Cursor,
+    database_engine: synapse.storage.engines.BaseDatabaseEngine,
+    config: synapse.config.homeserver.HomeServerConfig,
+) -> None:
+    """Called whenever an existing database is to be upgraded."""
+    ...
+
+

Boolean columns

+

Boolean columns require special treatment, since SQLite treats booleans the +same as integers.

+

There are three separate aspects to this:

+
    +
  • +

    Any new boolean column must be added to the BOOLEAN_COLUMNS list in +scripts/synapse_port_db. This tells the port script to cast the integer +value from SQLite to a boolean before writing the value to the postgres +database.

    +
  • +
  • +

    Before SQLite 3.23, TRUE and FALSE were not recognised as constants by +SQLite, and the IS [NOT] TRUE/IS [NOT] FALSE operators were not +supported. This makes it necessary to avoid using TRUE and FALSE +constants in SQL commands.

    +

    For example, to insert a TRUE value into the database, write:

    +
    txn.execute("INSERT INTO tbl(col) VALUES (?)", (True, ))
    +
    +
  • +
  • +

    Default values for new boolean columns present a particular +difficulty. Generally it is best to create separate schema files for +Postgres and SQLite. For example:

    +
    # in 00delta.sql.postgres:
    +ALTER TABLE tbl ADD COLUMN col BOOLEAN DEFAULT FALSE;
    +
    +
    # in 00delta.sql.sqlite:
    +ALTER TABLE tbl ADD COLUMN col BOOLEAN DEFAULT 0;
    +
    +

    Note that there is a particularly insidious failure mode here: the Postgres +flavour will be accepted by SQLite 3.22, but will give a column whose +default value is the string "FALSE" - which, when cast back to a boolean +in Python, evaluates to True.

    +
  • +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/v1.53/development/experimental_features.html b/v1.53/development/experimental_features.html new file mode 100644 index 0000000000..87e15ceb73 --- /dev/null +++ b/v1.53/development/experimental_features.html @@ -0,0 +1,288 @@ + + + + + + Experimental features - Synapse + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + +
+
+ +
+ +
+ +

Implementing experimental features in Synapse

+

It can be desirable to implement "experimental" features which are disabled by +default and must be explicitly enabled via the Synapse configuration. This is +applicable for features which:

+
    +
  • Are unstable in the Matrix spec (e.g. those defined by an MSC that has not yet been merged).
  • +
  • Developers are not confident in their use by general Synapse administrators/users +(e.g. a feature is incomplete, buggy, performs poorly, or needs further testing).
  • +
+

Note that this only really applies to features which are expected to be desirable +to a broad audience. The module infrastructure should +instead be investigated for non-standard features.

+

Guarding experimental features behind configuration flags should help with some +of the following scenarios:

+
    +
  • Ensure that clients do not assume that unstable features exist (failing +gracefully if they do not).
  • +
  • Unstable features do not become de-facto standards and can be removed +aggressively (since only those who have opted-in will be affected).
  • +
  • Ease finding the implementation of unstable features in Synapse (for future +removal or stabilization).
  • +
  • Ease testing a feature (or removal of feature) due to enabling/disabling without +code changes. It also becomes possible to ask for wider testing, if desired.
  • +
+

Experimental configuration flags should be disabled by default (requiring Synapse +administrators to explicitly opt-in), although there are situations where it makes +sense (from a product point-of-view) to enable features by default. This is +expected and not an issue.

+

It is not a requirement for experimental features to be behind a configuration flag, +but one should be used if unsure.

+

New experimental configuration flags should be added under the experimental +configuration key (see the synapse.config.experimental file) and either explain +(briefly) what is being enabled, or include the MSC number.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/v1.53/development/git.html b/v1.53/development/git.html new file mode 100644 index 0000000000..2960ab267a --- /dev/null +++ b/v1.53/development/git.html @@ -0,0 +1,376 @@ + + + + + + Git Usage - Synapse + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + +
+
+ +
+ +
+ +

Some notes on how we use git

+

On keeping the commit history clean

+

In an ideal world, our git commit history would be a linear progression of +commits each of which contains a single change building on what came +before. Here, by way of an arbitrary example, is the top of git log --graph b2dba0607:

+clean git graph +

Note how the commit comment explains clearly what is changing and why. Also +note the absence of merge commits, as well as the absence of commits called +things like (to pick a few culprits): +“pep8”, “fix broken +test”, +“oops”, +“typo”, or “Who's +the president?”.

+

There are a number of reasons why keeping a clean commit history is a good +thing:

+
    +
  • +

    From time to time, after a change lands, it turns out to be necessary to +revert it, or to backport it to a release branch. Those operations are +much easier when the change is contained in a single commit.

    +
  • +
  • +

    Similarly, it's much easier to answer questions like “is the fix for +/publicRooms on the release branch?” if that change consists of a single +commit.

    +
  • +
  • +

    Likewise: “what has changed on this branch in the last week?” is much +clearer without merges and “pep8” commits everywhere.

    +
  • +
  • +

    Sometimes we need to figure out where a bug got introduced, or some +behaviour changed. One way of doing that is with git bisect: pick an +arbitrary commit between the known good point and the known bad point, and +see how the code behaves. However, that strategy fails if the commit you +chose is the middle of someone's epic branch in which they broke the world +before putting it back together again.

    +
  • +
+

One counterargument is that it is sometimes useful to see how a PR evolved as +it went through review cycles. This is true, but that information is always +available via the GitHub UI (or via the little-known refs/pull +namespace).

+

Of course, in reality, things are more complicated than that. We have release +branches as well as develop and master, and we deliberately merge changes +between them. Bugs often slip through and have to be fixed later. That's all +fine: this not a cast-iron rule which must be obeyed, but an ideal to aim +towards.

+

Merges, squashes, rebases: wtf?

+

Ok, so that's what we'd like to achieve. How do we achieve it?

+

The TL;DR is: when you come to merge a pull request, you probably want to +“squash and merge”:

+

squash and merge.

+

(This applies whether you are merging your own PR, or that of another +contributor.)

+

“Squash and merge”1 takes all of the changes in the +PR, and bundles them into a single commit. GitHub gives you the opportunity to +edit the commit message before you confirm, and normally you should do so, +because the default will be useless (again: * woops typo is not a useful +thing to keep in the historical record).

+

The main problem with this approach comes when you have a series of pull +requests which build on top of one another: as soon as you squash-merge the +first PR, you'll end up with a stack of conflicts to resolve in all of the +others. In general, it's best to avoid this situation in the first place by +trying not to have multiple related PRs in flight at the same time. Still, +sometimes that's not possible and doing a regular merge is the lesser evil.

+

Another occasion in which a regular merge makes more sense is a PR where you've +deliberately created a series of commits each of which makes sense in its own +right. For example: a PR which gradually propagates a refactoring operation +through the codebase, or a +PR which is the culmination of several other +PRs. In this case the ability +to figure out when a particular change/bug was introduced could be very useful.

+

Ultimately: this is not a hard-and-fast-rule. If in doubt, ask yourself “do +each of the commits I am about to merge make sense in their own right”, but +remember that we're just doing our best to balance “keeping the commit history +clean” with other factors.

+

Git branching model

+

A lot +of +words have been +written in the past about git branching models (no really, a +lot). I tend to +think the whole thing is overblown. Fundamentally, it's not that +complicated. Here's how we do it.

+

Let's start with a picture:

+

branching model

+

It looks complicated, but it's really not. There's one basic rule: anyone is +free to merge from any more-stable branch to any less-stable branch at +any time2. (The principle behind this is that if a +change is good enough for the more-stable branch, then it's also good enough go +put in a less-stable branch.)

+

Meanwhile, merging (or squashing, as per the above) from a less-stable to a +more-stable branch is a deliberate action in which you want to publish a change +or a set of changes to (some subset of) the world: for example, this happens +when a PR is landed, or as part of our release process.

+

So, what counts as a more- or less-stable branch? A little reflection will show +that our active branches are ordered thus, from more-stable to less-stable:

+
    +
  • master (tracks our last release).
  • +
  • release-vX.Y (the branch where we prepare the next release)3.
  • +
  • PR branches which are targeting the release.
  • +
  • develop (our "mainline" branch containing our bleeding-edge).
  • +
  • regular PR branches.
  • +
+

The corollary is: if you have a bugfix that needs to land in both +release-vX.Y and develop, then you should base your PR on +release-vX.Y, get it merged there, and then merge from release-vX.Y to +develop. (If a fix lands in develop and we later need it in a +release-branch, we can of course cherry-pick it, but landing it in the release +branch first helps reduce the chance of annoying conflicts.)

+
+

[1]: “Squash and merge” is GitHub's term for this +operation. Given that there is no merge involved, I'm not convinced it's the +most intuitive name. ^

+

[2]: Well, anyone with commit access.^

+

[3]: Very, very occasionally (I think this has happened once in +the history of Synapse), we've had two releases in flight at once. Obviously, +release-v1.2 is more-stable than release-v1.3. ^

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/v1.53/development/img/git/branches.jpg b/v1.53/development/img/git/branches.jpg new file mode 100644 index 0000000000..715ecc8cd0 Binary files /dev/null and b/v1.53/development/img/git/branches.jpg differ diff --git a/v1.53/development/img/git/clean.png b/v1.53/development/img/git/clean.png new file mode 100644 index 0000000000..3accd7ccef Binary files /dev/null and b/v1.53/development/img/git/clean.png differ diff --git a/v1.53/development/img/git/squash.png b/v1.53/development/img/git/squash.png new file mode 100644 index 0000000000..234caca3e4 Binary files /dev/null and b/v1.53/development/img/git/squash.png differ diff --git a/v1.53/development/internal_documentation/index.html b/v1.53/development/internal_documentation/index.html new file mode 100644 index 0000000000..d869fd373a --- /dev/null +++ b/v1.53/development/internal_documentation/index.html @@ -0,0 +1,264 @@ + + + + + + Internal Documentation - Synapse + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + +
+
+ +
+ +
+ +

Internal Documentation

+

This section covers implementation documentation for various parts of Synapse.

+

If a developer is planning to make a change to a feature of Synapse, it can be useful for +general documentation of how that feature is implemented to be available. This saves the +developer time in place of needing to understand how the feature works by reading the +code.

+

Documentation that would be more useful for the perspective of a system administrator, +rather than a developer who's intending to change to code, should instead be placed +under the Usage section of the documentation.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/v1.53/development/releases.html b/v1.53/development/releases.html new file mode 100644 index 0000000000..e73e6ba9a2 --- /dev/null +++ b/v1.53/development/releases.html @@ -0,0 +1,285 @@ + + + + + + Release Cycle - Synapse + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + +
+
+ +
+ +
+ +

Synapse Release Cycle

+

Releases of Synapse follow a two week release cycle with new releases usually +occurring on Tuesdays:

+
    +
  • Day 0: Synapse N - 1 is released.
  • +
  • Day 7: Synapse N release candidate 1 is released.
  • +
  • Days 7 - 13: Synapse N release candidates 2+ are released, if bugs are found.
  • +
  • Day 14: Synapse N is released.
  • +
+

Note that this schedule might be modified depending on the availability of the +Synapse team, e.g. releases may be skipped to avoid holidays.

+

Release announcements can be found in the +release category of the Matrix blog.

+

Bugfix releases

+

If a bug is found after release that is deemed severe enough (by a combination +of the impacted users and the impact on those users) then a bugfix release may +be issued. This may be at any point in the release cycle.

+

Security releases

+

Security will sometimes be backported to the previous version and released +immediately before the next release candidate. An example of this might be:

+
    +
  • Day 0: Synapse N - 1 is released.
  • +
  • Day 7: Synapse (N - 1).1 is released as Synapse N - 1 + the security fix.
  • +
  • Day 7: Synapse N release candidate 1 is released (including the security fix).
  • +
+

Depending on the impact and complexity of security fixes, multiple fixes might +be held to be released together.

+

In some cases, a pre-disclosure of a security release will be issued as a notice +to Synapse operators that there is an upcoming security release. These can be +found in the security category of the Matrix blog.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/v1.53/development/room-dag-concepts.html b/v1.53/development/room-dag-concepts.html new file mode 100644 index 0000000000..59cead08ab --- /dev/null +++ b/v1.53/development/room-dag-concepts.html @@ -0,0 +1,305 @@ + + + + + + Room DAG concepts - Synapse + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + +
+
+ +
+ +
+ +

Room DAG concepts

+

Edges

+

The word "edge" comes from graph theory lingo. An edge is just a connection +between two events. In Synapse, we connect events by specifying their +prev_events. A subsequent event points back at a previous event.

+
A (oldest) <---- B <---- C (most recent)
+
+

Depth and stream ordering

+

Events are normally sorted by (topological_ordering, stream_ordering) where +topological_ordering is just depth. In other words, we first sort by depth +and then tie-break based on stream_ordering. depth is incremented as new +messages are added to the DAG. Normally, stream_ordering is an auto +incrementing integer, but backfilled events start with stream_ordering=-1 and decrement.

+
+
    +
  • /sync returns things in the order they arrive at the server (stream_ordering).
  • +
  • /messages (and /backfill in the federation API) return them in the order determined by the event graph (topological_ordering, stream_ordering).
  • +
+

The general idea is that, if you're following a room in real-time (i.e. +/sync), you probably want to see the messages as they arrive at your server, +rather than skipping any that arrived late; whereas if you're looking at a +historical section of timeline (i.e. /messages), you want to see the best +representation of the state of the room as others were seeing it at the time.

+

Forward extremity

+

Most-recent-in-time events in the DAG which are not referenced by any other events' prev_events yet.

+

The forward extremities of a room are used as the prev_events when the next event is sent.

+

Backward extremity

+

The current marker of where we have backfilled up to and will generally be the +prev_events of the oldest-in-time events we have in the DAG. This gives a starting point when +backfilling history.

+

When we persist a non-outlier event, we clear it as a backward extremity and set +all of its prev_events as the new backward extremities if they aren't already +persisted in the events table.

+

Outliers

+

We mark an event as an outlier when we haven't figured out the state for the +room at that point in the DAG yet.

+

We won't necessarily have the prev_events of an outlier in the database, +but it's entirely possible that we might.

+

For example, when we fetch the event auth chain or state for a given event, we +mark all of those claimed auth events as outliers because we haven't done the +state calculation ourself.

+

State groups

+

For every non-outlier event we need to know the state at that event. Instead of +storing the full state for each event in the DB (i.e. a event_id -> state +mapping), which is very space inefficient when state doesn't change, we +instead assign each different set of state a "state group" and then have +mappings of event_id -> state_group and state_group -> state.

+

Stage group edges

+

TODO: state_group_edges is a further optimization... +notes from @Azrenbeth, https://pastebin.com/seUGVGeT

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/v1.53/development/saml.html b/v1.53/development/saml.html new file mode 100644 index 0000000000..49d9b4227b --- /dev/null +++ b/v1.53/development/saml.html @@ -0,0 +1,293 @@ + + + + + + SAML - Synapse + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + +
+
+ +
+ +
+ +

How to test SAML as a developer without a server

+

https://fujifish.github.io/samling/samling.html (https://github.com/fujifish/samling) is a great resource for being able to tinker with the +SAML options within Synapse without needing to deploy and configure a complicated software stack.

+

To make Synapse (and therefore Element) use it:

+
    +
  1. Use the samling.html URL above or deploy your own and visit the IdP Metadata tab.
  2. +
  3. Copy the XML to your clipboard.
  4. +
  5. On your Synapse server, create a new file samling.xml next to your homeserver.yaml with +the XML from step 2 as the contents.
  6. +
  7. Edit your homeserver.yaml to include: +
    saml2_config:
    +  sp_config:
    +    allow_unknown_attributes: true  # Works around a bug with AVA Hashes: https://github.com/IdentityPython/pysaml2/issues/388
    +    metadata:
    +      local: ["samling.xml"]
    +
    +
  8. +
  9. Ensure that your homeserver.yaml has a setting for public_baseurl: +
    public_baseurl: http://localhost:8080/
    +
    +
  10. +
  11. Run apt-get install xmlsec1 and pip install --upgrade --force 'pysaml2>=4.5.0' to ensure +the dependencies are installed and ready to go.
  12. +
  13. Restart Synapse.
  14. +
+

Then in Element:

+
    +
  1. Visit the login page and point Element towards your homeserver using the public_baseurl above.
  2. +
  3. Click the Single Sign-On button.
  4. +
  5. On the samling page, enter a Name Identifier and add a SAML Attribute for uid=your_localpart. +The response must also be signed.
  6. +
  7. Click "Next".
  8. +
  9. Click "Post Response" (change nothing).
  10. +
  11. You should be logged in.
  12. +
+

If you try and repeat this process, you may be automatically logged in using the information you +gave previously. To fix this, open your developer console (F12 or Ctrl+Shift+I) while on the +samling page and clear the site data. In Chrome, this will be a button on the Application tab.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/v1.53/development/url_previews.html b/v1.53/development/url_previews.html new file mode 100644 index 0000000000..e225fca096 --- /dev/null +++ b/v1.53/development/url_previews.html @@ -0,0 +1,339 @@ + + + + + + URL Previews - Synapse + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + +
+
+ +
+ +
+ +

URL Previews

+

The GET /_matrix/media/r0/preview_url endpoint provides a generic preview API +for URLs which outputs Open Graph responses (with some Matrix +specific additions).

+

This does have trade-offs compared to other designs:

+
    +
  • Pros: +
      +
    • Simple and flexible; can be used by any clients at any point
    • +
    +
  • +
  • Cons: +
      +
    • If each homeserver provides one of these independently, all the HSes in a +room may needlessly DoS the target URI
    • +
    • The URL metadata must be stored somewhere, rather than just using Matrix +itself to store the media.
    • +
    • Matrix cannot be used to distribute the metadata between homeservers.
    • +
    +
  • +
+

When Synapse is asked to preview a URL it does the following:

+
    +
  1. Checks against a URL blacklist (defined as url_preview_url_blacklist in the +config).
  2. +
  3. Checks the in-memory cache by URLs and returns the result if it exists. (This +is also used to de-duplicate processing of multiple in-flight requests at once.)
  4. +
  5. Kicks off a background process to generate a preview: +
      +
    1. Checks the database cache by URL and timestamp and returns the result if it +has not expired and was successful (a 2xx return code).
    2. +
    3. Checks if the URL matches an oEmbed pattern. If it +does, update the URL to download.
    4. +
    5. Downloads the URL and stores it into a file via the media storage provider +and saves the local media metadata.
    6. +
    7. If the media is an image: +
        +
      1. Generates thumbnails.
      2. +
      3. Generates an Open Graph response based on image properties.
      4. +
      +
    8. +
    9. If the media is HTML: +
        +
      1. Decodes the HTML via the stored file.
      2. +
      3. Generates an Open Graph response from the HTML.
      4. +
      5. If a JSON oEmbed URL was found in the HTML via autodiscovery: +
          +
        1. Downloads the URL and stores it into a file via the media storage provider +and saves the local media metadata.
        2. +
        3. Convert the oEmbed response to an Open Graph response.
        4. +
        5. Override any Open Graph data from the HTML with data from oEmbed.
        6. +
        +
      6. +
      7. If an image exists in the Open Graph response: +
          +
        1. Downloads the URL and stores it into a file via the media storage +provider and saves the local media metadata.
        2. +
        3. Generates thumbnails.
        4. +
        5. Updates the Open Graph response based on image properties.
        6. +
        +
      8. +
      +
    10. +
    11. If the media is JSON and an oEmbed URL was found: +
        +
      1. Convert the oEmbed response to an Open Graph response.
      2. +
      3. If a thumbnail or image is in the oEmbed response: +
          +
        1. Downloads the URL and stores it into a file via the media storage +provider and saves the local media metadata.
        2. +
        3. Generates thumbnails.
        4. +
        5. Updates the Open Graph response based on image properties.
        6. +
        +
      4. +
      +
    12. +
    13. Stores the result in the database cache.
    14. +
    +
  6. +
  7. Returns the result.
  8. +
+

The in-memory cache expires after 1 hour.

+

Expired entries in the database cache (and their associated media files) are +deleted every 10 seconds. The default expiration time is 1 hour from download.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit 1.5.1