From 3979cd6b0a52325485496b67d54143ceb97e1820 Mon Sep 17 00:00:00 2001 From: qo-op Date: Wed, 29 Apr 2020 19:55:45 +0200 Subject: [PATCH] removes NOT friends from IPFS swarm --- zen/README.md | 11 ++++++++++- zen/ssb_IPFS_swarm.sh | 29 +++++++++++++++++------------ zen/tools/key_create_dunikey.py | 2 +- zen/tools/make_G1SSB_secret.sh | 2 +- zen/tools/sbotc-check-invite.sh | 6 ++++++ 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/zen/README.md b/zen/README.md index f2bcffe..a8cadd5 100644 --- a/zen/README.md +++ b/zen/README.md @@ -6,9 +6,18 @@ It contains per channel/wallets credentials and properties (each unique). SSB is the source of the gossip ipfs swarm structure Blob can accept commands from the differents channels it manages. +Channels are populated/monitored through to ~/.zen/ipfs_swarm IMPORTANT TODO!! -timeout.sh CPU problem to investigate +- timeout.sh CPU problem to investigate + +# MOVE swarm.key (once cron_MINUTE.sh is activated should be OK) +mv ~/.ipfs/swarm.key ~/.ipfs/swarm.key.old +sudo systemctl restart ipfs + +# Restart ssb-server +# kill -9 $(ps auxf --sort=+utime | grep -w ssb-server| grep -v -E 'color=auto|grep' | tail -n 1 | awk '{print $2}') + # IPFS FILESYSTEM STRUCTURE diff --git a/zen/ssb_IPFS_swarm.sh b/zen/ssb_IPFS_swarm.sh index 68df7dc..0c9252e 100755 --- a/zen/ssb_IPFS_swarm.sh +++ b/zen/ssb_IPFS_swarm.sh @@ -38,22 +38,27 @@ echo ' Get ipfs addresses from SSB friends and add to bootstrap & swarm peers' -# GET /tmp/ssb-friends.json to choose SWARM peers +# GET /tmp/ssb-friends.txt self=$(sbotc whoami | jq -r .id) -sbotc query.read '{"query":[{"$filter":{"value":{"author": "'"$self"'", "content":{"type":"contact"}}}}]}' | jq -r '.value?.content?.contact' > /tmp/ssb-friends.json || rm -f /tmp/ssb-friends.json +sbotc query.read '{"query":[{"$filter":{"value":{"author": "'"$self"'", "content":{"type":"contact"}}}}]}' | jq -r '.value?.content?.contact' > /tmp/ssb-friends.txt || rm -f /tmp/ssb-friends.txt +# GET /tmp/ssb-NOTfriends.txt +FEED_ID="$(sbotc whoami | jq .id -r)" +sbotc links "{\"source\": \"${FEED_ID}\", \"rel\": \"contact\", \"values\": true, \"reverse\": true}" | jq -c . | grep 'blocking":true' | jq -r .dest > /tmp/ssb-NOTfriends.txt -# SSB FRIENDS ARE "swarm connected" -for SSBFRIEND in $(cat /tmp/ssb-friends.json); do -# - ### GET SSB "ipfstryme" message type !!! +######################################################################## +# Let's look if our SSB Friends ARE "IPFS swarm connected" +######################################################################## +for SSBFRIEND in $(cat /tmp/ssb-friends.txt); do + + ### GET SSB "ipfstryme" message type !!! Astroport Node should have publish it during "ssb_INIT.sh" TRYME=$(sbotc query.read '{"query":[{"$filter":{"value":{"author": "'"$SSBFRIEND"'", "content":{"type":"ipfstryme"}}}}]}' | jq -r .value?.content?.text | tail -n 1) + + ## REMOVE NOTfriends from IPFS swarm + [[ $(grep -Rwl "$SSBFRIEND" /tmp/ssb-NOTfriends.txt) ]] && ipfs swarm disconnect $TRYME && ipfs bootstrap rm $TRYME && continue + + ## ADD Friend to our IPFS swarm [[ $TRYME ]] && ipfs swarm connect $TRYME && ipfs bootstrap add $TRYME - # Modify ipfs swarm peers and bootstrap related to ssb friends + done -# All memorized IPFS Nodes are swarm connected (again?) -#for IPFSNODEADDR in $(cat ~/.zen/ipfs_swarm/.Qm*/tryme.addr); do -# ipfs swarm connect $IPFSNODEADDR - # Renew ipfs_swarm knows ... -#done diff --git a/zen/tools/key_create_dunikey.py b/zen/tools/key_create_dunikey.py index af2b340..32720c8 100755 --- a/zen/tools/key_create_dunikey.py +++ b/zen/tools/key_create_dunikey.py @@ -18,7 +18,7 @@ from sys import argv from duniterpy.key import SigningKey # path to save to -path = "./.secret.dunikey" +path = "/tmp/secret.dunikey" key = SigningKey.from_credentials(argv[1], argv[2], None) key.save_pubsec_file(path) diff --git a/zen/tools/make_G1SSB_secret.sh b/zen/tools/make_G1SSB_secret.sh index c945e98..eb7455e 100755 --- a/zen/tools/make_G1SSB_secret.sh +++ b/zen/tools/make_G1SSB_secret.sh @@ -73,7 +73,7 @@ fi # CREATE ~/.ssb/secret.dunikey python3 $MY_PATH/key_create_dunikey.py "$salt" "$pepper" -mv $MY_PATH/.secret.dunikey ~/.ssb/secret.dunikey +mv /tmp/secret.dunikey ~/.ssb/secret.dunikey # CREATE SSB secret g1pub=$(cat ~/.ssb/secret.dunikey | grep "pub" | cut -d ' ' -f 2) diff --git a/zen/tools/sbotc-check-invite.sh b/zen/tools/sbotc-check-invite.sh index fa0c980..16e8558 100755 --- a/zen/tools/sbotc-check-invite.sh +++ b/zen/tools/sbotc-check-invite.sh @@ -1,4 +1,5 @@ #!/bin/sh +# Author @f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519 invite="${1?invite}" code="${invite##*~}" @@ -12,9 +13,14 @@ out="$(sbotc -s "$host" -p "$port" -k "$feed" -K "$code" -t async invite.use {} if echo "$out" | grep -q 'feed to follow is missing' then echo success +elif echo "$out" | grep -q 'method:invite,use is not in list of allowed methods' +then + echo invalid/expired + exit 1 else echo fail echo "$out" + echo trying another method: sbotc -s "$host" -p "$port" -k "$feed" -K "$code" -t source blobs.get '' exit 1 fi