ControlScripts/clients/transmission: transmission support files were created
authorp2p p2p-next-02 <p2p@p2p-next-02.grid.pub.ro>
Mon, 2 May 2011 10:56:06 +0000 (13:56 +0300)
committerp2p p2p-next-02 <p2p@p2p-next-02.grid.pub.ro>
Mon, 2 May 2011 10:56:06 +0000 (13:56 +0300)
ControlScripts/clients/transmission/detect_complete_transmission.sh [new file with mode: 0755]
ControlScripts/clients/transmission/parse_transmission.sh [new file with mode: 0755]
ControlScripts/clients/transmission/start_transmission_leecher.sh [new file with mode: 0755]
ControlScripts/clients/transmission/start_transmission_seeder.sh [new file with mode: 0755]
ControlScripts/clients/transmission/stop_transmission.sh [new file with mode: 0755]

diff --git a/ControlScripts/clients/transmission/detect_complete_transmission.sh b/ControlScripts/clients/transmission/detect_complete_transmission.sh
new file mode 100755 (executable)
index 0000000..19e36a7
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/bash
+#
+# 2011, Calin-Andrei Burloiu, calin.burloiu@gmail.com
+#
+# Bash script used to detect when a regular client finished
+# downloading a torrent
+#
+# The script
+#  * monitors a log file provided as an argument
+#  * as long as the doe is not finished the script keeps running
+#  * when the doe is finished it returns 0
+#  * blocks the caller - the script exits only when the doe has completed
+#                        the download
+#
+# Script arguments:
+#  * log file
+
+if [ ! $# -eq 1 ]; then
+       echo "usage: $0 log-file"
+       exit 1
+fi
+
+LOG_FILE=$1
+
+while true; do
+       # check for complete transfer
+       if cat $LOG_FILE | grep "Torrent finished" &> /dev/null; then
+               echo "Torrent transfer finished"
+               exit 0
+       fi
+
+       if cat $LOG_FILE | grep "Segmentation fault" &> /dev/null; then
+               echo "Segmentation fault when transferring torrent"
+               exit 0
+       fi
+
+       # check stat client is alive
+       if ! pgrep "hrktorrent" &> /dev/null; then
+               if ! pgrep -f "schedule_client.sh" &> /dev/null; then
+                       echo "No hrktorrent and no schedule_client.sh process"
+                       exit 0
+               fi
+       fi
+
+       # Don't do continuous polling
+       sleep 5
+done
diff --git a/ControlScripts/clients/transmission/parse_transmission.sh b/ControlScripts/clients/transmission/parse_transmission.sh
new file mode 100755 (executable)
index 0000000..c25eb24
--- /dev/null
@@ -0,0 +1,108 @@
+#!/bin/bash
+#
+# 2011, Calin-Andrei Burloiu, calin.burloiu@gmail.com
+#
+# Bash script used to parse the log file generated by a transmission client
+#
+# Script arguments:
+#  * a folder where the log and data files are stored
+#  * the name of a log file in that folder
+#
+# Sample run:
+#  ./parse_hrk.sh ../../../Results/samples/ p2p-next-01-101.log
+
+if [ ! $# -eq 2 ]; then
+       echo "usage: $0 log-folder log-file"
+       exit 1
+fi
+
+LOG_FOLDER=$1
+LOG_FILE=$2
+DATA_FILE=$LOG_FOLDER/${LOG_FILE}.data
+PEER_UPLOAD_DOWNLOAD_FILE=$LOG_FOLDER/${LOG_FILE}.updown
+
+# Check if the log folder exists
+if [ ! -d $LOG_FOLDER ]; then
+       echo "Error: The folder $LOG_FOLDER does not exist."
+       exit 1
+fi
+
+# Check if the log file exists
+if [ ! -e $LOG_FOLDER/$LOG_FILE ]; then
+       echo "Error: The log file $LOG_FOLDER/$LOG_FILE does not exist."
+       exit 1
+fi
+
+# Check if the log file is a regular file
+if [ ! -f $LOG_FOLDER/$LOG_FILE ]; then
+       echo "Error: The log file $LOG_FOLDER/$LOG_FILE is not a regular file."
+       exit 1
+fi
+
+# Write the header to the data file
+echo "time percent upspeed dlspeed" > $DATA_FILE
+
+# Clean and parse the log file
+grep '^ps\|SLEEP' $LOG_FOLDER/$LOG_FILE | awk -F '[ \t<>:,]+' '
+BEGIN  {
+       rel_time = 0;
+}
+
+{
+       if ($1 == "SLEEP")
+               rel_time = rel_time + $2;
+       else {
+               dlspeed = $4 + 0;
+               upspeed = $6 + 0;
+               download = $8 + 0;
+               size = $12 + 0;
+               percent = 100.0 * download / size;
+
+               printf "%d %.2f %.2f %.2f\n", rel_time, percent, upspeed, dlspeed;
+               rel_time++;
+       }
+}' >> $DATA_FILE
+
+# convert host_id and veid to veth IP address in 10.0.0.0/8 network
+host_veid_to_eth_ip()
+{
+       host_id=$1
+       veid=$2
+       ip_part1=$(($veid / 100))
+       ip_part2=$(($veid % 100))
+       id=$(echo "$host_id" | awk '{printf "%d", $1;}')
+       echo "10.$ip_part1.$id.$ip_part2"
+}
+
+# convert p2p-next-${host_id}-${veid} hostname to veth IP address
+hostname_to_ip()
+{
+       hostname=$1
+
+       veid=${hostname##*-}
+tmp=${hostname%-*}
+       host_id=${tmp##*-}
+
+       host_veid_to_eth_ip $host_id $veid
+}
+
+local_ip=$(hostname_to_ip ${LOG_FILE/%.log/})
+
+# Parse the peer log file; output peer download and upload files
+
+grep '^--Peers' $LOG_FOLDER/$LOG_FILE | awk -v ip=${local_ip} -F '[],() []+' '
+{
+       printf "[%s %s %s]", $2, $3, $4;
+       i = 6;
+       for (i = 6; i < NF; i += 6) {
+               j = i+2;
+               k = i+4;
+               down_speed = $j + 0;
+               up_speed = $k + 0;
+               split($i, ip_port, ":");
+               printf " (%s, %s, %s, %s)", ip, ip_port[1], down_speed, up_speed;
+       }
+       printf "\n";
+}' > $PEER_UPLOAD_DOWNLOAD_FILE
+
+exit 0
diff --git a/ControlScripts/clients/transmission/start_transmission_leecher.sh b/ControlScripts/clients/transmission/start_transmission_leecher.sh
new file mode 100755 (executable)
index 0000000..f725452
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/bash
+#
+# 2011, Calin-Andrei Burloiu, calin.burloiu@gmail.com
+#
+# Bash script used to start a hrktorrent instance
+# The script
+#  * changes current working directory to Regular
+#  * starts a transmission session
+#  * at the end deletes the downloaded data
+#
+# If you run this script manually, you must run it from the P2P-Testing-Infrastructure/ControlScripts folder
+#
+
+# Read the global configuration file
+# Check if the global configuration file exists
+if [ ! -e globalconfig ]; then
+       echo "Warning: The global config file globalconfig does not exist."
+else
+       source globalconfig
+fi
+
+# Read the node-specific configuration file (TORRENT_FILE)
+# Check if the node-specific configuration file exists
+if [ ! -e ../ClientWorkingFolders/TmpLogs/node_config ]; then
+       echo "Warning: The global config file ../ClientWorkingFolders/TmpLogs/node_config does not exist."
+else
+       source ../ClientWorkingFolders/TmpLogs/node_config
+fi
+
+cd $WORKING_FOLDER_REL_PATH/Regular/
+
+LD_LIBRARY_PATH=$HRK_ABS_PATH/../libtorrent-rasterbar/lib $HRK_ABS_PATH/hrktorrent --nodht ../TorrentsAndData/$TORRENT_FILE
+
+rm -rf *
diff --git a/ControlScripts/clients/transmission/start_transmission_seeder.sh b/ControlScripts/clients/transmission/start_transmission_seeder.sh
new file mode 100755 (executable)
index 0000000..0e81927
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/bash
+#
+# 2011, Calin-Andrei Burloiu, calin.burloiu@gmail.com
+#
+# Bash script used to start a transmission instance
+# The script
+#  * changes current working directory to TorrentsAndData
+#  * starts a transmission session
+#  * at the end deletes the downloaded data
+#
+# If you run this script manually, you must run it from the P2P-Testing-Infrastructure/ControlScripts folder
+#
+
+# Read the global configuration file
+# Check if the global configuration file exists
+if [ ! -e globalconfig ]; then
+       echo "Warning: The global config file globalconfig does not exist."
+else
+       source globalconfig
+fi
+
+# Read the node-specific configuration file (TORRENT_FILE)
+# Check if the node-specific configuration file exists
+if [ ! -e ../ClientWorkingFolders/TmpLogs/node_config ]; then
+       echo "Warning: The global config file ../ClientWorkingFolders/TmpLogs/node_config does not exist."
+else
+       source ../ClientWorkingFolders/TmpLogs/node_config
+fi
+
+cd $WORKING_FOLDER_REL_PATH/TorrentsAndData/
+
+LD_LIBRARY_PATH=$HRK_ABS_PATH/../libtorrent-rasterbar/lib $HRK_ABS_PATH/hrktorrent --nodht --nohashcheck $TORRENT_FILE
diff --git a/ControlScripts/clients/transmission/stop_transmission.sh b/ControlScripts/clients/transmission/stop_transmission.sh
new file mode 100755 (executable)
index 0000000..b0f31f7
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash
+#
+# 2011, Calin-Andrei Burloiu, calin.burloiu@gmail.com
+#
+# Bash script used to stop all transmission instances
+# The script
+#  * stops all the transmission instances
+
+if [ ! $# -eq 0 ]; then
+       echo "usage: $0"
+       exit 1
+fi
+
+pkill -KILL -f hrktorrent