Broadcast packets are now broadcasted by receiving nodes

This commit is contained in:
senft-desktop 2012-11-29 17:40:29 +01:00
parent ad5323cfaa
commit 1a61fdab0e

View File

@ -178,10 +178,13 @@ public class Node {
}
private void sendBroadcast(byte command, byte[] data) {
ByteBuffer buffer = ByteBuffer.allocate(BUF_SIZE);
// Random id?
int packet_id = generator.nextInt();
sendBroadcast(packet_id, command, data);
}
private void sendBroadcast(int packet_id, byte command, byte[] data) {
ByteBuffer buffer = ByteBuffer.allocate(BUF_SIZE);
buffer.put(MessageType.BROADCAST);
buffer.putInt(packet_id);
@ -194,6 +197,8 @@ public class Node {
byte[] packet = buffer.array();
for (SocketAddress n : neighbors) {
// TODO: by now, we also send the packet back to the node it was
// received from...
try {
channel.send(ByteBuffer.wrap(packet), n);
} catch (IOException e) {
@ -350,6 +355,10 @@ public class Node {
case MessageType.STATUS:
InetSocketAddress originalSender = readIPFromBuffer();
// Broadcast to my neighbors
sendBroadcast(packet_id, command,
addrToBytes(originalSender));
LOGGER.log(
Level.INFO,
"{0}: received status broadcast packet from {1}. original sender: {2}",