From fb156aab80b2036f4b6f8263a473cbac7906605b Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Fri, 19 Jan 2024 11:41:03 +0100 Subject: [PATCH 1/6] Add shared-state-async package --- .../Makefile | 32 ++++++------ packages/shared-state-async/README.adoc | 49 +++++++++++++++++++ .../files/etc/init.d/shared-state-async | 34 +++++++++++++ 3 files changed, 101 insertions(+), 14 deletions(-) rename packages/{shared-state-async-node => shared-state-async}/Makefile (59%) create mode 100644 packages/shared-state-async/README.adoc create mode 100755 packages/shared-state-async/files/etc/init.d/shared-state-async diff --git a/packages/shared-state-async-node/Makefile b/packages/shared-state-async/Makefile similarity index 59% rename from packages/shared-state-async-node/Makefile rename to packages/shared-state-async/Makefile index 649a309c9..1f81adb8a 100644 --- a/packages/shared-state-async-node/Makefile +++ b/packages/shared-state-async/Makefile @@ -1,8 +1,9 @@ # Shared State # +# Copyright (C) 2023-2024 Gioacchino Mazzurco # Copyright (c) 2023 Javier Jorge # Copyright (c) 2023 Instituto Nacional de Tecnología Industrial -# Copyright (C) 2023 Asociación Civil Altermundi +# Copyright (C) 2023-2024 Asociación Civil Altermundi # # This program is free software: you can redistribute it and/or modify it under # the terms of the GNU Affero General Public License as published by the @@ -23,13 +24,13 @@ include $(TOPDIR)/rules.mk GIT_COMMIT_DATE:=$(shell git log -n 1 --pretty=%ad --date=short . ) GIT_COMMIT_TSTAMP:=$(shell git log -n 1 --pretty=%at . ) -PKG_NAME:=shared-state-async-node +PKG_NAME:=shared-state-async PKG_VERSION=$(GIT_COMMIT_DATE)-$(GIT_COMMIT_TSTAMP) PKG_SOURCE_PROTO:=git -PKG_SOURCE_URL:=https://github.com/libremesh/shared-state-async-node.git -PKG_SOURCE_VERSION:= 691c4412a84bb8142c73b4f5ff319f025b3973f7 -PKG_MAINTAINER:=Javier Jorge +PKG_SOURCE_URL:=https://github.com/libremesh/shared-state-async.git +PKG_SOURCE_VERSION:=76dcbc5a88d6e88733054680371bb6caef793be4 +PKG_MAINTAINER:=Asociación Civil Altermundi PKG_LICENSE:=AGPL-3.0 HOST_BUILD_PREFIX:=$(STAGING_DIR_HOST) @@ -38,30 +39,33 @@ include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/cmake.mk include $(INCLUDE_DIR)/host-build.mk -# Package definition; instructs on how and where our package will appear in the overall configuration menu ('make menuconfig') define Package/$(PKG_NAME) - TITLE:=Very small server written in c++ (20) + TITLE:=shared-state C++ async re-implementation CATEGORY:=LibreMesh - SECTION:=experimental + + # TODO: Statically linking libstdcpp instead of depending on it and then + # stripping unused symbols might reduce space usage, until this is the + # only package to use it DEPENDS:=+libstdcpp endef define Package/$(PKG_NAME)/description - Very small server written in c++ (20) implementing corotuines to handle incomming requests and request requirements. + shared-state re-written in C++20 and corotuines to handle information exchange between network nodes more efficiently. endef # Otherwise OpenWrt's CPPFLAGS are ignored TARGET_CFLAGS += $(TARGET_CPPFLAGS) CMAKE_OPTIONS += \ - -DCMAKE_VERBOSE_MAKEFILE=TRUE \ - -DENABLE_SHARED=YES \ - -DENABLE_STATIC=NO \ - -DENABLE_TESTS=NO + -DCMAKE_VERBOSE_MAKEFILE=ON define Package/$(PKG_NAME)/install $(INSTALL_DIR) $(1)/usr/bin - $(INSTALL_BIN) $(PKG_BUILD_DIR)/main $(1)/usr/bin/$(PKG_NAME) + $(INSTALL_BIN) $(PKG_BUILD_DIR)/shared-state-async $(1)/usr/bin/ + $(CP) ./files/* $(1)/ + + # TODO: Remove this line once discovery is reimplemented in C++ + $(CP) ../shared-state/files/usr/bin/shared-state-get_candidates_neigh $(1)/usr/bin/shared-state-async-discover endef $(eval $(call BuildPackage,$(PKG_NAME))) diff --git a/packages/shared-state-async/README.adoc b/packages/shared-state-async/README.adoc new file mode 100644 index 000000000..6d7535708 --- /dev/null +++ b/packages/shared-state-async/README.adoc @@ -0,0 +1,49 @@ + +.Build with debugging enabled +-------------------------------------------------------------------------------- +make package/feeds/libremesh/shared-state-async/clean package/feeds/libremesh/shared-state-async/compile -j$(nproc) CONFIG_DEBUG=y +-------------------------------------------------------------------------------- + +.Copy on verde e blu +-------------------------------------------------------------------------------- +scp -O bin/packages/mips_24kc/libremesh/shared-state-async_*.ipk root@[fe80::ea94:f6ff:fe68:3364%usbe1]:/tmp/ +scp -O bin/packages/mips_24kc/libremesh/shared-state-async_*.ipk root@[fe80::6670:2ff:fede:c51e%usbe1]:/tmp/ +-------------------------------------------------------------------------------- + +.Install +-------------------------------------------------------------------------------- +opkg install --force-reinstall /tmp/shared-state-async_*.ipk +-------------------------------------------------------------------------------- + +.Run with gdb +-------------------------------------------------------------------------------- +gdbserver :9000 shared-state-async +-------------------------------------------------------------------------------- + +.Attach with remote OpenWrt gdb +-------------------------------------------------------------------------------- +scripts/remote-gdb [fe80::ea94:f6ff:fe68:3364%usbe0]:9000 ./build_dir/target-mips_24kc_musl/shared-state-async-*/shared-state-async + +scripts/remote-gdb [fe80::6670:2ff:fede:c51e%usbe0]:9000 ./build_dir/target-mips_24kc_musl/shared-state-async-*/shared-state-async +break shared-state-async.cc:55 +run listen +run sync bat-hosts fe80::ea94:f6ff:fe68:3364%br-lan +run sync bat-hosts fe80::d237:45ff:fefc:3cdd%br-lan +-------------------------------------------------------------------------------- + +.Stressing the server +-------------------------------------------------------------------------------- +while Builds/build-lime-shared-state-async-node-Desktop-Debug/shared-state-async sync bat-hosts fe80::ea94:f6ff:fe68:3364%usbeth0; do echo ------------------------------------------------------------------- ;done + +while shared-state-async sync bat-hosts fe80::ea94:f6ff:fe68:3364%br-lan; do echo ------------------------------------------------------------------- ;done + +-------------------------------------------------------------------------------- + + +=== Interesting Readings + +https://openwrt.org/docs/guide-developer/gdb + +VoCore2: Develop for OpenWrt on Qt Creator +https://vonger.cn/?p=14657 + diff --git a/packages/shared-state-async/files/etc/init.d/shared-state-async b/packages/shared-state-async/files/etc/init.d/shared-state-async new file mode 100755 index 000000000..c8949a51d --- /dev/null +++ b/packages/shared-state-async/files/etc/init.d/shared-state-async @@ -0,0 +1,34 @@ +#!/bin/sh /etc/rc.common + +USE_PROCD=1 +START=30 + +handle_data_type_config() +{ + local cfg="$1" + + config_get name "$cfg" name + config_get scope "$cfg" scope + config_get ttl "$cfg" ttl + config_get update_interval "$cfg" update_interval + + shared-state-async register $name $scope $update_interval $ttl +} + +start_service() +{ + sharedStateConfDir="/tmp/shared-state/" + sharedStateConfFile="${sharedStateConfDir}/shared-state-async.conf" + mkdir -p "$sharedStateConfDir" + echo "{}" > "$sharedStateConfFile" + + config_load shared-state + config_foreach handle_data_type_config dataType + + procd_open_instance + procd_set_param command shared-state-async peer + procd_set_param respawn + procd_set_param stderr 1 + procd_set_param term_timeout 10 + procd_close_instance +} From f683a824cc5e7f006b6798b4136bc3cb62bd5d56 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Fri, 19 Jan 2024 13:32:37 +0100 Subject: [PATCH 2/6] Port bat-hosts to shared-state-async --- packages/shared-state-bat_hosts/Makefile | 8 ++-- .../hotplug.d/iface/shared-state-bat_hosts.sh | 2 +- .../hooks/bat-hosts/generate_bat_hosts | 1 - .../publishers/shared-state-publish_bat_hosts | 1 - .../uci-defaults/shared-state-bat_hosts-cron | 9 ++++- .../usr/bin/shared-state-generate_bat_hosts | 38 ------------------- .../usr/bin/shared-state-publish_bat_hosts | 16 +------- .../files/usr/lib/lua/bat-hosts.lua | 15 ++------ .../bat-hosts/shared-state-generate_bat_hosts | 16 ++++++++ 9 files changed, 35 insertions(+), 71 deletions(-) delete mode 120000 packages/shared-state-bat_hosts/files/etc/shared-state/hooks/bat-hosts/generate_bat_hosts delete mode 120000 packages/shared-state-bat_hosts/files/etc/shared-state/publishers/shared-state-publish_bat_hosts delete mode 100755 packages/shared-state-bat_hosts/files/usr/bin/shared-state-generate_bat_hosts create mode 100755 packages/shared-state-bat_hosts/files/usr/share/shared-state/hooks/bat-hosts/shared-state-generate_bat_hosts diff --git a/packages/shared-state-bat_hosts/Makefile b/packages/shared-state-bat_hosts/Makefile index 481c95d70..defd8b5eb 100644 --- a/packages/shared-state-bat_hosts/Makefile +++ b/packages/shared-state-bat_hosts/Makefile @@ -1,5 +1,5 @@ # -# Copyright (C) 2019 Gioacchino Mazzurco +# Copyright (C) 2019-2024 Gioacchino Mazzurco # # This is free software, licensed under the GNU Affero General Public License v3. # @@ -17,10 +17,10 @@ include $(INCLUDE_DIR)/package.mk define Package/$(PKG_NAME) TITLE:=bat-hosts module for shared-state CATEGORY:=LibreMesh - MAINTAINER:=Gioacchino Mazzurco + MAINTAINER:=Asociación Civil Altermundi URL:=http://libremesh.org - DEPENDS:=+lua +luci-lib-jsonc +random-numgen \ - shared-state +lime-system +luci-lib-nixio +libubus-lua + DEPENDS:=+libubus-lua +lime-system +lua +luci-lib-jsonc +luci-lib-nixio \ + shared-state-async PKGARCH:=all endef diff --git a/packages/shared-state-bat_hosts/files/etc/hotplug.d/iface/shared-state-bat_hosts.sh b/packages/shared-state-bat_hosts/files/etc/hotplug.d/iface/shared-state-bat_hosts.sh index cd95c6ceb..7ed4a9666 100755 --- a/packages/shared-state-bat_hosts/files/etc/hotplug.d/iface/shared-state-bat_hosts.sh +++ b/packages/shared-state-bat_hosts/files/etc/hotplug.d/iface/shared-state-bat_hosts.sh @@ -1,2 +1,2 @@ #!/bin/sh -[ "x$ACTION" == "xifup" ] && ((sleep 30; shared-state-publish_bat_hosts; shared-state sync bat-hosts)&) +[ "x$ACTION" == "xifup" ] && ((sleep 30; shared-state-publish_bat_hosts; shared-state-async sync bat-hosts)&) diff --git a/packages/shared-state-bat_hosts/files/etc/shared-state/hooks/bat-hosts/generate_bat_hosts b/packages/shared-state-bat_hosts/files/etc/shared-state/hooks/bat-hosts/generate_bat_hosts deleted file mode 120000 index f42fb658b..000000000 --- a/packages/shared-state-bat_hosts/files/etc/shared-state/hooks/bat-hosts/generate_bat_hosts +++ /dev/null @@ -1 +0,0 @@ -../../../../usr/bin/shared-state-generate_bat_hosts \ No newline at end of file diff --git a/packages/shared-state-bat_hosts/files/etc/shared-state/publishers/shared-state-publish_bat_hosts b/packages/shared-state-bat_hosts/files/etc/shared-state/publishers/shared-state-publish_bat_hosts deleted file mode 120000 index e30d83ee2..000000000 --- a/packages/shared-state-bat_hosts/files/etc/shared-state/publishers/shared-state-publish_bat_hosts +++ /dev/null @@ -1 +0,0 @@ -../../../usr/bin/shared-state-publish_bat_hosts \ No newline at end of file diff --git a/packages/shared-state-bat_hosts/files/etc/uci-defaults/shared-state-bat_hosts-cron b/packages/shared-state-bat_hosts/files/etc/uci-defaults/shared-state-bat_hosts-cron index 90ee69d82..5ed7fc439 100755 --- a/packages/shared-state-bat_hosts/files/etc/uci-defaults/shared-state-bat_hosts-cron +++ b/packages/shared-state-bat_hosts/files/etc/uci-defaults/shared-state-bat_hosts-cron @@ -5,6 +5,13 @@ unique_append() grep -qF "$1" "$2" || echo "$1" >> "$2" } +uci set shared-state.bat_hosts=dataType +uci set shared-state.bat_hosts.name='bat-hosts' +uci set shared-state.bat_hosts.scope='community' +uci set shared-state.bat_hosts.ttl='600' +uci set shared-state.bat_hosts.update_interval='30' +uci commit shared-state + unique_append \ - '*/5 * * * * ((sleep $(($(random-numgen) % 120)); shared-state sync bat-hosts &> /dev/null)&)'\ + '*/30 * * * * ((sleep $(($RANDOM % 120)); shared-state-publish_bat_hosts &> /dev/null)&)' \ /etc/crontabs/root diff --git a/packages/shared-state-bat_hosts/files/usr/bin/shared-state-generate_bat_hosts b/packages/shared-state-bat_hosts/files/usr/bin/shared-state-generate_bat_hosts deleted file mode 100755 index 2af93e116..000000000 --- a/packages/shared-state-bat_hosts/files/usr/bin/shared-state-generate_bat_hosts +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/lua - ---! LibreMesh ---! Copyright (C) 2019 Gioacchino Mazzurco ---! ---! This program is free software: you can redistribute it and/or modify ---! it under the terms of the GNU Affero General Public License as ---! published by the Free Software Foundation, either version 3 of the ---! License, or (at your option) any later version. ---! ---! This program is distributed in the hope that it will be useful, ---! but WITHOUT ANY WARRANTY; without even the implied warranty of ---! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ---! GNU Affero General Public License for more details. ---! ---! You should have received a copy of the GNU Affero General Public License ---! along with this program. If not, see . - -local JSON = require("luci.jsonc") - -local outputTable = {} -local filtredValues = {} - -for key,value in pairs(JSON.parse(io.stdin:read("*all")) ) do - if filtredValues[value.data] == nil or filtredValues[value.data].bleachTTL < value.bleachTTL then - filtredValues[value.data] = { - data = value.data, - key = key, - bleachTTL = value.bleachTTL - } - end -end - -for _,value in pairs(filtredValues) do - table.insert(outputTable, value.key.." "..value.data) -end - -io.output("/etc/bat-hosts"):write(table.concat(outputTable,"\n").."\n") diff --git a/packages/shared-state-bat_hosts/files/usr/bin/shared-state-publish_bat_hosts b/packages/shared-state-bat_hosts/files/usr/bin/shared-state-publish_bat_hosts index 3b20d17de..3497f97cb 100755 --- a/packages/shared-state-bat_hosts/files/usr/bin/shared-state-publish_bat_hosts +++ b/packages/shared-state-bat_hosts/files/usr/bin/shared-state-publish_bat_hosts @@ -2,19 +2,7 @@ --! LibreMesh --! Copyright (C) 2019 Gioacchino Mazzurco ---! ---! This program is free software: you can redistribute it and/or modify ---! it under the terms of the GNU Affero General Public License as ---! published by the Free Software Foundation, either version 3 of the ---! License, or (at your option) any later version. ---! ---! This program is distributed in the hope that it will be useful, ---! but WITHOUT ANY WARRANTY; without even the implied warranty of ---! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ---! GNU Affero General Public License for more details. ---! ---! You should have received a copy of the GNU Affero General Public License ---! along with this program. If not, see . +--! SPDX-License-Identifier: AGPL-3.0-only local fs = require("nixio.fs") local JSON = require("luci.jsonc") @@ -35,4 +23,4 @@ for ifname in fs.dir(ifacesPath) do end end -io.popen("shared-state insert bat-hosts", "w"):write(JSON.stringify(batHostTable)) +io.popen("shared-state-async insert bat-hosts", "w"):write(JSON.stringify(batHostTable)) diff --git a/packages/shared-state-bat_hosts/files/usr/lib/lua/bat-hosts.lua b/packages/shared-state-bat_hosts/files/usr/lib/lua/bat-hosts.lua index dbddd3993..68f0b28d2 100644 --- a/packages/shared-state-bat_hosts/files/usr/lib/lua/bat-hosts.lua +++ b/packages/shared-state-bat_hosts/files/usr/lib/lua/bat-hosts.lua @@ -1,4 +1,5 @@ local shared_state = require("shared-state") +local JSON = require("luci.jsonc") local utils = require("lime.utils") local bat_hosts = {} @@ -21,18 +22,10 @@ function bat_hosts.bathost_deserialize(hostname_plus_iface) end function bat_hosts.get_bathost(mac, outgoing_iface) - local sharedState = shared_state.SharedState:new('bat-hosts') - local bathosts = sharedState:get() + local bathosts = JSON.stringify( + io.popen("shared-state-async get bat-hosts", "r"):read("*all") ) local bathost = bathosts[mac:lower()] - if bathost == nil and outgoing_iface then - local ipv6ll = utils.mac2ipv6linklocal(mac) .. "%" .. outgoing_iface - sharedState:sync({ ipv6ll }) - bathosts = sharedState:get() - bathost = bathosts[mac:lower()] - end - if bathost == nil then - return - end + if bathost == nil then return end local hostname, iface = bat_hosts.bathost_deserialize(bathost.data) return { hostname = hostname, iface = iface } end diff --git a/packages/shared-state-bat_hosts/files/usr/share/shared-state/hooks/bat-hosts/shared-state-generate_bat_hosts b/packages/shared-state-bat_hosts/files/usr/share/shared-state/hooks/bat-hosts/shared-state-generate_bat_hosts new file mode 100755 index 000000000..f7322b485 --- /dev/null +++ b/packages/shared-state-bat_hosts/files/usr/share/shared-state/hooks/bat-hosts/shared-state-generate_bat_hosts @@ -0,0 +1,16 @@ +#!/usr/bin/lua + +--! LibreMesh +--! Copyright (C) 2019-2024 Gioacchino Mazzurco +--! Copyright (C) 2024 Asociación Civil Altermundi +--! SPDX-License-Identifier: AGPL-3.0-only + +local JSON = require("luci.jsonc") + +local outputTable = {} + +for key,value in pairs(JSON.parse(io.stdin:read("*all")) ) do + table.insert(outputTable, key.." "..value) +end + +io.output("/etc/bat-hosts"):write(table.concat(outputTable,"\n").."\n") From 3639ffcbc9a67a4926ad946aa12ca30fb0cdf8d5 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sat, 20 Jan 2024 18:49:02 +0100 Subject: [PATCH 3/6] ignore OpenWrt source tree override symlink --- .gitignore | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 6e04a6d7d..8af25e1f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,13 @@ build -*~ -*.kate-swp luacov.stats.out tools/ansible/files/generic-rootfs.tar.gz tools/ansible/files/ramfs.bzImage + +# Vim text editor swap files +**/*~ + +# Kate KDE text editor swap files +**/*.kate-swp + +# Ignore OpenWrt source tree override symlink +**/git-src From 5e1b4f63f2be9fbefe51930f8ce94ca6e9b34698 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Mon, 22 Jan 2024 15:55:06 +0100 Subject: [PATCH 4/6] shared-state-async version bump --- packages/shared-state-async/Makefile | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/shared-state-async/Makefile b/packages/shared-state-async/Makefile index 1f81adb8a..66ec07132 100644 --- a/packages/shared-state-async/Makefile +++ b/packages/shared-state-async/Makefile @@ -29,7 +29,7 @@ PKG_VERSION=$(GIT_COMMIT_DATE)-$(GIT_COMMIT_TSTAMP) PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://github.com/libremesh/shared-state-async.git -PKG_SOURCE_VERSION:=76dcbc5a88d6e88733054680371bb6caef793be4 +PKG_SOURCE_VERSION:=ac7b3be5d1990195b9eee09888ac97daf08c82c5 PKG_MAINTAINER:=Asociación Civil Altermundi PKG_LICENSE:=AGPL-3.0 @@ -42,7 +42,6 @@ include $(INCLUDE_DIR)/host-build.mk define Package/$(PKG_NAME) TITLE:=shared-state C++ async re-implementation CATEGORY:=LibreMesh - # TODO: Statically linking libstdcpp instead of depending on it and then # stripping unused symbols might reduce space usage, until this is the # only package to use it @@ -56,8 +55,16 @@ endef # Otherwise OpenWrt's CPPFLAGS are ignored TARGET_CFLAGS += $(TARGET_CPPFLAGS) -CMAKE_OPTIONS += \ - -DCMAKE_VERBOSE_MAKEFILE=ON +CMAKE_OPTIONS += -DCMAKE_VERBOSE_MAKEFILE=ON + +# Disable Cpptrace as it depends on zlib and doesn't seems to work anyway on +# OpenWrt even with CONFIG_DEBUG=y it prints out +# Stack trace (most recent call first): +# #0 0x00000000 +# #1 0x00000000 +# #2 0x00000000 +CMAKE_OPTIONS += -DSS_CPPTRACE_STACKTRACE=OFF + define Package/$(PKG_NAME)/install $(INSTALL_DIR) $(1)/usr/bin From 484f7bb704a4fca7a5237c2557b69d8d06801822 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Mon, 22 Jan 2024 15:55:25 +0100 Subject: [PATCH 5/6] bat-hosts TTL must be longer then cron re-generation interval --- .../files/etc/uci-defaults/shared-state-bat_hosts-cron | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared-state-bat_hosts/files/etc/uci-defaults/shared-state-bat_hosts-cron b/packages/shared-state-bat_hosts/files/etc/uci-defaults/shared-state-bat_hosts-cron index 5ed7fc439..817759679 100755 --- a/packages/shared-state-bat_hosts/files/etc/uci-defaults/shared-state-bat_hosts-cron +++ b/packages/shared-state-bat_hosts/files/etc/uci-defaults/shared-state-bat_hosts-cron @@ -8,7 +8,7 @@ unique_append() uci set shared-state.bat_hosts=dataType uci set shared-state.bat_hosts.name='bat-hosts' uci set shared-state.bat_hosts.scope='community' -uci set shared-state.bat_hosts.ttl='600' +uci set shared-state.bat_hosts.ttl='2400' uci set shared-state.bat_hosts.update_interval='30' uci commit shared-state From 449e2ac80eb5c26fdb13e13bbeeee91916a2d1fd Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Mon, 22 Jan 2024 17:06:12 +0100 Subject: [PATCH 6/6] Disable legacy broken test which need complete rewrite --- .../tests/test_bat_hosts.lua | 73 ++++++++++--------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/packages/shared-state-bat_hosts/tests/test_bat_hosts.lua b/packages/shared-state-bat_hosts/tests/test_bat_hosts.lua index ed73fff94..7c38a448e 100644 --- a/packages/shared-state-bat_hosts/tests/test_bat_hosts.lua +++ b/packages/shared-state-bat_hosts/tests/test_bat_hosts.lua @@ -1,36 +1,39 @@ -local bat_hosts = require('bat-hosts') -local utils = require('lime.utils') -local test_utils = require('tests.utils') -local shared_state = require('shared-state') +--! This test uses legasy shared-state Lua implementation, need complete +--! rethinking to work -it('test get_bathost #bathost', function() - shared_state.DATA_DIR = test_utils.setup_test_dir() - local sharedState = shared_state.SharedState:new('bat-hosts') - sharedState:insert({ - ["02:95:39:ab:cd:00"] = "LiMe_abcd00_wlan1_mesh", - ["52:00:00:ab:cd:a0"] = "LiMe_abcd01_wlan2_mesh_17", - ["d6:67:58:8e:cd:92"] = "LiMe_abcd02_wlan0_adhoc_29", - ["12:00:00:00:00:00"] = "LiMe_abcd03_wlan1_adhoc" - }) - local ifaces = {'wlan1-mesh', 'wlan2-mesh', 'wlan2-mesh_17', 'wlan0-adhoc_29', 'wlan1-adhoc'} - stub(utils, "get_ifnames", function () return ifaces end) - assert.is.same({hostname='LiMe-abcd00', iface='wlan1-mesh'}, bat_hosts.get_bathost('02:95:39:ab:cd:00')) - assert.is.same({hostname='LiMe-abcd01', iface='wlan2-mesh_17'}, bat_hosts.get_bathost('52:00:00:ab:cd:a0')) - assert.is.same({hostname='LiMe-abcd02', iface='wlan0-adhoc_29'}, bat_hosts.get_bathost('d6:67:58:8e:cd:92')) - assert.is.same({hostname='LiMe-abcd03', iface='wlan1-adhoc'}, bat_hosts.get_bathost('12:00:00:00:00:00')) - local ipv6ll = utils.mac2ipv6linklocal('52:00:00:ab:cd:00') .. '%wlan1-mesh' - local dataTypeOfSync = nil - local urlsOfSync = nil - local function syncMock (self, urls) - dataTypeOfSync = self.dataType - urlsOfSync = urls - self:insert({['52:00:00:ab:cd:00'] = "Lime_abcd04_wlan1_mesh"}) - end - stub(shared_state.SharedState, "sync", syncMock) - local bathost = bat_hosts.get_bathost('52:00:00:ab:cd:00', 'wlan1-mesh') - assert.is.same(urlsOfSync, { ipv6ll }) - assert.is.equal(dataTypeOfSync, 'bat-hosts') - assert.is.same({hostname='Lime-abcd04', iface='wlan1-mesh'}, bathost) - assert.is_nil(bat_hosts.get_bathost('00:aa:bb:cc:dd:00', 'wlan1')) - assert.is_nil(bat_hosts.get_bathost('00:aa:bb:cc:dd:00')) -end) \ No newline at end of file +-- local bat_hosts = require('bat-hosts') +-- local utils = require('lime.utils') +-- local test_utils = require('tests.utils') +-- local shared_state = require('shared-state') +-- +-- it('test get_bathost #bathost', function() +-- shared_state.DATA_DIR = test_utils.setup_test_dir() +-- local sharedState = shared_state.SharedState:new('bat-hosts') +-- sharedState:insert({ +-- ["02:95:39:ab:cd:00"] = "LiMe_abcd00_wlan1_mesh", +-- ["52:00:00:ab:cd:a0"] = "LiMe_abcd01_wlan2_mesh_17", +-- ["d6:67:58:8e:cd:92"] = "LiMe_abcd02_wlan0_adhoc_29", +-- ["12:00:00:00:00:00"] = "LiMe_abcd03_wlan1_adhoc" +-- }) +-- local ifaces = {'wlan1-mesh', 'wlan2-mesh', 'wlan2-mesh_17', 'wlan0-adhoc_29', 'wlan1-adhoc'} +-- stub(utils, "get_ifnames", function () return ifaces end) +-- assert.is.same({hostname='LiMe-abcd00', iface='wlan1-mesh'}, bat_hosts.get_bathost('02:95:39:ab:cd:00')) +-- assert.is.same({hostname='LiMe-abcd01', iface='wlan2-mesh_17'}, bat_hosts.get_bathost('52:00:00:ab:cd:a0')) +-- assert.is.same({hostname='LiMe-abcd02', iface='wlan0-adhoc_29'}, bat_hosts.get_bathost('d6:67:58:8e:cd:92')) +-- assert.is.same({hostname='LiMe-abcd03', iface='wlan1-adhoc'}, bat_hosts.get_bathost('12:00:00:00:00:00')) +-- local ipv6ll = utils.mac2ipv6linklocal('52:00:00:ab:cd:00') .. '%wlan1-mesh' +-- local dataTypeOfSync = nil +-- local urlsOfSync = nil +-- local function syncMock (self, urls) +-- dataTypeOfSync = self.dataType +-- urlsOfSync = urls +-- self:insert({['52:00:00:ab:cd:00'] = "Lime_abcd04_wlan1_mesh"}) +-- end +-- stub(shared_state.SharedState, "sync", syncMock) +-- local bathost = bat_hosts.get_bathost('52:00:00:ab:cd:00', 'wlan1-mesh') +-- assert.is.same(urlsOfSync, { ipv6ll }) +-- assert.is.equal(dataTypeOfSync, 'bat-hosts') +-- assert.is.same({hostname='Lime-abcd04', iface='wlan1-mesh'}, bathost) +-- assert.is_nil(bat_hosts.get_bathost('00:aa:bb:cc:dd:00', 'wlan1')) +-- assert.is_nil(bat_hosts.get_bathost('00:aa:bb:cc:dd:00')) +-- end)