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 configurable connection limit #64

Merged
merged 1 commit into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 5 additions & 3 deletions mautrix/appservice/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ def __init__(self, server: str, domain: str, as_token: str, hs_token: str, bot_l
real_user_content_key: Optional[str] = "net.maunium.appservice.puppet",
state_store: ASStateStore = None, aiohttp_params: Dict = None,
ephemeral_events: bool = False, default_ua: str = HTTPAPI.default_ua,
default_http_retry_count: int = 0) -> None:
default_http_retry_count: int = 0, connection_limit: int = None) -> None:
sumnerevans marked this conversation as resolved.
Show resolved Hide resolved
super().__init__(ephemeral_events=ephemeral_events)
self.server = server
self.domain = domain
self.id = id
self.verify_ssl = verify_ssl
self.tls_cert = tls_cert
self.tls_key = tls_key
self.connection_limit = connection_limit or 100
sumnerevans marked this conversation as resolved.
Show resolved Hide resolved
self.as_token = as_token
self.hs_token = hs_token
self.bot_mxid = UserID(f"@{bot_localpart}:{domain}")
Expand Down Expand Up @@ -126,10 +127,11 @@ async def __aexit__(self) -> None:

async def start(self, host: str = "127.0.0.1", port: int = 8080) -> None:
await self.state_store.open()
connector = None
self.log.debug(f"Starting appservice web server on {host}:{port}")
if self.server.startswith("https://") and not self.verify_ssl:
connector = aiohttp.TCPConnector(verify_ssl=False)
connector = aiohttp.TCPConnector(limit=self.connection_limit, verify_ssl=False)
else:
connector = aiohttp.TCPConnector(limit=self.connection_limit)
default_headers = {"User-Agent": self.default_ua}
self._http_session = aiohttp.ClientSession(loop=self.loop, connector=connector,
headers=default_headers)
Expand Down
1 change: 1 addition & 0 deletions mautrix/bridge/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def prepare_appservice(self) -> None:
self.az = AppService(server=self.config["homeserver.address"],
domain=self.config["homeserver.domain"],
verify_ssl=self.config["homeserver.verify_ssl"],
connection_limit=self.config["homeserver.connection_limit"],

id=self.config["appservice.id"],
as_token=self.config["appservice.as_token"],
Expand Down
1 change: 1 addition & 0 deletions mautrix/bridge/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def do_update(self, helper: ConfigUpdateHelper) -> None:
copy("homeserver.domain")
copy("homeserver.verify_ssl")
copy("homeserver.http_retry_count")
copy("homeserver.connection_limit")
copy("homeserver.status_endpoint")
copy("homeserver.message_send_checkpoint_endpoint")

Expand Down