mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2024-11-19 09:50:19 +01:00
parent
a11349ed8d
commit
ce8d059158
@ -205,10 +205,13 @@ else
|
||||
# Sync Progress
|
||||
####################
|
||||
|
||||
# check number of peers
|
||||
source <(sudo -u admin /home/admin/config.scripts/network.monitor.sh peer-status)
|
||||
|
||||
# basic dialog info
|
||||
height=6
|
||||
width=43
|
||||
title="Node is Syncing (${scriptRuntime})"
|
||||
title="Node is Syncing (${peers} peers)"
|
||||
actionString="Please wait - this can take some time"
|
||||
|
||||
# formatting BLOCKCHAIN SYNC PROGRESS
|
||||
|
@ -176,6 +176,21 @@ do
|
||||
|
||||
fi
|
||||
|
||||
###############################
|
||||
# Blockchain Sync Monitor
|
||||
###############################
|
||||
|
||||
# check every 1min
|
||||
recheckSync=$(($counter % 60))
|
||||
if [ ${recheckSync} -eq 1 ]; then
|
||||
source <(sudo -u admin /home/admin/config.scripts/network.monitor.sh peer-status)
|
||||
echo "Blockchain Sync Monitoring: peers=${peers}"
|
||||
if [ "${peers}" == "0" ]; then
|
||||
echo "Blockchain Sync Monitoring: ZERO PEERS DETECTED .. doing out-of-band kickstart"
|
||||
sudo /home/admin/config.scripts/network.monitor.sh peer-kickstart
|
||||
fi
|
||||
fi
|
||||
|
||||
###############################
|
||||
# BlitzTUI Monitoring
|
||||
###############################
|
||||
|
146
home.admin/config.scripts/network.monitor.sh
Executable file
146
home.admin/config.scripts/network.monitor.sh
Executable file
@ -0,0 +1,146 @@
|
||||
#!/bin/bash
|
||||
|
||||
# command info
|
||||
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
|
||||
echo "monitor and troubleshot the bitcoin network"
|
||||
echo "network.monitor.sh peer-status"
|
||||
echo "network.monitor.sh peer-kickstart [ipv4|ipv6|tor|auto]"
|
||||
echo "network.monitor.sh peer-disconnectall"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source /mnt/hdd/raspiblitz.conf
|
||||
source /home/admin/raspiblitz.info
|
||||
|
||||
###################
|
||||
# STATUS
|
||||
###################
|
||||
if [ "$1" = "peer-status" ]; then
|
||||
echo "#network.monitor.sh peer-status"
|
||||
|
||||
# number of peers connected
|
||||
peerNum=$(${network}-cli getnetworkinfo | grep "connections" | tr -cd '[[:digit:]]')
|
||||
echo "peers=${peerNum}"
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
###################
|
||||
# PEER KICK START
|
||||
###################
|
||||
if [ "$1" = "peer-kickstart" ]; then
|
||||
echo "#network.monitor.sh peer-kickstart"
|
||||
|
||||
# check if started with sudo
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "error='missing sudo'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# get raw node data from bitnodes.io (use Tor if available)
|
||||
#if [ "${runBehindTor}" == "on" ]; then
|
||||
# call over tor proxy
|
||||
#bitnodesRawData=$(curl --socks5-hostname 127.0.0.1:9050 -H "Accept: application/json; indent=4" https://bitnodes.io/api/v1/snapshots/latest/ 2>/dev/null)
|
||||
#else
|
||||
# call over clearnet
|
||||
bitnodesRawData=$(curl -H "Accept: application/json; indent=4" https://bitnodes.io/api/v1/snapshots/latest/ 2>/dev/null)
|
||||
#fi
|
||||
if [ ${#bitnodesRawData} -lt 100 ]; then
|
||||
echo "error='no valid data from bitnodes.io'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# determine which address to choose
|
||||
addressFormat="$2"
|
||||
# set default to auto
|
||||
if [ "${addressFormat}" == "" ]; then
|
||||
addressFormat="auto"
|
||||
fi
|
||||
# check valid value
|
||||
if [ "${addressFormat}" != "ipv4" ] && [ "${addressFormat}" != "ipv6" ] && [ "${addressFormat}" != "tor" ] && [ "${addressFormat}" != "auto" ]; then
|
||||
echo "error='unvalid network type'"
|
||||
exit 1
|
||||
fi
|
||||
# if auto then deterine whats running
|
||||
if [ "${addressFormat}" == "auto" ]; then
|
||||
if [ "${runBehindTor}" == "on" ]; then
|
||||
addressFormat="tor"
|
||||
else
|
||||
source <(sudo ./config.scripts/internet.sh status global)
|
||||
if [ "${ipv6}" == "off" ]; then
|
||||
addressFormat="ipv4"
|
||||
else
|
||||
addressFormat="ipv6"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
echo "addressFormat='${addressFormat}'"
|
||||
|
||||
# filter raw data for node addresses based on what kind of connection is running
|
||||
if [ "${addressFormat}" == "tor" ]; then
|
||||
# get Tor nodes (v2 or v3)
|
||||
nodeList=$(echo "${bitnodesRawData}" | grep -o '[0-9a-z]\{16,56\}\.onion')
|
||||
elif [ "${addressFormat}" == "ipv4" ]; then
|
||||
# get IPv4 nodes
|
||||
nodeList=$(echo "${bitnodesRawData}" | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\:[0-9]\{3,5\}')
|
||||
elif [ "${addressFormat}" == "ipv6" ]; then
|
||||
# get IPv6 nodes
|
||||
nodeList=$(echo "${bitnodesRawData}" | grep -o '\[.\{5,45\}\]\:[0-9]\{3,5\}')
|
||||
else
|
||||
# unvalid address
|
||||
echo "error='unvalid 2nd parameter'"
|
||||
exit 1
|
||||
fi
|
||||
#echo "${nodeList}"
|
||||
nodesAvailable=$(echo "${nodeList}" | wc -l)
|
||||
echo "nodesAvailable=${nodesAvailable}"
|
||||
|
||||
# pick random node from list
|
||||
randomLineNumber=$((1 + RANDOM % ${nodesAvailable}))
|
||||
echo "randomNumber=${randomLineNumber}"
|
||||
nodeAddress=$(echo "${nodeList}" | sed -n "${randomLineNumber}p")
|
||||
if [ "${nodeAddress}" == "" ]; then
|
||||
# if random pick fails pick first line
|
||||
nodeAddress=$(echo "${nodeList}" | sed -n "1p")
|
||||
fi
|
||||
if [ "${nodeAddress}" == "" ]; then
|
||||
echo "error='selecting node from list failed'"
|
||||
exit 1
|
||||
fi
|
||||
echo "newpeer='${nodeAddress}"
|
||||
|
||||
# kick start node with
|
||||
sudo -u admin ${network}-cli addnode "${nodeAddress}" "onetry" 1>/dev/null
|
||||
echo "exitcode=$?"
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
###################
|
||||
# DISCONNECT ALL PEERS
|
||||
# for testing peer kick-start
|
||||
###################
|
||||
if [ "$1" = "peer-disconnectall" ]; then
|
||||
echo "#network.monitor.sh peer-disconnectall"
|
||||
|
||||
# check if started with sudo
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "error='missing sudo'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# get all peer id and disconnect them
|
||||
sudo -u admin ${network}-cli getpeerinfo | grep '"addr": "' | while read line
|
||||
do
|
||||
peerID=$(echo $line | cut -d '"' -f4)
|
||||
echo "# disconnecting peer with ID: ${peerID}"
|
||||
sudo -u admin ${network}-cli disconnectnode ${peerID}
|
||||
done
|
||||
|
||||
echo "#### FINAL PEER INFO FORM BITCOIND"
|
||||
sudo -u admin ${network}-cli getpeerinfo
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "FAIL - Unknown Parameter $1"
|
||||
exit 1
|
Loading…
Reference in New Issue
Block a user