doc: abstract + architecture
[p2p-kernel-protocol.git] / sendfile / test.sh
1 #!/bin/bash
2
3 MODULE_NAME=af_p2pkp
4 MODULE_DIR=../module
5 CLIENT=client/client
6 SERVER=server/server
7 FILE=/tmp/testfile32
8 OUTPUT_DIR=/tmp
9 IP="127.0.0.1"
10 WAIT_TIME=3
11
12 LISTENERS_PORTS=(
13         50000
14         50001
15         50002
16         50003
17         50004
18         50005
19 )
20
21 #use nc.traditional
22 echo 2 | update-alternatives --config nc &> /dev/null
23
24 [ -d $OUTPUT_DIR ] || mkdir -p $OUTPUT_DIR
25
26 #increase tests debugging
27 #set -x
28
29 # listen for UDP packets on localhost, port 50000 (run in background)
30 for port in "${LISTENERS_PORTS[@]}"; do
31         $SERVER $IP $port $OUTPUT_DIR/testfile.$port &
32         pids="$pids $!"
33         ARGUMENTS="$IP $port $ARGUMENTS"
34 done
35
36 # wait for netcat to start listening
37 sleep $WAIT_TIME
38
39 if [ $# -eq 0 ]; then
40         [ -e $FILE ] || exit
41         $CLIENT $FILE $ARGUMENTS
42 else
43         for file in $@; do
44                 [ -e $file ] || continue
45                 $CLIENT $file $ARGUMENTS
46         done
47 fi
48
49 sleep $WAIT_TIME
50 # kill netcat
51 for pid in $pids; do
52         kill -9 $pid &> /dev/null
53 done