Abstract: | This specification provides a mechanism to atomically Compare-And-Publish items to a PubSub node. |
Author: | Florian Schmaus |
Copyright: | © 1999 – 2017 XMPP Standards Foundation. SEE LEGAL NOTICES. |
Status: | Experimental |
Type: | Standards Track |
Version: | 0.1 |
Last Updated: | 2017-11-29 |
WARNING: This Standards-Track document is Experimental. Publication as an XMPP Extension Protocol does not imply approval of this proposal by the XMPP Standards Foundation. Implementation of the protocol described herein is encouraged in exploratory implementations, but production systems are advised to carefully consider whether it is appropriate to deploy implementations of this protocol before it advances to a status of Draft.
1. Introduction
2. Discoverying Support
3. Compare-And-Publish PubSub Items
3.1. PubSub Item Compare-And-Publish Value (CAP-V)
3.2. PubSub publishing using Compare-And-Publish
3.3. Could not publish because newest item ID did not match
4. Rationale
5. Security Considerations
6. IANA Considerations
7. XMPP Registrar Considerations
8. XML Schema
9. Acknowledgements
Appendices
A: Document Information
B: Author Information
C: Legal Notices
D: Relation to XMPP
E: Discussion Venue
F: Requirements Conformance
G: Notes
H: Revision History
This specification provides a mechanism to atomically publish items to a PubSub node depending on the item ID of the node's latest item. This allows to prevent race conditions and avoids data loss in certain situations.
If an entity supports the Compared-And-Publish feature it MUST advertise the fact by returning a <feature/> with the 'var' attribute set to 'urn:xmpp:pubsub:cap:0' in response to a Service Discovery (XEP-0030) [1] query for information.
PubSub services supporting the Compare-And-Publish PubSub extension MUST include a Comapre-and-Publish value (CAP-V) for every item in every response. The CAP-V value MUST change if the content of the item changed and different item content under the same node MUST NOT yield the same CAP-V. A simple computation of the CAP-ID would be to hash the String representation of the item's content.
CAP-Vs are assoicated with PubSub node's items via the item ID. The maping information is placed by the PubSub service in a <cap-v-map/> extension element, qualified by the 'urn:xmpp:pubsub:cap:0' namespace, as child element of the <items/> element. The <cap-v-map/> element contains one or more <cap-v-map-entry/> elements, of which each MUST have a 'item-id' and a 'cap-value' attribute. The former contains the PubSub item ID value and the later contains the according CAP-V of the item.
<iq type='result' from='pubsub.shakespeare.lit' to='francisco@denmark.lit/barracks' id='items1'> <pubsub xmlns='http://jabber.org/protocol/pubsub'> <items node='princely_musings'> <item id='368866411b877c30064a5f62b917cffe'> <entry xmlns='http://www.w3.org/2005/Atom'> <title>The Uses of This World</title> <summary> O, that this too too solid flesh would melt Thaw and resolve itself into a dew! </summary> </entry> </item> <item id='3300659945416e274474e469a1f0154c'> <entry xmlns='http://www.w3.org/2005/Atom'> <title>Ghostly Encounters</title> <summary> O all you host of heaven! O earth! what else? And shall I couple hell? O, fie! Hold, hold, my heart; And you, my sinews, grow not instant old, But bear me stiffly up. Remember thee! </summary> </entry> </item> <item id='4e30f35051b7b8b42abe083742187228'> <entry xmlns='http://www.w3.org/2005/Atom'> <title>Alone</title> <summary> Now I am alone. O, what a rogue and peasant slave am I! </summary> </entry> </item> <cap-v-map xmlns='urn:xmpp:pubsub:cap:0'> <cap-value-map-entry item-id='368866411b877c30064a5f62b917cffe' cap-value='35a204c2-5d6c-43a2-8e0d-a235a627b04a'/> <cap-value-map-entry item-id='3300659945416e274474e469a1f0154c' cap-value='166b7c04-ed4d-4872-aa56-a58268da84e2'/> <cap-value-map-entry item-id='4e30f35051b7b8b42abe083742187228' cap-value='67f7f792-f2ee-4918-8894-36a3c4a6dd5f'/> </cap-v-map> </items> </pubsub> </iq>
In order to atomically compare-and-publish an item, a client sends a XEP-0060 <publish/> IQ with a 'pubsub#prev_item_cap_value' precondition publishing option, set to the value of the currently assumed CAP-V of the latest item of the node.
The PubSub service MUST only publish the item if the node's latest item CAP-V is equal to the CAP-V found in the 'pubsub#prev_item_cap_value' field.
<iq type='set' from='hamlet@denmark.lit/blogbot' to='pubsub.shakespeare.lit' id='pub1'> <pubsub xmlns='http://jabber.org/protocol/pubsub'> <publish node='princely_musings'> <item id='2'> <entry xmlns='https://example.org'> <title>Soliloquy</title> <summary> To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them? </summary> </entry> </item> </publish> <publish-options> <x xmlns='jabber:x:data' type='submit'> <field var='FORM_TYPE' type='hidden'> <value>http://jabber.org/protocol/pubsub#publish-options</value> </field> <field var='pubsub#prev_item_cap_value'> <value>1</value> </field> </x> </publish-options> </pubsub> </iq>
In case the Compare-And-Publish operation failed because the latest node id is not the same as given in the 'previd' attribute in the request, the server returns an <conflict/> error of type 'modify' which a pubsub-specific condition of <precondition-not-met/> and a <compare-and-publish-failed/> element qualifed by the 'urn:xmpp:pubsub:cap:0' namespace. The element MUST have a 'cap-id' attribute with the CAP-V of the lastest item.
<iq type='error' from='pubsub.shakespeare.lit' to='hamlet@denmark.lit/elsinore' id='retract1'> <error type='modify'> <conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> <precondition-not-met xmlns='http://jabber.org/protocol/pubsub#errors'/> <compare-and-publish-failed xmlns='urn:xmpp:pubsub:cap:0' cap-id='2'/> </error> </iq>
Unfortunately it was not possible to re-use the PubSub item ID for the "Atomically Compare-And-Publish" purpose. This is mostly due XEP-0060 § 12.8 stating that:
"If a publisher publishes an item and the ItemID matches that of an existing item, the pubsub service MUST overwrite the existing item and generate a new event notification."
Which means that the content of an item could change without its ID, rendering the item ID unusable for CAP.
Injecting a "cap"-namespaced attribute carrying the item's CAP-V into PubSub's <item/> would be a very elegant approach to assign CAP-Vs to PubSub items (and the favored one of the XEP's author). But the usage of namespaces attributes within XMPP is controversial. Therefore this XEP resorts to using the <cap-v-map/> approach for now.
This extension protocol does not add any further security considerations to the ones mentioned in XEP-0060 § 14..
This document requires no interaction with the Internet Assigned Numbers Authority (IANA).
This specification defines the following XML namespaces:
<var> <name>urn:xmpp:pubsub:cap:0</name> <desc>Indicates support for Compare-And-Publish</desc> <doc>XEP-XXXX</doc> </var>
This specification defines the following <publish-options/> fields:
<field var='pubsub#prev_item_cap_value' type='text-single' label='Precondition: The assumed value of the latest item' CAP-V of the node'/>
TODO: Add after the XEP leaves the 'experimental' state.
Thanks to Kim Alvefur and Dave Cridland for their feedback.
Series: XEP
Number: 0395
Publisher: XMPP Standards Foundation
Status:
Experimental
Type:
Standards Track
Version: 0.1
Last Updated: 2017-11-29
Approving Body: XMPP Council
Dependencies: XEP-0030, XEP-0060
Supersedes: None
Superseded By: None
Short Name: cap
Source Control:
HTML
This document in other formats:
XML
PDF
Email:
flo@geekplace.eu
JabberID:
flo@geekplace.eu
The Extensible Messaging and Presence Protocol (XMPP) is defined in the XMPP Core (RFC 6120) and XMPP IM (RFC 6121) specifications contributed by the XMPP Standards Foundation to the Internet Standards Process, which is managed by the Internet Engineering Task Force in accordance with RFC 2026. Any protocol defined in this document has been developed outside the Internet Standards Process and is to be understood as an extension to XMPP rather than as an evolution, development, or modification of XMPP itself.
The primary venue for discussion of XMPP Extension Protocols is the <standards@xmpp.org> discussion list.
Discussion on other xmpp.org discussion lists might also be appropriate; see <http://xmpp.org/about/discuss.shtml> for a complete list.
Errata can be sent to <editor@xmpp.org>.
The following requirements keywords as used in this document are to be interpreted as described in RFC 2119: "MUST", "SHALL", "REQUIRED"; "MUST NOT", "SHALL NOT"; "SHOULD", "RECOMMENDED"; "SHOULD NOT", "NOT RECOMMENDED"; "MAY", "OPTIONAL".
1. XEP-0030: Service Discovery <https://xmpp.org/extensions/xep-0030.html>.
Note: Older versions of this specification might be available at http://xmpp.org/extensions/attic/
Accepted by Council as Expremental XEP
(XEP Editor (jwi))Use a custom item value (CAP-V).
(fs)Use PubSub publish-options preconditions.
(fs)First draft.
(fs)END