XMPP server-to-server - traffic optimization? - xmpp

I'm working on a design for a xmpp chat solution which involves some servers and where at least one server is connected with serious bandwidth limitations.
Assuming, we have two servers A and B, some users 0..n connected to Server A and some conferences 0..m provided by Server B.
Now assume, some users enter a conference room and a message is sent to that room. Will
Server B send this message once to
Server A and Server A distributes it
to the users or will
Server B send this message to each individual user of Server A?

According to the protocol spec, XEP 045, multi-user chat messages are reflected independently to each participant. I can't tell on a brief read if it is legal to send them server-to-server without reflecting. However, it might be worth asking this question on an xmpp.org mailing list, where the experts tend to hang out.

Related

Delivering messages to offline users in a multi-user chat (ejabberd)

Actually we are using ejabberd server for one of our client's Chat application. Everything is working well except for Group chat.
We are using MUC for Group chat but it is not sending Messages to the member whenever uses is offline. Is there any alternative plugin or something where we can make that working?
Or any one can suggest about how to receive offline messages for that user from Group chat history.
Thanks in advance
That's because there's no such concept for multi-user chat rooms. In fact, if you'll think about this a bit more you'll understand why:
Potentially unbound number of participants might be present in a room at any given time.
So exactly for which users not currently present in the MUC room should the server store the messages in the offline storage? I mean, in the generic case, the server does not know all the users who could ever possibly chat in a given room it hosts.
(Well, if this would be the only problem, it could possibly work for members-only rooms, I must admit.)
MUC rooms are not "local server only": a potentially unbound number of users from any number of other servers might join the room, and messages to those users will be delivered by routing them via their respective servers.
Obviously, this is another reason why such an idea of "MUC room offline storage" has no sense.
MUC rooms are by definition transient: when a user is offline, they're not in any room— (re-)joninig a room is an explicit action.
This is in fact the most important reason for not supporting offline storage.
As you can see, XMPP MUC rooms are much like IRC chats on steroids.
So what you really want is "room history"—a part of the XMPP-0045 extension which allows the client to explicitly ask the room for the message history they missed. In a sense, instead of storing offline message for each user, the room might be configured to store just a certain number of the most recent messages sent to it (or all such messages for a given period of time). Then the room supports querying these messages by the joined users.
There's another possibility which you might explore: "multicast addressing" of XEP-0033 ("Extended stanza addressing"). Basically it allows a client to use a special multicast service to send their message to multiple recipients at once. The upside is that offline storage is there again. The downside is that I doubt such a multicast service is supported out of the box in ejabberd, and it seems like that extension leaves much details about how it could be implemented unspecified.
I faced your issue as I sought to implement groupchats for my chatting app. I faced the same problem of MUC not storing offline messages for each recipient. And I did not want to retrieve MUC history which requires the user to rejoin every MUC to update his messages database. What I wanted is for the server to save offline messages by recipient, and for the recipient to get all MUC messages when he gets online (without having to join each MUC).
The way I did it is through pubsub. Using pubsub will force the server to store offline message per recipient. When the user reconnects, he gets all the offline messages including the pubsub messages which are sent as normal messages - that is it. One issue I had with pubsub over MUC though is that it is hard to get the list of subscribers. So when my app creates a groupchat, it creates a pubsub node for messages, invite all participants to subscribe (including self) to the pubsub and my app also creates a MUC and makes every participant an owner of that MUC. This way the list of the groupchat participants can be retrieved by checking the list of owners of the MUC. The only purposes of the MUC are to hold the list of participants as well as the name of the groupchat. Everything else is handled by the pubsub node.
Anything unclear please let me know.
ADDITIONAL DETAILS:
Essentially when the user wants to create a groupchat, our app creates a pubsub node as well as a MUC. You need to be familiar with both concepts. For the pubsub node, you need to set an option to allow any subscriber to post. When a user sends a message, he actually publishes on the node, and ejabberd will send the message to all subscribers as if it were a regular message (except it comes from pubsub.yourdomain.com). Therefore if a recipient is offline, ejabberd will store this message as any other regular message.
This is not how ejabberd handles MUC messages. Those are only sent to people CURRENTLY in the chatroom. History of messages can be stored by ejabberd however, but for a recipient to get the history he will need to join the MUC. Which means that everytime the app reconnects, it would have to join all the user's existing MUCs. We found this was not practical.
We also use a MUC for the same groupchat, but this is only to store participants so that a user can get the list at any time (no way to do it with pubsub).
An additional benefit of using pubsub over MUC is that the way ejabberd stores pubsub data is way more efficient. I have not studied this in depth, but I expect much better performance from pubsub.
New ejabberd server at 16.09 version have improvements for multi-user chat - MUC Sub:
The goal of MUC Sub is to try to rely as much as possible on existing MUC specification, while making the smallest possible change that make mobile group conversation client easy.
The feature is enabled by default. To use it, just make sure you set the new parameter “Allow subscription” in the room on which you want to use it.
Here is link to documentation: https://docs.ejabberd.im/developer/proposed-extensions/muc-sub/
More info here: https://blog.process-one.net/xmpp-mobile-groupchat-introducing-muc-subscription/

jabber-net and vysper message broadcast facility

