Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sliding Sync /sync endpoint (initial implementation) #17187

Merged
merged 123 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
f9e6e53
Configurable /sync/e2ee endpoint
MadLittleMods May 6, 2024
1e05a05
Add Sliding Sync `/sync/e2ee` endpoint for To-Device messages
MadLittleMods May 7, 2024
5e925f6
Share tests with test_sendtodevice
MadLittleMods May 8, 2024
69f9143
Comment on tests
MadLittleMods May 8, 2024
d4ff933
Prefer Sync v2 vs Sliding Sync distinction
MadLittleMods May 8, 2024
371ec57
Fix wait_for_sync_for_user in tests
MadLittleMods May 8, 2024
06d12e5
Ugly overloads
MadLittleMods May 8, 2024
b8b70ba
Fix lint
MadLittleMods May 8, 2024
c60a4f8
Add changelog
MadLittleMods May 8, 2024
10ffae6
Shared logic for `get_sync_result_builder()`
MadLittleMods May 8, 2024
6bf4896
Try calculate more
MadLittleMods May 9, 2024
8871dac
Share tests using inheritance
MadLittleMods May 9, 2024
0892283
Add comments docs
MadLittleMods May 9, 2024
adb7e20
Consolidate device_lists /sync tests
MadLittleMods May 9, 2024
f098355
Add `device_one_time_keys_count` tests
MadLittleMods May 9, 2024
6b7cfd7
Add tests for `device_unused_fallback_key_types` in `/sync`
MadLittleMods May 9, 2024
b9e5379
Describe test
MadLittleMods May 9, 2024
f9c9d44
Add stub Sliding Sync endpoint
MadLittleMods May 13, 2024
654e8f6
Add Pydantic model for the Sliding Sync API
MadLittleMods May 13, 2024
aee594a
Can't use StringConstraints
MadLittleMods May 14, 2024
2863fba
More optional
MadLittleMods May 15, 2024
2dd0cde
Fill out more options
MadLittleMods May 15, 2024
c8256b6
Start to map out response
MadLittleMods May 15, 2024
ee6baba
Iterating
MadLittleMods May 15, 2024
f3db068
Copy body to config
MadLittleMods May 15, 2024
9bdfa16
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-e2ee
MadLittleMods May 16, 2024
7331401
Lint
MadLittleMods May 16, 2024
b23abca
Fix test inheritance
MadLittleMods May 16, 2024
821a1b3
Add missing field to docstring
MadLittleMods May 16, 2024
35ca937
Format docstring
MadLittleMods May 16, 2024
4ad7a8b
No need to change this formatting from develop
MadLittleMods May 16, 2024
3092ab5
Calculate room derived membership info for device_lists
MadLittleMods May 20, 2024
3539abe
Membership in timeline for better derived info
MadLittleMods May 20, 2024
5f194f9
Exclude application services
MadLittleMods May 20, 2024
02cecfa
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-e2ee
MadLittleMods May 20, 2024
bfa8c63
Merge branch 'madlittlemods/msc3575-sliding-sync-e2ee' into madlittle…
MadLittleMods May 20, 2024
07d84ab
Start of gathering room list to display in sync
MadLittleMods May 20, 2024
6dadfe9
Try handle no from_token or to_token already newer
MadLittleMods May 20, 2024
9ffafe7
Try to think about this logic
MadLittleMods May 21, 2024
f6122ff
Use `client_patterns()` for endpoint URL
MadLittleMods May 21, 2024
2f112e7
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-e2ee
MadLittleMods May 21, 2024
c2221bb
Lint
MadLittleMods May 21, 2024
717b160
Adjust wording, add todo
MadLittleMods May 21, 2024
c826550
Add some tests
MadLittleMods May 21, 2024
fe48188
Handle more edge cases
MadLittleMods May 21, 2024
fd355f6
WIP
MadLittleMods May 21, 2024
dd9356a
Using unsigned prev_content
MadLittleMods May 21, 2024
17783c3
Log why no unsigned
MadLittleMods May 22, 2024
343de8f
Remove debug logs
MadLittleMods May 22, 2024
1b3a5bf
Fix referencing variable from other lexical scope
MadLittleMods May 22, 2024
c82a084
Update comments and test docstrings
MadLittleMods May 22, 2024
514aba5
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-e2ee
MadLittleMods May 22, 2024
9749795
Update filter to be more precise and avoid more work
MadLittleMods May 22, 2024
06ac1da
Restore copyright header
MadLittleMods May 22, 2024
3da6bc1
Use `@parameterized_class`
MadLittleMods May 22, 2024
d4b41aa
Fix lints
MadLittleMods May 22, 2024
89db566
Merge branch 'madlittlemods/msc3575-sliding-sync-e2ee' into madlittle…
MadLittleMods May 22, 2024
c7b8743
Add changelog
MadLittleMods May 22, 2024
a7c6476
Use `client_patterns()`
MadLittleMods May 22, 2024
13d6146
Fill out sliding window response types
MadLittleMods May 22, 2024
c7f7ae4
Start assembling lists
MadLittleMods May 22, 2024
4c7d7e6
Encode response
MadLittleMods May 22, 2024
6606ac1
Add docstring for parametized attributes
MadLittleMods May 23, 2024
ab0b844
Add actual typing for params (not just docstrings)
MadLittleMods May 23, 2024
a482545
Fix test after removing type ignore
MadLittleMods May 23, 2024
04eeee6
Merge branch 'madlittlemods/msc3575-sliding-sync-e2ee' into madlittle…
MadLittleMods May 23, 2024
8c3de84
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-0.0.1
MadLittleMods May 23, 2024
37af87a
Add test to make sure we don't confuse multiple rooms
MadLittleMods May 23, 2024
a822a05
Revert as TODO says
MadLittleMods May 23, 2024
f9fa683
Fix another leaking loop variable
MadLittleMods May 23, 2024
d1bd02d
Add TODO to handle partial stated rooms
MadLittleMods May 23, 2024
b5b3e77
Fix Pydantic `conint`/`constr` usage with mypy
MadLittleMods May 23, 2024
65d9b79
Fix lints
MadLittleMods May 23, 2024
adc0e2f
Fix unserialize type
MadLittleMods May 23, 2024
b12fee5
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-0.0.1
MadLittleMods May 28, 2024
44e9a92
Fill in rest docstring
MadLittleMods May 28, 2024
b632cbb
Add better comments
MadLittleMods May 28, 2024
abf139a
Fill out docstring todo
MadLittleMods May 28, 2024
a28569f
Add understanding of this skip
MadLittleMods May 28, 2024
950fd70
Tweak comments
MadLittleMods May 28, 2024
8bf5a62
Add rest test
MadLittleMods May 29, 2024
34d67fd
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-0.0.1
MadLittleMods May 29, 2024
49998e0
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-0.0.1
MadLittleMods May 30, 2024
09609cb
WIP: TODO comments after pairing with Erik
MadLittleMods Jun 3, 2024
8f09313
Add instance name alongside stream_ordering (`RoomsForUser.event_pos`)
MadLittleMods Jun 3, 2024
803fbbe
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-0.0.1
MadLittleMods Jun 3, 2024
a0c042e
Re-arrange how this list will be returned
MadLittleMods Jun 3, 2024
271a196
Use fully-qualified `PersistedEventPosition` when returning membershi…
MadLittleMods Jun 3, 2024
4155e18
Fix circular imports when running specific tests
MadLittleMods Jun 3, 2024
939695d
Update usage
MadLittleMods Jun 3, 2024
73c20d9
Use method to get instance name in tests
MadLittleMods Jun 3, 2024
7b41f41
Fix random lints
MadLittleMods Jun 3, 2024
09638ac
Add changelog
MadLittleMods Jun 3, 2024
8dca8f5
Merge branch 'madlittlemods/rooms-for-user-event-pos' into madlittlem…
MadLittleMods Jun 3, 2024
9c6ec25
Create `membership_snapshot_token` with `instance_map`
MadLittleMods Jun 4, 2024
1268a54
Properly compare tokens and event positions
MadLittleMods Jun 4, 2024
e4c66b8
Avoid serializing response that will never be heard
MadLittleMods Jun 4, 2024
35db057
Add support for kicks
MadLittleMods Jun 4, 2024
3514aa0
Add licensing headers
MadLittleMods Jun 4, 2024
970a0c6
Adjust wording
MadLittleMods Jun 4, 2024
64df6fb
Revert change that should be separated and is failing
MadLittleMods Jun 4, 2024
8bb357a
Note the extras
MadLittleMods Jun 4, 2024
03dd87a
Add test for `notifier.wait_for_stream_token(from_token)`
MadLittleMods Jun 4, 2024
9e46b2a
Fix typo
MadLittleMods Jun 4, 2024
54dbc27
Add None defaults
MadLittleMods Jun 4, 2024
f6a5905
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-0.0.1
MadLittleMods Jun 4, 2024
07f57a4
Give a summary of what rooms we're looking for
MadLittleMods Jun 4, 2024
d3ce27b
Balance parenthesis
MadLittleMods Jun 4, 2024
dfee21a
Switch fixup order to fix edge case with newly_left rooms
MadLittleMods Jun 4, 2024
3ce0892
Add test with multiple event persisters that fails the previous `get_…
MadLittleMods Jun 5, 2024
2864837
Allow new `get_sync_room_ids_for_user` implementation to work with mu…
MadLittleMods Jun 5, 2024
2af467d
Remove extra for-loop
MadLittleMods Jun 5, 2024
7bbe2ed
More clear way to express what membership we want to display
MadLittleMods Jun 5, 2024
1fc1b58
Remove assert since we no longer need that information
MadLittleMods Jun 5, 2024
6a6cdc6
Use Set because Tuple doesn't allow - operations
MadLittleMods Jun 5, 2024
278ba63
No need to check from/to token relationship
MadLittleMods Jun 5, 2024
5678307
Add validation for membership
MadLittleMods Jun 5, 2024
703cdc9
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-0.0.1
MadLittleMods Jun 5, 2024
c7d1fc3
Fix separator label
MadLittleMods Jun 5, 2024
0f6646d
Add test for no `from_token`
MadLittleMods Jun 6, 2024
0153a6e
Add test for `from_token` after `to_token`
MadLittleMods Jun 6, 2024
6f10b97
Simplify boolean logic and avoid set construction
MadLittleMods Jun 6, 2024
c89f012
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-0.0.1
MadLittleMods Jun 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'develop' into madlittlemods/msc3575-sliding-sync-e2ee
Conflicts:
	synapse/handlers/sync.py
	tests/handlers/test_sync.py
  • Loading branch information
MadLittleMods committed May 16, 2024
commit 9bdfa16b3e8f04503cd7c1236ca33c12b11a7267
10 changes: 5 additions & 5 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -1921,18 +1921,18 @@ async def get_sync_result_builder(
"""
user_id = sync_config.user.to_string()

# Note: we get the users room list *before* we get the current token, this
# avoids checking back in history if rooms are joined after the token is fetched.
token_before_rooms = self.event_sources.get_current_token()
mutable_joined_room_ids = set(await self.store.get_rooms_for_user(user_id))

# NB: The `now_token` gets changed by some of the `generate_sync_*` methods,
# this is due to some of the underlying streams not supporting the ability
# to query up to a given point.
# Always use the `now_token` in `SyncResultBuilder`
now_token = self.event_sources.get_current_token()
log_kv({"now_token": now_token})

# Note: we get the users room list *before* we get the current token, this
# avoids checking back in history if rooms are joined after the token is fetched.
token_before_rooms = self.event_sources.get_current_token()
mutable_joined_room_ids = set(await self.store.get_rooms_for_user(user_id))

# Since we fetched the users room list before the token, there's a small window
# during which membership events may have been persisted, so we fetch these now
# and modify the joined room list for any changes between the get_rooms_for_user
Expand Down
44 changes: 39 additions & 5 deletions tests/handlers/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,21 @@ def test_wait_for_sync_for_user_auth_blocking(self) -> None:
self.get_success(self.store.upsert_monthly_active_user(user_id1))
self.get_success(
self.sync_handler.wait_for_sync_for_user(
requester, sync_config, SyncVersion.SYNC_V2, generate_request_key()
requester,
sync_config,
sync_version=SyncVersion.SYNC_V2,
request_key=generate_request_key(),
)
)

# Test that global lock works
self.auth_blocking._hs_disabled = True
e = self.get_failure(
self.sync_handler.wait_for_sync_for_user(
requester, sync_config, SyncVersion.SYNC_V2, generate_request_key()
requester,
sync_config,
sync_version=SyncVersion.SYNC_V2,
request_key=generate_request_key(),
),
ResourceLimitError,
)
Expand All @@ -103,7 +109,10 @@ def test_wait_for_sync_for_user_auth_blocking(self) -> None:

e = self.get_failure(
self.sync_handler.wait_for_sync_for_user(
requester, sync_config, SyncVersion.SYNC_V2, generate_request_key()
requester,
sync_config,
sync_version=SyncVersion.SYNC_V2,
request_key=generate_request_key(),
),
ResourceLimitError,
)
Expand Down Expand Up @@ -286,7 +295,7 @@ def test_ban_wins_race_with_join(self) -> None:
eve_sync_config,
sync_version=SyncVersion.SYNC_V2,
request_key=generate_request_key(),
),
)
)

# Sanity check this sync result. We shouldn't be joined to the room.
Expand Down Expand Up @@ -735,7 +744,7 @@ def test_archived_rooms_do_not_include_state_after_leave(
generate_sync_config(bob),
sync_version=SyncVersion.SYNC_V2,
request_key=generate_request_key(),
),
)
)

# Alice sends a message and a state
Expand Down Expand Up @@ -924,6 +933,31 @@ def test_push_rules_with_bad_account_data(self) -> None:
"""Some old accounts have managed to set a `m.push_rules` account data,
which we should ignore in /sync response.
"""
user = self.register_user("alice", "password")

# Insert the bad account data.
self.get_success(
self.store.add_account_data_for_user(user, AccountDataTypes.PUSH_RULES, {})
)

sync_result: SyncResult = self.get_success(
self.sync_handler.wait_for_sync_for_user(
create_requester(user),
generate_sync_config(user),
sync_version=SyncVersion.SYNC_V2,
request_key=generate_request_key(),
)
)

for account_dict in sync_result.account_data:
if account_dict["type"] == AccountDataTypes.PUSH_RULES:
# We should have lots of push rules here, rather than the bad
# empty data.
self.assertNotEqual(account_dict["content"], {})
return

self.fail("No push rules found")


def generate_sync_config(
user_id: str,
Expand Down
4 changes: 2 additions & 2 deletions tests/rest/client/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
from twisted.test.proto_helpers import MemoryReactor

from synapse.api.errors import NotFoundError
from synapse.rest import admin, devices, room, sync
from synapse.rest.client import account, keys, login, register
from synapse.rest import admin, devices, sync
from synapse.rest.client import keys, login, register
from synapse.server import HomeServer
from synapse.types import JsonDict, UserID, create_requester
from synapse.util import Clock
Expand Down
4 changes: 0 additions & 4 deletions tests/rest/client/test_sendtodevice.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from twisted.test.proto_helpers import MemoryReactor

from synapse.server import HomeServer
from synapse.types import JsonDict
from synapse.util import Clock

from tests.rest.client.test_sendtodevice_base import SendToDeviceTestCaseBase
from tests.unittest import HomeserverTestCase
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.