diff --git a/ws2012/P2P/uebungen/4/src/network/Network.java b/ws2012/P2P/uebungen/4/src/network/Network.java new file mode 100644 index 00000000..1bf6a823 --- /dev/null +++ b/ws2012/P2P/uebungen/4/src/network/Network.java @@ -0,0 +1,13 @@ +package network; + +public class Network { + + + //grow a network: Starting with one peer, repeatedly let peers spawn or leave at random + public static void main(String[] args) { + + } + + + +} diff --git a/ws2012/P2P/uebungen/4/src/peer/Node.java b/ws2012/P2P/uebungen/4/src/peer/Node.java new file mode 100644 index 00000000..dfe72755 --- /dev/null +++ b/ws2012/P2P/uebungen/4/src/peer/Node.java @@ -0,0 +1,50 @@ +package peer; + +import java.util.Iterator; +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. + + private List neighbours; + + public Node(int id, List neighbours){ + this.id = id; + this.neighbours = neighbours; + } + + + //add one single neighbour + public void addSingleNeighbour(Node neighbour){ + this.neighbours.add(neighbour); + } + + //add a list of new neighbours + public void addMultiNeighbours(List neighbours){ + Iterator it = neighbours.iterator(); + while(it.hasNext()){ + this.neighbours.add(it.next()); + } + } + + public boolean hasNeighbours(){ + return (this.neighbours.size() > 0); + } + + //checks if actual node has neighbour with given id + public boolean hasNeighbour(int id){ + for(int i = 0; i < neighbours.size(); i++){ + Node tmp = neighbours.get(i); + if(tmp.id == id){ + return true; + } + } + return false; + } + + + + +} diff --git a/ws2012/P2P/uebungen/4/src/peer/Peer.java b/ws2012/P2P/uebungen/4/src/peer/Peer.java new file mode 100644 index 00000000..c0f14dc6 --- /dev/null +++ b/ws2012/P2P/uebungen/4/src/peer/Peer.java @@ -0,0 +1,31 @@ +package peer; + + +public class Peer { + + private Node node; + + + //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(){ + + } + + + + + + + + + + + +} diff --git a/ws2012/P2P/uebungen/4/u2.pdf b/ws2012/P2P/uebungen/4/u2.pdf new file mode 100644 index 00000000..0c21145d Binary files /dev/null and b/ws2012/P2P/uebungen/4/u2.pdf differ