get "onchain" duniter GVA node

This commit is contained in:
fred 2024-04-16 03:54:56 +02:00
parent 47764387cc
commit 36b000426b
5 changed files with 106 additions and 75 deletions

View File

@ -70,7 +70,7 @@ JSONUPLANET="${HOME}/.zen/tmp/${MOATS}/ONEuplanet.json"
[[ ! -s ${JSONUPLANET} ]] && echo "NO tag[ForkUPlanetZERO] for $PLAYER" && exit 0
UPNAME=$(cat ${JSONUPLANET} | jq -r ".title") # What name is given ?
[[ "${UPNAME}" == "null" || "${UPNAME}" == "" ]] && echo "FATAL ERROR UPNAME .title MISSING" && exit 1
[[ "${UPNAME}" == "null" || "${UPNAME}" == "" ]] && echo "NO FORK UPLANET NAME .title MISSING" && exit 1
HASH=$(cat ${JSONUPLANET} | jq -r ".hash") ## What text hash it has ?
SECRET=$(cat ${JSONUPLANET} | jq -r ".secret") ## What is secret ?
@ -87,9 +87,9 @@ AHAH=$(echo $CONTRACT | sha512sum | cut -d ' ' -f 1)
[[ ! -s $HOME/.zen/game/players/${PLAYER}/.ipfs/${UPNAME}.swarm.key ]] \
&& MSG=$MSG" ${PLAYER}/.ipfs/${UPNAME}.swarm.key NOT FOUND" && ERR="NO LOCAL KEY"
## CREATE 64 bit swarm.key ( maximum individual Fork 1,844674407×10¹⁹ )
## CREATE 32 octets swarm.key ( maximum individual Fork 7,922816251×10²⁸ )
echo -e '/key/swarm/psk/1.0.0/\n/base16/' > $HOME/.zen/tmp/${MOATS}/swarm.key
head -c 64 /dev/urandom | od -t x1 -A none - | tr -d '\n ' >> $HOME/.zen/tmp/${MOATS}/swarm.key
head -c 32 /dev/urandom | od -t x1 -A none - | tr -d '\n ' >> $HOME/.zen/tmp/${MOATS}/swarm.key
echo '' >> $HOME/.zen/tmp/${MOATS}/swarm.key
## EXTRACT CURRENT SECRET FROM JSONUPLANET
@ -144,15 +144,19 @@ echo "${ENCODING}"
#################################################################
## MAKE SAME ENCODING FOR FRIENDS
friends=($(ls ~/.zen/game/players/${PLAYER}/FRIENDS | grep "@" 2>/dev/null))
howmuch=0
for f in ${friends[@]};
do
## Extract FRIENDG1PUB from TW (Astroport Tiddler)
ftw=${HOME}/.zen/game/players/${PLAYER}/FRIENDS/${f}/index.html
tiddlywiki --load ${ftw} --output ~/.zen/tmp/${MOATS} --render '.' "${f}_Astroport.json" 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' 'Astroport'
FRIENDG1PUB=$(cat ~/.zen/tmp/${MOATS}/${f}_Astroport.json | jq -r .[].g1pub)
ASTROPORT=$(cat ~/.zen/tmp/${MOATS}/${f}_Astroport.json | jq -r .[].astroport)
[[ ${ASTROPORT} != "/ipns/${IPFSNODEID}" ]] && echo "FOREIGN ASTROPORT=${ASTROPORT}" && foreign="YES"
echo "$f : $FRIENDG1PUB"
if [[ ${FRIENDG1PUB} ]]; then
if [[ ${FRIENDG1PUB} && ${FRIENDG1PUB} != "null" ]]; then
#~ CHECK IF ALREADY IN JSON
echo "cat ${JSONUPLANET} | jq -r '.\"${f}\"'"
FRIENDIN=$(cat ${JSONUPLANET} | jq -r '."${f}"')
@ -171,11 +175,27 @@ do
&& mv ~/.zen/tmp/${MOATS}/json.up ${JSONUPLANET}
else
echo "- ERROR - Friend TW copy is broken !!"
echo "- FATAL ERROR - Friend TW ${ftw} is broken !!"
continue
fi
## CHECK IF FRIEND HAVE THE SAME ${UPNAME} tiddler
if [[ ${foreign} == "YES" ]]; then
howmuch=$(( howmuch + 1 ))
## SEARCH FOR ${UPNAME} tiddler IN FRIEND TW
tiddlywiki --load ${ftw} --output ~/.zen/tmp/${MOATS} --render '.' "${f}_${UPNAME}.json" 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' "${UPNAME}"
cat ~/.zen/tmp/${MOATS}/${f}_${UPNAME}.json | jq -r '[]."${PLAYER}"'
## CONTROL KEY DECODING
fi
done
echo "<<< MY FRIENDS ARE LOCATED IN $howmuch FOREIGN ASTROPORT >>>"
## UPDATE JSONUPLANET
cat ${JSONUPLANET} | jq '. | ."UPname" = "_UPNAME_"' > ~/.zen/tmp/${MOATS}/json.up \
&& sed -i 's/_UPNAME_/'"$UPNAME"'/g' ~/.zen/tmp/${MOATS}/json.up \

