From e567ffc0b0000d9787c0e88abe177b86e38a1a67 Mon Sep 17 00:00:00 2001 From: senft-lap Date: Tue, 13 Nov 2012 16:56:06 +0100 Subject: [PATCH] Added MessageType --- ws2012/P2P/uebungen/4/.classpath | 6 +++ ws2012/P2P/uebungen/4/.project | 17 +++++++++ .../uebungen/4/src/common/MessageType.java | 7 ++++ ws2012/P2P/uebungen/4/src/peer/Node.java | 32 ++++++++++------ ws2012/P2P/uebungen/4/src/peer/Peer.java | 37 ++++++++----------- 5 files changed, 66 insertions(+), 33 deletions(-) create mode 100644 ws2012/P2P/uebungen/4/.classpath create mode 100644 ws2012/P2P/uebungen/4/.project create mode 100644 ws2012/P2P/uebungen/4/src/common/MessageType.java diff --git a/ws2012/P2P/uebungen/4/.classpath b/ws2012/P2P/uebungen/4/.classpath new file mode 100644 index 00000000..fb501163 --- /dev/null +++ b/ws2012/P2P/uebungen/4/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/ws2012/P2P/uebungen/4/.project b/ws2012/P2P/uebungen/4/.project new file mode 100644 index 00000000..fd9846f2 --- /dev/null +++ b/ws2012/P2P/uebungen/4/.project @@ -0,0 +1,17 @@ + + + 4 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/ws2012/P2P/uebungen/4/src/common/MessageType.java b/ws2012/P2P/uebungen/4/src/common/MessageType.java new file mode 100644 index 00000000..01f7ceeb --- /dev/null +++ b/ws2012/P2P/uebungen/4/src/common/MessageType.java @@ -0,0 +1,7 @@ +package common; + +public class MessageType { + public final static byte BOOTSTRAP = 0; + public final static byte LEAVE = 1; + public final static byte NEW_NEIGHBOUR = 1; +} diff --git a/ws2012/P2P/uebungen/4/src/peer/Node.java b/ws2012/P2P/uebungen/4/src/peer/Node.java index dfe72755..da7c4885 100644 --- a/ws2012/P2P/uebungen/4/src/peer/Node.java +++ b/ws2012/P2P/uebungen/4/src/peer/Node.java @@ -5,9 +5,10 @@ import java.util.List; public class Node { - private int id; // node id must be unique! id = IP of peer ?!? - //-> Should be unique if we don't consider peers behind a NAT. - + // node id must be unique! id = IP of peer ?!? + // -> Should be unique if we don't consider peers behind a NAT. + private int id; + private List neighbours; public Node(int id, List neighbours){ @@ -16,12 +17,20 @@ public class Node { } - //add one single neighbour + /** + * Add one single neighbour + * + * @param neighbour + */ public void addSingleNeighbour(Node neighbour){ this.neighbours.add(neighbour); } - //add a list of new neighbours + /** + * Add a list of new neighbours + * + * @param neighbours + */ public void addMultiNeighbours(List neighbours){ Iterator it = neighbours.iterator(); while(it.hasNext()){ @@ -33,7 +42,12 @@ public class Node { return (this.neighbours.size() > 0); } - //checks if actual node has neighbour with given id + /** + * checks if actual node has neighbour with given id + * + * @param id + * @return + */ public boolean hasNeighbour(int id){ for(int i = 0; i < neighbours.size(); i++){ Node tmp = neighbours.get(i); @@ -43,8 +57,4 @@ public class Node { } return false; } - - - - -} +} \ No newline at end of file diff --git a/ws2012/P2P/uebungen/4/src/peer/Peer.java b/ws2012/P2P/uebungen/4/src/peer/Peer.java index c0f14dc6..69fca905 100644 --- a/ws2012/P2P/uebungen/4/src/peer/Peer.java +++ b/ws2012/P2P/uebungen/4/src/peer/Peer.java @@ -2,30 +2,23 @@ package peer; public class Peer { - + private Node node; - - - //create another peer, mutually link creator and spawn - public void spawn(){ - + + /** + * Create another peer, mutually link creator and spawn. + */ + public void spawn() { + } - - - - //circularly link all neighbours, remove itself form all neighbours and exit - public void leave(){ - + + /** + * Circularly link all neighbours, remove itself form all neighbours and + * exit. + */ + public void leave() { + } - - - - - - - - - - + }