P2P Uebung 4 Geruest

This commit is contained in:
M.Scholz 2012-11-13 16:22:50 +01:00
parent 4b714b0512
commit 28565562bd
4 changed files with 94 additions and 0 deletions

View 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) {
}
}

View 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;
}
}

View 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(){
}
}

Binary file not shown.