P2P Uebung 4 Geruest
This commit is contained in:
parent
4b714b0512
commit
28565562bd
13
ws2012/P2P/uebungen/4/src/network/Network.java
Normal file
13
ws2012/P2P/uebungen/4/src/network/Network.java
Normal file
@ -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) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
50
ws2012/P2P/uebungen/4/src/peer/Node.java
Normal file
50
ws2012/P2P/uebungen/4/src/peer/Node.java
Normal file
@ -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<Node> neighbours;
|
||||
|
||||
public Node(int id, List<Node> 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<Node> neighbours){
|
||||
Iterator<Node> 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
31
ws2012/P2P/uebungen/4/src/peer/Peer.java
Normal file
31
ws2012/P2P/uebungen/4/src/peer/Peer.java
Normal file
@ -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(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
BIN
ws2012/P2P/uebungen/4/u2.pdf
Normal file
BIN
ws2012/P2P/uebungen/4/u2.pdf
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user