166 lines
7.5 KiB

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE xep SYSTEM 'xep.dtd' [
<!ENTITY % ents SYSTEM 'xep.ent'>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<title>Whitespace Keepalive Negotiation</title>
<abstract>This specification defines a method for negotiating how to send keepalives in XMPP.</abstract>
<type>Standards Track</type>
<spec>XMPP Core</spec>
<remark><p>Initial published version.</p></remark>
<remark><p>First draft.</p></remark>
<section1 topic='Introduction' anchor='intro'>
<p>&rfc6120; specifies that XMPP servers and clients can send whitespace characters between first-level elements of an XML stream as a way to maintain the state of the stream. These "whitespace keepalives" are widely used on the XMPP network. However, currently it is not possible to negotiate the frequency of sending keepalives, or even whether to send keepalives at all (the server simply sends them according to its own schedule). Because certain kinds of devices might not want to use keepalives, or might wish to receive keepalives more frequently or less frequently than the server's default, this specification defines a method for negotiating how to send whitespace keepalives between an XMPP server and an XMPP client (this method could also be used between two servers, although that usage is expected to be rare).</p>
<section1 topic='Protocol' anchor='protocol'>
<p>The protocol defined in this document enables a client negotiate the time interval between whitespace keepalives, within a range determined by the server. Normally, the client starts the negotiation since not all kinds of the client support the feature.</p>
<p>The protocol defines a keepalive element and the normal negotaition process is quite simple, demonstrated as following:</p>
<ol start='1'>
<li>Server announces keepalive feature with a range of time intervals.</li>
<li>Client starts the keepalive negotiation by specifying a time interval. </li>
<li>Server checks the value and relpies with success or failure.</li>
<p>Then server and client send whitespace keepalive to each other at the agreed time interval.</p>
<section1 topic='Use Cases' anchor='usecases'>
<section2 topic='Stream Feature' anchor='feature'>
<p>During the stream negotiation process, the server can advertise this feature. The feature is negotiated after the resource binding. (See &xep0170; regarding the recommended order of stream feature negotiation.)</p>
<example caption='Server lists feature in the stream negotiation stage'><![CDATA[
C: <stream:stream
C: <stream:stream
S: <stream:features>
<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
<keepalive xmlns='urn:xmpp:keepalive:0'>
<interval min='60' max='300'/>
<section2 topic='Negotiate Keepalive' anchor='negotiate'>
<p>Client negotiates the keepalive feature by providing an interval value based on server limits and its own condition. The interval SHOULD be a positive interger, and zero is invalid.</p>
<example caption='Client sends its negotiating keepalive time interval'><![CDATA[
<iq from='client@example.com/foo' id='p03ns61g' to='example.com' type='set'>
<keepalive xmlns='urn:xmpp:keepalive:0'>
<p>The server checks the keepalive interval value and returns a success:</p>
<example caption='Server returns success of keepalive negotiation'><![CDATA[
<iq from='example.com' id='p03ns61g' to='client@example.com/foo' type='result'/>
<p>If a problem occurs, the server returns an error (in this example, the client sent a value outside the range of the server's preferences):</p>
<example caption='Server returns failure of keepalive negotiation'><![CDATA[
<iq from='example.com' id='p03ns61g' to='client@example.com/foo' type='error'>
<error type='cancel'>
<not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
<p>Then both the server and the client send whitespace keepalives at the interval of the negotiated value. The server SHOULD check to see if has received keepalives and MAY drop the connection if it has not received a keepalive for a period of time significantly longer than the negotiated value (the client MAY also implement this behavior).</p>
<section1 topic='Implementation Notes' anchor='impl'>
<p>Several things need to be noted:</p>
<ol start='1'>
<li>Both parties SHOULD keep a record of the keepalive status and honor the negotiated value when allowing stream resumption and session recreation. See &xep0198;</li>
<li>The length of the keepalive interval depends on the service type and network environment. Implementations are encouraged to use appropriate values based on implementation and deployment experience.</li>
<section1 topic='Security Considerations' anchor='security'>
<p>During negotiation, the server MUST check the keepalive interval value and reject any invalid values.</p>
<section1 topic='IANA Considerations' anchor='iana'>
<p>This document requires no interaction with &IANA;.</p>
<section1 topic='XMPP Registrar Considerations' anchor='registrar'>
<section2 topic='Protocol Namespaces' anchor='registrar-ns'>
<p>The &REGISTRAR; is requested to issue an initial namespace 'urn:xmpp:keepalive:0'</p>
<section2 topic='Stream Features' anchor='registrar-stream'>
<p>The &REGISTRAR; is requested to issue an initial stream feature namespace 'urn:xmpp:keepalive:0'.</p>
<section1 topic='XML Schema' anchor='schema'>
<?xml version='1.0' encoding='utf-8'?>
<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'
<xsd:element name='keepalive'>
<xsd:attribute name='min' type='positiveShort' use='optional'/>
<xsd:attribute name='max' type='positiveShort' use='optional'/>
<xsd:assert test='@min le @max'/>
<xsd:element name='interval' type='positiveShort' minOccurs='0' maxOccurs='1'/>
<xsd:simpleType name='positiveShort'>
<xsd:restriction base='xsd:unsignedShort'>
<xsd:minExclusive value='0'/>
<section1 topic='Acknowledgements' anchor='ack'>
<p>Thanks to Matt Miller and Peter Saint-Andre for their feedback.</p>