From 196bd48726d427d81ba400e6d735d0d7b6594aa7 Mon Sep 17 00:00:00 2001 From: Igor Artemenko Date: Wed, 7 Dec 2022 22:47:48 +0000 Subject: [PATCH 1/2] Add configuration option for client_max_size --- pantalaimon/config.py | 11 +++++++++++ pantalaimon/main.py | 3 +-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pantalaimon/config.py b/pantalaimon/config.py index 8ee51d2..f1634f3 100644 --- a/pantalaimon/config.py +++ b/pantalaimon/config.py @@ -40,6 +40,7 @@ class PanConfigParser(configparser.ConfigParser): "HistoryFetchDelay": "3000", "DebugEncryption": "False", "DropOldKeys": "False", + "ClientMaxSize": "104857600", }, converters={ "address": parse_address, @@ -124,6 +125,7 @@ class ServerConfig: requests in seconds. drop_old_keys (bool): Should Pantalaimon only keep the most recent decryption key around. + client_max_size (int): The maximum size of a request, in bytes. """ name = attr.ib(type=str) @@ -141,6 +143,7 @@ class ServerConfig: indexing_batch_size = attr.ib(type=int, default=100) history_fetch_delay = attr.ib(type=int, default=3) drop_old_keys = attr.ib(type=bool, default=False) + client_max_size = attr.ib(type=int, default=1024**2 * 100) @attr.s @@ -235,6 +238,13 @@ class PanConfig: listen_set.add(listen_tuple) drop_old_keys = section.getboolean("DropOldKeys") + client_max_size = section.getint("ClientMaxSize") + + if not 0 < client_max_size: + raise PanConfigError( + "The client max size must be a positive integer" + ) + server_conf = ServerConfig( section_name, homeserver, @@ -249,6 +259,7 @@ class PanConfig: indexing_batch_size, history_fetch_delay / 1000, drop_old_keys, + client_max_size, ) self.servers[section_name] = server_conf diff --git a/pantalaimon/main.py b/pantalaimon/main.py index 0ab42d6..b37c604 100644 --- a/pantalaimon/main.py +++ b/pantalaimon/main.py @@ -62,8 +62,7 @@ async def init(data_dir, server_conf, send_queue, recv_queue): client_store_class=store_class, ) - # 100 MB max POST size - app = web.Application(client_max_size=1024**2 * 100) + app = web.Application(client_max_size=server_conf.client_max_size) app.add_routes( [ From f3f27625970fb36c31eac14849df75fb9a81e346 Mon Sep 17 00:00:00 2001 From: Igor Artemenko Date: Thu, 8 Dec 2022 19:05:42 +0000 Subject: [PATCH 2/2] Update documentation --- docs/man/pantalaimon.5 | 2 ++ docs/man/pantalaimon.5.md | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/docs/man/pantalaimon.5 b/docs/man/pantalaimon.5 index 01fd2d1..6c00f64 100644 --- a/docs/man/pantalaimon.5 +++ b/docs/man/pantalaimon.5 @@ -56,6 +56,8 @@ This option configures if a proxy instance should only keep the latest version of a room key from a certain user around. This effectively means that only newly incoming messages will be decryptable, the proxy will be unable to decrypt the room history. Defaults to "No". +.It Cm ClientMaxSize +The maximum size of a request, in bytes. Defaults to "104857600". .It Cm SearchRequests This option configures if the proxy should make additional HTTP requests to the server when clients use the search API endpoint. Some data that is required to diff --git a/docs/man/pantalaimon.5.md b/docs/man/pantalaimon.5.md index 60be6f8..ed2696a 100644 --- a/docs/man/pantalaimon.5.md +++ b/docs/man/pantalaimon.5.md @@ -69,6 +69,10 @@ The following keys are optional in the proxy instance sections: > incoming messages will be decryptable, the proxy will be unable to decrypt the > room history. Defaults to "No". +**ClientMaxSize** + +> The maximum size of a request, in bytes. Defaults to "104857600". + Additional to the homeserver section a special section with the name **Default** can be used to configure the following values for all homeservers: