Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Asynchronous Uploads (#15503)
Browse files Browse the repository at this point in the history
Support asynchronous uploads as defined in MSC2246.
  • Loading branch information
sumnerevans authored Nov 15, 2023
1 parent 80922dc commit 999bd77
Show file tree
Hide file tree
Showing 14 changed files with 568 additions and 59 deletions.
1 change: 1 addition & 0 deletions changelog.d/15503.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for asynchronous uploads as defined by [MSC2246](https://github.com/matrix-org/matrix-spec-proposals/pull/2246). Contributed by @sumnerevans at @beeper.
34 changes: 34 additions & 0 deletions docs/usage/configuration/config_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,19 @@ rc_third_party_invite:
burst_count: 10
```
---
### `rc_media_create`

This option ratelimits creation of MXC URIs via the `/_matrix/media/v1/create`
endpoint based on the account that's creating the media. Defaults to
`per_second: 10`, `burst_count: 50`.

Example configuration:
```yaml
rc_media_create:
per_second: 10
burst_count: 50
```
---
### `rc_federation`

Defines limits on federation requests.
Expand Down Expand Up @@ -1814,6 +1827,27 @@ Example configuration:
media_store_path: "DATADIR/media_store"
```
---
### `max_pending_media_uploads`

How many *pending media uploads* can a given user have? A pending media upload
is a created MXC URI that (a) is not expired (the `unused_expires_at` timestamp
has not passed) and (b) the media has not yet been uploaded for. Defaults to 5.

Example configuration:
```yaml
max_pending_media_uploads: 5
```
---
### `unused_expiration_time`

How long to wait in milliseconds before expiring created media IDs. Defaults to
"24h"

Example configuration:
```yaml
unused_expiration_time: "1h"
```
---
### `media_storage_providers`

Media storage providers allow media to be stored in different
Expand Down
2 changes: 2 additions & 0 deletions synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class Codes(str, Enum):
USER_DEACTIVATED = "M_USER_DEACTIVATED"
# USER_LOCKED = "M_USER_LOCKED"
USER_LOCKED = "ORG_MATRIX_MSC3939_USER_LOCKED"
NOT_YET_UPLOADED = "M_NOT_YET_UPLOADED"
CANNOT_OVERWRITE_MEDIA = "M_CANNOT_OVERWRITE_MEDIA"

# Part of MSC3848
# https://github.com/matrix-org/matrix-spec-proposals/pull/3848
Expand Down
7 changes: 7 additions & 0 deletions synapse/config/ratelimiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,10 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
"rc_third_party_invite",
defaults={"per_second": 0.0025, "burst_count": 5},
)

# Ratelimit create media requests:
self.rc_media_create = RatelimitSettings.parse(
config,
"rc_media_create",
defaults={"per_second": 10, "burst_count": 50},
)
6 changes: 6 additions & 0 deletions synapse/config/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
"prevent_media_downloads_from", []
)

self.unused_expiration_time = self.parse_duration(
config.get("unused_expiration_time", "24h")
)

self.max_pending_media_uploads = config.get("max_pending_media_uploads", 5)

self.media_store_path = self.ensure_directory(
config.get("media_store_path", "media_store")
)
Expand Down
6 changes: 6 additions & 0 deletions synapse/media/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@
"audio/x-flac",
]

# Default timeout_ms for download and thumbnail requests
DEFAULT_MAX_TIMEOUT_MS = 20_000

# Maximum allowed timeout_ms for download and thumbnail requests
MAXIMUM_ALLOWED_MAX_TIMEOUT_MS = 60_000


def respond_404(request: SynapseRequest) -> None:
assert request.path is not None
Expand Down
Loading

0 comments on commit 999bd77

Please sign in to comment.