Implemented "status" cmd to check a nodes neighbors ad hoc. Printing a "new neighbor" message only if the received neighbor really is new.

This commit is contained in:
senft-lap 2012-11-23 16:16:43 +01:00
parent e363ab4f64
commit 64b1e0dc04
2 changed files with 19 additions and 8 deletions

View File

@ -58,6 +58,9 @@ public class Main {
theNode.leave();
nodes.remove(theNode);
break;
case "status":
System.out.println(nodes.get(node));
break;
default:
System.out.println("Unknown command.");
break;

View File

@ -49,13 +49,12 @@ public class Node {
/**
* Create another peer, mutually link creator and spawn.
*
* @return
* @return the spawned Node
* @throws IOException
* if no connection could be established to the new node
*/
public Node spawn() throws IOException {
LOGGER.info("Name: " + getName() + ", Spawning new node.");
// create a new node
// LOGGER.info("Name: " + getName() + ", Spawning new node.");
Node newNode = new Node();
buf.clear();
@ -167,6 +166,14 @@ public class Node {
return this.name;
}
public String toString() {
StringBuilder result = new StringBuilder(256);
result.append("Node ");
result.append(getName()).append(", Neighbors: ");
result.append(neighbors);
return result.toString();
}
public class UDPListen implements Runnable {
private volatile boolean running = true;
@ -221,12 +228,13 @@ public class Node {
// check, if we have the neighbor already.
if (!hasNeighbor(new_neighbor)) {
neighbors.add(new_neighbor);
LOGGER.info(name + " from "
+ receivedFrom.toString()
+ " received new neighbor:"
+ new_neighbor.toString());
}
LOGGER.info(name + " from "
+ receivedFrom.toString()
+ " received new neighbor:"
+ new_neighbor.toString());
break;
default: