@Override
 public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
   String welcome =
       "Welcome to Onion Router!\nYou're node name is "
           + GlobalVars.nodeName()
           + "\nType each command with a trailing semicolon\nType 'help;' to see the commands\n\n>";
   TerminalWrite.write(e.getChannel(), welcome);
 }
 @Override
 public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
   String command = (String) e.getMessage();
   if (command.equals(TerminalCommands.HELP)) {
     TerminalWrite.write(
         e.getChannel(),
         (TerminalCommands.NODE_LIST
                 + " - Display the list of available nodes from the directory server\n\n")
             .getBytes());
     TerminalWrite.write(
         e.getChannel(),
         (TerminalCommands.NEW_CIRCUIT
                 + " - Create a new circuit with a random node from the list\n\n")
             .getBytes());
     TerminalWrite.write(
         e.getChannel(),
         (TerminalCommands.EXTEND_CIRCUIT
                 + " - Extend the current circuit. Must have created a new circuit first.\n\n")
             .getBytes());
     TerminalWrite.write(
         e.getChannel(),
         (TerminalCommands.SEND
                 + " <url> - use the newly created circuit to perform an HTTP GET anonymously!\n\n")
             .getBytes());
     TerminalWrite.write(e.getChannel(), ">".getBytes());
   } else if (command.equals(TerminalCommands.QUIT)) {
     TerminalWrite.write(e.getChannel(), "Goodbye\n".getBytes())
         .addListener(
             new ChannelFutureListener() {
               @Override
               public void operationComplete(ChannelFuture future) throws Exception {
                 future.getChannel().close();
               }
             });
   } else if (command.equals(TerminalCommands.NEW_CIRCUIT)) {
     CreateCircuit.run(e.getChannel());
   } else if (command.equals(TerminalCommands.EXTEND_CIRCUIT)) {
     if (MyCircuit.hasCircuit()) {
       ExtendMyCircuit.run(e.getChannel());
     } else {
       TerminalWrite.write(
           e.getChannel(), "You do not have a circuit to extend. Try calling nc;\n>");
     }
   } else if (command.equals(TerminalCommands.NODE_LIST)) {
     // ClientRegister.run(e.getChannel());
     ArrayList<Node> nodeList = NodeList.getAll();
     for (int i = 0; i < nodeList.size(); i++) {
       Node node = nodeList.get(i);
       String out =
           node.getNodeName()
               + " "
               + node.getAddr().getAddress().getHostAddress()
               + " "
               + node.getAddr().getPort()
               + "\n";
       TerminalWrite.write(e.getChannel(), out.getBytes());
     }
     TerminalWrite.write(e.getChannel(), ">");
   } else if (command.equals(TerminalCommands.SEND)) {
     SendRequest.run(e.getChannel());
   } else {
     TerminalWrite.write(e.getChannel(), "unknown command: " + command + "\n>");
   }
 }