<p>&xep0060; defines an XMPP protocol extension for generic publish-subscribe features. However, it only allows notifications from nodes to which an entity is directly subscribed. It is useful in some circumstances to describe a relationship between nodes so that a publish on one node may be delivered via another node. For instance, if an entity is interested in notifications from a set of nodes the entity would discover each node somehow and then subscribe to them. With collection nodes, the entity would subscribe only to the collection which links the desired nodes, simplifying the subscription process.</p>
<p>In addition to simplifying the subscriber's usage, collection nodes also allow the owner to describe almost any type of relationship between nodes. Using various access models on different nodes the owner can also create almost any desired authorization semantics on a set of leaf nodes.</p>
<pclass='em'>Note: Any use cases not described herein are described in <cite>XEP-0060</cite>. Also, this document does not show error flows related to the generic publish-subscribe use cases referenced herein, since they are exhaustively defined in <cite>XEP-0060</cite>. The reader is referred to <cite>XEP-0060</cite> for all relevant protocol details related to the XMPP publish-subscribe extension.</p>
</section1>
<section1topic='Scope'anchor='scope'>
<p>This documents addresses the common requirements regarding configuration, publishing, subscribing, and notification semantics of collection nodes.</p>
</section1>
<section1topic='Glossary'anchor='glossary'>
<p>The following terms are used in this document to refer to collection node-specific features.</p>
<pclass='em'>Note: some of these terms are specified in greater detail within the body of this document.</p>
<dl>
<di>
<dt>Collection Node</dt>
<dd>A type of node that contains other nodes but no published items (<em>c.f.</em> Leaf Node).</dd>
<dd>How deep the collection node graph will be traversed when determining whether notifications will be sent. May be any integer, 0 or greater, or "all".</dd>
<p>Collection nodes link nodes together to unify notifications from a set of collection or leaf nodes. An entity can subscribe to the collection and receive notifications of any associated leaf nodes.</p>
<p>A collection node can link with any other node in order to create a directed acyclic graph (DAG). Collection nodes MUST NOT be linked in such a way as to produce a cyclic graph (<em>i.e.</em>, they cannot link to nodes that eventually link back to the initial node).</p>
<p>Collection nodes only contain other nodes and MUST NOT contain published items (therefore a collection MUST NOT support the "publish" feature or related features such as "persistent-items").</p>
</section2>
</section1>
<section1topic='Entity Use Cases'anchor='entity'>
<section2topic='Discovering Support for Collection Nodes'anchor='disco-support'>
<p>An entity might wish to discover if a service implements collection nodes; in order to do so, it sends a service discovery information ("disco#info") query to the component's JID using &xep0030;. If a service supports collection nodes it MUST return a "pubsub#collections" feature. In addition, if the service supports associating a node with more than one collection it MUST return a feature of "pubsub#multi-collections".</p>
<examplecaption='Entity requests features from a service'><![CDATA[
<p>The service discovery items ("disco#items") protocol enables an entity to query a service for a list of associated items, which, in the case of collection nodes would consist of the children associated with a given node.</p>
<section3topic='Generating Notifications for Collections'anchor='notify'>
<p>If a notification on a child node is created and then delivered via the collection then the notifications generated by the service MUST contain additional information. The 'node' attribute of the &ITEM; or <node/> element contained in the notification message MUST specify the node identifier of the node that generated the notification (not the collection) and the &MESSAGE; stanza MUST contain &xep0131; that specifies the node identifier of the collection.</p>
<pclass='em'>Note: The delivery options (such as "pubsub#deliver_payloads") are determined by the publishing leaf node, not by the collection node. If the owner of a collection node sets delivery options for a collection node, the service SHOULD ignore those options and apply the options set for the leaf node that publishes an item.</p>
<section4topic='Notifications about Items'anchor='notify-items'>
<p>Item notifications are notifications about the contents of a leaf node, and are generated by a publish, retract, or purge request.</p>
<examplecaption='Subscriber receives a publish notification from a collection'><![CDATA[
<section3topic='Node Association and Dissociation'anchor='notify-associate-dissociate'>
<p>If a collection node is configured to send notification of node associations and disassociations, the service shall send an event that contains a <collection/> element whose 'node' attribute specifies the NodeID of the collection; this element in turn contains an <associate/> or <dissociate/> element whose 'node' attribute specifies the NodeID of node that has been associated with the collection.</p>
<examplecaption='Notification of node association'><![CDATA[
<section1topic='Subscriber Use Cases'anchor='subscriber'>
<section2topic='Subscribe to a Collection Node'anchor='subscribe'>
<p>A service that implements collection nodes SHOULD allow entities to subscribe to collection nodes (subject to access models and local security policies).</p>
<p>In addition to the subscription configuration options already defined in <cite>XEP-0060</cite>, there are two subscription configuration options specific to collection nodes:</p>
<ul>
<li>
<p><strong>pubsub#subscription_type</strong></p>
<p>This subscription option enables the subscriber to subscribe either to notifications about items or notifications about nodes.</p>
<p>If the subscription type is "items", the subscriber shall be notified whenever any node contained in the collection has an item published to it, retracted from it, or the node is purged, as modified by the value of the "pubsub#subscription_depth" option.</p>
<p>If the subscription type is "nodes", the subscriber shall be notified whenever a new node is added to the collection, removed from the collection, or the configuration of a node within the collection has changed, as modified by the value of the "pubsub#subscription_depth" option.</p>
<p>If the subscription type is "all", the subscriber shall be notified about both "items" and "nodes" types of events, as modified by the value of the "pubsub#subscription_depth" option.</p>
<p>The default value of this subscription option SHOULD be "nodes".</p>
</li>
<li>
<p><strong>pubsub#subscription_depth</strong></p>
<p>This subscription option enables the subscriber to specify how far to traverse the node graph when determining whether a notification will be sent. It may be any integer value, 0 or greater, or the value "all" which means that any node within the collection will generate a notification.</p>
<p>The default value of this subscription option SHOULD be "1".</p>
</li>
</ul>
<p>In order to subscribe to a collection node, an entity MUST send a subscription request to the node; the subscription request MAY include subscription options, but this is not strictly necessary (especially if the entity does not wish to override the default settings for the "pubsub#subscription_type" and "pubsub#subscription_depth" options).</p>
<p>A service MAY allow an entity to subscribe to a collection node in two ways, once with a subscription of type "nodes" (to receive notification of any new nodes added to the collection or the entire tree) and once with a subscription of type "items" (to receive all items published within the tree). However, a service SHOULD NOT allow an entity to subscribe twice to a collection node (once with a subscription depth of "1" and once with a subscription depth of "all") for the same subscription type, since two such subscriptions are unnecessary (a depth of "all" includes by definition a depth of "1"); in this case the service SHOULD return a &conflict; error to the requesting entity.</p>
<examplecaption='Service does not allow mulitple subscriptions to the same node'><![CDATA[
<p>Depending on the nature of the node graph, a subscription type of "items" and depth of "all" may result in an extremely large number of notifications. Therefore, a service MAY disallow such a combination of subscription options, in which case it MUST return a ¬allowed; error to the requesting entity.</p>
<examplecaption='Service does not allow requested options'><![CDATA[
<section2topic='Retrieving Items on Collection Nodes'anchor='retrieve-items'>
<p>When an entity requests items on a collection node the service SHOULD return the items on any leaf nodes associated with it subject to the access model of the collection node.</p>
<p>Depending on the nature of the node graph it may be expensive to allow item retrieval from a collection node. Therefore the service MAY disallow item retrieval via collection nodes, in which case it MUST return a &feature; error to the requesting entity.</p>
<section2topic='Create a New Collection Node'anchor='createnode'>
<p>To create a new collection node, the requesting entity MUST include a Data Form containing a "pubsub#node_type" field whose <value/> element contains "collection". The default value for "pubsub#node_type" SHOULD be "leaf".</p>
<p>In addition to the errors already defined for leaf node creation, there are several reasons why the collection node creation request might fail:</p>
<ol>
<li>The service does not support collection nodes.</li>
<li>The service does not support creation of collection nodes.</li>
<li>The requesting entity does not have sufficient privileges to create collection nodes.</li>
</ol>
<p>These error cases are described more fully in the following sections.</p>
<p>If the service does not support collection nodes, it MUST respond with a &feature; error, specifying a pubsub-specific error condition of <unsupported/> and a feature of "collections".</p>
<examplecaption='Service does not support collection nodes'><![CDATA[
<p>In addition to the node configuration options specified in <cite>XEP-0060</cite>, there are three additional node configuration options that a service which supports collection nodes MUST supply.</p>
<ul>
<li><strong>pubsub#node_type</strong>
<p>Whether this is a "leaf" or "collection" node.</p></li>
<li><strong>pubsub#collection</strong>
<p>The parents of this node.</p></li>
<li><strong>pubsub#children</strong>
<p>The children of this node.</p></li>
</ul>
<p>To associate the root node to the collection the <value/> element MUST be empty.</p>
<p>A service MAY offer some node configuration options that are specific to collection nodes and SHOULD NOT be provided in configuration forms related to leaf nodes. The following are RECOMMENDED:</p>
<section4topic='Configuring a Leaf Node with Children'anchor='error-children-on-leaf'>
<p>Leaf nodes only contain published items and MUST NOT have any children. If an entity attempts to add children to a leaf node (either via "pubsub#children" on the leaf node or "pubsub#collection" on another node) the service MUST return a ¬allowed; error with a pubsub-specific error condition of <invalid-options/>.</p>
<examplecaption='Attempt to add a leaf node as the parent of another node'><![CDATA[
<section4topic='Maximum Number of Children Exceeded'anchor='error-max-children'>
<p>If the configuration would exceed the maximum number of children allowed on a node, either because the node's "pubsub#children" exceeds it's own "pubsub#children_max" value or because adding this node to a parent via "pubsub#collection" would exceed the parent's "pubsub#children_max" value, the service MUST return a ¬allowed; error with a pubsub-specific error condition of <max-nodes-exceeded/>.</p>
<examplecaption='Node would contain too many children'><![CDATA[
<p>The service MUST NOT allow the node type to be changed. If it is attempted the service MUST return a ¬allowed; error, specifying a pubsub-specific error condition of <invalid-options/></p>
<examplecaption='Attempt to change node type'><![CDATA[
<section4topic='Creating a Cycle in the Collection'anchor='error-collection-cycle'>
<p>The service MUST NOT allow a cycle to be created in the node graph (<em>e.g.</em>, node A to B to C to A). If an entity attempts to submit a configuration that would create a cycle the service MUST return a ¬allowed; error, specifying a pubsub-specific error condition of <invalid-options/>.</p>
<examplecaption='Cycle created in node graph'><![CDATA[
<p>A service MAY allow collection nodes to have children associated with them without changing the rest of the configuration. If the service allows this an entity can send and <associate/> element with a 'node' attribute that contains the child node within a <collection/> element that posesses a 'node' attribute containing the parent node to the service.</p>
<section4topic='Maximum Number of Children Exceeded'anchor='error-assoc-too-many-nodes'>
<p>If the configuration would exceed the maximum number of children allowed on a node, either because the node's "pubsub#children" exceeds it's own "pubsub#children_max" value or because adding this node to a parent via "pubsub#collection" would exceed the parent's "pubsub#children_max" value, the service MUST return a ¬allowed; error with a pubsub-specific error condition of <max-nodes-exceeded/>.</p>
<examplecaption='Node would contain too many children'><![CDATA[
<section4topic='Creating a Cycle in the Collection'anchor='error-assoc-cycle'>
<p>The service MUST NOT allow a cycle to be created in the node graph (<em>e.g</em>., node A to B to C to A). If an entity attempts to submit a configuration that would create a cycle the service MUST return a ¬allowed; error, specifying a pubsub-specific error condition of <invalid-options/>.</p>
<examplecaption='Cycle created in node graph'><![CDATA[
<p>A service MAY allow collection nodes to have children dissociated from them without changing the rest of the configuration. If the service allows this an entity can send and <dissociate/> element with a 'node' attribute that contains the child node within a <collection/> element that posesses a 'node' attribute containing the parent node to the service.</p>
<p>To provide a starting point for service discovery a service SHOULD support a root node. A root node represents the node belonging to a given service and MUST be identified by the lack of a node identifier (<em>i.e.</em>, the address of the pubsub service itself, such as "pubsub.shakespeare.lit"). Because the root node is owned by the service itself an entity SHOULD NOT be allowed create, delete, or configure the root node.</p>
<p>If a node is created or configured without any parents specified, a service MAY automatically associate otherwise orphaned nodes directly to the root node. If a service automatically associates a node with the root it MUST reflect that in the node configuration data form.</p>
<examplecaption='Entity subscribes to the root node'><![CDATA[
<p>Deletion of collection nodes can have a number of side effects due to implementation. Depending on the nature of the collection any of the following MAY happen when a collection node is deleted:</p>
<li>When the collection node is deleted and the child nodes have no other parents the child nodes are orphaned; meaning that they will have no parent node, but continue to exist.</li>
<li>When the collection node is deleted and the child nodes have no other parents the child nodes are re-assigned as children of the root node.</li>
<li>When the collection node is deleted and the child nodes have no other parents the child nodes are also deleted.</li>
<li>When the collection node is deleted and the child nodes have at least one other node the child nodes MUST remain associated with remaining parent nodes.</li>
</ul>
</section2>
<section2topic='Updating Node Configuration When Associating or Dissociating Nodes'anchor='impl-config'>
<p>Node configuration MUST always reflect the current state of the node graph. Because node configuration contains both a pointer to its parents as well as its children an update to a primary node's "pubsub#collection" value will change the value of the secondary node's "pubsub#children" value, and vice-versa. A service MAY send a notification of the configuration change on the secondary node to subscribers if "pubsub#notify_config" is enabled on the secondary node.</p>
<p>Collection nodes can be used to associate almost any node within the service, but only the access model of the collection node itself is used to determine what an entity is allowed to see. Therefore care should be taken that nodes are not linked in such a way as to leak private data (e.g., from a "closed" leaf node through an "open" collection) unless that behavior is specifically desired.</p>