I have establish chat communication between two users using jabber-net xmpp client and vysper server by apache.
I am looking for broadcast facility using the same.
There are different mechanisms for "broadcasting", a word which I understand as "sending one message which is distributed by the server to many receivers".
When a user changes his "status" (for example "do not disturb me - I'm coding") a so call "presence" message is sent out which is distributed to all his contacts. This is a broadcast, and presence messages are intended to do that in XMPP.
There is at least another popular possibility: multi-user chat ("MUC"). MUC has the notion of "rooms", where users can "enter" to become part of a "conversation". Every message sent by one of the participants is sent to all others.
There are more similar mechanisms available, depending on what you actually want to do.

Sharing Jabber chat session between multiple clients

I'm using Jitsi on client side and ejabberd on server.
It seems that the chat sessions are specific to clients, i.e. if I'm logged in to the same account from 2 different clients, there will be 2 separate sessions, and one can't see what's happening in another.
Is it possible to share the sessions for the same account on all clients? Like Skype or GTalk.
If yes, is it a server configuration or client?
Thank you.
I think what you're looking for is XEP-0280 Message Carbons. Basically the server takes care of relaying the chat to all of your online resources so that you have the same chat session across all devices.
You even get chatstates from all of your other resources so you can infer whether or not you should show an unread IM notification to the user on your resource or not. You'll need client and server support for this, and it looks like ejabberd has implemented it via this module.

How does Google Talk replicate messages across devices?

I'm wondering how (official) GTalk clients manage to show all messages received - even if it was originally consumed by another client. For example: I'm logged into GTalk on gmail.com on my laptop and, at the same time, via the official GTalk app on my Android device. A friend sends me a message, which is displayed on both the gmail.com client and the Android client. (I think it's originally only forwarded to one of either clients, but the second client fetches the message later on)
I recently found out that there's a very similar XMPP feature, called Carbons. However, after a quick service discovery request Google's servers didn't advertise this feature. XEP-0313 and XEP-0136 look good too, but the servers don't advertise them either.
Possibly related question: Deliver Google Talk message to all logged in clients using XMPPPY
When you initiate a new chat then you should send the first message to the users bare Jid. This is what most clients are doing. When the GTalk server retrieves a chat message to a bare Jid it routes the message to all available resources. For all following messages in this conversation the clients normally pick up the Resource and send them to full Jids. The messages should not be replicated then.
Many other servers don't route message to bare Jids to all resources, but to the most available resource which is the client with the highest priority.
Here is a quote form the RFC:
If there is more than one resource with a non-negative presence priority then the
server MUST either
(a) deliver the message to the "most available" resource or
resources (according to the server's implementation-specific algorithm, e.g., treating
the resource or resources with the highest presence priority as "most available") or
(b) deliver the message to all of the non-negative resources.
XEP-0280 defines this. As I understand, it defines the mechanism to notify all the resources from same user when one of them sends a message to anyone. I mean, Alice/pda sends a message to Bob, so Alice/mobile and Alice/PC will receive a copy of the message sent be Alice/pda.
Hope it helps. I am currently looking for a server that implements this, and also for a client library. If not, I will implement it by myself in both jabberd2 and gloox xmpp library.
Cheers,

Send XMPP message without starting a chat

I am basically writing a XMPP client to automatically reply to "specific" chat messages.
My setup is like this:
I have pidgin running on my machine configured to run with an account x#xyz.com.
I have my own jabber client configured to run with the same account x#xyz.com.
There could be other XMPP clients .
Here is my requirement:
I am trying to automate certain kind of messages that I receive on gtalk. So whenever I receive a specific message eg: "How are you" , my own XMPP client should reply automatically with say "fine". How are you". All messages sent (before and after my client replies) to x#xyz.com but should be received by all clients (my own client does not have a UI and can only respond to specific messages.).
Now I have already coded my client to reply automatically. This works fine. But the problem I am facing is that as soon as I reply (I use the smack library), all subsequent messages that are sent to x#xyz.com are received only by my XMPP client. This is obviously a problem as my own client is quite dump and does not have a UI, so I don't get to see the rest of the messages sent to me, thereby making me "lose" messages.
I have observed the same behavior with other XMPP clients as well. Now the question is, is this is a requirement of XMPP (I am sorry but I haven't read XMPP protocol too well). Is it possible to code an XMPP client to send a reply to a user and still be able to receive all subsequent messages in all clients currently listening for messages? Making my client a full fledged XMPP client is a solution, but I don't want to go that route.
I hope my question is clear.
You may have to set a negative presence priority for your bot..
First thing to know is that in XMPP protocol every client is supposed to have a full JID. This is a bare JID - in your case x#xyz.com with a resource in the end e.g. x#xyz.com/pidgin or x#xyz.com/home (where /pidgin and /home are the resource). This is a part of how routing messages to different clients is supposed to be achieved.
Then there are the presence stanzas. When going online a client usually sends a presence stanza to the server. This informs about e.g. if the client is available for chat or away for lunch. Along with this information can be sent a priority. When there are more than one clients connected the one with the highest priority will receive the messages sent to the bare JID (e.g. ClientA(prio=50) and ClientB(prio=60) -> ClientB receives the messages sent to x#xyz.com). But there are also negative priorities. A priority less than 0 states that this client should never be sent any messages. Such a stanza might look like this
<presence from="x#xyz.com/bot">
<priority>-1</priority>
</presence>
This may fit your case. Please keep in mind it also depends on the XMPP server where your account is located, which may or may have not fully implemented this part of the protocol.
So to summarize: I recommend you to look through the Smack API how to set a presence and set the priority to <0 for your bot client right after it connected.