-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaddpeers.sh
More file actions
68 lines (58 loc) · 1.96 KB
/
addpeers.sh
File metadata and controls
68 lines (58 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# This is a helper script for adding more peers to an already
# running tezos-node. It first queries for, and adds all
# foundation nodes, then queries tzscan's API for more peers and
# adds them as well.
#
# The tezos-admin-client binary will output 'Error' messages in
# most cases, even when already connected to a peer.
#
# Be sure to install jq and configure the TZPATH variable below
# [yum|apt] install jq
#
# If you found this script helpful, send us a tip!
# Baking Tacos! tz1RV1MBbZMR68tacosb7Mwj6LkbPSUS1er1
#
newpeers=0
# get foundation nodes
for i in dubnodes franodes sinnodes nrtnodes pdxnodes; do
for j in `dig $i.tzbeta.net +short`; do
echo "Connecting foundation $j..."
tezos-admin-client connect address [$j]:9732
if [ $? -eq 0 ]; then
((newpeers++))
# echo "New connection to $j established"
fi
done
done
# Public Nodes
# Loop over pages from tzscan. Swap variable below for use on alphanet nodes.
#TZSCANAPI=api.alphanet.tzscan.io"
TZSCANAPI="api6.tzscan.io"
for page in {0..5}; do
# get array of peers
peers=($(curl -s "https://$TZSCANAPI/v3/network?state=running&p=$page&n=50" | jq -r '.[] | .point_id' | xargs))
if [ ${#peers[@]} -eq 0 ]; then
# exit loop, no results for page
echo "No more peers found. Exiting."
break
fi
# loop through peers array
for i in ${peers[@]}; do
# handle ipv4 or ipv6
numparts=$(echo $i | awk -F: '{print NF}')
basenum=$((numparts-1))
port=$(echo $i | cut -d: -f$numparts)
base=$(echo $i | cut -d: -f1-$basenum)
formatted="[$base]:$port"
echo "Connecting $formatted..."
tezos-admin-client connect address $formatted
if [ $? -eq 0 ]; then
((newpeers++))
# echo "New connection to $j established"
fi
done
done
# how many peers do we have now? how many did we add?
numpeers=$($TZPATH/tezos-admin-client p2p stat | grep "BETA\|MAINNET" | wc -l)
echo "Added $newpeers peers. Currently $numpeers connected. Done."