aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NETWORKING45
-rw-r--r--README25
-rwxr-xr-xbin/ak-network12
-rwxr-xr-xlib/_ak_network84
4 files changed, 158 insertions, 8 deletions
diff --git a/NETWORKING b/NETWORKING
index a8df3cd..7e1d6c2 100644
--- a/NETWORKING
+++ b/NETWORKING
@@ -102,3 +102,48 @@ which is able to reach the whole public network of cjdns.
TODO: We should be storing the output on a relevant file so it can be reached by
the API as well or ask for current known nodes without rescanning the network.
+
+Part 5: Update on networking
+----------------------------
+Great news everyone! `ak-network` is here:
+```
+$ ak network
+ak-network - AK Nettool
+=======================
+
+Network tools
+
+Usage:
+
+ -h, --help Prints this help message
+
+ -c, --connect [ipfs|cjdns] Connect to network(s)
+
+ -p, --peers [ipfs|cjdns|stellar] Outputs peers found
+
+ -s, --scan [ipfs|cjdns|stellar] Scan network(s) for peers
+
+Bonus: CJDNS network scanning flags
+
+ -s, --scan cjdns [-w|--whole] Scan using HIA's knowledge
+
+ -s, --scan cjdns [-d|--dump] Scan using CJDNS' dumpLinks (default)
+
+```
+
+Though:
+```
+$ ak network --scan ipfs
+20240707_065927 <ak-network> [ERROR] Not implemented: _ak_network_scan_ipfs
+```
+
+Which I think I should not try to do since we use `ak-config` as the key on IPFS
+to publish our `node_info` at and we can not guess keys just in case we found
+one with `node_info`. A work around could be to use the `self` key and publish
+there instead of `ak-config`. Previously, since we were using for `IPFS_REPO`
+the default directory, it was thought that the `self` key could be already in
+use. Now that we do have our own dedicated path for `IPFS_REPO`, it could be
+revisited. But, as mentioned in other places, we are about to drop IPFS in the
+future. Whichever comes first?
+
+TODO ^^ maybe
diff --git a/README b/README
index 77c0836..94a4816 100644
--- a/README
+++ b/README
@@ -180,6 +180,31 @@ Running with no flags crawls your chain based on AK_ZLATEST environment
variable
```
+### Connect to networks ( `ak network` )
+```console
+$ ak network
+ak-network - AK Nettool
+=======================
+
+Network tools
+
+Usage:
+
+ -h, --help Prints this help message
+
+ -c, --connect [ipfs|cjdns] Connect to network(s)
+
+ -p, --peers [ipfs|cjdns|stellar] Outputs peers found
+
+ -s, --scan [ipfs|cjdns|stellar] Scan network(s) for peers
+
+Bonus: CJDNS network scanning flags
+
+ -s, --scan cjdns [-w|--whole] Scan using HIA's knowledge
+
+ -s, --scan cjdns [-d|--dump] Scan using CJDNS' dumpLinks (default)
+```
+
Podman (or Docker)
------------------
diff --git a/bin/ak-network b/bin/ak-network
index 26d4e3e..02bee20 100755
--- a/bin/ak-network
+++ b/bin/ak-network
@@ -6,12 +6,18 @@
##
## -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
##
+## -s, --scan [ipfs|cjdns|stellar] Scan network(s) for peers
+##
+## Bonus: CJDNS network scanning modes
+##
+## -s, --scan cjdns [-w|--whole] Scan using HIA's knowledge
+##
+## -s, --scan cjdns [-d|--dump] Scan using CJDNS' dumpLinks (default)
+##
fullprogrampath="$(realpath $0)"
PROGRAM=$(basename $0)
descriptionString="AK Nettool"
@@ -25,7 +31,7 @@ source $AK_LIBDIR/_ak_network
if [ ! -z $1 ]; then
case $1 in
-h | --help) _ak_usage; exit;;
- -s | --scan) _ak_network_scan $2; exit;;
+ -s | --scan) shift; _ak_network_scan $*; exit;;
-c | --connect) _ak_network_connect $2; exit;;
-p | --peers) _ak_network_show_peers $2; exit;;
* ) _ak_usage;;
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