Smack 4.4.7: Send presence stanza from app triggers smack to resend presence stanza even when with config setSendPresence to false

In aTalk implementation, it handles its own Presence sending; and the XMPP Connection Configuration is configured as config.setSendPresence(false).

However it is found that smack ServiceDiscoveryManager get triggered off to resend the same Presence stanza when aTalk sends the Presence available upon first registered with the server. This is shown in the aTalk logcat below.

There is some comment in source, but not quite understand “We only send a presence packet if there was already one send”. Is this meant to add <c/> extension before sending the Presence stanza.

            // Re-send the last sent presence, and let the stanza interceptor
            // add a <c/> node to it.
            // See http://xmpp.org/extensions/xep-0115.html#advertise
            // We only send a presence packet if there was already one send
            // to respect ConnectionConfiguration.isSendPresence()

I was initially concern resend of Presence(available) may trigger server duplicate sending of publish#event twice, but fount this is not the case on ejabberd server. However the server responses multiple times (2+4) to the two Presence stanzas sent.

Sending of Presence stanza may also contains the <show/> attributes, but I cannot locate where smack supports the manual sending of Presence stanza. Any reason?

// ======== aTalk logcat =========== //
07:40:49.075  E  java.lang.Exception: <presence xmlns='jabber:client' id='KG4SK-7'><status/><priority>30</priority></presence>
                 	at org.jivesoftware.smack.AbstractXMPPConnection.sendStanza(AbstractXMPPConnection.java:873)
                 	at net.java.sip.communicator.impl.protocol.jabber.OperationSetPersistentPresenceJabberImpl.publishPresenceStatus(OperationSetPersistentPresenceJabberImpl.java:584)
                 	at net.java.sip.communicator.impl.globaldisplaydetails.GlobalStatusServiceImpl$PublishPresenceStatusThread.run(GlobalStatusServiceImpl.java:527)
07:40:49.077  D  SENT (0): 
                 <presence id='KG4SK-7'>
                   <status/>
                   <priority>
                     30
                   </priority>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                 </presence>
07:40:49.101  E  java.lang.Exception: <presence xmlns='jabber:client' id='KG4SK-8'><status/><priority>30</priority><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/></presence>
                 	at org.jivesoftware.smack.AbstractXMPPConnection.sendStanza(AbstractXMPPConnection.java:873)
                 	at org.jivesoftware.smackx.disco.ServiceDiscoveryManager.lambda$renewEntityCapsVersion$1$org-jivesoftware-smackx-disco-ServiceDiscoveryManager(ServiceDiscoveryManager.java:974)
                 	at org.jivesoftware.smackx.disco.ServiceDiscoveryManager$$ExternalSyntheticLambda1.run(Unknown Source:2)
                 	at org.jivesoftware.smack.ScheduledAction.lambda$run$0$org-jivesoftware-smack-ScheduledAction(ScheduledAction.java:87)
                 	at org.jivesoftware.smack.ScheduledAction$$ExternalSyntheticLambda0.run(Unknown Source:2)
                 	at java.lang.Thread.run(Thread.java:1012)
07:40:49.104  D  SENT (0): 
                 <presence id='KG4SK-8'>
                   <status/>
                   <priority>
                     30
                   </priority>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                 </presence>

07:40:50.351  D  RECV (0): 
                 <presence xml:lang='en-US' to='swan@atalk.sytes.net/atalk-8oh83s' from='swan@atalk.sytes.net/atalk-8oh83s' id='KG4SK-7'>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                   <x xmlns='vcard-temp:x:update'>
                     <photo>
                       7ec4901ae9e5b9d9077acbf3a0f9700d9fbcabfa
                     </photo>
                   </x>
                   <priority>
                     30
                   </priority>
                   <status/>
                 </presence>
07:40:50.354  D  Smack presence update for: swan@atalk.sytes.net/atalk-8oh83s - available
07:40:50.355  D  RECV (0): 
                 <presence xml:lang='en-US' to='swan@atalk.sytes.net/atalk-8oh83s' from='swan@atalk.sytes.net/atalk-8oh83s' id='KG4SK-7'>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                   <x xmlns='vcard-temp:x:update'>
                     <photo>
                       7ec4901ae9e5b9d9077acbf3a0f9700d9fbcabfa
                     </photo>
                   </x>
                   <priority>
                     30
                   </priority>
                   <status/>
                 </presence>

