Commit 02b35b47 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

1) Regression test fix.

2) Optimization - removed bottleneck in cluster - removed counter of sessions from cache. Calculated now on demand.
3) Fixed counter of authenticated session to not decrement when non-authenticated session is removed. JM-1095

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8664 b35dd754-fafc-0310-a699-88a17e54d16e
parent 05de80b2
...@@ -243,7 +243,7 @@ public class IQRouter extends BasicModule { ...@@ -243,7 +243,7 @@ public class IQRouter extends BasicModule {
if (recipientJID != null) { if (recipientJID != null) {
if (routingTable.hasComponentRoute(recipientJID) || routingTable.hasServerRoute(recipientJID)) { if (routingTable.hasComponentRoute(recipientJID) || routingTable.hasServerRoute(recipientJID)) {
// A component/service/remote server was found that can handle the Packet // A component/service/remote server was found that can handle the Packet
routingTable.routePacket(recipientJID, packet); routingTable.routePacket(recipientJID, packet, false);
return; return;
} }
} }
...@@ -298,7 +298,7 @@ public class IQRouter extends BasicModule { ...@@ -298,7 +298,7 @@ public class IQRouter extends BasicModule {
} }
else { else {
// JID is of the form <node@domain/resource> // JID is of the form <node@domain/resource>
routingTable.routePacket(recipientJID, packet); routingTable.routePacket(recipientJID, packet, false);
} }
} }
catch (Exception e) { catch (Exception e) {
...@@ -325,7 +325,7 @@ public class IQRouter extends BasicModule { ...@@ -325,7 +325,7 @@ public class IQRouter extends BasicModule {
return; return;
} }
// Route the error packet to the original sender of the IQ. // Route the error packet to the original sender of the IQ.
routingTable.routePacket(reply.getTo(), reply); routingTable.routePacket(reply.getTo(), reply, false);
} }
private IQHandler getHandler(String namespace) { private IQHandler getHandler(String namespace) {
......
...@@ -93,7 +93,7 @@ public class MessageRouter extends BasicModule { ...@@ -93,7 +93,7 @@ public class MessageRouter extends BasicModule {
try { try {
// Deliver stanza to requested route // Deliver stanza to requested route
routingTable.routePacket(recipientJID, packet); routingTable.routePacket(recipientJID, packet, false);
} }
catch (Exception e) { catch (Exception e) {
routingFailed(recipientJID, packet); routingFailed(recipientJID, packet);
...@@ -182,7 +182,7 @@ public class MessageRouter extends BasicModule { ...@@ -182,7 +182,7 @@ public class MessageRouter extends BasicModule {
// If message was sent to an unavailable full JID of a user then retry using the bare JID // If message was sent to an unavailable full JID of a user then retry using the bare JID
if (serverName.equals(receipient.getDomain()) && receipient.getResource() != null && if (serverName.equals(receipient.getDomain()) && receipient.getResource() != null &&
userManager.isRegisteredUser(receipient.getNode())) { userManager.isRegisteredUser(receipient.getNode())) {
routingTable.routePacket(new JID(receipient.toBareJID()), packet); routingTable.routePacket(new JID(receipient.toBareJID()), packet, false);
} else { } else {
// Just store the message offline // Just store the message offline
messageStrategy.storeOffline((Message) packet); messageStrategy.storeOffline((Message) packet);
......
...@@ -133,7 +133,7 @@ public class PresenceRouter extends BasicModule { ...@@ -133,7 +133,7 @@ public class PresenceRouter extends BasicModule {
// Register the sent directed presence // Register the sent directed presence
updateHandler.directedPresenceSent(packet, jid, recipientJID.toString()); updateHandler.directedPresenceSent(packet, jid, recipientJID.toString());
// Route the packet // Route the packet
routingTable.routePacket(jid, packet); routingTable.routePacket(jid, packet, false);
} }
} }
...@@ -148,7 +148,7 @@ public class PresenceRouter extends BasicModule { ...@@ -148,7 +148,7 @@ public class PresenceRouter extends BasicModule {
else if (Presence.Type.probe == type) { else if (Presence.Type.probe == type) {
// Handle a presence probe sent by a remote server // Handle a presence probe sent by a remote server
if (!XMPPServer.getInstance().isLocal(recipientJID)) { if (!XMPPServer.getInstance().isLocal(recipientJID)) {
routingTable.routePacket(recipientJID, packet); routingTable.routePacket(recipientJID, packet, false);
} }
else { else {
// Handle probe to a local user // Handle probe to a local user
...@@ -158,7 +158,7 @@ public class PresenceRouter extends BasicModule { ...@@ -158,7 +158,7 @@ public class PresenceRouter extends BasicModule {
else { else {
// It's an unknown or ERROR type, just deliver it because there's nothing // It's an unknown or ERROR type, just deliver it because there's nothing
// else to do with it // else to do with it
routingTable.routePacket(recipientJID, packet); routingTable.routePacket(recipientJID, packet, false);
} }
} }
......
...@@ -143,10 +143,12 @@ public interface RoutingTable { ...@@ -143,10 +143,12 @@ public interface RoutingTable {
* *
* @param jid the receipient of the packet to route. * @param jid the receipient of the packet to route.
* @param packet the packet to route. * @param packet the packet to route.
* @param fromServer true if the packet was created by the server. This packets should
* always be delivered
* @throws PacketException thrown if the packet is malformed (results in the sender's * @throws PacketException thrown if the packet is malformed (results in the sender's
* session being shutdown). * session being shutdown).
*/ */
void routePacket(JID jid, Packet packet) throws PacketException; void routePacket(JID jid, Packet packet, boolean fromServer) throws PacketException;
/** /**
* Returns true if a registered user or anonymous user with the specified full JID is * Returns true if a registered user or anonymous user with the specified full JID is
......
...@@ -111,7 +111,7 @@ public class IQOfflineMessagesHandler extends IQHandler implements ServerFeature ...@@ -111,7 +111,7 @@ public class IQOfflineMessagesHandler extends IQHandler implements ServerFeature
offlineInfo.addElement("item").addAttribute("node", offlineInfo.addElement("item").addAttribute("node",
dateFormat.format(offlineMessage.getCreationDate())); dateFormat.format(offlineMessage.getCreationDate()));
} }
routingTable.routePacket(receipient, offlineMessage); routingTable.routePacket(receipient, offlineMessage, true);
} }
public IQHandlerInfo getInfo() { public IQHandlerInfo getInfo() {
......
...@@ -155,7 +155,7 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand ...@@ -155,7 +155,7 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
Presence presenteToSend = presence.createCopy(); Presence presenteToSend = presence.createCopy();
// Stamp the presence with the user's bare JID as the 'from' address // Stamp the presence with the user's bare JID as the 'from' address
presenteToSend.setFrom(senderJID.toBareJID()); presenteToSend.setFrom(senderJID.toBareJID());
routingTable.routePacket(jid, presenteToSend); routingTable.routePacket(jid, presenteToSend, false);
} }
} }
else { else {
......
...@@ -443,7 +443,7 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler ...@@ -443,7 +443,7 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler
for (String receiver : directedPresence.getReceivers()) { for (String receiver : directedPresence.getReceivers()) {
Presence presence = update.createCopy(); Presence presence = update.createCopy();
presence.setTo(receiver); presence.setTo(receiver);
routingTable.routePacket(directedPresence.getHandler(), presence); routingTable.routePacket(directedPresence.getHandler(), presence, false);
} }
} }
......
...@@ -181,7 +181,7 @@ public class PacketCopier implements PacketInterceptor, ComponentEventListener { ...@@ -181,7 +181,7 @@ public class PacketCopier implements PacketInterceptor, ComponentEventListener {
childElement.addAttribute("date", dateFormat.format(interceptedPacket.getCreationDate())); childElement.addAttribute("date", dateFormat.format(interceptedPacket.getCreationDate()));
childElement.add(interceptedPacket.getElement().createCopy()); childElement.add(interceptedPacket.getElement().createCopy());
// Send message notification to subscribed component // Send message notification to subscribed component
routingTable.routePacket(message.getTo(), message); routingTable.routePacket(message.getTo(), message, true);
} }
catch (Exception e) { catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e); Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
......
...@@ -40,21 +40,21 @@ public class SocketPacketWriteHandler implements ChannelHandler { ...@@ -40,21 +40,21 @@ public class SocketPacketWriteHandler implements ChannelHandler {
JID recipient = packet.getTo(); JID recipient = packet.getTo();
// Check if the target domain belongs to a remote server or a component // Check if the target domain belongs to a remote server or a component
if (server.matchesComponent(recipient) || server.isRemote(recipient)) { if (server.matchesComponent(recipient) || server.isRemote(recipient)) {
routingTable.routePacket(recipient, packet); routingTable.routePacket(recipient, packet, false);
} }
// The target domain belongs to the local server // The target domain belongs to the local server
else if (recipient == null || (recipient.getNode() == null && recipient.getResource() == null)) { else if (recipient == null || (recipient.getNode() == null && recipient.getResource() == null)) {
// no TO was found so send back the packet to the sender // no TO was found so send back the packet to the sender
routingTable.routePacket(packet.getFrom(), packet); routingTable.routePacket(packet.getFrom(), packet, false);
} }
else if (recipient.getResource() != null || !(packet instanceof Presence)) { else if (recipient.getResource() != null || !(packet instanceof Presence)) {
// JID is of the form <user@domain/resource> // JID is of the form <user@domain/resource>
routingTable.routePacket(recipient, packet); routingTable.routePacket(recipient, packet, false);
} }
else { else {
// JID is of the form <user@domain> // JID is of the form <user@domain>
for (JID route : routingTable.getRoutes(recipient)) { for (JID route : routingTable.getRoutes(recipient)) {
routingTable.routePacket(route, packet); routingTable.routePacket(route, packet, false);
} }
} }
} }
......
...@@ -584,7 +584,7 @@ public class Roster implements Cacheable, Externalizable { ...@@ -584,7 +584,7 @@ public class Roster implements Cacheable, Externalizable {
JID searchNode = new JID(item.getJid().getNode(), item.getJid().getDomain(), null, true); JID searchNode = new JID(item.getJid().getNode(), item.getJid().getDomain(), null, true);
for (JID jid : routingTable.getRoutes(searchNode)) { for (JID jid : routingTable.getRoutes(searchNode)) {
try { try {
routingTable.routePacket(jid, packet); routingTable.routePacket(jid, packet, false);
} }
catch (Exception e) { catch (Exception e) {
// Theoretically only happens if session has been closed. // Theoretically only happens if session has been closed.
...@@ -602,7 +602,7 @@ public class Roster implements Cacheable, Externalizable { ...@@ -602,7 +602,7 @@ public class Roster implements Cacheable, Externalizable {
} }
for (JID jid: routingTable.getRoutes(new JID(contact))) { for (JID jid: routingTable.getRoutes(new JID(contact))) {
try { try {
routingTable.routePacket(jid, packet); routingTable.routePacket(jid, packet, false);
} }
catch (Exception e) { catch (Exception e) {
// Theoretically only happens if session has been closed. // Theoretically only happens if session has been closed.
......
...@@ -716,7 +716,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us ...@@ -716,7 +716,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
else { else {
presence.setType(Presence.Type.unsubscribe); presence.setType(Presence.Type.unsubscribe);
} }
routingTable.routePacket(recipient, presence); routingTable.routePacket(recipient, presence, false);
} }
private Collection<Group> getVisibleGroups(Group groupToCheck) { private Collection<Group> getVisibleGroups(Group groupToCheck) {
......
...@@ -209,7 +209,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler { ...@@ -209,7 +209,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler {
} }
if (created) { if (created) {
// A connection to the remote server was created so get the route and send the packet // A connection to the remote server was created so get the route and send the packet
routingTable.routePacket(packet.getTo(), packet); routingTable.routePacket(packet.getTo(), packet, false);
} }
else { else {
throw new Exception("Failed to create connection to remote server"); throw new Exception("Failed to create connection to remote server");
...@@ -237,7 +237,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler { ...@@ -237,7 +237,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler {
reply.setFrom(to); reply.setFrom(to);
reply.setChildElement(((IQ) packet).getChildElement().createCopy()); reply.setChildElement(((IQ) packet).getChildElement().createCopy());
reply.setError(PacketError.Condition.remote_server_not_found); reply.setError(PacketError.Condition.remote_server_not_found);
routingTable.routePacket(reply.getTo(), reply); routingTable.routePacket(reply.getTo(), reply, true);
} }
else if (packet instanceof Presence) { else if (packet instanceof Presence) {
Presence reply = new Presence(); Presence reply = new Presence();
...@@ -245,7 +245,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler { ...@@ -245,7 +245,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler {
reply.setTo(from); reply.setTo(from);
reply.setFrom(to); reply.setFrom(to);
reply.setError(PacketError.Condition.remote_server_not_found); reply.setError(PacketError.Condition.remote_server_not_found);
routingTable.routePacket(reply.getTo(), reply); routingTable.routePacket(reply.getTo(), reply, true);
} }
else if (packet instanceof Message) { else if (packet instanceof Message) {
Message reply = new Message(); Message reply = new Message();
...@@ -255,7 +255,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler { ...@@ -255,7 +255,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler {
reply.setType(((Message)packet).getType()); reply.setType(((Message)packet).getType());
reply.setThread(((Message)packet).getThread()); reply.setThread(((Message)packet).getThread());
reply.setError(PacketError.Condition.remote_server_not_found); reply.setError(PacketError.Condition.remote_server_not_found);
routingTable.routePacket(reply.getTo(), reply); routingTable.routePacket(reply.getTo(), reply, true);
} }
} }
catch (Exception e) { catch (Exception e) {
......
...@@ -555,7 +555,7 @@ public class LocalOutgoingServerSession extends LocalSession implements Outgoing ...@@ -555,7 +555,7 @@ public class LocalOutgoingServerSession extends LocalSession implements Outgoing
reply.setFrom(packet.getTo()); reply.setFrom(packet.getTo());
reply.setChildElement(((IQ) packet).getChildElement().createCopy()); reply.setChildElement(((IQ) packet).getChildElement().createCopy());
reply.setError(PacketError.Condition.remote_server_not_found); reply.setError(PacketError.Condition.remote_server_not_found);
routingTable.routePacket(reply.getTo(), reply); routingTable.routePacket(reply.getTo(), reply, true);
} }
else if (packet instanceof Presence) { else if (packet instanceof Presence) {
Presence reply = new Presence(); Presence reply = new Presence();
...@@ -563,7 +563,7 @@ public class LocalOutgoingServerSession extends LocalSession implements Outgoing ...@@ -563,7 +563,7 @@ public class LocalOutgoingServerSession extends LocalSession implements Outgoing
reply.setTo(packet.getFrom()); reply.setTo(packet.getFrom());
reply.setFrom(packet.getTo()); reply.setFrom(packet.getTo());
reply.setError(PacketError.Condition.remote_server_not_found); reply.setError(PacketError.Condition.remote_server_not_found);
routingTable.routePacket(reply.getTo(), reply); routingTable.routePacket(reply.getTo(), reply, true);
} }
else if (packet instanceof Message) { else if (packet instanceof Message) {
Message reply = new Message(); Message reply = new Message();
...@@ -573,7 +573,7 @@ public class LocalOutgoingServerSession extends LocalSession implements Outgoing ...@@ -573,7 +573,7 @@ public class LocalOutgoingServerSession extends LocalSession implements Outgoing
reply.setType(((Message)packet).getType()); reply.setType(((Message)packet).getType());
reply.setThread(((Message)packet).getThread()); reply.setThread(((Message)packet).getThread());
reply.setError(PacketError.Condition.remote_server_not_found); reply.setError(PacketError.Condition.remote_server_not_found);
routingTable.routePacket(reply.getTo(), reply); routingTable.routePacket(reply.getTo(), reply, true);
} }
} }
catch (Exception e) { catch (Exception e) {
......
...@@ -397,7 +397,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -397,7 +397,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
presence.setType(Presence.Type.probe); presence.setType(Presence.Type.probe);
presence.setFrom(prober); presence.setFrom(prober);
presence.setTo(probee); presence.setTo(probee);
routingTable.routePacket(probee, presence); routingTable.routePacket(probee, presence, true);
} }
else { else {
// Check if the probee may be hosted by this server // Check if the probee may be hosted by this server
......
...@@ -180,7 +180,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -180,7 +180,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
} }
} }
public void routePacket(JID jid, Packet packet) throws PacketException { public void routePacket(JID jid, Packet packet, boolean fromServer) throws PacketException {
boolean routed = false; boolean routed = false;
if (serverName.equals(jid.getDomain())) { if (serverName.equals(jid.getDomain())) {
if (jid.getResource() == null) { if (jid.getResource() == null) {
...@@ -200,7 +200,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -200,7 +200,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
clientRoute = anonymousUsersCache.get(jid.toString()); clientRoute = anonymousUsersCache.get(jid.toString());
} }
if (clientRoute != null) { if (clientRoute != null) {
if (!clientRoute.isAvailable() && routeOnlyAvailable(packet)) { if (!clientRoute.isAvailable() && routeOnlyAvailable(packet, fromServer)) {
// Packet should only be sent to available sessions and the route is not available // Packet should only be sent to available sessions and the route is not available
routed = false; routed = false;
} }
...@@ -314,9 +314,15 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -314,9 +314,15 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
* Returns true if the specified packet must only be route to available client sessions. * Returns true if the specified packet must only be route to available client sessions.
* *
* @param packet the packet to route. * @param packet the packet to route.
* @param fromServer true if the packet was created by the server.
* @return true if the specified packet must only be route to available client sessions. * @return true if the specified packet must only be route to available client sessions.
*/ */
private boolean routeOnlyAvailable(Packet packet) { private boolean routeOnlyAvailable(Packet packet, boolean fromServer) {
if (fromServer) {
// Packets created by the server (no matter their FROM value) must always be delivered no
// matter the available presence of the user
return false;
}
boolean onlyAvailable = true; boolean onlyAvailable = true;
JID from = packet.getFrom(); JID from = packet.getFrom();
boolean hasSender = from != null; boolean hasSender = from != null;
......
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