From b68f36056dab9f7cd8f6b9fcda4db445df1b5ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=A4fer?= Date: Mon, 5 Aug 2019 18:23:41 +0200 Subject: XEP-0410: implement server-side optimisation for self-pings This prevents the ping from round-tripping through IRC and possibly a random other client of the user. Please see XEP-0410 for the rationale. Fixes #3385. --- src/bridge/bridge.cpp | 17 +++++++++++++++++ src/xmpp/biboumi_component.cpp | 2 +- src/xmpp/xmpp_component.hpp | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 65a345e..f065930 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -747,6 +747,23 @@ void Bridge::send_irc_participant_ping_request(const Iid& iid, const std::string "", true); return; } + if (chan->get_self()->nick == nick) + { + // XEP-0410 self-ping optimisation: always reply without going the full + // round-trip through IRC and possibly another XMPP client. See the XEP + // for details. + Jid iq_from(from_jid); + iq_from.local = std::to_string(iid); + iq_from.resource = nick; + + Stanza iq("iq"); + iq["from"] = iq_from.full(); + iq["to"] = to_jid; + iq["id"] = iq_id; + iq["type"] = "result"; + this->xmpp.send_stanza(iq); + return; + } if (chan->get_self()->nick != nick && !chan->find_user(nick)) { this->xmpp.send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "item-not-found", diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 4ed47cf..700e1e7 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -997,7 +997,7 @@ void BiboumiComponent::send_irc_channel_disco_info(const std::string& id, const identity["category"] = "conference"; identity["type"] = "irc"; identity["name"] = ""s + iid.get_local() + " on " + iid.get_server(); - for (const char *ns: {DISCO_INFO_NS, MUC_NS, ADHOC_NS, PING_NS, MAM_NS, VERSION_NS, STABLE_MUC_ID_NS}) + for (const char *ns: {DISCO_INFO_NS, MUC_NS, ADHOC_NS, PING_NS, MAM_NS, VERSION_NS, STABLE_MUC_ID_NS, SELF_PING_FLAG}) { XmlSubNode feature(query, "feature"); feature["var"] = ns; diff --git a/src/xmpp/xmpp_component.hpp b/src/xmpp/xmpp_component.hpp index e18da40..156e286 100644 --- a/src/xmpp/xmpp_component.hpp +++ b/src/xmpp/xmpp_component.hpp @@ -38,6 +38,7 @@ #define MUC_TRAFFIC_NS "http://jabber.org/protocol/muc#traffic" #define STABLE_ID_NS "urn:xmpp:sid:0" #define STABLE_MUC_ID_NS "http://jabber.org/protocol/muc#stable_id" +#define SELF_PING_FLAG MUC_NS"#self-ping-optimization" /** * An XMPP component, communicating with an XMPP server using the protocole -- cgit v1.2.3