Having 3 Packages with 1 class each is not exactly how its supposed to be....

This commit is contained in:
senft-desktop 2012-11-21 18:24:10 +01:00
parent f946f6a0b9
commit 8062d73901
3 changed files with 8 additions and 67 deletions

View File

@ -1,5 +1,3 @@
package network;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@ -7,9 +5,9 @@ import java.util.HashMap;
import java.util.Map;
import java.util.logging.LogManager;
import peer.Node;
import node.Node;
public class Network {
public class Main {
public static Map<String, Node> nodes = new HashMap<String, Node>();
@ -32,10 +30,7 @@ public class Network {
e.printStackTrace();
}
// int delay = 1000;
Node a = new Node();
nodes.put("a", a);
nodes.put("a", new Node());
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s;
@ -65,47 +60,5 @@ public class Network {
System.out.println("No such node.");
}
}
// try {
// Node b = a.spawn();
// Thread.sleep(delay);
//
// Node c = a.spawn();
// Thread.sleep(delay);
//
// Node d = a.spawn();
// Thread.sleep(delay);
//
// // Node ba = b.spawn();
// // Thread.sleep(delay);
// //
// // Node bb = b.spawn();
// // Thread.sleep(delay);
// //
// // Node bc = b.spawn();
// // Thread.sleep(delay);
// //
// // Node bd = b.spawn();
// // Thread.sleep(delay);
// //
// // Node be = b.spawn();
// // Thread.sleep(delay);
//
// a.leave();
// Thread.sleep(delay);
//
// b.leave();
// Thread.sleep(delay);
//
// c.leave();
// Thread.sleep(delay);
//
// d.leave();
//
// } catch (IOException e) {
// e.printStackTrace();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
}
}
}

View File

@ -1,4 +1,4 @@
package common;
package node;
public class MessageType {
public final static byte INVITE = 7;

View File

@ -1,4 +1,4 @@
package peer;
package node;
import java.io.IOException;
import java.net.InetSocketAddress;
@ -9,8 +9,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import common.MessageType;
public class Node {
private final static Logger LOGGER = Logger.getLogger(Node.class.getName());
@ -108,7 +106,6 @@ public class Node {
putAddrInBuf(buf, neighbors.get(j));
channel.send(buf, neighbors.get(i));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@ -136,10 +133,6 @@ public class Node {
}
}
public boolean hasNeighbors() {
return (this.neighbors.size() > 0);
}
public boolean hasNeighbor(SocketAddress adr) {
for (SocketAddress n : neighbors) {
if (n.toString().equals(adr.toString())) {
@ -193,7 +186,7 @@ public class Node {
case MessageType.NEW_NEIGHBOR:
StringBuilder theAddr = new StringBuilder();
// Read 4 Bytes and 1 Int
// Read 4 Bytes and 1 int
for (int i = 0; i < 4; i++) {
theAddr.append(buf.get());
if (i < 3)
@ -213,10 +206,6 @@ public class Node {
+ receivedFrom.toString()
+ " received new neighbor:"
+ new_neighbor.toString());
// TODO: maybe send PING to new neighbor and expect
// wait to get a PONG
break;
default:
@ -224,7 +213,6 @@ public class Node {
+ " received unknown command from "
+ receivedFrom.toString() + ": "
+ messageType + new String(buf.array()));
}
} else {
try {
@ -244,4 +232,4 @@ public class Node {
running = false;
}
}
}
}