IPv4 specific transfer of adresse
This commit is contained in:
parent
31b2dc68bd
commit
fed78ba956
@ -11,8 +11,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
|
||||
import common.MessageType;
|
||||
|
||||
public class Node {
|
||||
@ -91,17 +89,32 @@ public class Node {
|
||||
|
||||
if (a.getAddress() instanceof Inet6Address) {
|
||||
buf.put(MessageType.NEW_NEIGHBOR_IPV6);
|
||||
|
||||
// TODO Geht das so? Können wir auf der Empfängerseite einfach
|
||||
// anhand der Information " es ist eine IPV6 Adresse" eine bestimmte
|
||||
// Anzahl an Bytes lesen und dann nach X Bytes wissen wir,
|
||||
// "jetzt kommt der Port"? Bei IPV4 geht das ja: 4 Bytes und dann 1
|
||||
// Int für den Port
|
||||
buf.put(a.getHostName().getBytes());
|
||||
buf.putInt(a.getPort());
|
||||
|
||||
} else if (a.getAddress() instanceof Inet4Address) {
|
||||
buf.put(MessageType.NEW_NEIGHBOR_IPV4);
|
||||
|
||||
for (String part : addr.toString().split(".")) {
|
||||
if (!part.contains(":")) {
|
||||
buf.put(Byte.valueOf(part));
|
||||
} else {
|
||||
// Last part (contains port)
|
||||
String[] lastPart = part.split(":");
|
||||
buf.put(Byte.valueOf(lastPart[0]));
|
||||
buf.putInt(Integer.valueOf(lastPart[1]));
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO Geht das so? Können wir auf der Empfängerseite einfach anhand
|
||||
// der Information ob IPV4 oder IPV6 eine bestimmte Anzahl an Bytes
|
||||
// lesen und dann nach X Bytes wissen wir, "jetzt kommt der Port"?
|
||||
buf.put(a.getHostName().getBytes());
|
||||
buf.putInt(a.getPort());
|
||||
buf.flip();
|
||||
}
|
||||
|
||||
@ -217,16 +230,22 @@ public class Node {
|
||||
+ receivedFrom.toString() + ": "
|
||||
+ new String(buf.array()));
|
||||
|
||||
// TODO: Geht es, hier X Bytes zu lesen und dann ein
|
||||
// buf.getInt() für den Port zu machen? Oder braucht man
|
||||
// irgendwie ein Trennzeichen? Oder irgendwie eine fixe
|
||||
// Anzahl an Bytes und dann irgendwelche Füllzeichen?
|
||||
byte[] byte_addr = new byte[7];
|
||||
|
||||
addr = new StringBuilder(512);
|
||||
while (buf.hasRemaining()) {
|
||||
addr.append(buf.get());
|
||||
// Read 4 Bytes and 1 Int
|
||||
for (int i = 0; i < 8; i = i + 2) {
|
||||
byte_addr[i] = buf.get();
|
||||
if (i < 7)
|
||||
byte_addr[i + 1] = '.';
|
||||
}
|
||||
System.out.println(addr.toString());
|
||||
|
||||
int port = buf.getInt();
|
||||
|
||||
neighbors.add(new InetSocketAddress(new String(byte_addr),
|
||||
port));
|
||||
|
||||
// TODO: send PING to new neighbor and expect wait to get a
|
||||
// PONG
|
||||
|
||||
break;
|
||||
case MessageType.NEW_NEIGHBOR_IPV6:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user