View File

@ -196,6 +196,8 @@ while read LINE; do
&& echo "REDISTRIBUTION DONE" \
&& echo "$TXIDATE" > ~/.zen/game/players/${PLAYER}/.atdate
sleep 3
done < ~/.zen/tmp/${MOATS}/myPalPay.json
echo "====(•‿‿•)======= %%%%% (°▃▃°) %%%%%%% ======(•‿‿•)========"

View File

@ -149,7 +149,7 @@ for SECTOR in ${SECTORS[@]}; do
## IF NOT UPDATED FOR TOO LONG : STRAPS[0] get key control
[ ${DIFF_SECONDS} -gt $(( 26 * 60 * 60 )) ] \
&& echo "More than 26H update" \
&& echo ">>>>>>>>>>>>>> More than 26H update - BOOSTRAP 0 ACTION -" \
&& ACTINGNODE=${STRAPS[0]}
echo "* ACTINGNODE=${ACTINGNODE}"
@ -170,8 +170,7 @@ for SECTOR in ${SECTORS[@]}; do
mv ${UREFRESH}.shuf ${UREFRESH}
echo "SETTING NEXT REFRESHER : $(cat ${UREFRESH} | head -n 1)"
############ 101 ZEN REFILL ?!
############ 101 ZEN (11.1 G1) REFILL ?!
CURRENT=$(readlink ~/.zen/game/players/.current | rev | cut -d '/' -f 1 | rev)
[[ ${COINS} == "" || ${COINS} == "null" ]] \
&& [[ ${ZEN} -lt 100 && ${CURRENT} != "" ]] \

View File

@ -164,7 +164,7 @@ for UMAP in ${unique_combined[@]}; do
## IF NOT UPDATED FOR TOO LONG
[[ ${DIFF_SECONDS} -gt $(( 26 * 60 * 60 )) || ${DIFF_SECONDS} -eq 0 ]] \
&& echo "More than 26H update - BOOSTRAP 0 ACTION -" \
&& echo ">>>>>>>>>>>>>> More than 26H update - BOOSTRAP 0 ACTION -" \
&& ACTINGNODE=${STRAPS[0]}
echo "* ACTINGNODE=${ACTINGNODE}"
@ -191,7 +191,7 @@ for UMAP in ${unique_combined[@]}; do
echo ">> NEXT REFRESHER WILL BE $(cat ${UREFRESH} | head -n 1)"
######################################################## # NODE SELECTION in UMAP.refresher
############ 101 ZEN REFILL ?!
############ 101 ZEN (11.1 G1) REFILL ?!
CURRENT=$(readlink ~/.zen/game/players/.current | rev | cut -d '/' -f 1 | rev)
[[ ${COINS} == "" || ${COINS} == "null" ]] \
&& [[ ${ZEN} -lt 100 && ${CURRENT} != "" ]] \

View File

@ -10,66 +10,63 @@
checkonenode()
{
# Timeout in seconds for https nodes
httpsTimeout=1
# Timeout in seconds for http nodes
httpTimeout=1
# Timeout in seconds for https nodes
httpsTimeout=1
# Timeout in seconds for http nodes
httpTimeout=1
node=$1
watched=$2
outfile=$3
# Curl: -m timeout, -k ignore SSL certificate errors
cur=`echo "$( { curl -m $httpsTimeout -k https://$node/blockchain/current; } 2>&1 )"`
n=$node
if [[ "$cur" != *issuersFrameVar* ]]
then
# It failed in https, maybe try http?
cur=`echo "$( { curl -m $httpTimeout http://$node/blockchain/current; } 2>&1 )"`
if [[ "$cur" == *issuersFrameVar* ]]
then
# Indicate that the node is http
n="$n-(http)"
fi
fi
if [[ "$cur" != *issuersFrameVar* ]]
then
# The node didn't respond on time
cur="ERROR"
else
# The node did respond - grab the block number and hash of the block as key
cur="`echo "$cur"|grep '^ "number": '|awk '{print $2}'|awk -F, '{print $1}'`-`echo "$cur"|grep '^ "hash": '|awk '{print $2}'|awk '{print substr($1,2,13)}'`"
fi
if [[ $watched =~ .*#$node#.* ]]
then
# The node is a watched node, add some bold
n="\e[1m$n\e[0m"
fi
# Put the result into the file
echo "$cur $n">$outfile
# Notify that we're done here
touch $outfile.done
node=$1
watched=$2
outfile=$3
# Curl: -m timeout, -k ignore SSL certificate errors
cur=`echo "$( { curl -m $httpsTimeout -k https://$node/blockchain/current; } 2>&1 )"`
n=$node
if [[ "$cur" != *issuersFrameVar* ]]
then
# It failed in https, maybe try http?
cur=`echo "$( { curl -m $httpTimeout http://$node/blockchain/current; } 2>&1 )"`
if [[ "$cur" == *issuersFrameVar* ]]
then
# Indicate that the node is http
n="$n-(http)"
fi
fi
if [[ "$cur" != *issuersFrameVar* ]]
then
# The node didn't respond on time
cur="ERROR"
else
# The node did respond - grab the block number and hash of the block as key
cur="`echo "$cur"|grep '^ "number": '|awk '{print $2}'|awk -F, '{print $1}'`-`echo "$cur"|grep '^ "hash": '|awk '{print $2}'|awk '{print substr($1,2,13)}'`"
fi
if [[ $watched =~ .*#$node#.* ]]
then
# The node is a watched node, add some bold
n="\e[1m$n\e[0m"
fi
echo "$node : $cur"
# Put the result into the file
echo "$cur $n">$outfile
# Notify that we're done here
touch $outfile.done
}
# Temp dir where results are stored
rm -Rf /tmp/zen/gnodewatch
DIR=/tmp/zen/gnodewatch
rm -Rf ~/.zen/tmp/gnodewatch
DIR=~/.zen/tmp/gnodewatch
export DIR
mkdir -p $DIR/chains
# TODO: REMOVE 777 PATCH, ACTIVATE ramdisk
# sudo mkdir /mnt/ramdisk
# sudo mount -t tmpfs -o size=50m tmpfs /mnt/ramdisk
chmod -R 777 /tmp/zen/
# KEEP /tmp/zen/current.duniter for 5 mn
find /tmp/zen/ -mmin +5 -type f -name "current.duniter" -exec rm -f '{}' \;
[[ -f /tmp/zen/current.duniter ]] && cat /tmp/zen/current.duniter && exit 0
# KEEP ~/.zen/tmp/current.duniter for 5 mn
#~ find ~/.zen/tmp/ -mmin +5 -type f -name "current.duniter" -exec rm -f '{}' \;
#~ [[ -f ~/.zen/tmp/current.duniter ]] && cat ~/.zen/tmp/current.duniter && exit 0
##### $DIR/duniter_nodes.txt REFRESH after 20 minutes #####
find $DIR/ -mmin +20 -type f -name "duniter_*" -exec rm -f '{}' \;
if [[ ! -f $DIR/duniter_nodes.txt ]]; then
# Get New BMAS known Nodes list from shuffle one $DIR/good.nodes.txt
[[ -f $DIR/good.nodes.txt ]] && DUNITER=$(shuf -n 1 $DIR/good.nodes.txt) || DUNITER="duniter-g1.p2p.legal:443"
curl -s https://$DUNITER/network/peers | jq '.peers[] | .endpoints' | grep BMAS | awk '{print $2,$3}' | sed s/\"//g | sed s/\,//g | sed s/\ /:/g | sort -u > $DIR/duniter_nodes.txt
# Get New BMAS known Nodes list from shuffle one $DIR/good.nodes.txt
[[ -f $DIR/good.nodes.txt ]] && DUNITER=$(shuf -n 1 $DIR/good.nodes.txt) || DUNITER="g1.copylaradio.com:443"
curl -s https://$DUNITER/network/peers | jq '.peers[] | .endpoints' | grep GVA | awk '{print $3,$4}' | sed s/\"//g | sed s/\,//g | sed s/\ /:/g | sort -u > $DIR/duniter_nodes.txt
fi
# Grab the nodes we are actively watching - they will be in bold in the final output
@ -84,8 +81,10 @@ rm $DIR/*out $DIR/*done $DIR/chains/* $DIR/NODE.* 2>/dev/null
# Query all nodes in parallel
for node in $nodes
do
checkonenode $node "$watched" $DIR/$index.out &
((index++))
#~ echo "checkonenode $node "$watched" $DIR/$index.out"
checkonenode $node "$watched" $DIR/$index.out
#~ cat $DIR/$index.out
((index++))
done
# Wait a little for the first files to be created
@ -93,7 +92,7 @@ sleep 1s
# Wait for all the threads to report they are done
while [ `ls $DIR/*done|wc -l` -lt $index ]
do
sleep 1s
sleep 1s
done
# Grab all results
@ -105,28 +104,39 @@ chains="`echo "$curs"|grep -v ERROR|awk '{print $1}'|sort -r|uniq`"
nb=0
for chain in $chains
do
echo "$curs" | egrep "^$chain " | awk '{print $2}' >> $DIR/chains/$nb;
((nb++))
echo "$curs" | egrep "^$chain " | awk '{print $2}' >> $DIR/chains/$nb;
((nb++))
done
longchain=$(ls -S $DIR/chains/ | head -n 1)
echo "CHAIN:$chains"
# WRITE OUT shuffle Duniter Node Sync with longest chain
cp $DIR/chains/$longchain $DIR/good.nodes.txt
cat $DIR/chains/$longchain | shuf > $DIR/good.nodes.txt
## TEST if server is really running Duniter
Dtest=""; IDtest=""; lastresult=""; loop=0
while [[ $Dtest != "duniter" ]]; do
while [[ $lastresult == $result && $loop -lt 7 ]]; do result=$(shuf -n 1 $DIR/good.nodes.txt); ((loop++)); done
lastresult=$result
Dtest=$(curl -s https://$lastresult | jq -r .duniter.software)
while read lastresult;
do
## CHECK if server is not too slow
[[ $Dtest == "duniter" ]] && IDtest=$(silkaj -p $lastresult id Fred)
[[ $IDtest == "" ]] && Dtest=""
[[ $loop -eq 8 ]] && result="duniter-g1.p2p.legal:443" && break
echo "curl -s -m 5 https://$lastresult | jq -r .duniter.software"
Dtest=$(curl -s -m 5 https://$lastresult | jq -r .duniter.software)
echo "$Dtest"
gvaserver=$(echo $lastresult | sed "s~:443~/gva~g" )
[[ "$Dtest" == "duniter" ]] \
&& echo "jaklis -n https://$gvaserver balance -p DsEx1pS33vzYZg4MroyBV9hCw98j1gtHEhwiZ5tK7ech" \
&& IDtest=$(jaklis -n https://$gvaserver balance -p DsEx1pS33vzYZg4MroyBV9hCw98j1gtHEhwiZ5tK7ech 2>/dev/null)
echo $IDtest
[[ $IDtest != "" && $IDtest != "null" ]] && result="https://$gvaserver" && break
[[ $loop -eq 8 ]] \
&& result="g1.copylaradio.com:443" && break
((loop++))
done
done < $DIR/good.nodes.txt
echo "$result" > /tmp/zen/current.duniter
echo "$result" > ~/.zen/tmp/current.duniter
echo $result