[PATCH 2/2] configurehood: Check for timestamp of hood file over LAN

Tim Niemeyer tim at tn-x.org
So Apr 1 12:47:33 CEST 2018


Moin Adrian

Unten Kommentare.

Im allgemeinen gefällt mir die Architektur aber nicht:

Du vergleichst den Timestamp, aber nur, wenn kein hoodlocal (die config
in /etc) da ist und wenn der Knoten kein Internet Zugang hat und wenn
ein Gateway in der Nähe ist.

Dabei vergleichst du den Timestamp aber jeweils nur unter den Hoodfiles
der Nachbarn, vergisst dabei dein eigenes.

Dann lädst du das Hoodfile vom Gateway, nimmst es aber nur wenn die
Hood gleich heißt und der Timestamp neuer ist. Moment? Wenn das Gateway
nun nen neuen Namen hat, aktualisiert sich diese Wolke nicht mehr?

Ok, jetzt bin ich auch final verwirrt. 

Am Donnerstag, den 08.03.2018, 21:24 +0100 schrieb Adrian Schmutzler:
> This patch does no more take the first hood file it finds, but
> compares the timestamps provided.
> 
> Additionally, we again started to check for the gateway at the
> end, but only take the file if its newer and FROM THE SAME HOOD.
> 
> Thus, we enable updates, but prohobit switching from a cable
> hood to a WiFi peer. (Bug # 68)
> 
> Fixes #95.
> 
> > Signed-off-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>
> 
> ---
> 
> NOT TESTED!
> ---
>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 26 ++++++++++++++++------
>  1 file changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> index 127ce5b..3a6fb9b 100755
> --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> @@ -145,6 +145,7 @@ else
>  
> >  			# check eth first
> >  			oldhood=""
> +			oldtime="0"
Die Variable sollte doch mit dem (sofern es da ist) aktuell verwendeten
Hood-File initialisiert werden?

>  			ethfile="${hoodfile}eth"
> >  			for eth in $(batctl if | grep "eth" | sed -nE 's/.*(eth[^:]+):.*/\1/p'); do
> >  				for mac in $(batctl n | grep "$eth" | sed -nE 's/.*eth[0-9.]+\s+([^\s]+)\s.*/\1/p'); do
> @@ -154,6 +155,7 @@ else
> >  						json_load "$(cat "$ethfile")"
> >  						json_select hood
> >  						json_get_var newhood name
> > +						json_get_var newtime timestamp
> >  						if [ -n "$oldhood" ] && [ -n "$newhood" ] && ( ! [ "$newhood" = "$oldhood" ] ) ; then
> >  							# 2nd hood found, kill interface and go on (next try in 5 min.)
> >  							echo "Two hoods detected. Remove cables to stay in just one."
> @@ -161,18 +163,28 @@ else
> >  							touch "$resetnetworkfile"
> >  							continue 2 # go to the next interface
> >  						fi
> > -						mv "$ethfile" "$hoodfile" # Only use hoodfile if sane
> > +						if [ "$oldtime" -lt "$newtime" ] ; then
> > +							mv "$ethfile" "$hoodfile" # Only use hoodfile if sane and newer
> > +							oldtime="$newtime"
> > +						fi
> >  						[ -n "$oldhood" ] || oldhood="$newhood" # only set oldhood once
> >  					fi
> >  				done
> >  			done
> > -			if [ ! -s "$hoodfile" ]; then
> > -				# Only load hoodfile from gateway if not already present from local network
> > -				# - This gives local network a precedence (take the hood from local network)
> > -				# - This prevents file insertion from a third person, as I will only connect via LAN to who I trust
> > -				wget -T15 -t5 "http://[fe80::1%br-mesh]:2342/keyxchangev2data" -O "$hoodfile"
> +
> > +			# check gateway
> > +			wget -T15 -t5 "http://[fe80::1%br-mesh]:2342/keyxchangev2data" -O "$ethfile"
> > +			if [ -s "$ethfile" ]; then
> > +				json_load "$(cat "$ethfile")"
> > +				json_select hood
> > +				json_get_var newhood name
> > +				json_get_var newtime timestamp
> +				if [ -z "$oldhood" ] || [ "$newhood" = "$oldhood" ] ; then
s.o.

> +					# Gateway on same hood, check for newer hood file
> > +					[ "$oldtime" -lt "$newtime" ] && mv "$ethfile" "$hoodfile" # Only use hoodfile if sane and newer
> > +				fi
> >  			fi
> > -			#UPLINK: Do nothing
> +			#SECTORFILE: Do nothing
Verstehe den Kommentar nicht.

Tim
>  		fi
> >  	fi
>  fi
> -- 
> 2.7.4
> 
-------------- nächster Teil --------------
Ein Dateianhang mit Binärdaten wurde abgetrennt...
Dateiname   : signature.asc
Dateityp    : application/pgp-signature
Dateigröße  : 488 bytes
Beschreibung: This is a digitally signed message part
URL         : <http://lists.freifunk.net/pipermail/franken-dev-freifunk.net/attachments/20180401/4679d7b0/attachment.sig>


Mehr Informationen über die Mailingliste franken-dev