powered by Jive Software

Smack XMPPConnection #sendIqRequest And WaitForResponse() implementation clarification

aTalk is trying to add support for: XEP-0215: External Service Discovery

In the ExternalServiceDiscoveryManager, it attempts to use XMPPConnection.sendIqRequestAndWaitForResponse() to retrieve the IQ response for ExternalServiceDiscovery IQ request, but found that IQ result does not contain the expected Extension Element; instead it contains the last received stanza Extension Element.

Please advice the correct method of getting the desired result.

    public void getExtServices(XMPPConnection connection)
    {
        DomainBareJid serviceName = connection().getXMPPServiceDomain();
        ExternalServiceDiscovery extServiceDisco = new ExternalServiceDiscovery();
        extServiceDisco.setType(IQ.Type.get);
        extServiceDisco.setTo(serviceName);

        // Discover the entity's external services
        try {
            IQ iq = connection.sendIqRequestAndWaitForResponse(extServiceDisco);
            Timber.d("ExternalServiceDiscovery: %s", iq.toXML());
        } catch (SmackException.NotConnectedException | InterruptedException | SmackException.NoResponseException | XMPPException.XMPPErrorException e) {
            LOGGER.log(Level.SEVERE, "Could not get external services: " + e, e);
        }
    }

aTalk logcat

2022-10-29 12:45:53.347 13478-13634/org.atalk.android D/SMACK: SENT (0): 
    <iq to='atalk.sytes.net' id='L13ZT-16' type='get'>
      <services xmlns='urn:xmpp:extdisco:2'/>
    </iq>
    
2022-10-29 12:45:54.614 13478-13635/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-US' to='abc123@atalk.sytes.net/atalk' from='atalk.sytes.net' type='result' id='L13ZT-16'>
      <services xmlns='urn:xmpp:extdisco:2'>
        <service type='stun' transport='udp' restricted='false' port='3478' host='42.60.99.4'/>
        <service username='1667061955:1074796f99cde8d3' type='turn' transport='udp' restricted='true' port='3478' password='nFdkBtLGV+ymucX5uVvYMcACSyw=' host='42.60.99.4' expires='2022-10-29T16:45:55Z'/>
        <service type='stun' transport='udp' restricted='false' port='3478' host='fe80::a5e2:4bc8:f5ea:2560'/>
        <service username='1667061955:1074796f99cde8d3' type='turn' transport='udp' restricted='true' port='3478' password='nFdkBtLGV+ymucX5uVvYMcACSyw=' host='fe80::a5e2:4bc8:f5ea:2560' expires='2022-10-29T16:45:55Z'/>
        <service type='stun' transport='tcp' restricted='false' port='5349' host='42.60.99.4'/>
        <service username='1667061955:1074796f99cde8d3' type='turn' transport='tcp' restricted='true' port='5349' password='nFdkBtLGV+ymucX5uVvYMcACSyw=' host='42.60.99.4' expires='2022-10-29T16:45:55Z'/>
        <service type='stuns' transport='tcp' restricted='false' port='5349' host='atalk.sytes.net'/>
        <service username='1667061955:1074796f99cde8d3' type='turns' transport='tcp' restricted='true' port='5349' password='nFdkBtLGV+ymucX5uVvYMcACSyw=' host='atalk.sytes.net' expires='2022-10-29T16:45:55Z'/>
      </services>
    </iq>
    
// Result of ExternalServiceDiscoveryProvider for verification:
2022-10-29 12:45:54.631 13478-13635/org.atalk.android D/(ExternalServiceDiscoveryProvider.java:64)#parse: ExternalServices: <services xmlns='urn:xmpp:extdisco:2'><service type='stun' transport='udp' restricted='false' port='3478' host='42.60.99.4'/><service username='1667061955:1074796f99cde8d3' type='turn' transport='udp' restricted='true' port='3478' password='nFdkBtLGV+ymucX5uVvYMcACSyw=' host='42.60.99.4' expires='2022-10-29T16:45:55Z'/><service type='stun' transport='udp' restricted='false' port='3478' host='fe80::a5e2:4bc8:f5ea:2560'/><service username='1667061955:1074796f99cde8d3' type='turn' transport='udp' restricted='true' port='3478' password='nFdkBtLGV+ymucX5uVvYMcACSyw=' host='fe80::a5e2:4bc8:f5ea:2560' expires='2022-10-29T16:45:55Z'/><service type='stun' transport='tcp' restricted='false' port='5349' host='42.60.99.4'/><service username='1667061955:1074796f99cde8d3' type='turn' transport='tcp' restricted='true' port='5349' password='nFdkBtLGV+ymucX5uVvYMcACSyw=' host='42.60.99.4' expires='2022-10-29T16:45:55Z'/><service type='stuns' transport='tcp' restricted='false' port='5349' host='atalk.sytes.net'/><service username='1667061955:1074796f99cde8d3' type='turns' transport='tcp' restricted='true' port='5349' password='nFdkBtLGV+ymucX5uVvYMcACSyw=' host='atalk.sytes.net' expires='2022-10-29T16:45:55Z'/></services>
    
