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 copy import deepcopy
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
|
from twisted.application.internet import ClientService
|
||||||
from twisted.internet.endpoints import HostnameEndpoint
|
from twisted.internet.endpoints import HostnameEndpoint
|
||||||
from twisted.internet.protocol import ClientFactory
|
from twisted.internet.protocol import ClientFactory
|
||||||
from twisted.internet import reactor, task, defer, threads
|
from twisted.internet import reactor, task, defer, threads
|
||||||
from twisted.application.internet import ClientService
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import certifi
|
import certifi
|
||||||
@ -752,7 +752,10 @@ class SyncplayClient(object):
|
|||||||
return(0.1 * (2 ** min(retries, 5)))
|
return(0.1 * (2 ** min(retries, 5)))
|
||||||
|
|
||||||
self._reconnectingService = ClientService(self._endpoint, self.protocolFactory, retryPolicy=retry)
|
self._reconnectingService = ClientService(self._endpoint, self.protocolFactory, retryPolicy=retry)
|
||||||
waitForConnection = self._reconnectingService.whenConnected(failAfterFailures=1)
|
try:
|
||||||
|
waitForConnection = self._reconnectingService.whenConnected(failAfterFailures=1)
|
||||||
|
except TypeError:
|
||||||
|
waitForConnection = self._reconnectingService.whenConnected()
|
||||||
self._reconnectingService.startService()
|
self._reconnectingService.startService()
|
||||||
|
|
||||||
def connectedNow(f):
|
def connectedNow(f):
|
||||||
|
|||||||
@ -4,8 +4,10 @@ import time
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from twisted.protocols.basic import LineReceiver
|
from twisted import version as twistedVersion
|
||||||
from twisted.internet.interfaces import IHandshakeListener
|
from twisted.internet.interfaces import IHandshakeListener
|
||||||
|
from twisted.protocols.basic import LineReceiver
|
||||||
|
from twisted.python.versions import Version
|
||||||
from zope.interface.declarations import implementer
|
from zope.interface.declarations import implementer
|
||||||
|
|
||||||
import syncplay
|
import syncplay
|
||||||
@ -335,10 +337,23 @@ class SyncClientProtocol(JSONCommandProtocol):
|
|||||||
answer = message["startTLS"] if "startTLS" in message else None
|
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:
|
if "true" in answer and not self.logged and self._client.protocolFactory.options is not None:
|
||||||
self.transport.startTLS(self._client.protocolFactory.options)
|
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:
|
elif "false" in answer:
|
||||||
self._client.ui.showErrorMessage(getMessage("startTLS-not-supported-server"))
|
self._client.ui.showErrorMessage(getMessage("startTLS-not-supported-server"))
|
||||||
self.sendHello()
|
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):
|
def handshakeCompleted(self):
|
||||||
self._serverCertificateTLS = self.transport.getPeerCertificate()
|
self._serverCertificateTLS = self.transport.getPeerCertificate()
|
||||||
self._subjectTLS = self._serverCertificateTLS.get_subject().CN
|
self._subjectTLS = self._serverCertificateTLS.get_subject().CN
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user