2.2.3 Cycle 3 - Configuration Handler
Design
Objectives
For this cycle the main objective is to turn the node software into something more aligned with what a user would actually be able to use, as although it will mainly be computer oriented people using this part of the project having it easy to understand is still a big benefit.
Usability Features
Configuration handler
For the configuration handler it will originally start of very simply and will probably be somewhat a pain to use, but the hope is that by laying out a ground framework now that contains the console interface that will be used to interact with the configuration handler to be in plain, easy to understand English. This will give users the best chance at being able to run through the configuration setup with as little friction as possible.
Plain, easy to read English text based interface.
Allows user to respond in a variety of ways ("yes", "y","confirm","approve", etc).
Key Variables
user_config
to store the user's current configuration settings for various parts of the system. (which port to use for the server, etc)
config_path
the default place for user configurations to be stored by the software for loading/saving configs.
Pseudocode
The handler will be built with three main functions:
get_configmeant for collecting the configuration for use by other parts of the program.create_configurationmeant for generating a new configuration for the user if they don't already have one.save_configmeant for saving the current version of the configuration to the file.
Getting the configuration.
get_config will allow any part of the software to load the newest version of the configuration, ideally this will be from memory but will likely just be from the file to start with. It will look something like the following:
Generating a new config
create_configuration is a pretty simple function that collects data from other functions - such as the ask_for_port one also in the pseudocode below - and formats that data into a configuration object before saving it and returning the config to wherever it has been called from.
Saving the configuration
This function simply saves the configuration to a file so that it can be loaded/updated by other parts of the program as needed, and will keep its contents if the node/computer running the program is shut down or stopped.
The code will look something like the following:
Development
Most of the development for this cycle went pretty smoothly, which was very nice!
This was mainly due to the module being relatively simple, so most of the development was simply converting the pseudocode and concept specified above into V code.
In order to do this I first created the "configuration" module, which is done simply by creating a new folder with the name of the module and adding the line module configuration to the top of any files that are part of that module.
Once the module was setup I created three files for the code to help separate it out and make it easier for anyone looking at the code base to see what was going on, the files were:
configHandler.v- This is the main file of the module and contains theget_config()function mentioned earlier, this then calls on a function from theconfigFileHandler.vfile below and if there is a config file setup, loads it, and if not then calls on theconfigCreator.vfile to create a new configuration.configCreator.v- This just houses some basic user interfacing functions that ask for various pieces of data required to generate a new configuration and then turns that into a new configuration object and saves it using theconfigFileHandler.vfile below.configFileHandler.v- This is a basic file used to load, save, and check the existence of configuration files, any file read through this is type safe due to the language being used (VLang) reading json data using the expected object type and rejecting the file if it is incorrectly formatted. This means that all the data loaded to and from files using this part of the module are the correct object types and shouldn't cause any formatting crashes in other parts of the program.
Outcome
Because there is actually quite a lot of code in this module, I will just include some major functions such as the ones mentioned in the pseudocode.
Getting the config file
This version of the code can be found on Github Commit bc45df98e7.
Generating a new config
This version of the code can be found on Github Commit bc45df98e7.
Saving the configuration files
This includes the save_config function as expected, but also the load_config function which was originally planned to just be built into the get_config function from earlier.
This version of the code can be found on Github Commit bc45df98e7.
Testing
Tests
1
Create a new configuration file using "create_configuration()"
Console logs to confirm the operation is commencing and a configuration file to be generated.
As Expected
Pass
2
Load the new config file using "load_config()"
Config file should be loaded and returned
As Expected
Pass
3
Load the new config file using "get_config()"
Config file should be loaded and returned
As Expected
Pass
Evidence



Last updated