Added MessageType

This commit is contained in:
senft-lap 2012-11-13 16:56:06 +01:00
parent bed8846407
commit e567ffc0b0
5 changed files with 66 additions and 33 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>4</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

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

View File

@ -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<Node> neighbours;
public Node(int id, List<Node> 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<Node> neighbours){
Iterator<Node> 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;
}
}
}

View File

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