aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2024-06-30 22:39:50 +0300
committerkaotisk <kaotisk@arching-kaos.org>2024-06-30 22:39:50 +0300
commitde53c55383ed07e0b65f69d33f5284a31d791664 (patch)
treef1e426c88a5d0a48ca463eccd21c1d12524d8f3a /lib
parent9531bcdffff4e44e8aadb000f0b577d59a32ea3f (diff)
downloadarching-kaos-tools-de53c55383ed07e0b65f69d33f5284a31d791664.tar.gz
arching-kaos-tools-de53c55383ed07e0b65f69d33f5284a31d791664.tar.bz2
arching-kaos-tools-de53c55383ed07e0b65f69d33f5284a31d791664.zip
Refactoring
Diffstat (limited to 'lib')
-rwxr-xr-xlib/_ak_network5
-rwxr-xr-xlib/_ak_schain93
-rwxr-xr-xlib/_ak_zblock2
-rwxr-xr-xlib/_ak_zchain107
4 files changed, 194 insertions, 13 deletions
diff --git a/lib/_ak_network b/lib/_ak_network
index 1d77eef..25fa68a 100755
--- a/lib/_ak_network
+++ b/lib/_ak_network
@@ -231,7 +231,6 @@ _ak_network_show_peers_ipfs(){
_ak_not_implemented _ak_network_show_peers_ipfs
}
-
_ak_network_show_peers(){
if [ ! -z $1 ] && [ -n "$1" ]
then
@@ -246,9 +245,7 @@ _ak_network_show_peers(){
jq -j | \
sed -e 's/]\[/,/g' | \
jq
-
fi
-
}
_ak_network_ipfs_connect_bootstrap(){
@@ -267,11 +264,9 @@ _ak_network_cjdns_connect(){
tmpon="yes"
curl -s "https://arching-kaos.net/files/ak_cjdns_bootstrap_peers" > $peersfile
fi
-
totalpeers="$(jq '. | length' < $peersfile)"
number="0"
interface="0"
-
while [ $number -lt $totalpeers ]
do
address="$(jq -r '.['$number'].address' < $peersfile)"
diff --git a/lib/_ak_schain b/lib/_ak_schain
new file mode 100755
index 0000000..2ff56eb
--- /dev/null
+++ b/lib/_ak_schain
@@ -0,0 +1,93 @@
+#!/bin/bash
+AK_SCHAINSDIR=$AK_WORKDIR/schains
+GENESIS="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
+
+_ak_schain_latest_cached(){
+ if [ ! -f $AK_WORKDIR/schain.latest ]
+ then
+ ak-find-latest-mined-sblock > $AK_WORKDIR/schain.latest
+ fi
+ cat $AK_WORKDIR/schain.latest
+}
+
+_ak_schain_tidy(){
+ SLATEST=$(ak-find-latest-mined-sblock | jq -r '.latest_block')
+ if [ ! -d $AK_SCHAINSDIR ]
+ then
+ mkdir $AK_SCHAINSDIR
+ fi
+}
+
+_ak_schain_block_latest_block_hash(){
+ ak-find-latest-mined-sblock | jq -r '.latest_block'
+}
+
+_ak_schain_crawl(){
+ if [ ! -z $1 ] && [ -n "$1" ]
+ then
+ CUR_TARGET="$1"
+ else
+ _ak_log_warning "No next target found. So long for $1"
+ exit 1
+ fi
+
+ if [ $counter -eq 0 ]
+ then
+ echo '['
+ counter=$(($counter + 1))
+ else
+ _ak_log_info "Counter: $counter, LIMIT_ENABLED: $LIMIT_ENABLED, LIMIT: $LIMIT"
+ if [ "$LIMIT_ENABLED" == "yes" ]
+ then
+ if [ $counter -eq $LIMIT ]
+ then
+ echo ']'
+ exit 0
+ fi
+ fi
+ echo ','
+ counter=$(($counter + 1))
+ fi
+
+ if [ "$1" == "$GENESIS" ]
+ then
+ echo '{"genesis":"genesis"}' | jq
+ echo ']'
+ _ak_log_warning "Looks like genesis. Exiting with 0"
+ exit 0
+ fi
+
+ if [ ! -f "$AK_MINEDBLOCKSDIR/$CUR_TARGET" ]
+ then
+ _ak_log_warning "Could not find $CUR_TARGET"
+ else
+ ( echo -n '{"sblock":"'$1'",' &&
+ ak-sblock-show $CUR_TARGET | sed -e 's/^{//g') | jq
+ NEXT_TARGET="$(ak-sblock-show $CUR_TARGET | jq -r '.previous')"
+ _ak_log_info "Found previous: $NEXT_TARGET"
+ _ak_schain_crawl "$NEXT_TARGET"
+ fi
+}
+
+_ak_schain_crawl_interface(){
+ LIMIT_ENABLED="no"
+ LIMIT=0
+ counter=0
+ if [ -z $1 ] || [ ! -n "$1" ]
+ then
+ _ak_schain_crawl `_ak_schain_block_latest_block_hash`
+ else
+ while [ "$#" ]; do
+ case "$1" in
+ -l)
+ LIMIT_ENABLED="yes"
+ LIMIT=$2
+ shift 2
+ ;;
+ *)
+ _ak_schain_crawl "$1"
+ ;;
+ esac
+ done
+ fi
+}
diff --git a/lib/_ak_zblock b/lib/_ak_zblock
index f379870..278619f 100755
--- a/lib/_ak_zblock
+++ b/lib/_ak_zblock
@@ -457,7 +457,7 @@ _ak_zblock_pack(){
# We check firstly if the encapsulated value of the "ipfs" key has already
# appeared in the zchain.
TO_CHECK="$(cat $MESSAGE | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g')"
- ak-enter | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' | sort | uniq > tempisalreadythere
+ _ak_zchain_crawl | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' | sort | uniq > tempisalreadythere
while IFS="" read -r p || [ -n "$p" ]
do
if [ "$p" == "$TO_CHECK" ]
diff --git a/lib/_ak_zchain b/lib/_ak_zchain
index d15048a..5dbcf62 100755
--- a/lib/_ak_zchain
+++ b/lib/_ak_zchain
@@ -80,18 +80,18 @@ _ak_zchain_rebase(){
_ak_zchain_extract_cids(){
if [ ! -z $1 ] && [ -n "$1" ]
then
- ak-enter $1 | jq -M | grep Qm | sed -e 's/".*"://g; s/ //g; s/[{,"]//g' | sort | uniq
+ ak zchain --crawl $1 | jq -M | grep Qm | sed -e 's/".*"://g; s/ //g; s/[{,"]//g' | sort | uniq
else
- ak-enter | jq -M | grep Qm | sed -e 's/".*"://g; s/ //g; s/[{,"]//g' | sort | uniq
+ ak zchain --crawl | jq -M | grep Qm | sed -e 's/".*"://g; s/ //g; s/[{,"]//g' | sort | uniq
fi
}
_ak_zchain_extract_data_cids(){
if [ ! -z $1 ]
then
- ak-enter $1 | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g'
+ ak zchain --crawl $1 | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g'
else
- ak-enter | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g'
+ ak zchain --crawl | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g'
fi
}
@@ -120,14 +120,107 @@ _ak_zchain_calculate_size(){
rm -rf $temp
}
+_ak_zchain_crawl(){
+ entrance="$(cat $AK_ZLATEST)"
+ verify=1
+ limit=0
+ fromIpns=0
+ while [ "$#" ]; do
+ case "$1" in
+ -h | --help)
+ printf "
+ak zchain --crawl [-N | --no-verify] [-l | --limit <number>] [zblock]
+ak zchain --crawl [-N | --no-verify] [-l | --limit <number>] -n <zchain>
+Usage:
+
+ --help, -h Print this help and exit
+
+ --chain <ipns-link>, -n <ipns-link> Crawl specified chain
+
+ --no-verify, -N Don't verify signatures
+
+ <ipfs-link> Specify IPFS CID for entrance
+
+Note that combined flags don't work for now
+Running with no flags crawls your chain based on AK_ZLATEST environment
+variable"
+ exit 1
+ ;;
+ -l | --limit)
+ limit=$2
+ shift 2
+ ;;
+ -N | --no-verify)
+ verify=0
+ shift
+ ;;
+ -n | --chain | --ipns)
+ fromIpns=1
+ ipns=$1
+ shift
+ ol=$1
+ entrance="$(_ak_ipns_resolve $1)"
+ if [ $? -ne 0 ]
+ then
+ _ak_log_error "Could not resolve IPNS name"
+ exit 1
+ fi
+ shift
+ ;;
+ *)
+ test="$1"
+ if [ ! -z "$test" ] && [ $fromIpns -eq 0 ]
+ then
+ _ak_ipfs_cid_v0_check "$test"
+ entrance="$test"
+ elif [ -z "$entrance" ] && [ $fromIpns -eq 1 ]
+ then
+ entrance="$(cat $AK_ZLATEST)"
+ fi
+ break
+ esac
+ done
+ # We assign the IPFS CIDv0 of an empty file as this is used
+ # as our GENESIS block, hence the "seed" that the tree grows
+ # from.
+ seed="$(cat $AK_ZGENESIS)"
+ # We assume that we found the entrance inside a block, hence
+ # ZBLOCK is labeled as previous
+ zblock="$entrance"
+ # Enter temp folder
+ TEMPASSIN="$(_ak_make_temp_directory)"
+ cd $TEMPASSIN
+ counter=0
+ # The loop
+ # We break the loop from inside the loop
+ while true
+ do
+ if [ $counter -eq 0 ]
+ then
+ echo -n '['
+ fi
+ counter=$(($counter + 1))
+ _ak_zblock_show "$zblock"
+ if [ $limit -ne 0 ] && [ $limit -eq $counter ]
+ then
+ echo -n ']'
+ exit 0
+ else
+ echo -n ','
+ fi
+ done
+}
+
_ak_zchain_crawl_self(){
- ak enter
+ _ak_zchain_crawl
}
_ak_zchain_crawl_remote_ipfs(){
- ak enter $1
+ _ak_zchain_crawl $1
+ #ak enter $1
}
_ak_zchain_crawl_remote_ipns(){
- ak enter -n $1
+ _ak_zchain_crawl -n $1
+ #ak enter -n $1
}