Author Topic: HOWTO: Test many OFF nodes on a single Linux system  (Read 2573 times)

0 Members and 1 Guest are viewing this topic.

Offline scripter

  • Regular
  • **
  • Posts: 88
  • Karma: +2/-0
    • View Profile
HOWTO: Test many OFF nodes on a single Linux system
« on: September 10, 2008, 02:08:34 AM »
The scripts below create new directories for each test node, including all the config options and proper port settings so you can test as many OFF nodes on one system as you can handle.

Communications are over the local interface (lo) of course, which can be monitored with tcpdump if you like.

You must compile OFF with the option RELEASE_ON disabled (see offconstants.h at about line 335 and comment it out) then it doesn't create a lock file for each instance.

Create a new directory and put a default OFF setup in there, including the OFF executable, config, themes and other folders.

Put the two scripts in there and chmod them so they are executable.

Open a terminal and cd to that directory. When you run "./go-test.sh 4" it will create 4 new directories named "1", "2", etc.. and copy the executable and config files over, changing the ports and node name in the config file accordingly. It also adds nodes to connect to within the test range.

When you are done you can use "cleanup.sh 4" to kill OFF and remove the test directories "1", "2" etc..

"go-test.sh"
Code: [Select]
#!/bin/bash

# Script for testing lots of OFF nodes on the same computer
# You must compile OFF with the option RELEASE_ON disabled
# (see offconstants.h at about line 335 and comment it out)
# then it doesn't create a lock file for each instance
# Place a default OFF setup in the working directory, including
# the OFF executable, config and themes folders
# Written by Scripter Sept, 2008

make_nodes=$1

if [ "$make_nodes" == "" ]; then
echo "Usage:  go-test.sh NUMBER (of nodes to make)"
exit
fi

# set this if you only want each node to connect to the next node at
# startup, otherwise each node will try to connect to all other nodes
connect_to_next_node=0

# setup variables we will use
node=1
port=23501

while [ $node -le $make_nodes ]; do

echo "Copying files for Node $node"
if [ ! -d $node ]; then
mkdir $node
fi

cp -a config $node/
cp -a blockcache $node/
cp -a retrieved $node/
cp -a pads $node/
cp -a lang $node/
cp -a keys $node/
cp -a themes $node/
cp -a temp $node/
cp -a offsystem $node/

# remove config lines we want to change, then put them back with what we want
# OFF wants each line to be exactly in order for whatever reason
cat $node/config/offsystem.conf | grep -v "verbose" | grep -v "trusted_search" \
 | grep -v "username" | grep -v "incoming_p" > $node/config/offsystem-temp.conf
echo " verbose: 1" > $node/config/offsystem.conf
echo " username: \"Node-$node\"" >> $node/config/offsystem.conf
echo " trusted_search_in: 0" >> $node/config/offsystem.conf
echo " trusted_search_out: 0" >> $node/config/offsystem.conf
echo " incoming_port_number: $port" >> $node/config/offsystem.conf
cat $node/config/offsystem-temp.conf >> $node/config/offsystem.conf

# connect to the next node, last node gets connected
# to 23403 for a special running node you may have
if [ $connect_to_next_node -ne 0 ]; then
  if [ $node -ne $make_nodes ]; then
    port1=`expr $port + 1`
    echo "localhost $port1" > $node/config/known_nodes.txt
  else
    echo "localhost 23403" > $node/config/known_nodes.txt
  fi
else
  # each node tries to connect to all other nodes at startup
  node1=1
  port2=23501
  echo "localhost $port2" > $node/config/known_nodes.txt
  while [ $node1 -lt $make_nodes ]; do
    port2=`expr $port2 + 1`
    echo "localhost $port2" >> $node/config/known_nodes.txt
    node1=`expr $node1 + 1`
  done
  echo "localhost 23403" >> $node/config/known_nodes.txt
fi

# remove the rsa keys, will be regenerated
rm -f $node/config/off_rsa.pub
rm -f $node/config/off_rsa

node=`expr $node + 1`
port=`expr $port + 1`
done

node=1

while [ $node -le $make_nodes ]; do

echo "Starting Node $node"
cd $node

# my usual run with a terminal for each node
gnome-terminal --title=Node-$node -x ./offsystem &

# just run it
# ./offsystem &

# with gdb, you should killall offsystem; killall gdb before using cleanup.sh
# gnome-terminal --title=Node-$node -x gdb -ex run offsystem

cd ..

node=`expr $node + 1`
done

exit

"cleanup.sh"
Code: [Select]
#!/bin/bash

# Script for cleaning up after using the OFF go-test.sh script
# It will kill OFF and remove the directories
# Written by Scripter Sept, 2008

make_nodes=$1

if [ "$make_nodes" == "" ]; then
echo "Usage:  cleanup.sh NUMBER (of nodes to cleanup)"
exit
fi

node=1

echo "killall offsystem"
killall offsystem
echo "(giving it a little time...)"
sleep 10

while [ $node -le $make_nodes ]; do

if [ -d $node ]; then
echo "Removing folder $node"
rm -fr $node
fi
  node=`expr $node + 1`
done

exit


Note: On Ubuntu you should install "gnome-terminal" so this works properly.