07:40:50.407  D  RECV (0): 
                 <presence xml:lang='en-US' to='swan@atalk.sytes.net/atalk-8oh83s' from='swan@atalk.sytes.net/atalk-8oh83s' id='KG4SK-8'>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                   <x xmlns='vcard-temp:x:update'>
                     <photo>
                       7ec4901ae9e5b9d9077acbf3a0f9700d9fbcabfa
                     </photo>
                   </x>
                   <priority>
                     30
                   </priority>
                   <status/>
                 </presence>
07:40:50.443  D  RECV (0): 
                 <presence xml:lang='en-US' to='swan@atalk.sytes.net/atalk-8oh83s' from='swan@atalk.sytes.net/atalk-8oh83s' id='KG4SK-8'>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                   <x xmlns='vcard-temp:x:update'>
                     <photo>
                       7ec4901ae9e5b9d9077acbf3a0f9700d9fbcabfa
                     </photo>
                   </x>
                   <delay from='swan@atalk.sytes.net/atalk-8oh83s' stamp='2024-03-07T23:40:54.607814Z' xmlns='urn:xmpp:delay'/>
                   <priority>
                     30
                   </priority>
                   <status/>
                 </presence>
07:40:50.450  D  RECV (0): 
                 <presence xml:lang='en-US' to='swan@atalk.sytes.net/atalk-8oh83s' from='swan@atalk.sytes.net/atalk-8oh83s' id='KG4SK-8'>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                   <x xmlns='vcard-temp:x:update'>
                     <photo>
                       7ec4901ae9e5b9d9077acbf3a0f9700d9fbcabfa
                     </photo>
                   </x>
                   <delay from='swan@atalk.sytes.net/atalk-8oh83s' stamp='2024-03-07T23:40:54.607814Z' xmlns='urn:xmpp:delay'/>
                   <priority>
                     30
                   </priority>
                   <status/>
                 </presence>
07:40:50.450  D  RECV (0): 
                 <presence xml:lang='en-US' to='swan@atalk.sytes.net/atalk-8oh83s' from='swan@atalk.sytes.net/atalk-8oh83s' id='KG4SK-8'>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                   <x xmlns='vcard-temp:x:update'>
                     <photo>
                       7ec4901ae9e5b9d9077acbf3a0f9700d9fbcabfa
                     </photo>
                   </x>
                   <delay from='swan@atalk.sytes.net/atalk-8oh83s' stamp='2024-03-07T23:40:54.607814Z' xmlns='urn:xmpp:delay'/>
                   <priority>
                     30
                   </priority>
                   <status/>
                 </presence>

If aTalk set config.setSendPresence(true);
Then only one Presence standard is being sent by smack; but server responses with 4 Presence results, with 2 of them <delay.>. Still trying to figure out why the server behaves this way.

08:50:28.729  E  java.lang.Exception: <presence xmlns='jabber:client' id='3XB6Z-14'/>
                 	at org.jivesoftware.smack.AbstractXMPPConnection.sendStanza(AbstractXMPPConnection.java:873)
                 	at org.jivesoftware.smack.AbstractXMPPConnection.afterSuccessfulLogin(AbstractXMPPConnection.java:800)
                 	at org.jivesoftware.smack.tcp.XMPPTCPConnection.afterSuccessfulLogin(XMPPTCPConnection.java:372)p.XMPPTCPConnection.loginInternal(XMPPTCPConnection.java:470)
                 	at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:639)
                 	at net.java.sip.communicator.impl.protocol.jabber.LoginByPasswordStrategy.login(LoginByPasswordStrategy.java:105)
                 	at net.java.sip.communicator.impl.protocol.jabber.ProtocolProviderServiceJabberImpl.connectAndLogin(ProtocolProviderServiceJabberImpl.java:1274)
                 	at net.java.sip.communicator.impl.protocol.jabber.ProtocolProviderServiceJabberImpl.initializeConnectAndLogin(ProtocolProviderServiceJabberImpl.java:870)
                 	at net.java.sip.communicator.impl.protocol.jabber.ProtocolProviderServiceJabberImpl.register(ProtocolProviderServiceJabberImpl.java:727)
                 	at net.java.sip.communicator.util.account.LoginManager$RegisterProvider.run(LoginManager.java:300)
