Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreutarass2011-06-04 01:05:49 +0000
committereutarass2011-06-04 01:05:49 +0000
commitcad9f08c15c6ca56b74d98b6e291cfafecbd5815 (patch)
tree53bee3abaf00d965f798258554ba6403c915c7bf
parentfae8eeff08bde9128e4e3379db67a34e3c9dbfc8 (diff)
downloadorg.eclipse.tcf-cad9f08c15c6ca56b74d98b6e291cfafecbd5815.tar.gz
org.eclipse.tcf-cad9f08c15c6ca56b74d98b6e291cfafecbd5815.tar.xz
org.eclipse.tcf-cad9f08c15c6ca56b74d98b6e291cfafecbd5815.zip
Bug 331819 - Peers not removed when Channels are reset.
-rw-r--r--docs/TCF_UDP_Discovery.html25
-rw-r--r--plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/LocatorService.java144
-rw-r--r--plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/services/ILocator.java3
3 files changed, 112 insertions, 60 deletions
diff --git a/docs/TCF_UDP_Discovery.html b/docs/TCF_UDP_Discovery.html
index 931592e36..f8ab338fb 100644
--- a/docs/TCF_UDP_Discovery.html
+++ b/docs/TCF_UDP_Discovery.html
@@ -16,7 +16,7 @@ Designed by Eugene Tarassov (eugene.tarassov@windriver.com)<br>
Documented by John Cortell (john.cortell@freescale.com)<br>
<br>
Created on: December 5, 2009<br>
-Last modified on: June 24, 2010<br>
+Last modified on: June 03, 2011<br>
<h3>Overview</h3>
@@ -139,12 +139,14 @@ The following are the TCF UDP Discovey <i>Rules of Engagement. </i>Unless explic
<li>
tell the new slave about all known peers and slaves
</li>
- </ul>
- <ul>
<li>
advertise the new slave to all slaves that have sent CONF_REQ_SLAVES to this agent within the last X seconds (retention period)
</li>
</ul>
+ <li>
+ <p>
+ On shutdown, agent may broadcast CONF_PEERS_REMOVED to all local networks and known slaves.
+ </li>
</ol>
<h3>UDP Packets</h3>
@@ -174,6 +176,9 @@ All TCF discovery UDP packets have an eight byte header:
<li>
4 = CONF_SLAVES_INFO<br>
</li>
+ <li>
+ 5 = CONF_PEERS_REMOVED<br>
+ </li>
</ul>
<li>
bytes 5-7 are reserved for future use<br>
@@ -218,6 +223,12 @@ This indicates knowledge of a TCF slave agent running at 192.168.0.1, listening
<br>
Multiple such descriptions can appear in a CONF_SLAVES_INFO packet. Agents should take care to not send excessively large UDP packets, though.
The TCF reference implementation keeps packets under 1500 bytes. Agents should split large tables across multiple UDP packets.
+<dt>
+CONF_PEERS_REMOVED
+<dd>
+This is a packet which notifies removal of peers. When an agent is about to exit, it may send the packet to notify others about removing of peers that the agent implements.
+This allows other agents to remove stale peer info right away instead of waiting until the data become expired. Following the eight-byte header, this packet contains
+sequence of zero-terminated peer IDs.
</dd>
<h3>Timing</h3>
@@ -308,6 +319,14 @@ An agent should check and ignore any packets it has sent.
UDP_REQ_SLAVES
</td>
</tr>
+ <tr>
+ <td width=50%>
+ CONF_PEERS_REMOVED
+ </td>
+ <td width=50%>
+ UDP_PEERS_REMOVED
+ </td>
+ </tr>
</tbody>
</table>
diff --git a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/LocatorService.java b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/LocatorService.java
index 0a2cb24b3..627b4628d 100644
--- a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/LocatorService.java
+++ b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/LocatorService.java
@@ -289,7 +289,7 @@ public class LocatorService implements ILocator {
});
}
catch (IllegalStateException x) {
- // TCF event dispatch is shutdown
+ // TCF event dispatch is shut down
return;
}
catch (Exception x) {
@@ -747,7 +747,8 @@ public class LocatorService implements ILocator {
"CONF_REQ_INFO",
"CONF_PEER_INFO",
"CONF_REQ_SLAVES",
- "CONF_SLAVES_INFO"
+ "CONF_SLAVES_INFO",
+ "CONF_PEER_REMOVE"
};
private boolean sendDatagramPacket(SubNet subnet, int size, InetAddress addr, int port) {
@@ -765,8 +766,10 @@ public class LocatorService implements ILocator {
if (TRACE_DISCOVERY) {
Map<String,String> map = null;
- if (out_buf[4] == CONF_PEER_INFO) {
- parsePeerAtrributes(out_buf, 8);
+ switch (out_buf[4]) {
+ case CONF_PEER_INFO: map = parsePeerAtrributes(out_buf, size); break;
+ case CONF_SLAVES_INFO: map = parseIDs(out_buf, size); break;
+ case CONF_PEERS_REMOVED: map = parseIDs(out_buf, size); break;
}
traceDiscoveryPacket(false, packetTypes[out_buf[4]], map, addr, port);
}
@@ -779,12 +782,10 @@ public class LocatorService implements ILocator {
}
/**
- * Parse peer attributes in CONF_INFO_PEER packet data
+ * Parse peer attributes in CONF_PEER_INFO packet data.
*
- * @param data
- * the packet section that contain the peer attributes
- * @param size
- * the number of bytes in [data] that contain peer attributes
+ * @param data - the packet data
+ * @param size - the packet size
* @return a map containing the attributes
* @throws UnsupportedEncodingException
*/
@@ -809,6 +810,32 @@ public class LocatorService implements ILocator {
return map;
}
+ /**
+ * Parse list of IDs in CONF_SLAVES_INFO and CONF_PEERS_REMOVED packet data.
+ *
+ * @param data - the packet data
+ * @param size - the packet size
+ * @return a map containing the IDs
+ * @throws UnsupportedEncodingException
+ */
+ private static Map<String,String> parseIDs(byte[] data, int size) throws UnsupportedEncodingException {
+ int cnt = 0;
+ Map<String,String> map = new HashMap<String,String>();
+ String s = new String(data, 8, size - 8, "UTF-8");
+ int l = s.length();
+ int i = 0;
+ while (i < l) {
+ int i0 = i;
+ while (i < l && s.charAt(i) != 0) i++;
+ if (i > i0) {
+ String id = s.substring(i0, i);
+ map.put(Integer.toString(cnt++), id);
+ }
+ while (i < l && s.charAt(i) == 0) i++;
+ }
+ return map;
+ }
+
private void sendPeersRequest(InetAddress addr, int port) {
out_buf[4] = CONF_REQ_INFO;
for (SubNet subnet : subnets) {
@@ -939,35 +966,40 @@ public class LocatorService implements ILocator {
int remote_port = p.getPort();
InetAddress remote_address = p.getAddress();
if (isRemote(remote_address, remote_port)) {
- Slave sl = null;
- if (remote_port != DISCOVEY_PORT) {
- sl = addSlave(remote_address, remote_port, time, time);
- }
- switch (buf[4]) {
- case CONF_PEER_INFO:
- handlePeerInfoPacket(p);
- break;
- case CONF_REQ_INFO:
- handleReqInfoPacket(p, sl, time);
- break;
- case CONF_SLAVES_INFO:
- handleSlavesInfoPacket(p, time);
- break;
- case CONF_REQ_SLAVES:
- handleReqSlavesPacket(p, sl, time);
- break;
+ if (buf[4] == CONF_PEERS_REMOVED) {
+ handlePeerRemovedPacket(p);
}
- for (SubNet subnet : subnets) {
- if (!subnet.contains(remote_address)) continue;
- long delay = DATA_RETENTION_PERIOD / 3;
- if (remote_port != DISCOVEY_PORT) delay = DATA_RETENTION_PERIOD / 3 * 2;
- else if (!subnet.address.equals(remote_address)) delay = DATA_RETENTION_PERIOD / 2;
- if (subnet.last_slaves_req_time + delay <= time) {
- sendSlavesRequest(subnet, remote_address, remote_port);
- subnet.last_slaves_req_time = time;
+ else {
+ Slave sl = null;
+ if (remote_port != DISCOVEY_PORT) {
+ sl = addSlave(remote_address, remote_port, time, time);
}
- if (subnet.address.equals(remote_address) && remote_port == DISCOVEY_PORT) {
- last_master_packet_time = time;
+ switch (buf[4]) {
+ case CONF_PEER_INFO:
+ handlePeerInfoPacket(p);
+ break;
+ case CONF_REQ_INFO:
+ handleReqInfoPacket(p, sl, time);
+ break;
+ case CONF_SLAVES_INFO:
+ handleSlavesInfoPacket(p, time);
+ break;
+ case CONF_REQ_SLAVES:
+ handleReqSlavesPacket(p, sl, time);
+ break;
+ }
+ for (SubNet subnet : subnets) {
+ if (!subnet.contains(remote_address)) continue;
+ long delay = DATA_RETENTION_PERIOD / 3;
+ if (remote_port != DISCOVEY_PORT) delay = DATA_RETENTION_PERIOD / 3 * 2;
+ else if (!subnet.address.equals(remote_address)) delay = DATA_RETENTION_PERIOD / 2;
+ if (subnet.last_slaves_req_time + delay <= time) {
+ sendSlavesRequest(subnet, remote_address, remote_port);
+ subnet.last_slaves_req_time = time;
+ }
+ if (subnet.address.equals(remote_address) && remote_port == DISCOVEY_PORT) {
+ last_master_packet_time = time;
+ }
}
}
}
@@ -1021,16 +1053,11 @@ public class LocatorService implements ILocator {
private void handleSlavesInfoPacket(InputPacket p, long time_now) {
try {
- Map<String,String> trace_map = null; // used for tracing only
- int slave_index = 0; // used for tracing only
- if (TRACE_DISCOVERY) {
- trace_map = new HashMap<String,String>(3);
- }
-
- String s = new String(p.getData(), 8, p.getLength() - 8, "UTF-8");
- int l = s.length();
- int i = 0;
- while (i < l) {
+ Map<String,String> map = parseIDs(p.getData(), p.getLength());
+ if (TRACE_DISCOVERY) traceDiscoveryPacket(true, "CONF_SLAVES_INFO", map, p);
+ for (String s : map.values()) {
+ int i = 0;
+ int l = s.length();
int time0 = i;
while (i < l&& s.charAt(i) != ':' && s.charAt(i) != 0) i++;
int time1 = i;
@@ -1042,13 +1069,9 @@ public class LocatorService implements ILocator {
int host0 = i;
while (i < l && s.charAt(i) != 0) i++;
int host1 = i;
- if (i < l && s.charAt(i) == 0) i++;
int port = Integer.parseInt(s.substring(port0, port1));
String timestamp = s.substring(time0, time1);
String host = s.substring(host0, host1);
- if (TRACE_DISCOVERY) {
- trace_map.put("slave[" + slave_index++ + ']', timestamp + ':' + port + ':' + host);
- }
if (port != DISCOVEY_PORT) {
InetAddress addr = getInetAddress(host);
if (addr != null) {
@@ -1079,9 +1102,6 @@ public class LocatorService implements ILocator {
}
}
}
- if (TRACE_DISCOVERY) {
- traceDiscoveryPacket(true, "CONF_SLAVES_INFO", trace_map, p);
- }
}
catch (Exception x) {
log("Invalid datagram packet received from " + p.getAddress() + "/" + p.getPort(), x);
@@ -1089,13 +1109,25 @@ public class LocatorService implements ILocator {
}
private void handleReqSlavesPacket(InputPacket p, Slave sl, long time) {
- if (TRACE_DISCOVERY) {
- traceDiscoveryPacket(true, "CONF_REQ_SLAVES", null, p);
- }
+ if (TRACE_DISCOVERY) traceDiscoveryPacket(true, "CONF_REQ_SLAVES", null, p);
if (sl != null) sl.last_req_slaves_time = time;
sendSlavesInfo(p.getAddress(), p.getPort(), time);
}
+ private void handlePeerRemovedPacket(InputPacket p) {
+ try {
+ Map<String,String> map = parseIDs(p.getData(), p.getLength());
+ if (TRACE_DISCOVERY) traceDiscoveryPacket(true, "CONF_PEERS_REMOVED", map, p);
+ for (String id : map.values()) {
+ IPeer peer = peers.get(id);
+ if (peer instanceof RemotePeer) ((RemotePeer)peer).dispose();
+ }
+ }
+ catch (Exception x) {
+ log("Invalid datagram packet received from " + p.getAddress() + "/" + p.getPort(), x);
+ }
+ }
+
/*----------------------------------------------------------------------------------*/
public static LocatorService getLocator() {
diff --git a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/services/ILocator.java b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/services/ILocator.java
index ddb88190e..be7cfef97 100644
--- a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/services/ILocator.java
+++ b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/services/ILocator.java
@@ -49,7 +49,8 @@ public interface ILocator extends IService {
CONF_REQ_INFO = 1,
CONF_PEER_INFO = 2,
CONF_REQ_SLAVES = 3,
- CONF_SLAVES_INFO = 4;
+ CONF_SLAVES_INFO = 4,
+ CONF_PEERS_REMOVED = 5;
/**
* @return Locator service name: "Locator"

Back to the top