From d7fb0c7fa02a693776e9f09b64d014972033ff1f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 23 Apr 2015 18:18:13 +0200 Subject: [PATCH] gluon-announced: use respondd This also adds an extended query protocol and deflate compression. --- package/gluon-announced/Makefile | 14 +- .../etc/hotplug.d/iface/10-gluon-announced | 16 +- .../files/usr/lib/lua/gluon/announced.lua | 33 +++ package/gluon-announced/src/Makefile | 6 - package/gluon-announced/src/gluon-announced.c | 221 ------------------ 5 files changed, 44 insertions(+), 246 deletions(-) create mode 100644 package/gluon-announced/files/usr/lib/lua/gluon/announced.lua delete mode 100644 package/gluon-announced/src/Makefile delete mode 100644 package/gluon-announced/src/gluon-announced.c diff --git a/package/gluon-announced/Makefile b/package/gluon-announced/Makefile index 1f802dc2..d5b06dce 100644 --- a/package/gluon-announced/Makefile +++ b/package/gluon-announced/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=gluon-announced -PKG_VERSION:=1 +PKG_VERSION:=2 PKG_RELEASE:=1 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) @@ -11,30 +11,22 @@ include $(INCLUDE_DIR)/package.mk define Package/gluon-announced SECTION:=gluon CATEGORY:=Gluon - TITLE:=announced support - DEPENDS:=+gluon-announce -endef - -define Package/gluon-announced/description - Gluon community wifi mesh firmware framework: announced support + TITLE:=Provides node information to the network + DEPENDS:=+gluon-announce +respondd +lua-deflate endef define Build/Prepare mkdir -p $(PKG_BUILD_DIR) - $(CP) ./src/* $(PKG_BUILD_DIR)/ endef define Build/Configure endef define Build/Compile - CFLAGS="$(TARGET_CFLAGS)" CPPFLAGS="$(TARGET_CPPFLAGS)" $(MAKE) -C $(PKG_BUILD_DIR) $(TARGET_CONFIGURE_OPTS) endef define Package/gluon-announced/install $(CP) ./files/* $(1)/ - $(INSTALL_DIR) $(1)/usr/bin - $(INSTALL_BIN) $(PKG_BUILD_DIR)/gluon-announced $(1)/usr/bin/ endef $(eval $(call BuildPackage,gluon-announced)) diff --git a/package/gluon-announced/files/etc/hotplug.d/iface/10-gluon-announced b/package/gluon-announced/files/etc/hotplug.d/iface/10-gluon-announced index 4e8635bd..a1e2c45f 100644 --- a/package/gluon-announced/files/etc/hotplug.d/iface/10-gluon-announced +++ b/package/gluon-announced/files/etc/hotplug.d/iface/10-gluon-announced @@ -4,7 +4,7 @@ . /lib/functions/service.sh DEVLIST=/var/run/gluon-announced.devs -DAEMON=/usr/bin/gluon-announced +DAEMON=/usr/bin/respondd ifname_to_dev () { json_load "$(ubus call network.interface.$1 status)" @@ -18,10 +18,10 @@ restart_announced () { SERVICE_WRITE_PID=1 SERVICE_DAEMONIZE=1 - DEVS=$(cat $DEVLIST | while read dev iface;do echo -n " -i $dev";done) + DEVS=$(cat $DEVLIST | while read dev iface; do echo -n " -i $dev"; done) service_stop $DAEMON - service_start $DAEMON -g ff02:0:0:0:0:0:2:1001 -p 1001 -s '/lib/gluon/announce/collect.lua nodeinfo' $DEVS + service_start $DAEMON -g ff02::2:1001 -p 1001 -c 'return require("gluon.announced").handle_request' $DEVS } case "$ACTION" in @@ -29,14 +29,14 @@ case "$ACTION" in sed -i "/$INTERFACE/d" $DEVLIST ;; ifup) - DEVICE=$(ifname_to_dev $INTERFACE) - MESH=$(cat /sys/class/net/$DEVICE/batman_adv/mesh_iface) + DEVICE="$(ifname_to_dev "$INTERFACE")" + MESH="$(cat "/sys/class/net/$DEVICE/batman_adv/mesh_iface" 2>/dev/null)" - [ $MESH = "bat0" ] || exit 0 + [ "$MESH" = "bat0" -o "$INTERFACE" = "client" ] || exit 0 - DEVS="$(cat $DEVLIST; echo $DEVICE $INTERFACE)" + DEVS=$(cat $DEVLIST; echo $DEVICE $INTERFACE) - echo "$DEVS" | sort | uniq > $DEVLIST + echo "$DEVS" | sort -u > $DEVLIST restart_announced diff --git a/package/gluon-announced/files/usr/lib/lua/gluon/announced.lua b/package/gluon-announced/files/usr/lib/lua/gluon/announced.lua new file mode 100644 index 00000000..99116b81 --- /dev/null +++ b/package/gluon-announced/files/usr/lib/lua/gluon/announced.lua @@ -0,0 +1,33 @@ +local announce = require 'gluon.announce' +local deflate = require 'deflate' +local json = require 'luci.json' + + +local function collect(type) + return announce.collect_dir('/lib/gluon/announce/' .. type .. '.d') +end + + +module('gluon.announced', package.seeall) + +function handle_request(query) + if query:match('^nodeinfo$') then + return json.encode(collect('nodeinfo')) + end + + local m = query:match('^GET ([a-z ]+)$') + if m then + local data = {} + + for q in m:gmatch('([a-z]+)') do + local ok, val = pcall(collect, q) + if ok then + data[q] = val + end + end + + if next(data) then + return deflate.compress(json.encode(data)) + end + end +end diff --git a/package/gluon-announced/src/Makefile b/package/gluon-announced/src/Makefile deleted file mode 100644 index 73e7a9e2..00000000 --- a/package/gluon-announced/src/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -all: gluon-announced - -gluon-announced: gluon-announced.c - -clean: - rm gluon-announced diff --git a/package/gluon-announced/src/gluon-announced.c b/package/gluon-announced/src/gluon-announced.c deleted file mode 100644 index 27de6ece..00000000 --- a/package/gluon-announced/src/gluon-announced.c +++ /dev/null @@ -1,221 +0,0 @@ -/* - Copyright (c) 2014, Nils Schneider - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -void usage() { - puts("Usage: gluon-announced [-h] -g -p -i [-i ..] -s