[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge pull request #4 from myou11/list-routing-tables
Browse files Browse the repository at this point in the history
finished list-routing-tables command
  • Loading branch information
myou11 committed Feb 14, 2018
2 parents 13de23a + 069f2b3 commit a1b7c4d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/cs455/overlay/node/Registry.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cs455.overlay.node;

import cs455.overlay.routing.RoutingTable;
import cs455.overlay.transport.TCPConnection;
import cs455.overlay.transport.TCPConnectionsCache;
import cs455.overlay.transport.TCPServerThread;
Expand All @@ -22,6 +23,9 @@ public class Registry implements Protocol, Node {
private TCPConnectionsCache connectionsCache;
private ServerSocket serverSocket;

// Routing table for each node ID
private TreeMap<Integer, RoutingTable> nodeRoutingTables = new TreeMap<>();

private int numNodesRegistered; // set when setup-overlay is initiated
private int numNodesEstablishedConnections = 0;

Expand All @@ -44,6 +48,10 @@ public Registry(int portNum, ServerSocket serverSocket) {

public TreeMap<Integer, String> getRegisteredNodes() { return registeredNodes; }

public TreeMap<Integer, RoutingTable> getNodeRoutingTables() {
return nodeRoutingTables;
}

public TCPConnectionsCache getConnectionsCache() {
return connectionsCache;
}
Expand Down
15 changes: 14 additions & 1 deletion src/cs455/overlay/util/InteractiveCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,13 @@ public void setupOverlay(int routingTableSize) {
routingTable.addRoutingEntry(ID, IPportNumStr);
}

// Store the routing table so it's easy to display them for the user on list-routing-tables command
int nodeID = registeredNodesList.get(nodeIndex).getKey();
registry.getNodeRoutingTables().put(nodeID, routingTable);

// Look at IDs in each routing tbl. Easier to see which nodes in which routing tbls and to spot if a node is in its own tbl.
if (DEBUG)
System.out.printf("Routing table for node %d is:\n%s", registeredNodesList.get(nodeIndex).getKey(), routingTable);
System.out.printf("Routing table for node %d is:\n%s", nodeID, routingTable);

/* Retrieve the connection to the current node and send it its routing table and info about all nodes in the system */
try {
Expand All @@ -97,6 +101,15 @@ public void setupOverlay(int routingTableSize) {
// Info about routing tbls of each node
public void listRoutingTables() {
System.out.printf("Executing list-routing-tables...\n");

Registry registry = (Registry) node;
System.out.println("Routing Tables:\n");

for (Map.Entry<Integer, RoutingTable> entry : registry.getNodeRoutingTables().entrySet()) {
int nodeID = entry.getKey();
RoutingTable routingTable = entry.getValue();
System.out.printf("Node %d:\n%s\n\n\n", nodeID, routingTable.toString());
}
}

// start number-of-messages (e.g. start 25000)
Expand Down

0 comments on commit a1b7c4d

Please sign in to comment.