How a Node Works

From Death of Net Neutrality Wiki
Jump to: navigation, search

There's a lot going on in the NetWeather program. Threads, mutexes, pipes, shared memory and sockets programming all makes it a bit much to take in all at once. The purpose of this page is to explain how things work so someone could go about making changes to the program.

File Structure

  • CLI.h & CLI.cpp - command line interface
  • ports.cpp - contains code needed for cross platform compatibility ('porting' the software to other platforms)
  • main.cpp & main.h - starts the appropriate interface based on parameters (currently only CLI interface exists)
  • RemoteHost.cpp & RemoteHost.h - A remote host is a representation of a remote, Internet-connected machine that is running a copy of this program.
  • NetworkNode.cpp & NetworkNode.h - Handles all network traffic, including incoming test traffic, incoming commands, outgoing test traffic, and outgoing commands.
  • timer.hpp - Sets up timing details. Used for obtaining the most accurate time measurements possible.
  • String.cpp && String.h - A copy of Dr. Ramsey's RamseyString class, designed to abstract away some of the complexities of interacting with strings in C++.
  • stringdriver.cpp - A test file used to demonstrate RamseyString.
  • text/ - This directory contains the text used by the CLI, such as --help text.
  • utilities.cpp & utilities.h - Contains various useful methods that make working in C++ a little easier.
  • config/ - Contains all configuration files.

Initialization

The following occurs when the program is initially run.

  1. ./cli or ./cli.exe runs main.cpp, processing arguments and creating an instance of the CLI.
    • Note: If no parameters were given, the configuration in config/config.txt is loaded.
  2. The CLI initializes localNetworkNode to be a new NetworkNode based the command line parameters given. (or the config file, if there aren't any)
    1. localNetworkNode initializes its variables
      • controlPortNumber: based on parameters - will fail if not a valid port number.
      • testingPortNumber: based on parameters - will fail if not a valid port number.
      • connectedClient = NULL;
      • listOfPotentialSockets = NULL;
      • Others not listed here.
    2. Opens networknode.log for use as a log file.
    3. Makes a pipe to itself known as the pipeToMainThread - with itself being the main thread.
    4. Spawns child threads by calling startThreads(). Refer to the #NetworkNode section for details on these threads.
  3. The startup commands in config/startup.txt are read and executed.
  4. The CLI starts to listen for commands and processing them as they come in.

Network Tests

All network tests involve two NetworkNodes communicating with one another.

Ping Test

A ping test measures latency.

Remotely Initiated

  1. The remote host connects to the local host on the local host's control port.
  2. The local host accepts the connection and begins to processCommandsFromConnectedClient().
  3. The remote host sends the command "TEST LATENCY" to the remote host's control port.
  4. The local network node responds by executing localNetworkNode.cmdTESTLATENCY(); which...
    1. Tells the testing port thread to get ready by writing RP to pipeToTestingPortThread
    2. Waits for the testing port thread to write back by writing to pipeToMainThread
    3. Sends "READY FOR LATENCY TEST" to the remote host, signaling that the local host is ready to receive the ping data.

Locally Initiated

Network Node

Each network node contains the following threads. Each child thread gets a pipe to it that can be used to tell it to shutdown.

Control Port Thread

A thread in a NetworkNode dedicated to monitoring the NetworkNode's control port for connections and commands.

Creation Process

  1. pipeToControlPortThread is initialized with a new pipe.
  2. listOfOfPotentialSockets is populated with the following options
    • AF_INET - IPv4
    • SOCK_STREAM - TCP
    • AI_PASSIVE - Use wildcards for addresses
  3. Make controlPortSocketFileDescriptor a socket file descriptor for the NetworkNode's control port.
  4. Make controlPortThread the boost::thread for the control port. This thread will listen to the socket for connections, accept them, and process the commands as they come through.

Testing Port Thread

A thread in a NetworkNode dedicated to sending and receiving test data over the NetworkNode's testing port.

Creation Process

  1. pipeToTestingPortThread is initialized with a new pipe.
  2. listOfOfPotentialSockets is populated with the following options
    • AF_INET - IPv4
    • SOCK_DGRAM - UDP
    • AI_PASSIVE - Use wildcards for addresses
  3. Make testingPortSocketFileDescriptor a socket file descriptor for the NetworkNode's testing port.
  4. Make testingPortThread the boost::thread for the control port.

Error Handling

Each instance of NetworkNode has an errorOccurred boolean and an errorMessage string. If errorOccurred is ever true, then something went wrong and errorMessage is overwritten which a (hopefully) useful description of what happened.

Miscellaneous Notes