jaklis update

This commit is contained in:
fred 2023-07-19 14:02:45 +02:00
parent 4c05a66edf
commit 14aa8911fd
31 changed files with 166140 additions and 266 deletions

137
duniter_getnode.sh Executable file
View File

@ -0,0 +1,137 @@
#!/bin/bash
################################################################################
# Authors: @jytou (https://git.duniter.org/jytou)
# Modified by Fred (support@qo-op.com)
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
################################################################################
# Checks the current block number of $DIR/duniter_nodes.txt (is run in parallel)
# and output random (from last synchronized) node
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
checkonenode()
{
# 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
}
# Temp dir where results are stored
rm -Rf /tmp/zen/gnodewatch
DIR=/tmp/zen/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
##### $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="g1.duniter.org"
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
fi
# Grab the nodes we are actively watching - they will be in bold in the final output
watched=`grep -v "#" $DIR/duniter_nodes.txt|egrep "\!$"|awk '{print "#" $1 "#"}'`
# All nodes we are watching
nodes=`grep -v "#" $DIR/duniter_nodes.txt|awk '{print $1}'`
# The index to generate separate file names
index=0
# Wipe out the output directory
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++))
done
# Wait a little for the first files to be created
sleep 1s
# Wait for all the threads to report they are done
while [ `ls $DIR/*done|wc -l` -lt $index ]
do
sleep 1s
done
# Grab all results
curs=`cat $DIR/*out|sort`
# Extract all forks, excluding all errors
chains="`echo "$curs"|grep -v ERROR|awk '{print $1}'|sort -r|uniq`"
# Count the number of chains and output most recent consensus to "good.nodes.txt"
nb=0
for chain in $chains
do
echo "$curs" | egrep "^$chain " | awk '{print $2}' >> $DIR/chains/$nb;
((nb++))
done
longchain=$(ls -S $DIR/chains/ | head -n 1)
echo "longchain=$longchain"
# WRITE OUT shuffle Duniter Node Sync with longest chain
cp $DIR/chains/$longchain $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)
## CHECK if server is not too slow
[[ $Dtest == "duniter" ]] && break
((loop++))
done
[[ $(echo "$result" | grep ":443") ]] \
&& res="https://"$(echo "$result" | cut -d ':' -f 1) \
|| res="https://$result"
echo "$res" > /tmp/zen/current.duniter
echo $res

165650
geoloc-members.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -2,9 +2,15 @@
DUNIKEY=/.zen/game/players/.current/secret.dunikey
# Noeud Duniter
NODE=https://g1.asycn.io/gva
#NODE=https://g1.asycn.io/gva
NODE=https://duniter.pini.fr/gva
#NODE=https://g1.brussels.ovh/gva
# https://ginspecte.mithril.re/service_types/1
# ??? NODE=https://g1.geragc.es/gva
# ??? NODE=https:g1.cuates.net/gva
#NODE=https://g1.duniter.org
# Adresse du pod Cesium ou Gchange à utiliser
#POD=https://g1.data.le-sou.org
POD=https://g1.data.le-sou.org
#POD=https://g1.data.duniter.fr
POD=https://data.gchange.fr
#POD=https://data.gchange.fr

File diff suppressed because it is too large Load Diff

51
run.sh
View File

