aboutsummaryrefslogtreecommitdiff
path: root/lib/_ak_network
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2024-06-24 06:22:47 +0300
committerkaotisk <kaotisk@arching-kaos.org>2024-06-24 06:22:47 +0300
commite34b1cbf66a3b810ad103cf757cfb20031188d4d (patch)
treef1247508194458a30127a934c899459f519322f4 /lib/_ak_network
parent21c7f1852b0d2ca145d18a165d6d90c6127dc44a (diff)
downloadarching-kaos-tools-e34b1cbf66a3b810ad103cf757cfb20031188d4d.tar.gz
arching-kaos-tools-e34b1cbf66a3b810ad103cf757cfb20031188d4d.tar.bz2
arching-kaos-tools-e34b1cbf66a3b810ad103cf757cfb20031188d4d.zip
refactoring
Diffstat (limited to 'lib/_ak_network')
-rwxr-xr-xlib/_ak_network116
1 files changed, 57 insertions, 59 deletions
diff --git a/lib/_ak_network b/lib/_ak_network
index 2cdec02..76af4c0 100755
--- a/lib/_ak_network
+++ b/lib/_ak_network
@@ -4,64 +4,6 @@ source $AK_LIBDIR/_ak_ipfs
cjdnstoolspath="$HOME/cjdns/tools"
-_ak_network_cjdns_scanner(){
- #
- # 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="$(_ak_make_temp_directory)"
- 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
- if [ ! -n "$node_info" ]
- then
- node_info="null"
- 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
-}
-
_ak_network_stellar_show_ids(){
i=0
flag=0
@@ -185,7 +127,63 @@ _ak_network_scan_ipfs(){
}
_ak_network_scan_cjdns(){
- _ak_network_cjdns_scanner
+ #
+ # 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="$(_ak_make_temp_directory)"
+ AK_ZPEERSFILE="$HOME/.arching-kaos/peersFile"
+ cd $TEMPDIR
+ counter=0
+ printf '[' > walk.aknet
+ dumpLinks \
+ | grep -v '0000\.0000\.0000\.0001 ' \
+ | cut -d ' ' -f 2,4 \
+ | sed 's/ /\n/g' \
+ | sort \
+ | uniq \
+ | while read -r ip || [ -n "$ip" ]
+ do
+ _ak_log_debug "Scanning $(publictoip6 $ip)..."
+ 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
+ if [ ! -n "$node_info" ]
+ then
+ node_info="null"
+ 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
}
_ak_network_scan(){