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

Commit

Permalink
Try and make TLS federation client code faster (#4674)
Browse files Browse the repository at this point in the history
* fix to use makeContext so that we don't need to rebuild the certificateoptions each time
  • Loading branch information
richvdh authored Feb 19, 2019
2 parents 968a30a + 107aeb6 commit 7c70b8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.d/4674.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reduce the overhead of creating outbound federation connections over TLS by caching the TLS client options.
14 changes: 6 additions & 8 deletions synapse/crypto/context_factory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2019 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -11,6 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging

from zope.interface import implementer
Expand Down Expand Up @@ -105,9 +107,7 @@ def __init__(self, hostname, ctx):
self._hostnameBytes = _idnaBytes(hostname)
self._sendSNI = True

ctx.set_info_callback(
_tolerateErrors(self._identityVerifyingInfoCallback)
)
ctx.set_info_callback(_tolerateErrors(self._identityVerifyingInfoCallback))

def clientConnectionForTLS(self, tlsProtocol):
context = self._ctx
Expand All @@ -128,10 +128,8 @@ class ClientTLSOptionsFactory(object):

def __init__(self, config):
# We don't use config options yet
pass
self._options = CertificateOptions(verify=False)

def get_options(self, host):
return ClientTLSOptions(
host,
CertificateOptions(verify=False).getContext()
)
# Use _makeContext so that we get a fresh OpenSSL CTX each time.
return ClientTLSOptions(host, self._options._makeContext())

0 comments on commit 7c70b8f

Please sign in to comment.