@ -11,6 +11,7 @@ ME="${0##*/}"
################################################################################
DUNITER="https://g1.le-sou.org"
CESIUM="https://g1.data.le-sou.org"
CESIUM="https://g1.data.e-is.pro"
# TEST INTERNET CONNEXION
#~ ip="$(ifconfig wlan0 | grep "inet " | awk '{print $2}')"
@ -31,6 +32,8 @@ CESIUM="https://g1.data.le-sou.org"
total=$(cat "${MY_PATH}/members.json" | jq '.results' | jq length)
echo "$total membres"
mkdir -p ${MY_PATH}/tmp
# Forever Loop
while :
do
@ -38,6 +41,9 @@ do
numero=$((RANDOM % $total))
member=$(($numero - 1))
NODE=$(${MY_PATH}/duniter_getnode.sh | tail -n 1)
# Récupération de son uid et pubkey
MEMBER=$(cat "${MY_PATH}/members.json" | jq ".results[$member].uid" | sed s/\"//g)
PUBKEY=$(cat "${MY_PATH}/members.json" | jq ".results[$member].pubkey" | sed s/\"//g)
@ -48,18 +54,24 @@ do
mkdir -p "${MY_PATH}/SCAN/${PUBKEY}"
# silkaj : Record uid / history / amount
touch "${MY_PATH}/SCAN/${PUBKEY}/${MEMBER}"
echo ${PUBKEY} > "${MY_PATH}/SCAN/${PUBKEY}/.g1pub" # uid
${MY_PATH}/jaklis/jaklis.py balance -p ${PUBKEY} > "${MY_PATH}/SCAN/${PUBKEY}/COINS"
${MY_PATH}/jaklis/jaklis.py history -p ${PUBKEY} -j -n 200 > "${MY_PATH}/SCAN/${PUBKEY}/history.json" # history
echo ${PUBKEY} > "${MY_PATH}/SCAN/${PUBKEY}/G1PUB" # uid
silkaj money balance ${PUBKEY} > "${MY_PATH}/SCAN/${PUBKEY}/COINS"
amount=$(cat "${MY_PATH}/SCAN/${PUBKEY}/COINS")
zen=$(echo $amount | awk '{print $1 * 100}')
g1=$(echo $amount | cut -d '.' -f 1)
[[ ! $g1 -gt 0 ]] && echo "ERROR $g1" && sleep 30 && continue
${MY_PATH}/jaklis/jaklis.py -n $NODE history -p ${PUBKEY} -j -n 200 > "${MY_PATH}/SCAN/${PUBKEY}/history.json" # history
[ $? != 0 ] && echo "ERROR ${MY_PATH}/jaklis/jaklis.py -n $NODE history -p ${PUBKEY} -j -n 200" && sleep 30 && continue
usage=$(cat "${MY_PATH}/SCAN/${PUBKEY}/history.json" | jq length)
mkdir -p "${MY_PATH}/USAGE/$usage"
ln -s ${MY_PATH}/SCAN/${PUBKEY} ${MY_PATH}/USAGE/$usage/${MEMBER}
amount=$(cat "${MY_PATH}/SCAN/${PUBKEY}/COINS")
zen=$(echo $amount | awk '{print $1 * 100}')
g1=$(echo $amount | cut -d '.' -f 1)
mkdir -p "${MY_PATH}/COINS/$g1/"
ln -s ${MY_PATH}/SCAN/${PUBKEY} ${MY_PATH}/COINS/$g1/${MEMBER}
@ -72,32 +84,23 @@ do
if [[ "$zen" != "" ]]; then
echo "Profiling..."
echo "Profiling... ${CESIUM}/user/profile/${PUBKEY}"
curl -s ${CESIUM}/user/profile/${PUBKEY} > "${MY_PATH}/tmp/${PUBKEY}"
curl -s ${CESIUM}/user/profile/${PUBKEY} > "${MY_PATH}/SCAN/${PUBKEY}/profile.json"
[[ ! -s "${MY_PATH}/SCAN/${PUBKEY}/profile.json" ]] && echo "NO PROFILE" && continue
echo "$zen" > "${MY_PATH}/SCAN/${PUBKEY}/ZEN"
# Write Member details
cat "${MY_PATH}/tmp/${PUBKEY}" | jq '._source.socials' > "${MY_PATH}/SCAN/${PUBKEY}/social.json"
cat "${MY_PATH}/tmp/${PUBKEY}" | jq '._source.title' > "${MY_PATH}/SCAN/${PUBKEY}/adressse.json"
cat "${MY_PATH}/tmp/${PUBKEY}" | jq '._source.address' >> "${MY_PATH}/SCAN/${PUBKEY}/adressse.json"
cat "${MY_PATH}/tmp/${PUBKEY}" | jq '._source.city' >> "${MY_PATH}/SCAN/${PUBKEY}/adressse.json"
cat "${MY_PATH}/tmp/${PUBKEY}" | jq '._source.description' > "${MY_PATH}/SCAN/${PUBKEY}/description.json"
cat "${MY_PATH}/tmp/${PUBKEY}" | jq '._source.geoPoint' > "${MY_PATH}/SCAN/${PUBKEY}/geoPoint.json"
cat "${MY_PATH}/IPFS/MEMBERS/${MEMBER}/social.json" | jq -r
cat "${MY_PATH}/IPFS/MEMBERS/${MEMBER}/social.json" >> ${MY_PATH}/collect.log
fi
# Téléchargement de la photo Cesium+?
test=$(curl -s ${CESIUM}/user/profile/${PUBKEY} | jq '._source.avatar._content')
test=$(cat "${MY_PATH}/SCAN/${PUBKEY}/profile.json" | jq '._source.avatar._content')
if [[ $test != null && $test != "" ]]; then
# GET avatar.png, rotate, put over in G1.png, write member name, 3 color then display
curl -s ${CESIUM}/user/profile/${PUBKEY} | jq '._source.avatar._content' | sed 's/\"//g' | base64 -d > "${MY_PATH}/SCAN/${PUBKEY}/avatar.png"
cat "${MY_PATH}/SCAN/${PUBKEY}/profile.json" | jq '._source.avatar._content' | sed 's/\"//g' | base64 -d > "${MY_PATH}/SCAN/${PUBKEY}/avatar.png"
convert "${MY_PATH}/SCAN/${PUBKEY}/avatar.png" -rotate 90 "${MY_PATH}/tmp/rotate.png"
composite -compose Over -gravity East "${MY_PATH}/tmp/rotate.png" "${MY_PATH}/G1.png" "/tmp/image0.png"
@ -116,7 +119,9 @@ do
fi
echo "g1_avatar.png"
cp "${MY_PATH}/tmp/uid.png" "${MY_PATH}/IPFS/MEMBERS/${MEMBER}/g1_avatar.png"
echo "COOL g1_avatar.png"
cp "${MY_PATH}/tmp/uid.png" "${MY_PATH}/SCAN/${PUBKEY}/g1_avatar.png"
sleep 1
done