Commit a940eeff authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Several fixes (offline delivery with presence priority chage, concurrency...

Several fixes (offline delivery with presence priority chage, concurrency problem & anonymous error when using old iq:auth).

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8648 b35dd754-fafc-0310-a699-88a17e54d16e
parent 6776fb26
...@@ -112,8 +112,9 @@ public interface RoutingTable { ...@@ -112,8 +112,9 @@ public interface RoutingTable {
* *
* @param route the address associated to the route. * @param route the address associated to the route.
* @param destination the client session. * @param destination the client session.
* @return true if route was added to the table or false if already present.
*/ */
void addClientRoute(JID route, LocalClientSession destination); boolean addClientRoute(JID route, LocalClientSession destination);
/** /**
* Routes a packet to the specified address. The packet destination can be a * Routes a packet to the specified address. The packet destination can be a
......
...@@ -500,18 +500,19 @@ public class SessionManager extends BasicModule implements ClusterEventListener ...@@ -500,18 +500,19 @@ public class SessionManager extends BasicModule implements ClusterEventListener
} }
/** /**
* Add a new session to be managed. The session has been authenticated by * Add a new session to be managed. The session has been authenticated and resource
* a non-anonymous user. * binding has been done.
* *
* @param session the session that was authenticated. * @param session the session that was authenticated.
*/ */
public void addSession(LocalClientSession session) { public void addSession(LocalClientSession session) {
// Remove the pre-Authenticated session but remember to use the temporary ID as the key // Remove the pre-Authenticated session but remember to use the temporary ID as the key
localSessionManager.getPreAuthenticatedSessions().remove(session.getStreamID().toString()); localSessionManager.getPreAuthenticatedSessions().remove(session.getStreamID().toString());
// Increment counter of authenticated sessions
incrementCounter("usercounter");
// Add session to the routing table (routing table will know session is not available yet) // Add session to the routing table (routing table will know session is not available yet)
routingTable.addClientRoute(session.getAddress(), session); if (routingTable.addClientRoute(session.getAddress(), session)) {
// Increment counter of authenticated sessions
incrementCounter("usercounter");
}
SessionEventDispatcher.EventType event = session.getAuthToken().isAnonymous() ? SessionEventDispatcher.EventType event = session.getAuthToken().isAnonymous() ?
SessionEventDispatcher.EventType.anonymous_session_created : SessionEventDispatcher.EventType.anonymous_session_created :
SessionEventDispatcher.EventType.session_created; SessionEventDispatcher.EventType.session_created;
...@@ -614,7 +615,7 @@ public class SessionManager extends BasicModule implements ClusterEventListener ...@@ -614,7 +615,7 @@ public class SessionManager extends BasicModule implements ClusterEventListener
return; return;
} }
int newPriority = session.getPresence().getPriority(); int newPriority = session.getPresence().getPriority();
if (newPriority >= 0 && oldPriority < 0) { if (newPriority < 0 || oldPriority >= 0) {
// Do nothing if new presence priority is not positive and old presence negative // Do nothing if new presence priority is not positive and old presence negative
return; return;
} }
......
...@@ -34,6 +34,11 @@ public class AuthToken { ...@@ -34,6 +34,11 @@ public class AuthToken {
this.username = username; this.username = username;
} }
public AuthToken(String username, Boolean anonymous) {
this.username = username;
this.anonymous = anonymous;
}
/** /**
* Returns the username associated with this AuthToken. * Returns the username associated with this AuthToken.
* *
......
...@@ -520,6 +520,9 @@ public class LocalClientSession extends LocalSession implements ClientSession { ...@@ -520,6 +520,9 @@ public class LocalClientSession extends LocalSession implements ClientSession {
String resource = getAddress().getResource(); String resource = getAddress().getResource();
setAddress(new JID(resource, getServerName(), resource, true)); setAddress(new JID(resource, getServerName(), resource, true));
setStatus(Session.STATUS_AUTHENTICATED); setStatus(Session.STATUS_AUTHENTICATED);
if (authToken == null) {
authToken = new AuthToken(resource, true);
}
// Add session to the session manager. The session will be added to the routing table as well // Add session to the session manager. The session will be added to the routing table as well
sessionManager.addSession(this); sessionManager.addSession(this);
} }
......
...@@ -38,9 +38,10 @@ class LocalRoutingTable { ...@@ -38,9 +38,10 @@ class LocalRoutingTable {
* *
* @param address the string representation of the JID associated to the route. * @param address the string representation of the JID associated to the route.
* @param route the route hosted by this node. * @param route the route hosted by this node.
* @return true if the element was added or false if was already present.
*/ */
void addRoute(String address, RoutableChannelHandler route) { boolean addRoute(String address, RoutableChannelHandler route) {
routes.put(address, route); return routes.put(address, route) != route;
} }
/** /**
......
...@@ -20,6 +20,7 @@ import org.jivesoftware.openfire.container.BasicModule; ...@@ -20,6 +20,7 @@ import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.handler.PresenceUpdateHandler; import org.jivesoftware.openfire.handler.PresenceUpdateHandler;
import org.jivesoftware.openfire.server.OutgoingSessionPromise; import org.jivesoftware.openfire.server.OutgoingSessionPromise;
import org.jivesoftware.openfire.session.*; import org.jivesoftware.openfire.session.*;
import org.jivesoftware.util.ConcurrentHashSet;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.cache.Cache; import org.jivesoftware.util.cache.Cache;
...@@ -121,10 +122,10 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -121,10 +122,10 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
} }
} }
public void addClientRoute(JID route, LocalClientSession destination) { public boolean addClientRoute(JID route, LocalClientSession destination) {
String address = destination.getAddress().toString(); String address = destination.getAddress().toString();
boolean available = destination.getPresence().isAvailable(); boolean available = destination.getPresence().isAvailable();
localRoutingTable.addRoute(address, destination); boolean added = localRoutingTable.addRoute(address, destination);
if (destination.getAuthToken().isAnonymous()) { if (destination.getAuthToken().isAnonymous()) {
anonymousUsersCache.put(address, new ClientRoute(server.getNodeID(), available)); anonymousUsersCache.put(address, new ClientRoute(server.getNodeID(), available));
// Add the session to the list of user sessions // Add the session to the list of user sessions
...@@ -148,7 +149,13 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -148,7 +149,13 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
lock.lock(); lock.lock();
Collection<String> jids = usersSessions.get(route.toBareJID()); Collection<String> jids = usersSessions.get(route.toBareJID());
if (jids == null) { if (jids == null) {
jids = new HashSet<String>(); // Optimization - use different class depending on current setup
if (ClusterManager.isClusteringStarted()) {
jids = new HashSet<String>();
}
else {
jids = new ConcurrentHashSet<String>();
}
} }
jids.add(route.toString()); jids.add(route.toString());
usersSessions.put(route.toBareJID(), jids); usersSessions.put(route.toBareJID(), jids);
...@@ -158,6 +165,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -158,6 +165,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
} }
} }
} }
return added;
} }
public void broadcastPacket(Message packet, boolean onlyLocal) { public void broadcastPacket(Message packet, boolean onlyLocal) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment