[2/3] fff-hoods: Improve hoodfile gathering logic

Submitted by Fabian Blaese on May 6, 2020, 2:48 p.m.

Details

Message ID 20200506144803.590699-2-fabian@blaese.de
State Changes Requested
Headers show

Commit Message

Fabian Blaese May 6, 2020, 2:48 p.m.
Instead of seperately checking for various conditions,
which don't actually guarantee that the hoodfile can be
fetched in a certain way (e.g. internet is available but
keyxchange is down), the already built in return value of
the hoodfile gathering functions is utilized.

This change slightly changes the behaviour of nodes in
certian edge cases:
- If no hoodfile could be fetched from keyxchange, the
  next delivery method (getGatewayHoodfile) is used
- If the gateway is unable to deliver a hoodfile, nodes
  now behave like the gateway is unreachable, instead of
  continuing to use old hoodfiles

These behaviour changes should be an improvement over the
previous behaviour:
- VPN nodes don't disconnect and break the whole network
  if the keyxchange is unreachable, but instead try to
  fetch the hoodfile from the gateway
- Instead of checking for batman gateway announcements,
  which are completely unrelated to hoodfile delivery using
  fe80::1, the actual status of the hoodfile download is
  utilized. This has two effects:
  - hoodfile delivery using fe80::1 works even if batmans
    gateway selection isn't used at all
  - if the batman gateway selection is active, but fe80::1
    hoodfile delivery is broken in the hood, the nodes disconnect
    from the hood and try to gather their hoodfile from nerby
    nodes. Previously they continued to use the old hoodfile.
    This should make misconfigured gateways more apparent.

Signed-off-by: Fabian Bläse <fabian@blaese.de>
---
 .../fff-hoods/files/usr/sbin/configurehood    | 46 +++++++++----------
 1 file changed, 22 insertions(+), 24 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
index 3b92cbc..261b926 100755
--- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
+++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
@@ -69,32 +69,30 @@  if [ -s "$hoodfilelocal" ]; then
 	cp "$hoodfilelocal" "$hoodfiletmp"
 	echo "Use local hood file"
 else
-	# if we have Internet, we download the Hoodfile from the keyxchangev2
-	if hasInternet ; then
-		getKeyserverHoodfile "$hoodfiletmp" && cp "$hoodfiletmp" "$hoodfilewww"
-
-		#if no Internet, we connect to the hidden AP and download the file from another Node in range
+	# if internet is available, the hoodfile is downloaded from our keyserver
+	if getKeyserverHoodfile "$hoodfiletmp"; then
+		cp "$hoodfiletmp" "$hoodfilewww"
+
+	# if no internet is available, but the node is already configured,
+	# a gateway with the appropriate hoodfile should be available
+	else if getGatewayHoodfile "$hoodfiletmp"; then
+		cp "$hoodfiletmp" "$hoodfilewww"
+
+	# no internet and no gateway available. the node is either unconfigured,
+	# has lost connectivity or the hood is broken. Try to regain connectivity by
+	# fetching hoodfiles from nearby nodes
 	else
-		# connect to wireless hidden ap here and download the json File from the nearest router
-		# Only do that, when we have no gateway in range. If the Uplinkrouter changed the hood, we lost the GW and do this automatically again, I think! Nice idea?
-		if ! isGatewayAvailable ; then
-			#now we haven't a gateway in Range, we search for a hidden AP to get a keyxchangev2data file!
-			#first we delete all wifi settings
-			rm -f "$hoodfileref" # delete this, so interfaces are recreated if reconnect with unchanged hood file takes place
-			rm -f "$hoodfilewww" # delete this, so wrong hood file is not broadcasted anymore
-
-			uci -q del "system.@system[0].hood"
-			uci -q del "system.@system[0].hoodid"
-			uci commit system
-			reload_config
-		
-			sleep 30 # Wait for the config AP, which may be created at the same time as this script has started
+		rm -f "$hoodfileref" # delete this, so interfaces are recreated if reconnect with unchanged hood file takes place
+		rm -f "$hoodfilewww" # delete this, so wrong hood file is not broadcasted anymore
 
