mirror of https://github.com/Syncplay/syncplay
Ensure client support for Twisted >=16.4.0
This commit is contained in:
parent
f8ea2381a6
commit
d3a3635736
|
@ -12,10 +12,10 @@ import time
|
|||
from copy import deepcopy
|
||||
from functools import wraps
|
||||
|
||||
from twisted.application.internet import ClientService
|
||||
from twisted.internet.endpoints import HostnameEndpoint
|
||||
from twisted.internet.protocol import ClientFactory
|
||||
from twisted.internet import reactor, task, defer, threads
|
||||
from twisted.application.internet import ClientService
|
||||
|
||||
try:
|
||||
import certifi
|
||||
|
@ -752,7 +752,10 @@ class SyncplayClient(object):
|
|||
return(0.1 * (2 ** min(retries, 5)))
|
||||
|
||||
self._reconnectingService = ClientService(self._endpoint, self.protocolFactory, retryPolicy=retry)
|
||||
try:
|
||||
waitForConnection = self._reconnectingService.whenConnected(failAfterFailures=1)
|
||||
except TypeError:
|
||||
waitForConnection = self._reconnectingService.whenConnected()
|
||||
self._reconnectingService.startService()
|
||||
|
||||
def connectedNow(f):
|
||||
|
|
|
@ -4,8 +4,10 @@ import time
|
|||
from datetime import datetime
|
||||
from functools import wraps
|
||||
|
||||
from twisted.protocols.basic import LineReceiver
|
||||
from twisted import version as twistedVersion
|
||||
from twisted.internet.interfaces import IHandshakeListener
|
||||
from twisted.protocols.basic import LineReceiver
|
||||
from twisted.python.versions import Version
|
||||
from zope.interface.declarations import implementer
|
||||
|
||||
import syncplay
|
||||
|
@ -335,10 +337,23 @@ class SyncClientProtocol(JSONCommandProtocol):
|
|||
answer = message["startTLS"] if "startTLS" in message else None
|
||||
if "true" in answer and not self.logged and self._client.protocolFactory.options is not None:
|
||||
self.transport.startTLS(self._client.protocolFactory.options)
|
||||
# To be deleted when the support for Twisted between >=16.4.0 and < 17.1.0 is dropped
|
||||
minTwistedVersion = Version('twisted', 17, 1, 0)
|
||||
if twistedVersion < minTwistedVersion:
|
||||
self._client.protocolFactory.options._ctx.set_info_callback(self.customHandshakeCallback)
|
||||
elif "false" in answer:
|
||||
self._client.ui.showErrorMessage(getMessage("startTLS-not-supported-server"))
|
||||
self.sendHello()
|
||||
|
||||
def customHandshakeCallback(self, conn, where, ret):
|
||||
# To be deleted when the support for Twisted between >=16.4.0 and < 17.1.0 is dropped
|
||||
from OpenSSL.SSL import SSL_CB_HANDSHAKE_START, SSL_CB_HANDSHAKE_DONE
|
||||
if where == SSL_CB_HANDSHAKE_START:
|
||||
self._client.ui.showDebugMessage("TLS handshake started")
|
||||
if where == SSL_CB_HANDSHAKE_DONE:
|
||||
self._client.ui.showDebugMessage("TLS handshake done")
|
||||
self.handshakeCompleted()
|
||||
|
||||
def handshakeCompleted(self):
|
||||
self._serverCertificateTLS = self.transport.getPeerCertificate()
|
||||
self._subjectTLS = self._serverCertificateTLS.get_subject().CN
|
||||
|
|
Loading…
Reference in New Issue