From 4bb2dc339c91fae552fad1125eb89a78eb112133 Mon Sep 17 00:00:00 2001 From: javierbrk Date: Thu, 5 Sep 2024 13:18:19 -0300 Subject: [PATCH] ref_state:add datatype check and improve docs --- .../shared-state-ref_state_commons/README.md | 25 +++++++++++++++++-- .../usr/lib/lua/shared_state_links_info.lua | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/shared-state-ref_state_commons/README.md b/packages/shared-state-ref_state_commons/README.md index 7c18fb699..a6df03029 100644 --- a/packages/shared-state-ref_state_commons/README.md +++ b/packages/shared-state-ref_state_commons/README.md @@ -4,6 +4,18 @@ Shared-state has modules with information about the node, each information data type like wifi_links_info may have a reference type called wifi_links_info_ref. + +**TOC** +- [Reference State](#reference-state) + - [Possible use cases](#possible-use-cases) + - [Usage](#usage) + - [Get](#get) + - [Insert](#insert) + - [Delete](#delete) + - [Default initialization](#default-initialization) + - [Available datatypes](#available-datatypes) + + Reference state is designed to contain information about the node that will persist and that is not changed to often. This is because it is stored in the device persistent memory and to many consequent write operations may damage the persistent memory. @@ -43,6 +55,7 @@ the network and define the "perfect" status, because this information may be use to detect deviations from the perfect status and easily identify and fix the problem. +### Get You can get the information about the wifi links using this command ```bash @@ -65,6 +78,7 @@ If this information about cheche or part of it is relevant you may want to use it as the reference state. This will stablish a "permanent" or "stable" wifi_links_info called wifi_links_info_ref +### Insert To insert a reference state just put the json part related to this node into shared state async. @@ -89,6 +103,10 @@ or using the rpcd ubus wraper ```JSON {"data":{"cheche":{"src_loc":{"long":"-64.4228178","lat":"-31.8019512"},"links":{"ae40411f73a8c64a00fc3abe":{"freq":2462,"iface":"wlan0-mesh","tx_rate":144,"dst_mac":"c6:4a:00:fc:3a:be","channel":11,"chains":[-40,-35],"signal":-34,"rx_rate":144400,"src_mac":"ae:40:41:1f:73:a8"}}},"graciela":[]},"error":0} ``` +### Delete + +echo '{"cheche": []}' | shared-state-async insert wifi_links_info_ref + ## Default initialization Files are in default state as an empty json object... "{}" Ubus call to get method will return empty array "[]". That is a limitation of the @@ -99,5 +117,8 @@ ubus -S call shared-state-async get '{"data_type": "wifi_links_info_ref" }' {"data":{"cheche":[],"graciela":[],"tito":[]},"error":0} ``` ## Available datatypes -Data types must be declared. Available datatypes are babel_links_info_ref, -bat_links_info_ref, wifi_links_info_ref and node_info_ref +Data types must be declared. Available datatypes are +- babel_links_info_ref, +- bat_links_info_ref, +- wifi_links_info_ref and +- node_info_ref diff --git a/packages/shared-state-ref_state_commons/files/usr/lib/lua/shared_state_links_info.lua b/packages/shared-state-ref_state_commons/files/usr/lib/lua/shared_state_links_info.lua index 31eaaac10..604a887b1 100644 --- a/packages/shared-state-ref_state_commons/files/usr/lib/lua/shared_state_links_info.lua +++ b/packages/shared-state-ref_state_commons/files/usr/lib/lua/shared_state_links_info.lua @@ -15,7 +15,7 @@ function shared_state_links_info.add_dst_loc(links_info, shared_state_sample, ho if shared_state_sample ~= nil then for link, l_data in pairs(links_info.links) do for node, data in pairs(shared_state_sample) do - if node ~= hostname and data.links ~= nil then + if node ~= hostname and type(data) == "table" and data.links ~= nil then local link_data = data.links[link] if link_data ~= nil and data.src_loc~= nil then l_data.dst_loc = {}