jp: jp asyncio port:

/!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\

This patch implements the port of jp to asyncio, so it is now correctly using the bridge
asynchronously, and it can be used with bridges like `pb`. This also simplify the code,
notably for things which were previously implemented with many callbacks (like pagination
with RSM).

During the process, some behaviours have been modified/fixed, in jp and backends, check
diff for details.
This commit is contained in:
Goffi 2019-09-25 08:56:41 +02:00
commit 76aadbb3fb

View file

@ -113,9 +113,11 @@ class XEP_0166(object):
try:
del client.jingle_sessions[sid]
except KeyError:
log.debug("Jingle session id [{}] is unknown, nothing to delete".format(sid))
log.debug(
f"Jingle session id {sid!r} is unknown, nothing to delete "
f"[{client.profile}]")
else:
log.debug("Jingle session id [{}] deleted".format(sid))
log.debug(f"Jingle session id {sid!r} deleted [{client.profile}]")
## helpers methods to build stanzas ##
@ -146,7 +148,7 @@ class XEP_0166(object):
condition=error_condition
)
)
client.send(iq_elt)
return client.send(iq_elt)
def _terminateEb(self, failure_):
log.warning(_("Error while terminating session: {msg}").format(msg=failure_))
@ -188,23 +190,22 @@ class XEP_0166(object):
)
self._delSession(client, sid)
def _jingleErrorCb(self, fail, sid, request, client):
def _jingleErrorCb(self, failure_, session, request, client):
"""Called when something is going wrong while parsing jingle request
The error condition depend of the exceptions raised:
exceptions.DataError raise a bad-request condition
@param fail(failure.Failure): the exceptions raised
@param sid(unicode): jingle session id
@param session(dict): data of the session
@param request(domsih.Element): jingle request
@param client: %(doc_client)s
"""
log.warning("Error while processing jingle request")
if isinstance(fail, exceptions.DataError):
self.sendError(client, "bad-request", sid, request)
log.warning(f"Error while processing jingle request [{client.profile}]")
if isinstance(failure_, exceptions.DataError):
return self.sendError(client, "bad-request", session['id'], request)
else:
log.error("Unmanaged jingle exception")
self._delSession(client, sid)
raise fail
log.error(f"Unmanaged jingle exception: {failure_}")
return self.terminate(client, self.REASON_FAILED_APPLICATION, session)
## methods used by other plugins ##
@ -706,19 +707,10 @@ class XEP_0166(object):
"""
return elt
def _callPlugins(
self,
client,
action,
session,
app_method_name="jingleHandler",
transp_method_name="jingleHandler",
app_default_cb=None,
transp_default_cb=None,
delete=True,
elements=True,
force_element=None,
):
def _callPlugins(self, client, action, session, app_method_name="jingleHandler",
transp_method_name="jingleHandler", app_default_cb=None,
transp_default_cb=None, delete=True, elements=True,
force_element=None):
"""Call application and transport plugin methods for all contents
@param action(unicode): jingle action name
@ -819,7 +811,7 @@ class XEP_0166(object):
confirm_dlist = defer.gatherResults(confirm_defers)
confirm_dlist.addCallback(self._confirmationCb, session, jingle_elt, client)
confirm_dlist.addErrback(self._jingleErrorCb, session["id"], request, client)
confirm_dlist.addErrback(self._jingleErrorCb, session, request, client)
def _confirmationCb(self, confirm_results, session, jingle_elt, client):
"""Method called when confirmation from user has been received
@ -952,7 +944,7 @@ class XEP_0166(object):
negociate_defers = []
negociate_defers = self._callPlugins(client, XEP_0166.A_SESSION_ACCEPT, session)
negociate_dlist = defer.DeferredList(negociate_defers)
negociate_dlist = defer.gatherResults(negociate_defers)
# after negociations we start the transfer
negociate_dlist.addCallback(