diff --git a/ISOconfig.sh b/ISOconfig.sh index 133db4f..79d6a42 100755 --- a/ISOconfig.sh +++ b/ISOconfig.sh @@ -47,6 +47,8 @@ jq -r --arg PeerID "$PeerID" '.Identity.PeerID=$PeerID' ~/.ipfs/config > /tmp/co jq -r --arg PrivKEY "$PrivKEY" '.Identity.PrivKey=$PrivKEY' /tmp/config.tmp > /tmp/config.ipfs rm /tmp/config.tmp +IPFSNODEID=$PeerID + ## Directory transfered to IPFS IPFS_sync_directory="$HOME/.zen/miam" @@ -80,16 +82,16 @@ sleep 10 echo 'EXTEND ~/.bashrc' ~/.zen/astroport/.install/update_bashrc.sh -mkdir -p ~/.zen/ipfs/.${PeerID}/G1SSB -echo "" > ~/.zen/ipfs/.${PeerID}/tryme.addr +mkdir -p ~/.zen/ipfs/.${IPFSNODEID}/G1SSB +echo "" > ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr for tryme in $(ipfs id | jq -r .Addresses[]); do isLAN=$(echo $tryme | cut -f3 -d '/' | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") - [[ ! $isLAN ]] && echo "$tryme" >> ~/.zen/ipfs/.${PeerID}/tryme.addr && echo "$tryme" + [[ ! $isLAN ]] && echo "$tryme" >> ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr && echo "$tryme" done echo 'SEND ipfstryme to oasis' -./jaklis.py send -d 2jQUH4HfHxdTesjCjvMCx1VJgA5AnpuvrWRq1swfRdsS -t "ipfstryme" -f ~/.zen/ipfs/.${PeerID}/tryme.addr +./jaklis.py send -d 2jQUH4HfHxdTesjCjvMCx1VJgA5AnpuvrWRq1swfRdsS -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr diff --git a/zen/gchange_IPFS_swarm.sh b/zen/gchange_IPFS_swarm.sh index f2ffee4..049c29c 100755 --- a/zen/gchange_IPFS_swarm.sh +++ b/zen/gchange_IPFS_swarm.sh @@ -8,6 +8,9 @@ MY_PATH="`dirname \"$0\"`" # relative MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized ME="${0##*/}" +# Connect to IPFS peers with bidirectionnal "like" (gchange friends) +# + ######################################################################## # \\/// # qo-op @@ -37,7 +40,8 @@ IPFSNODEID=$(ipfs id -f='\n') # Force Strict #swarm0 !!? # ipfs bootstrap rm --all -echo "" > /tmp/A_liking_me_NO_ipfstryme.txt +echo "" > ~/.zen/A_allow_ip.txt +echo "" > ~/.zen/A_liking_me_NO_ipfstryme.txt # contains "friends" with no "ipfstryme" incoming message liking_me_count=0 friend_of_mine_count=0 ######################################################################## @@ -51,16 +55,35 @@ do # 2. Searching "ipfstryme" message from friend_of_mine [[ $friend_of_mine != null ]] && echo "Connect to my friend $liking_me" && friend_of_mine_count=$((friend_of_mine_count+1)) && ipfsadd=0 \ && for peer in $(./jaklis.py read -n50 -j | jq -r --arg friendKEY "$liking_me" '.[] | select(.pubkey == $friendKEY)' | jq 'select(.title == "ipfstryme")' | jq -r '.content'); + # ipfstryme message contains peer ipfs adresses do + ip=$(echo "$peer" | awk -F '/' '{print $3}') + echo $ip >> ~/.zen/A_allow_ip.txt + ipfsnodeid=$(echo "$peer" | awk -F '/' '{print $7}') # 3. liking_me friend_of_mine can join my swarm & bootstrap ipfs swarm connect $peer; ipfs bootstrap add $peer; ipfsadd=$((ipfsadd+1)) done; - [[ $friend_of_mine != null && $ipfsadd == 0 ]] && echo "No ipfstryme message..." && echo "$liking_me" >> /tmp/A_liking_me_NO_ipfstryme.txt + + # Friend of mine with no ipfstryme message + [[ $friend_of_mine != null && $ipfsadd == 0 ]] && echo "No ipfstryme message..." && echo "$liking_me" >> ~/.zen/A_liking_me_NO_ipfstryme.txt + # 4. liking_me IS NOT a friend_of_mine!! - [[ $friend_of_mine == null ]] && echo "I am NOT LIKING $liking_me"; - liking_me_count=$((liking_me_count+1)) + if [[ $friend_of_mine == null ]]; then + echo "I am NOT LIKING $liking_me"; + # GET its ~/.zen/ipfs IPNS sharing + ipfs get --output=/tmp/ipfs_swarm/ /ipns/$ipfsnodeid + g1pub=$(cat /tmp/ipfs_swarm/.$ipfsnodeid/G1SSB/_g1.pubkey) + + ### NO G1SSB node => BAN IP (must be sudo with no password !!) + [[ $g1pub == "" && ( $USER == "pi" || $USER == "xbian") ]] && "SHOULD BAN $liking_me" \ + && sudo fail2ban-client add recidive && sudo fail2ban-client set recidive banip $ip + + # Automatic level_1 like from oasis.astroport.com (add other default bootstrap) + [[ $G1PUB == "2jQUH4HfHxdTesjCjvMCx1VJgA5AnpuvrWRq1swfRdsS" ]] && ./jaklis.py like -p $g1pub -s 1 + fi + liking_me_count=$((liking_me_count+1)) done @@ -71,7 +94,10 @@ My actual #SWARM0" ipfs swarm peers echo "__________________________________________" echo -for line in $(cat /tmp/A_liking_me_NO_ipfstryme.txt | uniq); do +## Send message to +for line in $(cat ~/.zen/A_liking_me_NO_ipfstryme.txt | uniq); do + echo "Liking ME, but no ipfstryme received..." + echo "cd ~/.zen/astroport/zen/jaklis" echo "./jaklis.py send -d $liking_me -t 'Astroport' -m 'Rejoins mon #Swarm0 sur https://qo-op.com'" done diff --git a/zen/ipfs_SWARM_refresh.sh b/zen/ipfs_SWARM_refresh.sh index 62bfbad..e26aeba 100755 --- a/zen/ipfs_SWARM_refresh.sh +++ b/zen/ipfs_SWARM_refresh.sh @@ -7,8 +7,17 @@ MY_PATH="`dirname \"$0\"`" # relative MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized ME="${0##*/}" +######################################################################## +# This script is controling IPFS swarm -## NOT WORKING !!! +# Removes from peers not friends on gchange+ +# remember Nodes ID and IPs +# add IPs to fail2ban + +# Sync friends peers ~/.zen/ipfs/ into ~/.zen/ipfs_swarm/.IPFSNODEID's/ directories +# + +## NOT WORKING !!! YET exit 1 ######################################################################## # \\/// @@ -16,8 +25,8 @@ exit 1 ############# '$MY_PATH/$ME' ######################################################################## # ex: ./'$ME' -# SYNC IPFS SWARM PEERS SHARED DATA .12D3KooW**** -########################################################################' +######################################################################## +# TODO remove because it is in~/.bashrc export YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) export IPFSNODEID=$(ipfs id -f='\n') ######################################################################## @@ -31,13 +40,30 @@ _|_| | __) __)\/\//--\| \| | | \|_| | \|___)| | ' echo "I am $IPFSNODEID" -## TODO CHANNELS SWARM INDEX COPY PROCEDURE -## SIGNAL ~/.zen/g1sms/ TODO +for peer in $(ipfs swarm peers); +do + id=$(echo "$peer" | awk -F '/' '{print $7}') + ip=$(echo "$peer" | awk -F '/' '{print $3}') + nowdate=$(date) + timestamp=$(date -u +%s%N | cut -b1-13) + + echo "$nowdate - $id - $ip" + foundIp=$(cat ~/.zen/allow_ip.txt | grep "$ip" | wc -l) + if [ "$foundIp" -eq 0 ] ; then + echo "${ip} of peer ${id} is not in the authorized ip list. ${peer} will be removed from the swarm" + ipfs swarm disconnect $peer + ipfs bootstrap rm $peer + else + ${path_script}/timeout.sh -t 30 ipfs get --output ${path_shared_files}/ /ipns/$id + fi +done echo "PUBLISHING MY OWN /home/$YOU/.zen/ipfs/ to SWARM" [[ ! -d /home/$YOU/.zen/ipfs ]] && echo "ERROR : /home/$YOU/.zen/ipfs/ NOT FOUND" && exit 1 IWALLETS=$(ipfs add -rHq /home/$YOU/.zen/ipfs | tail -n 1) NODEIPNS=$(ipfs name publish --quieter /ipfs/$IWALLETS) + +# Put my own data in /home/$YOU/.zen/ipfs_swarm/ ipfs get --output=/home/$YOU/.zen/ipfs_swarm/ /ipns/$IPFSNODEID echo "REFRESHING /home/$YOU/.zen/ipfs_swarm/ from my SWARM peers"