2022-10-29 12:45:54.633 13478-13635/org.atalk.android D/SMACK: RECV (0): 
    <message to='abc123@atalk.sytes.net/atalk' from='abc123@atalk.sytes.net' type='headline'>
      <event xmlns='http://jabber.org/protocol/pubsub#event'>
        <items node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='682CF0BAE552B'>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='459141212'/>
              <device id='660938212'/>
              <device id='2028266418'/>
              <device id='1605373784'/>
              <device id='1201354019'/>
              <device id='1312485350'/>
            </list>
          </item>
        </items>
      </event>
      <addresses xmlns='http://jabber.org/protocol/address'>
        <address jid='abc123@atalk.sytes.net/atalk' type='replyto'/>
      </addresses>
    </message>
    
// Result of connection.sendIqRequestAndWaitForResponse(ExternalServiceDiscovery)
2022-10-29 12:45:54.634 13478-13620/org.atalk.android D/(ExternalServiceDiscoveryManager.java:200)#getExtServices: ExternalServiceDiscovery: <iq xmlns='jabber:client' to='abc123@atalk.sytes.net/atalk' from='atalk.sytes.net' id='L13ZT-16' type='result'><addresses xmlns='http://jabber.org/protocol/address'&lt;addresses xmlns=&apos;http://jabber.org/protocol/address&apos;&gt;&lt;address jid=&apos;abc123@atalk.sytes.net/atalk&apos; type=&apos;replyto&apos;/&gt;&lt;/addresses&gt;</addresses></iq>

Is there a way that I can see more of the related code parts? I assume that ExternalServiceDiscoveryManager and the related classes are part of atalk. But I couldn’t find anything in GitHub - cmeng-git/atalk-android: xmpp/jabber client for android. Could you publish the unfinished external service discovery code in a branch?

Hi,

I hope it is OK just to attach the related sources here for your reference; the sources are in the very early stage of development and contains many errors.

externalservicediscovery.zip (8.9 KB)

Found that the result is inconsistent, and pending on what was being received prior to the printout. Below logcat is another possible output.

2022-10-29 17:32:11.461 5192-5346/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-US' to='abc123@atalk.sytes.net/atalk' from='abc123@atalk.sytes.net' type='result' id='TGHKF-17'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <items node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='682CF0BAE552B'>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='459141212'/>
              <device id='660938212'/>
              <device id='2028266418'/>
              <device id='1605373784'/>
              <device id='1201354019'/>
              <device id='1312485350'/>
            </list>
          </item>
        </items>
      </pubsub>
    </iq>
2022-10-29 17:32:11.462 5192-5335/org.atalk.android D/(ExternalServiceDiscoveryManager.java:201)#getExtServices: ExternalServiceDiscovery#1: <iq xmlns='jabber:client' to='abc123@atalk.sytes.net/atalk' from='atalk.sytes.net' id='TGHKF-16' type='result'><services xmlns='urn:xmpp:extdisco:2'/></iq>
2022-10-29 17:32:11.486 5192-5335/org.atalk.android D/(ExternalServiceDiscoveryManager.java:204)#getExtServices: ExternalServiceDiscovery#2: <services xmlns='urn:xmpp:extdisco:2'><service type='stun' transport='udp' restricted='false' port='3478' host='42.60.99.4'/><service username='1667079131:1074796f99cde8d3' type='turn' transport='udp' restricted='true' port='3478' password='NYXEi825lsyxpmFUUAkdoh9g808=' host='42.60.99.4' expires='2022-10-29T21:32:11Z'/><service type='stun' transport='udp' restricted='false' port='3478' host='fe80::a5e2:4bc8:f5ea:2560'/><service username='1667079131:1074796f99cde8d3' type='turn' transport='udp' restricted='true' port='3478' password='NYXEi825lsyxpmFUUAkdoh9g808=' host='fe80::a5e2:4bc8:f5ea:2560' expires='2022-10-29T21:32:11Z'/><service type='stun' transport='tcp' restricted='false' port='5349' host='42.60.99.4'/><service username='1667079131:1074796f99cde8d3' type='turn' transport='tcp' restricted='true' port='5349' password='NYXEi825lsyxpmFUUAkdoh9g808=' host='42.60.99.4' expires='2022-10-29T21:32:11Z'/><service type='stuns' transport='tcp' restricted='false' port='5349' host='atalk.sytes.net'/><service username='1667079131:1074796f99cde8d3' type='turns' transport='tcp' restricted='true' port='5349' password='NYXEi825lsyxpmFUUAkdoh9g808=' host='atalk.sytes.net' expires='2022-10-29T21:32:11Z'/></services>

Thanks, but actually I would very much prefer a branch hosted on github, gitlab, or something similar. It just makes it way easier to discuss code and I don’t have to perform extra steps to view the code.

Sorry for the inconvenience cause to your team. Was found to be aTalk problem caused by ExternalServiceDiscoveryProvider#parse() did not exit properly. It is now fixed with the new source attached below.

    public ExternalServiceDiscovery parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
            throws IOException, XmlPullParserException, SmackParsingException
    {
        ExternalServiceDiscovery iqESD = null;

        if (ExternalServices.ELEMENT.equals(parser.getName()) && ExternalServices.NAMESPACE.equals(parser.getNamespace())) {
            DefaultXmlElementProvider<ExternalServices> servicesProvider = new DefaultXmlElementProvider<>(ExternalServices.class);
            ExternalServices externalServices = servicesProvider.parse(parser);
            iqESD = new ExternalServiceDiscovery();
            iqESD.setServices(externalServices);
        }
        return iqESD;
    }