Application URL: https://can-model.herokuapp.com/ *** No setup is required. Just visit the link *** *** Refresh the page to reset the model ***
The following application is a web based model of a Content Addressable Network. The model demonstrates the way nodes should be added to the network as well as a deterministic way of dividing up the area of responsibility per node.
The technology used for this application is as follows: Twitter Bootstrap: UI / Presentation layer Vanilla JavaScript: Application layer ExpressJS: Middleware and HTTP functionality NodeJS: Asynchronous JavaScript runtime Heroku: Cloud deployment
The program fully works for adding a Node to the network. The full application logic resides in the javascript file nodeFunctions.js. Below, I will describe what each function does.
-
function add_node: This function adds a node to the cartesian grid. It is dependent on three other functions which will be further discussed. This function is the link between the DOM and the application logic.
-
function generate_number: This function returns a random number for the add_node function to use. A required feature of a CAN is for nodes to be randomly placed on the cartesian grid. This function ensures this requirement.
-
function generate_hex: This function returns a random hex number for the add_node and label_zone functions to use. It picks 6 random indices from a predefined array of hex values (0-9,a-f)
-
function append_table: This function displays what’s currently in the network. It shows the order in which nodes were placed, their locations, and it’s hex color representation.
5 label_zone: This function divides the network up according to a deterministic way and labels each area a color that was generated by the generate_hex function.
The flow is pretty simple. The user clicks a button to add a node. A random number and hex is generated. The node is inserted at the random number and the background of the area for the node to control is changed to the random hex. The information is then recorded in the table for reference. This process repeats until there is no more room in the network (36 max spots ) which will result in each node in charge of only the area where it was initially inserted.