08:50:28.733  D  SENT (0): 
                 <presence id='3XB6Z-14'>
                   <priority>
                     0
                   </priority>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                 </presence>

08:50:28.997  D  RECV (0): 
                 <presence xml:lang='en-US' to='swan@atalk.sytes.net/atalk-1urlh35' from='swan@atalk.sytes.net/atalk-1urlh35' id='3XB6Z-14'>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                   <x xmlns='vcard-temp:x:update'>
                     <photo>
                       7ec4901ae9e5b9d9077acbf3a0f9700d9fbcabfa
                     </photo>
                   </x>
                   <priority>
                     0
                   </priority>
                 </presence>

08:50:29.015  D  RECV (0): 
                 <presence xml:lang='en-US' to='swan@atalk.sytes.net/atalk-1urlh35' from='swan@atalk.sytes.net/atalk-1urlh35' id='3XB6Z-14'>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                   <x xmlns='vcard-temp:x:update'>
                     <photo>
                       7ec4901ae9e5b9d9077acbf3a0f9700d9fbcabfa
                     </photo>
                   </x>
                   <priority>
                     0
                   </priority>
                 </presence>

08:50:29.023  D  RECV (0): 
                 <presence xml:lang='en-US' to='swan@atalk.sytes.net/atalk-1urlh35' from='swan@atalk.sytes.net/atalk-1urlh35' id='3XB6Z-14'>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                   <x xmlns='vcard-temp:x:update'>
                     <photo>
                       7ec4901ae9e5b9d9077acbf3a0f9700d9fbcabfa
                     </photo>
                   </x>
                   <delay from='swan@atalk.sytes.net/atalk-1urlh35' stamp='2024-03-08T00:50:33.281666Z' xmlns='urn:xmpp:delay'/>
                   <priority>
                     0
                   </priority>
                 </presence> 

08:50:29.032  D  RECV (0): 
                 <presence xml:lang='en-US' to='swan@atalk.sytes.net/atalk-1urlh35' from='swan@atalk.sytes.net/atalk-1urlh35' id='3XB6Z-14'>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                   <x xmlns='vcard-temp:x:update'>
                     <photo>
                       7ec4901ae9e5b9d9077acbf3a0f9700d9fbcabfa
                     </photo>
                   </x>
                   <delay from='swan@atalk.sytes.net/atalk-1urlh35' stamp='2024-03-08T00:50:33.281666Z' xmlns='urn:xmpp:delay'/>
                   <priority>
                     0
                   </priority>
                 </presence>       

With reference to

After reading section 4.2.2 of the above document i.e.:

4.2.  Initial Presence
4.2.2.  Server Processing of Outbound Initial Presence
   Upon receiving initial presence from a client, the user's server MUST
   send the initial presence stanza from the full JID
   <user@domainpart/resourcepart> of the user to all contacts that are
   subscribed to the user's presence; such contacts are those for which
   a JID is present in the user's roster with the 'subscription'
   attribute set to a value of "from" or "both".

   The user's server MUST also broadcast initial presence from the
   user's newly available resource to all of the user's available
   resources, including the resource that generated the presence
   notification in the first place (i.e., an entity is implicitly
   subscribed to its own presence).

I begin to understand why there is 4 x Presence stanzas being send when ServiceDiscoveryManager resend the Initial user <presence/>.

image

In aTalk implementation, the user swan has two identities i.e. user and contact. This is to allow the user to send to the contact himself.

As per section 4.2.2, the user server hence will send the received <presence/>, one to the user, and another to the contact.

After aTalk sends the first initial <presence/>, upon received the second initial <presence/> send by ServiceDiscoveryManager, Server treats this as from another swan resource, hence relays the first received <presence/> as <delay/> <presence/> in response to ServiceDiscoveryManager stanza sending.

Look like it is no good to send the initial <presence/> stanza twice, else unexpected result arises.
Since aTalk is handled the sending of initial <presence/>, Is that a way that aTalk can disable ServiceDiscoveryManager from sending the initial <presence/> again.

I have modified the ServiceDiscoveryManager, to stop it from resend the initial <presence/> if ConnectionConfiguration#isSendPresence() is false. The resulted aTalk logcat is attached.