-			getEthernetHoodfile "$hoodfiletmp" || getWirelessHoodfile "$hoodfiletmp"
-		else
-			echo "We have a Gateway in Range, we load the keyxchangev2data from fe80::1"
-			getGatewayHoodfile "$hoodfiletmp" && cp "$hoodfiletmp" "$hoodfilewww"
-		fi
+		uci -q del "system.@system[0].hood"
+		uci -q del "system.@system[0].hoodid"
+		uci commit system
+		reload_config
+
+		sleep 30 # Wait for the config AP, which may be created at the same time as this script has started
+
+		getEthernetHoodfile "$hoodfiletmp" || getWirelessHoodfile "$hoodfiletmp"
 	fi
 fi
 

Comments

Robert Langhammer June 17, 2020, 6:50 a.m.
Hi Fabian,

soweit ich das überschauen kann, und das ist beim configurehood nicht
immer einfach, sollte es funktionieren.

Reviewed-by: Robert Langhammer <rlanghammer@web.de>

Am 06.05.20 um 16:48 schrieb Fabian Bläse:
> Instead of seperately checking for various conditions,
> which don't actually guarantee that the hoodfile can be
> fetched in a certain way (e.g. internet is available but
> keyxchange is down), the already built in return value of
> the hoodfile gathering functions is utilized.
>
> This change slightly changes the behaviour of nodes in
> certian edge cases:
> - If no hoodfile could be fetched from keyxchange, the
>   next delivery method (getGatewayHoodfile) is used
> - If the gateway is unable to deliver a hoodfile, nodes
>   now behave like the gateway is unreachable, instead of
>   continuing to use old hoodfiles
>
> These behaviour changes should be an improvement over the
> previous behaviour:isGatewayAvailable
> - VPN nodes don't disconnect and break the whole network
>   if the keyxchange is unreachable, but instead try to
>   fetch the hoodfile from the gateway
> - Instead of checking for batman gateway announcements,
>   which are completely unrelated to hoodfile delivery using
>   fe80::1, the actual status of the hoodfile download is
>   utilized. This has two effects:
>   - hoodfile delivery using fe80::1 works even if batmans
>     gateway selection isn't used at all
>   - if the batman gateway selection is active, but fe80::1
>     hoodfile delivery is broken in the hood, the nodes disconnect
>     from the hood and try to gather their hoodfile from nerby
>     nodes. Previously they continued to use the old hoodfile.
>     This should make misconfigured gateways more apparent.
>
> Signed-off-by: Fabian Bläse <fabian@blaese.de>
> ---
>  .../fff-hoods/files/usr/sbin/configurehood    | 46 +++++++++----------
>  1 file changed, 22 insertions(+), 24 deletions(-)
>
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> index 3b92cbc..261b926 100755
> --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> @@ -69,32 +69,30 @@ if [ -s "$hoodfilelocal" ]; then
>  	cp "$hoodfilelocal" "$hoodfiletmp"
>  	echo "Use local hood file"
>  else
> -	# if we have Internet, we download the Hoodfile from the keyxchangev2
> -	if hasInternet ; then
> -		getKeyserverHoodfile "$hoodfiletmp" && cp "$hoodfiletmp" "$hoodfilewww"
> -
> -		#if no Internet, we connect to the hidden AP and download the file from another Node in range
> +	# if internet is available, the hoodfile is downloaded from our keyserver
> +	if getKeyserverHoodfile "$hoodfiletmp"; then
> +		cp "$hoodfiletmp" "$hoodfilewww"
> +
> +	# if no internet is available, but the node is already configured,
> +	# a gateway with the appropriate hoodfile should be available
> +	else if getGatewayHoodfile "$hoodfiletmp"; then
> +		cp "$hoodfiletmp" "$hoodfilewww"
> +
> +	# no internet and no gateway available. the node is either unconfigured,
> +	# has lost connectivity or the hood is broken. Try to regain connectivity by
> +	# fetching hoodfiles from nearby nodes
>  	else
> -		# connect to wireless hidden ap here and download the json File from the nearest router
> -		# Only do that, when we have no gateway in range. If the Uplinkrouter changed the hood, we lost the GW and do this automatically again, I think! Nice idea?
> -		if ! isGatewayAvailable ; then
> -			#now we haven't a gateway in Range, we search for a hidden AP to get a keyxchangev2data file!
> -			#first we delete all wifi settings
> -			rm -f "$hoodfileref" # delete this, so interfaces are recreated if reconnect with unchanged hood file takes place
> -			rm -f "$hoodfilewww" # delete this, so wrong hood file is not broadcasted anymore
> -
> -			uci -q del "system.@system[0].hood"
> -			uci -q del "system.@system[0].hoodid"
> -			uci commit system
> -			reload_config
> -		
> -			sleep 30 # Wait for the config AP, which may be created at the same time as this script has started
> +		rm -f "$hoodfileref" # delete this, so interfaces are recreated if reconnect with unchanged hood file takes place
> +		rm -f "$hoodfilewww" # delete this, so wrong hood file is not broadcasted anymore
>  
> -			getEthernetHoodfile "$hoodfiletmp" || getWirelessHoodfile "$hoodfiletmp"
> -		else
> -			echo "We have a Gateway in Range, we load the keyxchangev2data from fe80::1"
> -			getGatewayHoodfile "$hoodfiletmp" && cp "$hoodfiletmp" "$hoodfilewww"
> -		fi
> +		uci -q del "system.@system[0].hood"
> +		uci -q del "system.@system[0].hoodid"
> +		uci commit system
> +		reload_config
> +
> +		sleep 30 # Wait for the config AP, which may be created at the same time as this script has started
> +
> +		getEthernetHoodfile "$hoodfiletmp" || getWirelessHoodfile "$hoodfiletmp"
>  	fi
>  fi
>
Adrian Schmutzler June 18, 2020, 10:59 a.m.
Erscheint mir sinnvoll und mir fällt im Moment auch nichts ein, wo es kaputt geht.

