Project

General

Profile

Getting two packets in response

Razor Ra
Added over 5 years ago

Hi,

I am using Tigase server-5.1.4 on linux machine.

I have created couple of tigase plugins which trigger one another.

For example, I have created a plugin which triggers disco#info plugin to send disco#info stanzas.

In response of that disco#info, I am getting two packets, whereas I was expecting only one packet.

First Packet:

from=c2s@my-tigase-server/127.0.1.1_5222_127.0.0.1_43284, 
to=sess-man@my-tigase-server, 
DATA=<iq id="a12k" from="testuser@my-tigase-server/PSI" type="result" xmlns="jabber:client" to="admin@my-tigase-server">
    <query xmlns="http://jabber.org/protocol/disco#info">
        <identity category="directory" name="chat room" type="chatroom"/>
        <feature var="http://jabber.org/protocol/muc"/>
        <feature var="http://jabber.org/protocol/bytestreams"/>
        <feature var="http://jabber.org/protocol/commands"/>
        <feature var="http://jabber.org/protocol/disco#info"/>
        <feature var="jabber:x:data"/>
        <feature var="http://www.xmpp.org/extensions/xep-0084.html#ns-metadata+notify"/>
    </query>
</iq>, SIZE=694, XMLNS=jabber:client, PRIORITY=NORMAL, PERMISSION=NONE, TYPE=result

Second Packet:

from=sess-man@my-tigase-server, 
to=sess-man@my-tigase-server, 
DATA=<iq id="a12k" from="testuser@my-tigase-server/PSI" type="result" xmlns="jabber:client" to="admin@my-tigase-server">
    <query xmlns="http://jabber.org/protocol/disco#info">
        <identity category="directory" name="chat room" type="chatroom"/>
        <feature var="http://jabber.org/protocol/muc"/>
        <feature var="http://jabber.org/protocol/bytestreams"/>
        <feature var="http://jabber.org/protocol/commands"/>
        <feature var="http://jabber.org/protocol/disco#info"/>
        <feature var="jabber:x:data"/>
        <feature var="http://www.xmpp.org/extensions/xep-0084.html#ns-metadata+notify"/>
    </query>
</iq>, SIZE=694, XMLNS=jabber:client, PRIORITY=NORMAL, PERMISSION=AUTH, TYPE=result

I want to know where does this from=c2s@my-tigase-server/127.0.1.1_5222_127.0.0.1_43284 came from and why I am getting two packets in response?

Thanks


Replies (8)

Added by Wojciech Kapcia TigaseTeam over 5 years ago

Would it be possible to share mentioned plugin code? or at least the part that handles creation of disco query packet?

Added by Razor Ra over 5 years ago

Yeah sure, I am sending an Iq stanza like this:

Element sendDiscoInfo = createIqQuery("admin@my-tigase-server", "testuser@my-tigaes-server", StanzaType.get, UUID.randomUUID().toString(),  http://jabber.org/protocol/disco#info");

Packet p = Packet.packetInstance(sendDiscoInfo);

queue.offer(p);

and to create an Iq stanza:

public static Element createIqQuery(
          final String from,
          final String to,
          final StanzaType type,
          final String id,
          final String xmlns) 
  {
    Element iq = new Element("iq",
            new String[]{"from", "to", "type", "id"},
            new String[]{from, to, type.toString(), id});

    Element query = new Element("query");

    query.setXMLNS(xmlns);

    iq.addChild(query);

    return iq;

  }

Added by Wojciech Kapcia TigaseTeam over 5 years ago

OK, there is not two packets. Let's go through what happens. You create query (iq, get), it's sent to the client (through c2s component), client responds (iq, result - what you included above), sends the response to the server, the response (as it comes from a client) is processed by c2s and then is routed subsequently to session manager component (session related to the "from" user) and then routed again to session manager (but this time related to "to" user).

Added by Razor Ra over 5 years ago

Thanks for clarifying that.

What I am trying to do is, when I receive the (iq, result) packet, I am performing some particular task.

But in this current scenario, that task is performed twice.

So how can I avoid this situation?

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 5 years ago

Have a look at this guide: http://www.tigase.org/content/how-packets-are-processed-sm-and-plugins

It should explain why your plugins gets some packets twice, hence it is processing them twice. Each time is in a different context. You need a logic to recognize that and take a correct action.

Added by Razor Ra over 5 years ago

After re-reading the guide, what I think is causing the packet to process twice is:

Quote:

The most obvious processing workflow is when a user sends request to the server and expects a response from the server: This design has one surprising consequence though. 
If you look at the picture below showing communication between 2 users you can see that the packet is copied twice before it is delivered to a final destination:
The packet has to be processed twice by the session manager. The first time it is processed on behalf of the User A as an outgoing packet and the second time it is 
processed on behalf of the User B as an incoming packet

Could you please give me some pointers on how to avoid this situation?

Should I filter out all the packets from c2s@my-tigase-server in my plugin and only process the packets I need ?

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 5 years ago

Please have a look at the Message plugin. This is a good example code which takes care of both cases and there is plenty of inline comments explaining this.

Added by Razor Ra over 5 years ago

Thanks, Message plugin solved the problem.

    (1-8/8)