Look like my earlier assumption is not correct. There are still 4 <presence/> responses send by server, with 2 of them as <delay/>. Now I have no idea why the <delay/> stanzas are being sent.

Tested conversations client on aTalk ejabberd server, the server sends 2 <presence/> stanzas, one of them is <delay/>. Look like server always send in pair for each user/contact for aTalk.

Will include ServiceDiscoveryManager updates in aTalk next release.

// ====== aTalk logcat =======/

 05:21:51.921  E  user: swan@atalk.sytes.net/atalk-1dv6dpn
                 java.lang.Exception: <presence xmlns='jabber:client' id='SBY7R-7'><status/><priority>30</priority></presence>
                 	at org.jivesoftware.smack.AbstractXMPPConnection.sendStanza(AbstractXMPPConnection.java:873)
                 	at net.java.sip.communicator.impl.protocol.jabber.OperationSetPersistentPresenceJabberImpl.publishPresenceStatus(OperationSetPersistentPresenceJabberImpl.java:590)
                 	at net.java.sip.communicator.impl.globaldisplaydetails.GlobalStatusServiceImpl$PublishPresenceStatusThread.run(GlobalStatusServiceImpl.java:510)
05:21:51.927  D  SENT (0): 
                 <presence id='SBY7R-7'>
                   <status/>
                   <priority>
                     30
                   </priority>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                 </presence>

05:21:53.192  D  RECV (0): 
                 <presence xml:lang='en-US' to='swan@atalk.sytes.net/atalk-1dv6dpn' from='swan@atalk.sytes.net/atalk-1dv6dpn' id='SBY7R-7'>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                   <x xmlns='vcard-temp:x:update'>
                     <photo>
                       7ec4901ae9e5b9d9077acbf3a0f9700d9fbcabfa
                     </photo>
                   </x>
                   <priority>
                     30
                   </priority>
                   <status/>
                 </presence>

05:21:53.205  D  RECV (0): 
                 <presence xml:lang='en-US' to='swan@atalk.sytes.net/atalk-1dv6dpn' from='swan@atalk.sytes.net/atalk-1dv6dpn' id='SBY7R-7'>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                   <x xmlns='vcard-temp:x:update'>
                     <photo>
                       7ec4901ae9e5b9d9077acbf3a0f9700d9fbcabfa
                     </photo>
                   </x>
                   <priority>
                     30
                   </priority>
                   <status/>
                 </presence>

05:21:53.232  D  RECV (0): 
                 <presence xml:lang='en-US' to='swan@atalk.sytes.net/atalk-1dv6dpn' from='swan@atalk.sytes.net/atalk-1dv6dpn' id='SBY7R-7'>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                   <x xmlns='vcard-temp:x:update'>
                     <photo>
                       7ec4901ae9e5b9d9077acbf3a0f9700d9fbcabfa
                     </photo>
                   </x>
                   <delay from='swan@atalk.sytes.net/atalk-1dv6dpn' stamp='2024-03-08T21:22:00.319512Z' xmlns='urn:xmpp:delay'/>
                   <priority>
                     30
                   </priority>
                   <status/>
                 </presence>

05:21:53.238  D  RECV (0): 
                 <presence xml:lang='en-US' to='swan@atalk.sytes.net/atalk-1dv6dpn' from='swan@atalk.sytes.net/atalk-1dv6dpn' id='SBY7R-7'>
                   <c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://atalk.org' ver='i/QosNuYTO9lDz6/GUxZBJxCfKk='/>
                   <x xmlns='vcard-temp:x:update'>
                     <photo>
                       7ec4901ae9e5b9d9077acbf3a0f9700d9fbcabfa
                     </photo>
                   </x>
                   <delay from='swan@atalk.sytes.net/atalk-1dv6dpn' stamp='2024-03-08T21:22:00.319512Z' xmlns='urn:xmpp:delay'/>
                   <priority>
                     30
                   </priority>
                   <status/>
                 </presence>

Made correction to my last comment:

From logcat, there are 4 x <presence/> responses send by server, with 2 of them as <delay/>.
Test conversations client (user identity only) on aTalk ejabberd server, the server sends 2 x <presence/> stanzas, one of them is <delay/>.

Look like my earlier view is not 100% correct. Seems that the ejabberd server will always send a <delay> <presence> in its implementation.