Der Codefluss wird zudem schöner.

Reviewed-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>

> -----Original Message-----
> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
> Of Fabian Bläse
> Sent: Mittwoch, 6. Mai 2020 16:48
> To: franken-dev@freifunk.net
> Subject: [PATCH 2/3] fff-hoods: Improve hoodfile gathering logic
> 
> Instead of seperately checking for various conditions, which don't actually
> guarantee that the hoodfile can be fetched in a certain way (e.g. internet is
> available but keyxchange is down), the already built in return value of the
> hoodfile gathering functions is utilized.
> 
> This change slightly changes the behaviour of nodes in certian edge cases:
> - If no hoodfile could be fetched from keyxchange, the
>   next delivery method (getGatewayHoodfile) is used
> - If the gateway is unable to deliver a hoodfile, nodes
>   now behave like the gateway is unreachable, instead of
>   continuing to use old hoodfiles
> 
> These behaviour changes should be an improvement over the previous
> behaviour:
> - VPN nodes don't disconnect and break the whole network
>   if the keyxchange is unreachable, but instead try to
>   fetch the hoodfile from the gateway
> - Instead of checking for batman gateway announcements,
>   which are completely unrelated to hoodfile delivery using
>   fe80::1, the actual status of the hoodfile download is
>   utilized. This has two effects:
>   - hoodfile delivery using fe80::1 works even if batmans
>     gateway selection isn't used at all
>   - if the batman gateway selection is active, but fe80::1
>     hoodfile delivery is broken in the hood, the nodes disconnect
>     from the hood and try to gather their hoodfile from nerby
>     nodes. Previously they continued to use the old hoodfile.
>     This should make misconfigured gateways more apparent.
> 
> Signed-off-by: Fabian Bläse <fabian@blaese.de>
> ---
>  .../fff-hoods/files/usr/sbin/configurehood    | 46 +++++++++----------
>  1 file changed, 22 insertions(+), 24 deletions(-)
> 
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> index 3b92cbc..261b926 100755
> --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> @@ -69,32 +69,30 @@ if [ -s "$hoodfilelocal" ]; then
>  	cp "$hoodfilelocal" "$hoodfiletmp"
>  	echo "Use local hood file"
>  else
> -	# if we have Internet, we download the Hoodfile from the
> keyxchangev2
> -	if hasInternet ; then
> -		getKeyserverHoodfile "$hoodfiletmp" && cp "$hoodfiletmp"
> "$hoodfilewww"
> -
> -		#if no Internet, we connect to the hidden AP and download
> the file from another Node in range
> +	# if internet is available, the hoodfile is downloaded from our
> keyserver
> +	if getKeyserverHoodfile "$hoodfiletmp"; then
> +		cp "$hoodfiletmp" "$hoodfilewww"
> +
> +	# if no internet is available, but the node is already configured,
> +	# a gateway with the appropriate hoodfile should be available
> +	else if getGatewayHoodfile "$hoodfiletmp"; then
> +		cp "$hoodfiletmp" "$hoodfilewww"
> +
> +	# no internet and no gateway available. the node is either
> unconfigured,
> +	# has lost connectivity or the hood is broken. Try to regain
> connectivity by
> +	# fetching hoodfiles from nearby nodes
>  	else
> -		# connect to wireless hidden ap here and download the json
> File from the nearest router
> -		# Only do that, when we have no gateway in range. If the
> Uplinkrouter changed the hood, we lost the GW and do this automatically
> again, I think! Nice idea?
> -		if ! isGatewayAvailable ; then
> -			#now we haven't a gateway in Range, we search for a
> hidden AP to get a keyxchangev2data file!
> -			#first we delete all wifi settings
> -			rm -f "$hoodfileref" # delete this, so interfaces are
> recreated if reconnect with unchanged hood file takes place
> -			rm -f "$hoodfilewww" # delete this, so wrong hood
> file is not broadcasted anymore
> -
> -			uci -q del "system.@system[0].hood"
> -			uci -q del "system.@system[0].hoodid"
> -			uci commit system
> -			reload_config
> -
> -			sleep 30 # Wait for the config AP, which may be
> created at the same time as this script has started
> +		rm -f "$hoodfileref" # delete this, so interfaces are recreated
> if reconnect with unchanged hood file takes place
> +		rm -f "$hoodfilewww" # delete this, so wrong hood file is not
> +broadcasted anymore
> 
> -			getEthernetHoodfile "$hoodfiletmp" ||
> getWirelessHoodfile "$hoodfiletmp"
> -		else
> -			echo "We have a Gateway in Range, we load the
> keyxchangev2data from fe80::1"
> -			getGatewayHoodfile "$hoodfiletmp" && cp
> "$hoodfiletmp" "$hoodfilewww"
> -		fi
> +		uci -q del "system.@system[0].hood"
> +		uci -q del "system.@system[0].hoodid"
> +		uci commit system
> +		reload_config
> +
> +		sleep 30 # Wait for the config AP, which may be created at
> the same
> +time as this script has started
> +
> +		getEthernetHoodfile "$hoodfiletmp" || getWirelessHoodfile
> "$hoodfiletmp"
>  	fi
>  fi
> 
> --
> 2.26.2
Adrian Schmutzler July 20, 2020, 12:33 p.m.
> +     else if getGatewayHoodfile "$hoodfiletmp"; then 

Wie schon im IRC besprochen:

"else if" is keine valide Syntax für shell.

Bitte entsprechend korrigieren und testen.

Ansonsten erscheint mir der Code wie schon testiert sinnvoll, kann also nach Änderung/Test auch gerne gleich gemergt werden.

Beste Grüße

Adrian