[v2] fff-hoods: Improve hoodfile gathering logic

Submitted by Fabian Blaese on July 31, 2020, 8:58 p.m.

Details

Message ID 20200731205849.868789-1-fabian@blaese.de
State Accepted
Headers show

Commit Message

Fabian Blaese July 31, 2020, 8:58 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>
---
Changes in v2:
- Fix incorrect 'else if' syntax
---
 .../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..766066a 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
+	elif 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

Adrian Schmutzler Aug. 1, 2020, 10:11 a.m.
Applied.

> -----Original Message-----
> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
> Of Fabian Bläse
> Sent: Freitag, 31. Juli 2020 22:59
> To: franken-dev@freifunk.net
> Subject: [PATCH v2] 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>
> ---
> Changes in v2:
> - Fix incorrect 'else if' syntax
> ---
>  .../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..766066a 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
> +	elif 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.28.0