aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README8
-rw-r--r--api/routes/default/index.js13
-rwxr-xr-xbin/ak-network8
-rwxr-xr-xlib/_ak_ipfs6
-rwxr-xr-xlib/_ak_network5
-rwxr-xr-xlib/_ak_network_incoming92
-rwxr-xr-xlib/_ak_network_stellar43
-rwxr-xr-xlib/_ak_network_utils79
8 files changed, 218 insertions, 36 deletions
diff --git a/README b/README
index 246acbc..7323655 100644
--- a/README
+++ b/README
@@ -334,10 +334,10 @@ $ ak network
#
# Usage:
#
-# -h, --help Prints this help message
-# -c, --connect [ipfs|cjdns] Connect to network(s)
-# -p, --peers [ipfs|cjdns|stellar|yggdrasil] Outputs peers found
-# -s, --scan [ipfs|cjdns|stellar|yggdrasil] Scan network(s) for peers
+# -h, --help Prints this help message
+# -c, --connect [ipfs|cjdns] Connect to network(s)
+# -p, --peers [ipfs|cjdns|stellar|yggdrasil|incoming] Outputs peers found
+# -s, --scan [ipfs|cjdns|stellar|yggdrasil|incoming] Scan network(s) for peers
#
# Bonus: CJDNS network scanning modes
#
diff --git a/api/routes/default/index.js b/api/routes/default/index.js
index c9f6bd3..24e334b 100644
--- a/api/routes/default/index.js
+++ b/api/routes/default/index.js
@@ -10,6 +10,17 @@ module.exports = (req, res) => {
routes:{
GET:[
{welcome:settings.DEF_PROTO+req.headers.host+"/"},
+ {peers:settings.DEF_PROTO+req.headers.host+settings.URL_PREFIX+"/peers"},
+ {node_info:settings.DEF_PROTO+req.headers.host+settings.URL_PREFIX+"/node_info"},
+ {ipfs_hash:settings.DEF_PROTO+req.headers.host+settings.URL_PREFIX+"/ipfs_hash/<hash>"},
+ {zlatest:settings.DEF_PROTO+req.headers.host+settings.URL_PREFIX+"/zlatest"},
+ {sblock:settings.DEF_PROTO+req.headers.host+settings.URL_PREFIX+"/sblock/<hash>"},
+ {slatest:settings.DEF_PROTO+req.headers.host+settings.URL_PREFIX+"/slatest"},
+ {chunk:settings.DEF_PROTO+req.headers.host+settings.URL_PREFIX+"/chunk/<hash>"},
+ {leaf:settings.DEF_PROTO+req.headers.host+settings.URL_PREFIX+"/leaf/<hash>"},
+ {map:settings.DEF_PROTO+req.headers.host+settings.URL_PREFIX+"/map/<hash>"},
+ ],
+ oldGET:[
{gathered_zblocks:settings.DEF_PROTO+req.headers.host+settings.URL_PREFIX+"/see"},
{node_local_chain:settings.DEF_PROTO+req.headers.host+settings.URL_PREFIX+"/chain"},
{node_local_peers:settings.DEF_PROTO+req.headers.host+settings.URL_PREFIX+"/peers"},
@@ -19,7 +30,7 @@ module.exports = (req, res) => {
{show_mined_block:settings.DEF_PROTO+req.headers.host+settings.URL_PREFIX+"/sblock"},
{getMerkleTree:settings.DEF_PROTO+req.headers.host+settings.URL_PREFIX+"/mrk/:mkr"},
],
- POST:[
+ oldPOST:[
{send_me_a_zblock:settings.DEF_PROTO+req.headers.host+settings.URL_PREFIX+"/announce/zblock"},
]
}
diff --git a/bin/ak-network b/bin/ak-network
index f20d750..9873d12 100755
--- a/bin/ak-network
+++ b/bin/ak-network
@@ -22,10 +22,10 @@
##
## Usage:
##
-## -h, --help Prints this help message
-## -c, --connect [ipfs|cjdns] Connect to network(s)
-## -p, --peers [ipfs|cjdns|stellar|yggdrasil] Outputs peers found
-## -s, --scan [ipfs|cjdns|stellar|yggdrasil] Scan network(s) for peers
+## -h, --help Prints this help message
+## -c, --connect [ipfs|cjdns] Connect to network(s)
+## -p, --peers [ipfs|cjdns|stellar|yggdrasil|incoming] Outputs peers found
+## -s, --scan [ipfs|cjdns|stellar|yggdrasil|incoming] Scan network(s) for peers
##
## Bonus: CJDNS network scanning modes
##
diff --git a/lib/_ak_ipfs b/lib/_ak_ipfs
index eb4ee31..d904645 100755
--- a/lib/_ak_ipfs
+++ b/lib/_ak_ipfs
@@ -116,7 +116,7 @@ function _ak_ipfs_scanner(){
function _ak_ipfs_add(){
if [ -z $1 ] || [ ! -n "$1" ]
then
- _ak_log_error "no argument given"
+ _ak_log_error "_ak_ipfs_add: no argument given"
exit 1
fi
# Receives a file
@@ -132,7 +132,7 @@ function _ak_ipfs_add(){
function _ak_ipfs_block_stat(){
if [ -z $1 ] || [ ! -n "$1" ]
then
- _ak_log_error "no argument given"
+ _ak_log_error "_ak_ipfs_block_stat: no argument given"
exit 1
fi
_ak_ipfs block stat "$1"
@@ -256,7 +256,7 @@ function _ak_ipfs_get(){
function _ak_ipfs_cat(){
if [ -z $1 ] || [ ! -n "$1" ]
then
- _ak_log_error "no argument given"
+ _ak_log_error "_ak_ipfs_cat: no argument given"
exit 1
fi
if [ ! -f $AK_IPFS_ARTIFACTS/$1 ]
diff --git a/lib/_ak_network b/lib/_ak_network
index d23d913..a7ef4fc 100755
--- a/lib/_ak_network
+++ b/lib/_ak_network
@@ -22,6 +22,7 @@ source $AK_LIBDIR/_ak_network_ipfs
source $AK_LIBDIR/_ak_network_cjdns
source $AK_LIBDIR/_ak_network_yggdrasil
source $AK_LIBDIR/_ak_network_stellar
+source $AK_LIBDIR/_ak_network_incoming
function _ak_network_scan(){
if [ ! -z $1 ] && [ -n "$1" ]
@@ -31,6 +32,7 @@ function _ak_network_scan(){
ipfs) _ak_network_ipfs_scan; exit;;
cjdns) shift; _ak_network_cjdns_scan $1; exit;;
yggdrasil) shift; _ak_network_yggdrasil_scan $1; exit;;
+ incoming) shift; _ak_network_incoming_scan; exit;;
* ) _ak_log_error "Unknown network $1";exit 1;;
esac
else
@@ -49,10 +51,11 @@ function _ak_network_show_peers(){
cjdns) _ak_network_cjdns_show_peers; exit;;
ipfs) _ak_network_ipfs_show_peers; exit;;
yggdrasil) _ak_network_yggdrasil_show_peers; exit;;
+ incoming) _ak_network_incoming_show_peers; exit;;
* ) _ak_log_error "Unknown network $1";exit 1;;
esac
else
- (_ak_network_stellar_show_peers; _ak_network_cjdns_show_peers; _ak_network_yggdrasil_show_peers; _ak_network_ipfs_show_peers) | \
+ (_ak_network_stellar_show_peers; _ak_network_cjdns_show_peers; _ak_network_yggdrasil_show_peers; _ak_network_incoming_show_peers) | \
jq -j | \
sed -e 's/]\[/,/g' | \
jq
diff --git a/lib/_ak_network_incoming b/lib/_ak_network_incoming
new file mode 100755
index 0000000..439dfa2
--- /dev/null
+++ b/lib/_ak_network_incoming
@@ -0,0 +1,92 @@
+#!/usr/bin/env bash
+###
+### arching-kaos-tools
+### Tools to interact and build an Arching Kaos Infochain
+### Copyright (C) 2021 - 2025 kaotisk
+###
+### This program is free software: you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation, either version 3 of the License, or
+### (at your option) any later version.
+###
+### This program is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with this program. If not, see <http://www.gnu.org/licenses/>.
+###
+source $AK_LIBDIR/_ak_log
+source $AK_LIBDIR/_ak_utils
+source $AK_LIBDIR/_ak_network_utils
+source $AK_LIBDIR/_ak_fm
+
+export AK_ZPEERSINCOMING=$AK_ZPEERSDIR/incomingRequests
+
+function _ak_network_incoming_tidy(){
+ exit 224
+}
+
+function _ak_network_incoming_show_peers(){
+ if [ -f $AK_ZPEERSFILE.incoming ]
+ then
+ cat $AK_ZPEERSFILE.incoming | jq
+ else
+ _ak_log_debug "No incoming peers found"
+ fi
+}
+
+function _ak_network_incoming_scan(){
+ if [ -f "${AK_ZPEERSINCOMING}" ]
+ then
+ if [ $(cat ${AK_ZPEERSINCOMING}|wc -l) -gt 0 ]
+ then
+ counter=0
+ count=0
+ _ak_fm_sort_uniq_file ${AK_ZPEERSINCOMING}
+ max="$(cat ${AK_ZPEERSINCOMING}|wc -l)"
+ printf '[' > walk.aknet
+ cat ${AK_ZPEERSINCOMING} \
+ | sort \
+ | uniq \
+ | while read -r uip || [ -n "$uip" ]
+ do
+ ip="$(_ak_network_utils_pad_ip $uip)"
+ count="$(( $count + 1 ))"
+ _ak_log_debug "Scanning [${count}/${max}] $ip..."
+ node_fs_path="$AK_ZPEERSDIR/inc/$(echo -n $ip| sed 's/://g')"
+ scan_ts="$(_ak_datetime_unix)"
+ if [ ! -d ${node_fs_path} ]
+ then
+ mkdir -p ${node_fs_path}
+ fi
+ node_fs_pathname="${node_fs_path}/${scan_ts}"
+ 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 > ${node_fs_pathname}
+ node_info="$(cat ${node_fs_pathname})"
+ 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 '{"incoming":{"ip":"%s"},"node_info":%s}' \
+ "$ip" "$node_info" >> walk.aknet
+ counter="`expr $counter + 1`"
+ fi
+ done
+ printf ']' >> walk.aknet
+ mv walk.aknet $AK_ZPEERSFILE.incoming
+ rm -rf $TEMPDIR
+ else
+ _ak_log_info "No incoming requests found."
+ fi
+ fi
+}
diff --git a/lib/_ak_network_stellar b/lib/_ak_network_stellar
index 04ce29b..5d739ec 100755
--- a/lib/_ak_network_stellar
+++ b/lib/_ak_network_stellar
@@ -19,6 +19,15 @@
###
source $AK_LIBDIR/_ak_log
source $AK_LIBDIR/_ak_ipfs
+source $AK_LIBDIR/_ak_script
+
+stellarPeersDir="$AK_ZPEERSDIR/stellar"
+_ak_check_and_create_dir $stellarPeersDir
+
+stellarParticipants="$stellarPeersDir/trustlines"
+_ak_let_there_be_file $stellarParticipants
+stellarParticipantsOnline="$stellarPeersDir/configured.trustlines"
+_ak_let_there_be_file $stellarParticipantsOnline
function _ak_network_stellar_show_ids(){
i=0
@@ -73,24 +82,8 @@ function _ak_network_stellar_scan(){
tempdir=`_ak_make_temp_directory`
tempfile="$tempdir/tmp"
tempaddr="$tempdir/tmpaddr"
- 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
+ _ak_let_there_be_file $tempdir
+ _ak_let_there_be_file $tempaddr
if [ ! -z $1 ] && [ "$1" == "-l" ] && [ ! -z $2 ]
then
limit=$2
@@ -135,8 +128,6 @@ function _ak_network_stellar_scan(){
}
function _ak_network_stellar_show_peers(){
- stellarParticipants="$AK_WORKDIR/stellar-network-participants"
- stellarParticipantsOnline="$AK_WORKDIR/stellar-network-participants-online"
if [ -f "${stellarParticipantsOnline}" ]
then
(
@@ -150,10 +141,16 @@ function _ak_network_stellar_show_peers(){
fi
counter=$(( $counter + 1 ))
akConfigHash="$(_ak_ipfs_name_resolve /ipns/$akConfig|cut -d '/' -f 3)"
- printf '{"stellar":{"address":"%s","config":"%s"},"node_info":%s}' \
+ printf '{"stellar":{"address":"%s","config":"%s"}' \
"$stellarAddress" \
- "$akConfig" \
- "$(_ak_ipfs_cat $akConfigHash)"
+ "$akConfig"
+ if [ -n "$akConfigHash" ]
+ then
+ printf ',"node_info":%s}' \
+ "$(_ak_ipfs_cat $akConfigHash)"
+ else
+ printf '}'
+ fi
done
printf ']'
) | sed -e 's/\[]//g' #| jq
diff --git a/lib/_ak_network_utils b/lib/_ak_network_utils
new file mode 100755
index 0000000..bef7936
--- /dev/null
+++ b/lib/_ak_network_utils
@@ -0,0 +1,79 @@
+#!/usr/bin/env bash
+###
+### arching-kaos-tools
+### Tools to interact and build an Arching Kaos Infochain
+### Copyright (C) 2021 - 2025 kaotisk
+###
+### This program is free software: you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation, either version 3 of the License, or
+### (at your option) any later version.
+###
+### This program is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with this program. If not, see <http://www.gnu.org/licenses/>.
+###
+source $AK_LIBDIR/_ak_log
+source $AK_LIBDIR/_ak_utils
+
+##
+# Copied from http://y.yggdrasil-network.ca/yia/crawler/crawler-yia.sh made by
+# ircerr
+#
+# Changes:
+# - name of function from padip to _ak_network_utils_pad_ip
+#
+function _ak_network_utils_pad_ip() { #Pad IP - fill in missing zeros
+ ip=$1
+ if [ "$ip" == "" ]; then return; fi
+ PADIP=""
+ if [ "`echo \"$ip\"|grep '::'`" != "" ]
+ then
+ CC="$((`echo \"$ip\"|sed 's/:://g'|tr ':' '\n'|wc -l`))" #count cols
+ if [ "$CC" != "8" ]
+ then
+ NC=$((7-$CC))
+ RS=""
+ for X in `seq 1 $NC`
+ do
+ if [ "$RS" == "" ]
+ then
+ RS="0000"
+ else
+ RS="$RS:0000"
+ fi
+ done
+ ip="`echo \"$ip\"|sed \"s/\:\:/\:$RS\:/g\"`"
+ fi
+ fi
+ SEGIP="`echo $ip|tr ':' ' '`"
+ for S in $SEGIP
+ do
+ while :
+ do
+ if [ "`echo $S|cut -b 4`" == "" ]
+ then
+ S="0$S"
+ continue
+ fi
+ if [ "$PADIP" == "" ]
+ then
+ PADIP="$S"
+ else
+ PADIP="$PADIP:$S"
+ fi
+ break
+ done
+ done
+ if [ "$PADIP" != "" ]
+ then
+ ip="$PADIP"
+ fi
+ echo "$ip"
+ return
+}
+