aboutsummaryrefslogtreecommitdiff
path: root/lib/_ak_network
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2024-07-07 08:51:39 +0300
committerkaotisk <kaotisk@arching-kaos.org>2024-07-07 08:51:39 +0300
commit26b1835efa72a4555fb4717e52b100e28c5658dc (patch)
tree121598f70c42f6573de428f4d14980ee41ef295b /lib/_ak_network
parentf9dc7b451097ad361ed0eaea2f5f156e28cb732b (diff)
downloadarching-kaos-tools-26b1835efa72a4555fb4717e52b100e28c5658dc.tar.gz
arching-kaos-tools-26b1835efa72a4555fb4717e52b100e28c5658dc.tar.bz2
arching-kaos-tools-26b1835efa72a4555fb4717e52b100e28c5658dc.zip
Added HIA-based scanning mode for CJDNS
Diffstat (limited to 'lib/_ak_network')
-rwxr-xr-xlib/_ak_network84
1 files changed, 79 insertions, 5 deletions
diff --git a/lib/_ak_network b/lib/_ak_network
index b002296..62f410f 100755
--- a/lib/_ak_network
+++ b/lib/_ak_network
@@ -126,7 +126,7 @@ _ak_network_scan_ipfs(){
_ak_not_implemented _ak_network_scan_ipfs
}
-_ak_network_scan_cjdns(){
+_ak_network_scan_cjdns_dump(){
#
# Needs CJDNS tools in your PATH
#
@@ -138,14 +138,12 @@ _ak_network_scan_cjdns(){
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
@@ -180,19 +178,95 @@ _ak_network_scan_cjdns(){
fi
done
printf ']' >> walk.aknet
-
mv walk.aknet $AK_ZPEERSFILE
+ rm -rf $TEMPDIR
+}
+_ak_network_scan_cjdns_full(){
+ # This scan is using HIA resources to scan the whole cjdns network for peers
+ #
+ # Ref:
+ # - https://github.com/ircerr/hia/
+ # - http://hia.cjdns.ca/watchlist/c/walk.pubkey
+ # - http://hia.cjdns.ca/watchlist/hia.iplist
+ #
+ TEMPDIR="$(_ak_make_temp_directory)"
+ cd $TEMPDIR
+ pubkeys_ips="$TEMPDIR/pi"
+ online_ips="$TEMPDIR/oi"
+ filtered_online_pubkeys_ips="$TEMPDIR/fopi"
+ curl -s \
+ --connect-timeout=5 \
+ "http://hia.cjdns.ca/watchlist/c/walk.pubkey" > $pubkeys_ips
+ if [ $? -ne 0 ]
+ then
+ _ak_log_error "Couldn't fetch DB from HIA"
+ exit 1
+ fi
+ curl -s \
+ --connect-timeout=5 \
+ "http://hia.cjdns.ca/watchlist/hia.iplist" > $online_ips
+ if [ $? -ne 0 ]
+ then
+ _ak_log_error "Couldn't fetch iplist from HIA"
+ exit 1
+ fi
+ cat $online_ips | while read line
+ do
+ grep -F "$line" $pubkeys_ips >> $filtered_online_pubkeys_ips
+ done
+ counter=0
+ printf '[' > walk.aknet
+ cat $filtered_online_pubkeys_ips \
+ | sort \
+ | uniq \
+ | while read -r pkey ip || [ -n "$ip" ]
+ do
+ _ak_log_debug "Scanning $ip..."
+ node_info="$(curl \
+ --connect-timeout 3 \
+ -A 'akd/0.1.0; https://github.com/arching-kaos' \
+ "http://[$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}' \
+ "$pkey" "$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_cjdns(){
+ if [ ! -z $1 ] && [ -n "$1" ]
+ then
+ case $1 in
+ -w | --whole) _ak_network_scan_cjdns_full; exit;;
+ -d | --dump) _ak_network_scan_cjdns_dump; exit;;
+ *) _ak_network_scan_cjdns_dump; exit;;
+ esac
+ else
+ _ak_network_scan_cjdns_dump
+ fi
+}
+
_ak_network_scan(){
if [ ! -z $1 ] && [ -n "$1" ]
then
case $1 in
stellar) _ak_network_scan_stellar; exit;;
ipfs) _ak_network_scan_ipfs; exit;;
- cjdns) _ak_network_scan_cjdns; exit;;
+ cjdns) shift; _ak_network_scan_cjdns $1; exit;;
* ) _ak_log_error "Unknown network $1";exit 1;;
esac
else