Commit 36c95744 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

More fixes in routing based on availability.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8527 b35dd754-fafc-0310-a699-88a17e54d16e
parent 86250e68
...@@ -173,11 +173,6 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -173,11 +173,6 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
public void routePacket(JID jid, Packet packet) throws PacketException { public void routePacket(JID jid, Packet packet) throws PacketException {
boolean routed = false; boolean routed = false;
JID address = packet.getTo();
if (address == null) {
throw new PacketException("To address cannot be null.");
}
if (serverName.equals(jid.getDomain())) { if (serverName.equals(jid.getDomain())) {
if (jid.getResource() == null) { if (jid.getResource() == null) {
// Packet sent to a bare JID of a user // Packet sent to a bare JID of a user
...@@ -191,22 +186,12 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -191,22 +186,12 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
} }
else { else {
// Packet sent to local user (full JID) // Packet sent to local user (full JID)
boolean onlyAvailable = true;
if (packet instanceof IQ) {
onlyAvailable = packet.getFrom() != null && !serverName.equals(packet.getFrom().toString());
}
else if (packet instanceof Message) {
onlyAvailable = packet.getFrom() == null || !serverName.equals(packet.getFrom().toString());
}
else if (packet instanceof Presence) {
onlyAvailable = packet.getFrom() == null || !serverName.equals(packet.getFrom().toString());
}
ClientRoute clientRoute = usersCache.get(jid.toString()); ClientRoute clientRoute = usersCache.get(jid.toString());
if (clientRoute == null) { if (clientRoute == null) {
clientRoute = anonymousUsersCache.get(jid.toString()); clientRoute = anonymousUsersCache.get(jid.toString());
} }
if (clientRoute != null) { if (clientRoute != null) {
if (onlyAvailable && !clientRoute.isAvailable()) { if (!clientRoute.isAvailable() && routeOnlyAvailable(packet)) {
// 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;
} }
...@@ -316,6 +301,31 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -316,6 +301,31 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
} }
} }
/**
* Returns true if the specified packet must only be route to available client sessions.
*
* @param packet the packet to route.
* @return true if the specified packet must only be route to available client sessions.
*/
private boolean routeOnlyAvailable(Packet packet) {
boolean onlyAvailable = true;
JID from = packet.getFrom();
boolean hasSender = from != null;
if (packet instanceof IQ) {
onlyAvailable = hasSender && !(serverName.equals(from.getDomain()) && from.getResource() == null) &&
!componentsCache.containsKey(from.toString());
}
else if (packet instanceof Message) {
onlyAvailable = !hasSender ||
(!serverName.equals(from.toString()) && !componentsCache.containsKey(from.toString()));
}
else if (packet instanceof Presence) {
onlyAvailable = !hasSender ||
(!serverName.equals(from.toString()) && !componentsCache.containsKey(from.toString()));
}
return onlyAvailable;
}
/** /**
* Deliver the message sent to the bare JID of a local user to the best connected resource. If the * Deliver the message sent to the bare JID of a local user to the best connected resource. If the
* target user is not online then messages will be stored offline according to the offline strategy. * target user is not online then messages will be stored offline according to the offline strategy.
......
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