2.2.11 Cycle 11 - Remembering Nodes
Design
Objectives
The next step to building a network in which nodes can successfully communicate across is for the node software to remember which nodes it has come into contact with previously so that it can send messages it receives from other nodes onto it's remembered nodes in the future.
This is what will create the networking effect that allows for messages to flow throughout the entire network without having to have any form of central server.

The diagram above shows how such a message flow would work, with node 'a' wanting to send a message across the network which will end up with every node having read it, including node 'g' at the opposite side. The way in which this will work can be explained using a few stages:
Node 'a' sends the message to all nodes it's aware of, in this case only node 'b', this is represented by green arrow and number.
Node 'b' receives the message, checks it's valid, approves it and then forwards it on to all the nodes it knows (apart from the node it just came from - 'a'), this is blue.
Nodes 'c' and 'd' receive the message from 'b', validate it and then forward it on to the nodes they know of, this is pink.
Nodes 'e' and 'f' both receive the message, validate it and then begin to send it on to any node they know of that didn't send them the message. Although in this case they don't know that the other node has already seen the message so they send it on anyway. Since node 'f' is also connected to node 'g' this does mean that 'g' is also sent the message. This is represented by the colour orange.
All nodes have now seen the message and therefore the cycle is complete.
Therefore the primary objectives this cycle are:
Usability Features
Storing the node data locally so that nodes will only send messages to a smaller pool of nodes rather than to every node on large, publically accessible lists speeds the network up and limits the number of duplicate messages.
Once the network reaches the point at which it is large enough that every node knows atleast two other nodes, we can be sure that if any one node shuts down or goes offline any messages will still be distributed across the network.
Key Variables
This is the references object which holds all the known references that a node has encountered as well as some functionality to check if the node is aware of a specific reference, add a new reference, etc.
This is the file path of the file at which the references object is stored and loaded from. This is stored as a parameter within the configuration object.
Pseudocode
Handling References
This piece of code handles the initial definition of the 'References' object and the loading, saving generation of that object. Like most of the rest of the key objects in the codebase the object is saved and loaded in json.
Using the Reference object
The functions in this block of code allow for other parts of the codebase to add keys to both the standard reference and the blacklist reference simply by supplying the reference (and key for the main reference type). Then also to check if the references object is already aware of a specified reference for use in areas such as the handshake code expanded in Cycle 10.
Using references when receiving a handshake.
This is a piece of code taken from the handshake responder api route that checks if the node has come into contact with the node sending a handshake request before and if not, starts a new handshake to 'get to know' the new node.
Using references when sending a handshake.
This allows the node to remember if a node successfully completed a handshake request - in which case it is added to the main reference map - or unsuccessfully didn't complete the request - in which case the reference is temporarily blacklisted until the node restarts.
Development
Although the changes introduced in this cycle were fairly simple to do and didn't take many changes to the rest of the program to start being used properly, they are still very substantial, as the addition of referencing at memorising which nodes a node has come into contact with before is what will allow the network to truly grow and become as interconnected as it will need to be to work properly.
Outcome
Handling References
Using the Reference object
Using references when receiving a handshake.
Using references when sending a handshake.
Challenges
Since the actual logic for this part of the software is somewhat simple, this cycle didn't have many algorithmic based challenges but that doesn't mean it didn't have it's hurdles. In this case the main hurdle was trying to figure out what the reference for a node was and initially I trialled using ip tracking and cryptography signatures to attach a secure method of ensuring that a node was who they said they were. However this didn't work out as the ip tracking wasn't always perfect and this lead to the other testing servers running this version of the node software semi-randomly blacklisting each other at various points.
The solution to this was to realise that as long as any secure requests/responses contain a signature validating that transmission, the node's reference doesn't really need to be secure and can mainly just be used to remember where nodes are on the internet and then anything else can be done using signed messages to and from the referenced node. This means that if a node is lying about it's reference, it won't matter as it will still be signing the messages with a different
Testing
Tests
1
Create a new references object and log it to the console.
An empty references object to be logged in the console.
As Expected
2
Create a new references object and log it to the console using the "get_refs" function.
An empty references object to be logged in the console and a file created with that object.
As Expected
3
Add a test reference to the references object and save it to a test file.
A references object with the test reference to be saved to the test file.
As Expected
4
Load the test references object created in test 3 and check if the node is still aware of that node using the "aware_of" function.
The references object to be aware of the test reference.
As Expected
5
Add a test reference to the references object as a blacklisted node and save it to a test file.
A references object with the test reference as a blacklisted node to be saved to the test file.
As Expected
6
Load the test references object created in test 3 and check if the node is still aware of that node using the "aware_of" function.
The references object to not be aware of the test reference.
As Expected
Last updated





