Commit 8e3a0b3d authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Fixed loss of routes when using anonymous users. JM-95


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@766 b35dd754-fafc-0310-a699-88a17e54d16e
parent f2600087
...@@ -47,14 +47,13 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable { ...@@ -47,14 +47,13 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable {
public ChannelHandler addRoute(JID node, RoutableChannelHandler destination) { public ChannelHandler addRoute(JID node, RoutableChannelHandler destination) {
ChannelHandler route = null; ChannelHandler route = null;
String nodeJID = node.getNode() == null ? "" : node.getNode();
String resourceJID = node.getResource() == null ? "" : node.getResource();
routeLock.writeLock().lock(); routeLock.writeLock().lock();
try { try {
if (node.getNode() == null) { if (routes.isEmpty()) {
Object item = routes.put(node.getDomain(), destination); routes.put(node.getDomain(), destination);
if (item instanceof ChannelHandler) {
route = (ChannelHandler)item;
}
} }
else { else {
Object nameRoutes = routes.get(node.getDomain()); Object nameRoutes = routes.get(node.getDomain());
...@@ -62,29 +61,21 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable { ...@@ -62,29 +61,21 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable {
nameRoutes = new Hashtable(); nameRoutes = new Hashtable();
routes.put(node.getDomain(), nameRoutes); routes.put(node.getDomain(), nameRoutes);
} }
if (node.getResource() == null) { if (((Hashtable)nameRoutes).isEmpty()) {
Object item = ((Hashtable)nameRoutes).put(node.getNode(), ((Hashtable)nameRoutes).put(nodeJID, destination);
destination);
if (item instanceof ChannelHandler) {
route = (ChannelHandler)item;
}
} }
else { else {
Object resourceRoutes = Object resourceRoutes = ((Hashtable)nameRoutes).get(nodeJID);
((Hashtable)nameRoutes).get(node.getNode()); if (resourceRoutes == null || resourceRoutes instanceof ChannelHandler) {
if (resourceRoutes == null
|| resourceRoutes instanceof ChannelHandler) {
resourceRoutes = new Hashtable(); resourceRoutes = new Hashtable();
Object item = ((Hashtable)nameRoutes).put(node.getNode(), Object item = ((Hashtable)nameRoutes).put(nodeJID, resourceRoutes);
resourceRoutes);
if (item instanceof ChannelHandler) { if (item instanceof ChannelHandler) {
// Associate the previous Route with the bare JID // Associate the previous Route with the bare JID
((Hashtable)resourceRoutes).put("", item); ((Hashtable)resourceRoutes).put("", item);
} }
} }
Object resourceRoute = Object resourceRoute =
((Hashtable)resourceRoutes).put(node.getResource(), ((Hashtable)resourceRoutes).put(resourceJID, destination);
destination);
if (resourceRoute != null) { if (resourceRoute != null) {
if (resourceRoute instanceof ChannelHandler) { if (resourceRoute instanceof ChannelHandler) {
route = (ChannelHandler)resourceRoute; route = (ChannelHandler)resourceRoute;
...@@ -102,6 +93,9 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable { ...@@ -102,6 +93,9 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable {
public RoutableChannelHandler getRoute(JID node) throws NoSuchRouteException { public RoutableChannelHandler getRoute(JID node) throws NoSuchRouteException {
RoutableChannelHandler route = null; RoutableChannelHandler route = null;
String nodeJID = node.getNode() == null ? "" : node.getNode();
String resourceJID = node.getResource() == null ? "" : node.getResource();
routeLock.readLock().lock(); routeLock.readLock().lock();
try { try {
Object nameRoutes = routes.get(node.getDomain()); Object nameRoutes = routes.get(node.getDomain());
...@@ -109,13 +103,12 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable { ...@@ -109,13 +103,12 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable {
route = (RoutableChannelHandler)nameRoutes; route = (RoutableChannelHandler)nameRoutes;
} }
else { else {
Object resourceRoutes = ((Hashtable)nameRoutes).get(node.getNode()); Object resourceRoutes = ((Hashtable)nameRoutes).get(nodeJID);
if (resourceRoutes instanceof ChannelHandler) { if (resourceRoutes instanceof ChannelHandler) {
route = (RoutableChannelHandler)resourceRoutes; route = (RoutableChannelHandler)resourceRoutes;
} }
else if (resourceRoutes != null) { else if (resourceRoutes != null) {
String resource = node.getResource() == null ? "" : node.getResource(); route = (RoutableChannelHandler) ((Hashtable)resourceRoutes).get(resourceJID);
route = (RoutableChannelHandler) ((Hashtable)resourceRoutes).get(resource);
} }
else { else {
throw new NoSuchRouteException(node.toString()); throw new NoSuchRouteException(node.toString());
...@@ -235,43 +228,36 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable { ...@@ -235,43 +228,36 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable {
public ChannelHandler removeRoute(JID node) { public ChannelHandler removeRoute(JID node) {
ChannelHandler route = null; ChannelHandler route = null;
String nodeJID = node.getNode() == null ? "" : node.getNode();
String resourceJID = node.getResource() == null ? "" : node.getResource();
routeLock.writeLock().lock(); routeLock.writeLock().lock();
//System.err.println("Remove route " + node.toString());
try { try {
if (node.getNode() == null) { Object nameRoutes = routes.get(node.getDomain());
// Chop off all hosted names for this domain if (nameRoutes instanceof Hashtable) {
Object item = routes.remove(node.getDomain()); Object resourceRoutes = ((Hashtable)nameRoutes).get(nodeJID);
if (item instanceof ChannelHandler) { if (resourceRoutes instanceof Hashtable) {
route = (ChannelHandler)item; // Remove the requested resource for this user
} route = (ChannelHandler) ((Hashtable)resourceRoutes).remove(resourceJID);
} if (((Hashtable)resourceRoutes).isEmpty()) {
else { ((Hashtable)nameRoutes).remove(nodeJID);
Object nameRoutes = routes.get(node.getDomain()); if (((Hashtable)nameRoutes).isEmpty()) {
if (nameRoutes instanceof Hashtable) { routes.remove(node.getDomain());
if (node.getResource() == null || node.getResource().trim().length() == 0) {
// Chop off all hosted resources for the given name
Object item = ((Hashtable)nameRoutes).remove(node.getNode());
if (item instanceof ChannelHandler) {
route = (ChannelHandler)item;
}
}
else {
Object resourceRoutes =
((Hashtable)nameRoutes).get(node.getNode());
if (resourceRoutes instanceof Hashtable) {
route = (ChannelHandler)
((Hashtable)resourceRoutes).remove(node.getResource());
if (((Hashtable)resourceRoutes).isEmpty()) {
((Hashtable)nameRoutes).remove(node.getNode());
if (((Hashtable)nameRoutes).isEmpty()) {
routes.remove(node.getDomain());
}
}
} }
} }
} }
else {
// Remove the unique route to this node
((Hashtable)nameRoutes).remove(nodeJID);
}
}
else {
// The retrieved route points to a RoutableChannelHandler
if (((RoutableChannelHandler)nameRoutes).getAddress().equals(node)) {
// Remove the route to this domain
routes.remove(node.getDomain());
}
} }
} }
catch (Exception e) { catch (Exception e) {
......
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