From 4a0eb4d951361d77ef726bdee1df86ad328bdc5a Mon Sep 17 00:00:00 2001 From: anoadragon453 Date: Tue, 14 Sep 2021 10:02:07 +0000 Subject: deploy: 01c88a09cd6e90fa28c1282a56a08e481727ce20 --- v1.43/development/cas.html | 317 ++++++++++++ v1.43/development/contributing_guide.html | 568 +++++++++++++++++++++ v1.43/development/database_schema.html | 376 ++++++++++++++ v1.43/development/git.html | 376 ++++++++++++++ v1.43/development/img/git/branches.jpg | Bin 0 -> 72228 bytes v1.43/development/img/git/clean.png | Bin 0 -> 110840 bytes v1.43/development/img/git/squash.png | Bin 0 -> 29667 bytes .../development/internal_documentation/index.html | 264 ++++++++++ v1.43/development/room-dag-concepts.html | 306 +++++++++++ v1.43/development/saml.html | 294 +++++++++++ v1.43/development/url_previews.html | 320 ++++++++++++ 11 files changed, 2821 insertions(+) create mode 100644 v1.43/development/cas.html create mode 100644 v1.43/development/contributing_guide.html create mode 100644 v1.43/development/database_schema.html create mode 100644 v1.43/development/git.html create mode 100644 v1.43/development/img/git/branches.jpg create mode 100644 v1.43/development/img/git/clean.png create mode 100644 v1.43/development/img/git/squash.png create mode 100644 v1.43/development/internal_documentation/index.html create mode 100644 v1.43/development/room-dag-concepts.html create mode 100644 v1.43/development/saml.html create mode 100644 v1.43/development/url_previews.html (limited to 'v1.43/development') diff --git a/v1.43/development/cas.html b/v1.43/development/cas.html new file mode 100644 index 0000000000..940580dc80 --- /dev/null +++ b/v1.43/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.43/development/contributing_guide.html b/v1.43/development/contributing_guide.html new file mode 100644 index 0000000000..894a84b171 --- /dev/null +++ b/v1.43/development/contributing_guide.html @@ -0,0 +1,568 @@ + + + + + + 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?

+

The code of Synapse is written in Python 3. To do pretty much anything, you'll need a recent version of Python 3.

+

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

+

Under Unix (macOS, Linux, BSD, ...)

+

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 -e ".[all,lint,mypy,test]"
+pip install tox
+
+

This will install the developer dependencies for the project.

+

Under Windows

+

TBD

+

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.
  • +
+

They're pretty fast, don't hesitate!

+
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
+
+

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.43/development/database_schema.html b/v1.43/development/database_schema.html new file mode 100644 index 0000000000..9e58553b90 --- /dev/null +++ b/v1.43/development/database_schema.html @@ -0,0 +1,376 @@ + + + + + + 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.

+

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.43/development/git.html b/v1.43/development/git.html new file mode 100644 index 0000000000..f2438420e5 --- /dev/null +++ b/v1.43/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.43/development/img/git/branches.jpg b/v1.43/development/img/git/branches.jpg new file mode 100644 index 0000000000..715ecc8cd0 Binary files /dev/null and b/v1.43/development/img/git/branches.jpg differ diff --git a/v1.43/development/img/git/clean.png b/v1.43/development/img/git/clean.png new file mode 100644 index 0000000000..3accd7ccef Binary files /dev/null and b/v1.43/development/img/git/clean.png differ diff --git a/v1.43/development/img/git/squash.png b/v1.43/development/img/git/squash.png new file mode 100644 index 0000000000..234caca3e4 Binary files /dev/null and b/v1.43/development/img/git/squash.png differ diff --git a/v1.43/development/internal_documentation/index.html b/v1.43/development/internal_documentation/index.html new file mode 100644 index 0000000000..bbd12e4cc4 --- /dev/null +++ b/v1.43/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.43/development/room-dag-concepts.html b/v1.43/development/room-dag-concepts.html new file mode 100644 index 0000000000..c389127ac6 --- /dev/null +++ b/v1.43/development/room-dag-concepts.html @@ -0,0 +1,306 @@ + + + + + + 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.

+

Backwards extremity

+

The current marker of where we have backfilled up to and will generally be the +oldest-in-time events we know of in the DAG.

+

This is an event where we haven't fetched all of the prev_events for.

+

Once we have fetched all of its prev_events, it's unmarked as a backwards +extremity (although we may have formed new backwards extremities from the prev +events during the backfilling process).

+

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. The status of whether we have all of +the prev_events is marked as a backwards extremity.

+

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.43/development/saml.html b/v1.43/development/saml.html new file mode 100644 index 0000000000..49686449c4 --- /dev/null +++ b/v1.43/development/saml.html @@ -0,0 +1,294 @@ + + + + + + SAML - Synapse + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + +
+
+ +
+ +
+ +

How to test SAML as a developer without a server

+

https://capriza.github.io/samling/samling.html (https://github.com/capriza/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 Riot) 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 Riot:

+
    +
  1. Visit the login page with a Riot pointing at your homeserver.
  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.43/development/url_previews.html b/v1.43/development/url_previews.html new file mode 100644 index 0000000000..7189a53575 --- /dev/null +++ b/v1.43/development/url_previews.html @@ -0,0 +1,320 @@ + + + + + + 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, fetch the oEmbed +response. If this is an image, replace the URL to fetch and continue. If +if it is HTML content, use the HTML as the document and continue.
    4. +
    5. If it doesn't match an oEmbed pattern, 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 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. +
        +
      6. +
      +
    10. +
    11. Stores the result in the database cache.
    12. +
    +
  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