Project

General

Profile

Plugin for limiting the number of sessions..

Steffen Larsen
Added almost 5 years ago

Hi,

I am trying to develop a plugin that can take a given number of session pr JID and limiting below that. If another JID (with a given resrouce) try to connect, the first lived session should disconnect.

So for example, if a user with a JID connects two time (test@test.tld/1, test@test.tld/2), everything is fine. If he connects the third time, the plugin should remove the first one connected (test@test.tld/1) and let the third one in.

Where is it the most optimal place to code this? to extend the XMPPProcessor or? Of course I want to do this as early as possible in the "pipeline" as possible

-Cheers!

/Steffen


Replies (7)

Added by Wojciech Kapcia TigaseTeam almost 5 years ago

Yes, extending XMPPProcessor would be the most optimal option that would use provided APIs.

Added by Steffen Larsen almost 5 years ago

Thanks. I've already done the plugin, but just asking to be 100% sure about my assumptions. :-)

-Cheers!

/Steffen

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam almost 5 years ago

I would extend or modify resource bind plugin. This is where we disconnect old user's connection with the same resource.

However, to be honest I think a correct solution to this is different. I mean your approach is correct because you use existing API and achieving what you need is possible through plugins only. When I thought about implementing connections number limit in Tigase I thought of making it a built-in feature. In XMPPSession there is a method: addResourceConnection which takes care of the connections with the same resource and executes disconnection for old connections with the same resource. This method could also take care of a connections number limit.

Added by Steffen Larsen almost 5 years ago

Hi Artur,

Yes you are right, prob. the most optimal way would be to change the XMPPSession method that does the resource/bind process. But that leads to many changes that are within Tigase, so for now I have done it in a seperate plugin that can be installed and de-installed from the customer side (because its a plugin for a customer).

I might just do the proper implementation in XMPPSession where you can set the options (like the limit, vhost etc.) in the init.properties file. But if I do that I can hopefully give you guys a patch, so you can get it into mainline of git. Otherwise the XMPPsession will be obsoleted the next time Tigase server is bumped in version. :-)

-Cheers!

/Steffen

Added by Pratap Patil over 4 years ago

Where do I find this plugin and how do I install it?

Thanks,

Pratap

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 4 years ago

Pratap, I am afraid we do not have such a plugin yet. Right now Tigase allows for unlimited number of users connection. As discussed above, however, it should be quite easy to implement such a plugin.

Added by Steffen Larsen over 4 years ago

Yes. A simple but not the most effective example could be to implement it like a simple processor plugin, something like this:

public class SessionHandlerPlugin extends XMPPProcessor implements XMPPProcessorIfc {
..
..
   public void process(Packet packet, XMPPResourceConnection session, NonAuthUserRepository repo, Queue<Packet> qPacket, Map<String, Object> args) throws XMPPException {
      //get the sessions
      List<XMPPResourceConnection> activeSessions = session.getActiveSessions();
      if (activeSessions.size() > threshold) {
         // do stuff!.. disconnect this session etc.
      }
   }

   // this will catch only the presence that are initially sent.
   public String[] supElements() {
      return new String[] { "presence" };
   }

   public String[] supNamespaces() {
      return new String[] { "jabber:client" };
   }
}

In this way you can plug and unplug the plugin. But like we stated earlier, changing the XMPPSession method that does the resource and bind process would be better and more effective.

    (1-7/7)