diff options
author | Uwe Stieber | 2013-04-16 08:56:58 +0000 |
---|---|---|
committer | Uwe Stieber | 2013-04-16 08:57:34 +0000 |
commit | 7a9f26975eaacee164e35122e8e4c27c912da563 (patch) | |
tree | add1bbe5bd7fc212bd4eb5da831dcf3a8520084a | |
parent | ad1f64eecdbb4d4cfa4f574f32ac96d0c8ddc568 (diff) | |
download | org.eclipse.tcf-7a9f26975eaacee164e35122e8e4c27c912da563.tar.gz org.eclipse.tcf-7a9f26975eaacee164e35122e8e4c27c912da563.tar.xz org.eclipse.tcf-7a9f26975eaacee164e35122e8e4c27c912da563.zip |
Target Explorer: Neighborhood node shown for peers already in the tree
2 files changed, 52 insertions, 2 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/LocatorListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/LocatorListener.java index d42e89639..be91fb585 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/LocatorListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/LocatorListener.java @@ -264,7 +264,7 @@ public class LocatorListener implements ILocator.LocatorListener { newId.append(':'); newId.append(ip); newId.append(':'); - newId.append(id.substring(endIndex)); + newId.append(id.substring(endIndex + 1)); // Try the lookup again peerNode = model.getService(ILocatorModelLookupService.class).lkupPeerModelById(newId.toString()); diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java index 6f6fb16ae..285eefcc7 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java @@ -626,10 +626,36 @@ public class LocatorModel extends PlatformObject implements ILocatorModel { } // If the child node is already visible as root node, drop the child node - if (getService(ILocatorModelLookupService.class).lkupPeerModelById(node.getPeerId()) != null) { + String id = node.getPeerId(); + if (isRootNode(id)) { return null; } + int beginIndex = id.indexOf(':'); + int endIndex = id.lastIndexOf(':'); + String ip = beginIndex != -1 && endIndex != -1 ? id.substring(beginIndex+1, endIndex) : ""; //$NON-NLS-1$ + + // Get the loopback address + String loopback = IPAddressUtil.getInstance().getIPv4LoopbackAddress(); + // Empty IP address means loopback + if ("".equals(ip)) ip = loopback; //$NON-NLS-1$ + + // If the IP is a localhost IP, try the loopback IP + if (IPAddressUtil.getInstance().isLocalHost(ip)) { + // Build up the new id to lookup + StringBuilder newId = new StringBuilder(); + newId.append(id.substring(0, beginIndex)); + newId.append(':'); + newId.append(loopback); + newId.append(':'); + newId.append(id.substring(endIndex + 1)); + + // Try the lookup again + if (isRootNode(newId.toString())) { + return null; + } + } + // Get the peer from the peer node IPeer peer = node.getPeer(); @@ -684,6 +710,30 @@ public class LocatorModel extends PlatformObject implements ILocatorModel { } /** + * Checks if the given peer id belongs to an already known root node + * or to one of the discovered nodes. + * + * @param id The peer id. Must not be <code>null</code>. + * @return <code>True</code> if the given id belongs to a root node, <code>false</code> otherwise. + */ + private boolean isRootNode(String id) { + Assert.isNotNull(id); + + boolean isRoot = false; + + if (getService(ILocatorModelLookupService.class).lkupPeerModelById(id) != null) { + isRoot = true; + } else { + Map<String, IPeer> peers = Protocol.getLocator().getPeers(); + if (peers.containsKey(id)) { + isRoot = true; + } + } + + return isRoot; + } + + /** * Fire the model listener for the given peer model. * * @param peer The peer model. Must not be <code>null</code>. |