2.2.10 Cycle 10 - Basic Inter-Nodal Communication

Design

Objectives

The objective for this cycle is to turn the basic inter-nodal communication from Cycle 6 into something a little more advanced, allowing Nodes to start using post requests rather than get requests so that the data can be supplied within the body of the request, and other similar quality of life upgrades.

Alongside this there is also a very bad security flaw with the way in which Nodes sign data sent to their pong routes, and that is that they will just sign anything sent their way. This means that node A could just ask node B to sign a transaction that gives all of B's assets to A and then B would just do it and send the signed transaction back to A. This is obviously bad and needs to be fixed.

Usability Features

The main usability feature introduced within this cycle is the renaming and structuring of the "ping/pong" functions and routes within the node software to a "handshake" route which more accurately describes what is actually going on.

Key Variables

Variable Name
Use

Stores all the configuration object's data, such as the node's reference to itself, its port and other essential information.

Contains the keys object, which has the ability to sign, validate and verify data.

Pseudocode

Only signing date-time objects

Luckily implementing this, and dramatically improving the node software's current security, should actually be pretty easy. All the code will need to do is attempt to parse the message received within the handshake (ping/pong) request as a date-time object and if it succeeds, then the message is okay to be signed and if not then fail the request and do not sign it.

Parsing date-time objects is different for every language and standard library so for this pseudocode the function Parse_Date will represent a function which takes a string in the format YYYY-MM-DD hh:mm:ss and either returns a date-time object in some format or errors out.

Converting the handshake route from a get request to a post request

As both the conversion from a get request to a post request and converting from using queries to using the body to send data is so similar I'll use the below examples to summarise both changes.

Api Route

Because this is based upon code from a previous cycle where I introduced the nodal communication, I've copied that pseudocode as the base and then edited it from there. Visit here to see the original Pseudocode

Requester Function

Development

The development for this cycle was primarily based upon changing the code, pushing the changes, downloading the new code and running it on two nodes and seeing if either of them had communication issues. This was fairly repetitive but due to having ssh access to both servers It wasn't too time consuming and allowed me to just keep testing the new code until it stopped having errors, which lowered the error rates a lot due to so many tests as I was programming.

Outcome

Signing Date-Time Objects

Converting the pseudocode to actual code for this was pretty simple, although I ended up keeping the parsing within the main handshake route function rather than splitting it out into a separate function, so that's why the code isn't in a function below.

This code can be found in this commit here, although bear in mind that the code above removed some in-code comments meant for future use in a different cycle that is not in development and is just being planned at the moment.

Converting the handshake route from a get request to a post request

The Api route

This is the endpoint at which a node will send a http POST request to in order to request a handshake response in accordance to the details sent in the request.

The Handshake Requester

This code handles the assembly of a handshake request, then the http request and finally the handling of the returned data then returns a boolean value that represents whether the handshake was successful or not.

This version of the code can be found here.

Challenges

The main challenge faced in this cycle was surrounding responding to the handshake requests, as in a future cycle I plan to complete a check after a node receives a request to check if they have seen the requester before and if not send them their own request to get info on them.

This involved planning for the future and examining how to get the reference of the node that sent a request, however my initial plan, which was just to examine the http headers failed because due to how my primary node (https://nano.monochain.network) uses cloud-flare tunnelling to increase security so all nodes that send requests appear to have the same ip -> one of cloud-flare's servers. Therefore if I was having that problem then other people probably would as well so after some testing and probing I decided not to try and cover that in this cycle and it will instead be covered in a future cycle.

Testing

Tests

Test
Instructions
What I expect
What actually happens
Pass/Fail

1

Completing a correct and valid handshake using a time object as the message.

A series of console logs on both nodes confirming that the handshake was successful.

As expected

Pass

2

Completing an invalid handshake using the string "invalid data" as the message.

For both nodes to record the handshake as unsuccessful and log such to the console.

As expected

Pass

Evidence

Test 1 Evidence - Valid data in a valid handshake

The handshake initiator
The handshake Recipient

As shown, both the initiator and recipient successfully agreed on the handshake, with both showing the same time message to prove this was the same handshake as the test.

Test 2 Evidence - Invalid data in the handshake

The handshake initiator
The handshake Recipient

As shown both nodes classified the handshake as failed, with the initiator predicting that incorrect data may have been sent (although that is not guaranteed as another error may have occurred but in this case we know it was the case of invalid data); and the Recipient logging an incorrect time format supplied and who it was claimed to be supplied by.

Last updated