only the port-number is now important, if a node checks, if he has already the incoming neighbor + fixed some minor stuff
This commit is contained in:
parent
bf50156ced
commit
269c1e4e1b
@ -3,7 +3,6 @@ package peer;
|
||||
import java.io.IOException;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
@ -31,14 +30,15 @@ public class Node {
|
||||
private UDPListen udpListen;
|
||||
|
||||
public Node() {
|
||||
//System.setProperty("java.net.preferIPv4Stack" , "true"); // optional IPv4 (mac, windows)
|
||||
// System.setProperty("java.net.preferIPv4Stack" , "true"); // optional
|
||||
// IPv4 (mac, windows)
|
||||
try {
|
||||
channel = DatagramChannel.open();
|
||||
channel.socket().bind(null);
|
||||
channel.configureBlocking(false);
|
||||
|
||||
buf = ByteBuffer.allocate(BUF_SIZE);
|
||||
|
||||
|
||||
this.name = channel.socket().getLocalSocketAddress().toString();
|
||||
|
||||
udpListen = new UDPListen();
|
||||
@ -225,20 +225,23 @@ public class Node {
|
||||
case MessageType.LEAVE:
|
||||
LOGGER.info(name + ": " + receivedFrom.toString()
|
||||
+ " is leaving. Deleting...");
|
||||
|
||||
|
||||
// search the neighbor in the list and remove him.
|
||||
for (int i = 0; i < neighbors.size(); i++) {
|
||||
if (neighbors.get(i).equals(receivedFrom)) {
|
||||
if (((InetSocketAddress) neighbors.get(i))
|
||||
.getPort() == ((InetSocketAddress) receivedFrom)
|
||||
.getPort()) {
|
||||
neighbors.remove(i);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MessageType.NEW_NEIGHBOR_IPV4:
|
||||
LOGGER.info(name + " received new IPV4 neighbor"
|
||||
LOGGER.info(name
|
||||
+ " received new IPv6 neighbor"
|
||||
+ receivedFrom.toString() + ": "
|
||||
+ new String(buf.array()));
|
||||
|
||||
|
||||
byte[] byte_addr = new byte[7];
|
||||
|
||||
// Read 4 Bytes and 1 Int
|
||||
@ -252,10 +255,12 @@ public class Node {
|
||||
|
||||
InetSocketAddress new_neighbor = new InetSocketAddress(
|
||||
new String(byte_addr), port);
|
||||
|
||||
|
||||
// check, if we have the neighbor already.
|
||||
if (!hasNeighbor(new_neighbor)) {
|
||||
neighbors.add(new_neighbor);
|
||||
LOGGER.info(name + " adds new neighbor: "
|
||||
+ new String(buf.array()));
|
||||
}
|
||||
|
||||
// TODO: send PING to new neighbor and expect wait
|
||||
@ -266,7 +271,7 @@ public class Node {
|
||||
break;
|
||||
case MessageType.NEW_NEIGHBOR_IPV6:
|
||||
LOGGER.info(name
|
||||
+ " received new IPV6 neighbor from: "
|
||||
+ " received new IPv6 neighbor from: "
|
||||
+ receivedFrom.toString() + ": "
|
||||
+ new String(buf.array()));
|
||||
|
||||
@ -286,12 +291,13 @@ public class Node {
|
||||
|
||||
new_neighbor = new InetSocketAddress(new_hostname,
|
||||
new_port);
|
||||
|
||||
|
||||
// check, if we have the neighbor already.
|
||||
if (!hasNeighbor(new_neighbor)) {
|
||||
neighbors.add(new_neighbor);
|
||||
LOGGER.info(name + " adds new neighbor: "
|
||||
+ new String(buf.array()));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user