Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added scripts for getting peers #49

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ Chain stats: `cybernode.ai`
Bostrom genesis: [QmYubyVNfghD4xCrTFj26zBwrF9s5GJhi1TmxvrwmJCipr](https://gateway.ipfs.cybernode.ai/ipfs/QmYubyVNfghD4xCrTFj26zBwrF9s5GJhi1TmxvrwmJCipr)

------
## To get peers

If you want to get up-to-date peers use one of the scripts below for bash or nushell:

**[Bash](get_peers/getpeers.sh)**
**[Nushell](get_peers/getpeers.nu)**
How to use nushell with cyber [Cyber-Prophet](https://github.com/cyber-prophet/cy)

------

## Chainstats

[![chain](https://img.shields.io/badge/Chain-bostrom--testnet--7-success.svg?style=flat-square)](https://github.com/cybercongress/cyberd/blob/master/docs/run_validator.md)
Expand Down
1 change: 1 addition & 0 deletions get_peers/getpeers.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http get https://rpc.space-pussy.cybernode.ai:443/net_info | get result.peers | each {|i| $i | get remote_ip node_info.id node_info.listen_addr} | each {|i| $'($i.1)@($i.0):($i.2 | split row ":" | last)'} | str join ',' | $'persistent_peers = "($in)"'
57 changes: 57 additions & 0 deletions get_peers/getpeers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

##https://gist.github.com/Cordtus/87b147862627d3039f394695b78e4361
## dump connected peers to comma separated persistent_peers list

RED='\033[0;91m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
x=0

printf "\n${RED}rpc${NC} address?: "
read -r RPC
DATA=$(curl -s $RPC/net_info)
if [ -z "$DATA" ]
then
printf "%b\n${RED}rpc%b${NC} error\n\n"
exit
fi
NETWORK=$(echo $DATA | jq '.result | .peers | .[0] | .node_info | .network' | tr -d '"')
COUNT=$(echo $DATA | jq '.result | .n_peers' | tr -d '"')
while [ $x -lt $COUNT ]
do
if [ $(echo $DATA | jq ".result | .peers | .[$x] | .is_outbound") == 'true' ]
then
ID=$(echo $DATA | jq ".result | .peers | .[$x] | .node_info | .id" 2> /dev/null)
ADDRESS=$(echo $DATA | jq ".result | .peers | .[$x] | .remote_ip" 2> /dev/null)
PORT=$(echo $DATA | jq ".result | .peers | .[$x] | .node_info | .listen_addr" 2> /dev/null | tr -d '"')
PEER=$(echo $ID | tr -d '"')@$(echo $ADDRESS | tr -d '"'):${PORT##*:}
PEERS[${#PEERS[@]}]="$PEER"
((x++))
else
((x++))
fi
done

printf "\n${RED}$x${NC} outbound peers found"

printf "\n${RED}number${NC} of peers to list? (1,3,10,all): "
read -r NUMBER

if [ -z $NUMBER ]
then
TOTAL="$x"
elif [ $NUMBER == "all" ] || [ $NUMBER -ge $x ]
then
TOTAL="$x"
else
TOTAL="$NUMBER"
fi

while [[ $i -lt $TOTAL ]]
do
P_LIST="$P_LIST,$(echo ${PEERS[$i]} | tr -d '\n')"
((i++))
done
printf "\npersistent_peers = \"${P_LIST:1}\"\n"