diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2024-06-24 04:00:36 +0300 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2024-06-24 04:00:36 +0300 |
commit | 432acf6bf5cd42025a63266e77bacd8c5256c0a5 (patch) | |
tree | ef2ef8b80a9741f648f01e8a2f5c50da1f98b83b /bin | |
parent | 0c8f9f5ed254c923c368c8fa92d352f8da89b3ca (diff) | |
download | arching-kaos-tools-432acf6bf5cd42025a63266e77bacd8c5256c0a5.tar.gz arching-kaos-tools-432acf6bf5cd42025a63266e77bacd8c5256c0a5.tar.bz2 arching-kaos-tools-432acf6bf5cd42025a63266e77bacd8c5256c0a5.zip |
ak-network: script to handle connectivity
```bash
ak-network - AK Nettool
=======================
Network tools
Usage:
-h, --help Prints this help message
-s, --scan [ipfs|cjdns|stellar] Scan network(s) for peers
-c, --connect [ipfs|cjdns] Connect to network(s)
-p, --peers [ipfs|cjdns|stellar] Outputs peers found
1719190884 <ak> [ERROR] ak-network command finished (1)
```
Functions introduced or refactored:
- _ak_network_cjdns_scanner
- _ak_network_stellar_show_ids
- _ak_network_stellar_get_next_page
- _ak_network_stellar_proceed_to_next_page
- _ak_network_stellar_get_asset_holders
- _ak_network_scan_stellar
- _ak_network_scan_ipfs
- _ak_network_scan_cjdns
- _ak_network_scan
- _ak_network_show_peers_stellar
- _ak_network_show_peers_cjdns
- _ak_network_show_peers_ipfs
- _ak_network_show_peers
- _ak_network_ipfs_connect_bootstrap
- _ak_network_cjdns_connect
- _ak_network_cjdns_connect_bootstrap
- _ak_network_connect
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/ak-cjdns-scanner | 52 | ||||
-rwxr-xr-x | bin/ak-network | 37 | ||||
-rwxr-xr-x | bin/ak-peers-get-cjdns | 2 | ||||
-rwxr-xr-x | bin/ak-peers-get-stellar | 18 | ||||
-rwxr-xr-x | bin/ak-stellar-get-participants | 111 |
5 files changed, 33 insertions, 187 deletions
diff --git a/bin/ak-cjdns-scanner b/bin/ak-cjdns-scanner deleted file mode 100755 index 044670b..0000000 --- a/bin/ak-cjdns-scanner +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash -# -# Needs CJDNS tools in your PATH -# -# Ref: https://github.com/cjdelisle/cjdns -# -which dumpLinks > /dev/null 2>&1 -if [ $? -ne 0 ] -then - echo "You need to install cjdns and cjdns-tools" - exit 1 -fi - -which publictoip6 > /dev/null 2>&1 -if [ $? -ne 0 ] -then - echo "You need to install cjdns and cjdns-tools" - exit 1 -fi - -TEMPDIR="$(mktemp -d)" -AK_ZPEERSFILE="$HOME/.arching-kaos/peersFile" -cd $TEMPDIR -counter=0 -printf '[' > walk.aknet -dumpLinks \ - | cut -d ' ' -f 2,4 \ - | sed 's/ /\n/g' \ - | sort \ - | uniq \ - | while read -r ip || [ -n "$ip" ] -do - node_info="$(curl \ - --connect-timeout 3 \ - -A 'akd/0.1.0; https://github.com/arching-kaos' \ - "http://[$(publictoip6 $ip)]:8610/v0/node_info" 2>/dev/null | jq -c -M)" - if [ $? -eq 0 ] && [ $(echo -n "$node_info" | wc -c) -gt 0 ] - then - if [ "$counter" -ne "0" ] - then - printf ',' >> walk.aknet - fi - printf '{"cjdns":{"public_key":"%s","ip":"%s"},"node_info":%s}' \ - "$ip" "`publictoip6 $ip`" "$node_info" >> walk.aknet - counter="`expr $counter + 1`" - fi -done -printf ']' >> walk.aknet - -mv walk.aknet $AK_ZPEERSFILE - -rm -rf $TEMPDIR diff --git a/bin/ak-network b/bin/ak-network index c506879..26d4e3e 100755 --- a/bin/ak-network +++ b/bin/ak-network @@ -1,5 +1,34 @@ #!/bin/bash -while true -do - cat $ZLATEST | nc -lv 127.0.0.1 5050 -done +## +## Network tools +## +## Usage: +## +## -h, --help Prints this help message +## +## -s, --scan [ipfs|cjdns|stellar] Scan network(s) for peers +## +## -c, --connect [ipfs|cjdns] Connect to network(s) +## +## -p, --peers [ipfs|cjdns|stellar] Outputs peers found +## +fullprogrampath="$(realpath $0)" +PROGRAM=$(basename $0) +descriptionString="AK Nettool" + +# At least these +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_script +source $AK_LIBDIR/_ak_network + +# Flags to run +if [ ! -z $1 ]; then + case $1 in + -h | --help) _ak_usage; exit;; + -s | --scan) _ak_network_scan $2; exit;; + -c | --connect) _ak_network_connect $2; exit;; + -p | --peers) _ak_network_show_peers $2; exit;; + * ) _ak_usage;; + esac +else _ak_usage +fi diff --git a/bin/ak-peers-get-cjdns b/bin/ak-peers-get-cjdns deleted file mode 100755 index dee8af4..0000000 --- a/bin/ak-peers-get-cjdns +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -cat $AK_ZPEERSFILE | jq
\ No newline at end of file diff --git a/bin/ak-peers-get-stellar b/bin/ak-peers-get-stellar deleted file mode 100755 index ec9eaa6..0000000 --- a/bin/ak-peers-get-stellar +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/bash -source $AK_LIBDIR/_ak_ipfs -stellarParticipants="$AK_WORKDIR/stellar-network-participants" -stellarParticipantsOnline="$AK_WORKDIR/stellar-network-participants-online" -( -printf '[' -counter=0 -cat $stellarParticipantsOnline | while read stellarAddress akConfig -do - if [ $counter -ne 0 ] - then - printf ',' - fi - counter=$(( $counter + 1 )) - printf '{"stellar":{"address":"%s","config":"%s"},"node_info":%s}' "$stellarAddress" "$akConfig" "$(_ak_ipfs_cat /ipns/$akConfig)" -done -printf ']' -) #| jq diff --git a/bin/ak-stellar-get-participants b/bin/ak-stellar-get-participants deleted file mode 100755 index 779e9e1..0000000 --- a/bin/ak-stellar-get-participants +++ /dev/null @@ -1,111 +0,0 @@ -#!/bin/bash -PROGRAM="$(basename $0)" -tempdir=`mktemp -d` -tempfile="$tempdir/tmp" -tempaddr="$tempdir/tmpaddr" -source $AK_LIBDIR/_ak_log - -stellarParticipants="$AK_WORKDIR/stellar-network-participants" -stellarParticipantsOnline="$AK_WORKDIR/stellar-network-participants-online" -if [ ! -f "$stellarParticipants" ] -then - touch $stellarParticipants -fi -if [ ! -f "$stellarParticipantsOnline" ] -then - touch $stellarParticipantsOnline -fi -if [ ! -f "$tempdir" ] -then - touch $tempdir -fi -if [ ! -f "$tempaddr" ] -then - touch $tempaddr -fi - -if [ ! -z $1 ] && [ "$1" == "-l" ] && [ ! -z $2 ] -then - limit=$2 -else - limit=3 -fi - -show_ids(){ - i=0 - flag=0 - while [ "$i" -lt "$limit" ] - do - test="$(cat $tempfile | jq '.["_embedded"]' | jq .'["records"]' | jq '.['$i']' | jq '.["id"]' | sed -e 's/\"//g')" - while IFS="" read -r p || [ -n "$p" ] - do - if [ "$p" == "$test" ] - then - flag=1 - break - fi - done < $stellarParticipants - if [ "$flag" == "0" ] - then - echo $test >> $stellarParticipants - _ak_log_info "Added $test" - else - _ak_log_info "$test already there. Skipping..." - fi - i="$(expr $i + 1)" - done -} - -get_next_page(){ - cat $tempfile | grep -1 next | grep https | sed -e 's/^.*https/https/' | sed -e 's/\u0026/\&/g; s/"//g; s/\\//g' -} - -proceed_to_next_page(){ - nextURL="$(get_next_page)" - curl \ - --connect-timeout 3 \ - "$nextURL" > $tempfile 2>/dev/null -} - -get_asset_holders(){ - curl \ - --connect-timeout 3 \ - https://horizon.stellar.org/accounts\?asset\=ARCHINGKAOS:GB4QVKD6NW3CSNO5TNPARAWNPPXOPSSTKB35XCWB7PUNBIQTK3DVELB2\&limit\=$limit > $tempfile 2>/dev/null -} - -get_asset_holders -while [ "$(tail -1 $stellarParticipants)" != "null" ] -do - show_ids - proceed_to_next_page -done - -grep G $stellarParticipants > $tempaddr -cat $tempaddr > $stellarParticipants -rm $tempfile $tempaddr -while IFS="" read -r p || [ -n "$p" ] -do - flag=0 - test="$(curl \ - --connect-timeout 3 \ - https://horizon.stellar.org/accounts/$p/data/config 2>/dev/null | grep value)" - if [ "$?" == 0 ] - then - addressValuePair="$(printf '%s %s\n' "$p" "$(echo $test | sed -e 's/^.*: "//g; s/"//g' | base64 -d)")" - while IFS="" read -r x || [ -n "$x" ] - do - if [ "$x" == "$addressValuePair" ] - then - flag=1 - break - fi - done < $stellarParticipantsOnline - if [ "$flag" == "0" ] - then - echo $addressValuePair >> $stellarParticipantsOnline - _ak_log_info "$p is configured with $(echo $addressValuePair | awk '{ print $2 }'). Added to online participants." - else - _ak_log_info "$(echo $addressValuePair | awk '{ print $2 }') is already in $stellarParticipantsOnline. Skipping..." - fi - fi -done < $stellarParticipants |