Commit 33892c55 authored by Marc Schink's avatar Marc Schink
Browse files

protocol: Create the features future internally

parent 694cf2b9
Pipeline #6 failed with stages
in 0 seconds
......@@ -177,11 +177,9 @@ class STARTTLSConnector(BaseConnector):
:attr:`~.XMLStream.deadtime_hard_limit` on the returned XML stream.
"""
features_future = asyncio.Future(loop=loop)
stream = protocol.XMLStream(
to=domain,
features_future=features_future,
loop=loop,
base_logger=base_logger,
)
if base_logger is not None:
......@@ -207,13 +205,13 @@ class STARTTLSConnector(BaseConnector):
stream.deadtime_hard_limit = timedelta(seconds=negotiation_timeout)
features = await features_future
features = await stream.features_future()
try:
features[nonza.StartTLSFeature]
except KeyError:
if not metadata.tls_required:
return transport, stream, await features_future
return transport, stream, await stream.features_future()
logger.debug(
"attempting STARTTLS despite not announced since it is"
" required")
......@@ -247,7 +245,7 @@ class STARTTLSConnector(BaseConnector):
)
raise errors.TLSUnavailable(message)
return transport, stream, await features_future
return transport, stream, await stream.features_future()
verifier = metadata.certificate_verifier_factory()
await verifier.pre_handshake(
......@@ -335,11 +333,9 @@ class XMPPOverTLSConnector(BaseConnector):
:attr:`~.XMLStream.deadtime_hard_limit` on the returned XML stream.
"""
features_future = asyncio.Future(loop=loop)
stream = protocol.XMLStream(
to=domain,
features_future=features_future,
loop=loop,
base_logger=base_logger,
)
......@@ -379,4 +375,4 @@ class XMPPOverTLSConnector(BaseConnector):
stream.deadtime_hard_limit = timedelta(seconds=negotiation_timeout)
return transport, stream, await features_future
return transport, stream, await stream.features_future()
......@@ -310,9 +310,9 @@ class XMLStream(asyncio.Protocol):
self._sorted_attributes = sorted_attributes
self._logger = base_logger.getChild("XMLStream")
self._transport = None
self._features_future = features_future
self._exception = None
self._loop = loop or asyncio.get_event_loop()
self._features_future = asyncio.Future(loop=self._loop)
self._error_futures = []
self._smachine = statemachine.OrderedStateMachine(State.READY)
self._transport_closing = False
......@@ -718,6 +718,14 @@ class XMLStream(asyncio.Protocol):
await self._transport.starttls(ssl_context, post_handshake_callback)
self._reset_state()
def features_future(self):
"""
Return a future which will receive the next XML stream feature.
It is safe to cancel the future at any time.
"""
return self._features_future
def error_future(self):
"""
Return a future which will receive the next XML stream error as
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment