From 196bd48726d427d81ba400e6d735d0d7b6594aa7 Mon Sep 17 00:00:00 2001 From: Igor Artemenko Date: Wed, 7 Dec 2022 22:47:48 +0000 Subject: [PATCH] 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( [