gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated: -added optional stunserver to netjail sc


From: gnunet
Subject: [gnunet] branch master updated: -added optional stunserver to netjail script
Date: Sun, 02 May 2021 21:35:58 +0200

This is an automated email from the git hooks/post-receive script.

thejackimonster pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 2a027d304 -added optional stunserver to netjail script
2a027d304 is described below

commit 2a027d304a09fa9645cb7e121a2650085328fb6c
Author: TheJackiMonster <thejackimonster@gmail.com>
AuthorDate: Sun May 2 21:33:35 2021 +0200

    -added optional stunserver to netjail script
    
    Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
---
 contrib/scripts/netjail/netjail_core.sh           | 29 ++++++++++++++++++++
 contrib/scripts/netjail/netjail_setup_internet.sh | 33 +++++++++++++++++++++--
 2 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/contrib/scripts/netjail/netjail_core.sh 
b/contrib/scripts/netjail/netjail_core.sh
index 6a18ea902..8dbbeacf1 100755
--- a/contrib/scripts/netjail/netjail_core.sh
+++ b/contrib/scripts/netjail/netjail_core.sh
@@ -9,6 +9,25 @@ JAILOR=${SUDO_USER:?must run in sudo}
 
 export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
 
+netjail_opt() {
+       OPT=$1
+       shift 1
+
+       INDEX=1
+
+       while [ $# -gt 0 ]; do
+               if [ "$1" = "$OPT" ]; then
+                       printf "%d" $INDEX
+                       return
+               fi
+
+               INDEX=$(($INDEX + 1))
+               shift 1
+       done
+
+       printf "%d" 0
+}
+
 netjail_check() {
        NODE_COUNT=$1
 
@@ -74,6 +93,15 @@ netjail_node_link_bridge() {
        ip link set $LINK_BR up
 }
 
+netjail_node_unlink_bridge() {
+       NODE=$1
+       BRIDGE=$2
+       
+       LINK_BR="$NODE-$BRIDGE-1"
+
+       ip link delete $LINK_BR
+}
+
 netjail_node_add_nat() {
        NODE=$1
        ADDRESS=$2
@@ -98,3 +126,4 @@ netjail_node_exec() {
        unshare -fp --kill-child -- ip netns exec $NODE sudo -u $JAILOR -- $@ 
1>& $FD_OUT 0<& $FD_IN
 }
 
+
diff --git a/contrib/scripts/netjail/netjail_setup_internet.sh 
b/contrib/scripts/netjail/netjail_setup_internet.sh
index d99709555..2d448168a 100755
--- a/contrib/scripts/netjail/netjail_setup_internet.sh
+++ b/contrib/scripts/netjail/netjail_setup_internet.sh
@@ -9,16 +9,19 @@ export 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
 LOCAL_M=$1
 GLOBAL_N=$2
 
-# TODO: stunserver? ..and globally known peer?
+# TODO: globally known peer?
 
 shift 2
 
 netjail_check $(($LOCAL_M * $GLOBAL_N))
 
+# Starts optionally 'stunserver' on "92.68.150.$(($GLOBAL_N + 1))":
+STUN=$(netjail_opt '--stun' $@)
+
 LOCAL_GROUP="192.168.15"
 GLOBAL_GROUP="92.68.150"
 
-echo "Start [local: $LOCAL_GROUP.0/24, global: $GLOBAL_GROUP.0/24]"
+echo "Start [local: $LOCAL_GROUP.0/24, global: $GLOBAL_GROUP.0/24, stun: 
$STUN]"
 
 NETWORK_NET=$(netjail_print_name "n" $GLOBAL_N $LOCAL_M)
 
@@ -53,6 +56,22 @@ for N in $(seq $GLOBAL_N); do
        done
 done
 
+WAITING=""
+KILLING=""
+
+if [ $STUN -gt 0 ]; then
+       shift 1
+       
+       S=$(($GLOBAL_N + 1))
+       STUN_NODE=$(netjail_print_name "S" $S)
+
+       netjail_node $STUN_NODE
+       netjail_node_link_bridge $STUN_NODE $NETWORK_NET "$GLOBAL_GROUP.$S" 24
+
+       netjail_node_exec $STUN_NODE 0 1 stunserver &
+       KILLING="$!"
+fi
+
 for N in $(seq $GLOBAL_N); do
        for M in $(seq $LOCAL_M); do
                NODE=$(netjail_print_name "N" $N $M)
@@ -62,11 +81,21 @@ for N in $(seq $GLOBAL_N); do
                FD_Y=$(($INDEX * 2 + 3 + 1))
 
                netjail_node_exec $NODE $FD_X $FD_Y $@ &
+               WAITING="$! $WAITING"
        done
 done
 
+for PID in $WAITING; do wait $PID; done
+for PID in $KILLING; do kill $PID; done
 wait
 
+if [ $STUN -gt 0 ]; then
+       STUN_NODE=$(netjail_print_name "S" $(($GLOBAL_N + 1)))
+
+       netjail_node_unlink_bridge $STUN_NODE $NETWORK_NET
+       netjail_node_clear $STUN_NODE
+fi
+
 for N in $(seq $GLOBAL_N); do
        for M in $(seq $LOCAL_M); do
                netjail_node_clear $(netjail_print_name "N" $N $M)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]