aboutsummaryrefslogtreecommitdiff
path: root/contrib/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/scripts')
-rw-r--r--contrib/scripts/.gitignore2
-rwxr-xr-xcontrib/scripts/afferify110
-rwxr-xr-xcontrib/scripts/coverage.sh14
-rwxr-xr-xcontrib/scripts/debug37
-rw-r--r--contrib/scripts/documentation/gnunet-doc.scm182
-rw-r--r--contrib/scripts/find_typedefs.py102
-rw-r--r--contrib/scripts/gdb-iterate-dll.py43
-rwxr-xr-xcontrib/scripts/generate-monkey-db.sh17
-rwxr-xr-xcontrib/scripts/gnunet-bugreport252
-rwxr-xr-xcontrib/scripts/gnunet-chk.py.in381
-rwxr-xr-xcontrib/scripts/gnunet-logread/gnunet-logread198
-rwxr-xr-xcontrib/scripts/gnunet-logread/gnunet-logread-ipc10
-rwxr-xr-xcontrib/scripts/gnunet-logread/gnunet-logread-ipc-sdedit60
-rwxr-xr-xcontrib/scripts/gnunet-suidfix27
-rw-r--r--contrib/scripts/gnunet_janitor.py.in79
-rw-r--r--contrib/scripts/gnunet_pyexpect.py.in82
-rwxr-xr-xcontrib/scripts/lint-python.sh24
-rwxr-xr-xcontrib/scripts/process_log.sh30
-rw-r--r--contrib/scripts/pydiffer.py.in44
-rwxr-xr-xcontrib/scripts/pydmesg75
-rwxr-xr-xcontrib/scripts/regression.sh54
-rwxr-xr-xcontrib/scripts/removetrailingwhitespace.py.in15
-rwxr-xr-xcontrib/scripts/revisionary.sh98
-rw-r--r--contrib/scripts/terminate.py.in66
-rwxr-xr-xcontrib/scripts/testbed_cleanup.sh14
-rw-r--r--contrib/scripts/texinfo-hacks.el18
-rwxr-xr-xcontrib/scripts/visualize_stats.sh86
-rwxr-xr-xcontrib/scripts/zonewalk-to-types.sh35
28 files changed, 2155 insertions, 0 deletions
diff --git a/contrib/scripts/.gitignore b/contrib/scripts/.gitignore
new file mode 100644
index 000000000..547c89185
--- /dev/null
+++ b/contrib/scripts/.gitignore
@@ -0,0 +1,2 @@
1gnunet-chk.py
2removetrailingwhitespace.py
diff --git a/contrib/scripts/afferify b/contrib/scripts/afferify
new file mode 100755
index 000000000..2fa607e1a
--- /dev/null
+++ b/contrib/scripts/afferify
@@ -0,0 +1,110 @@
1#!/usr/bin/perl
2# Catch all in-source GPL2/3 license declarations and convert
3# them to AGPL.
4#
5# You expected this to be using diff & patch? Well, the source
6# files have all sorts of different commenting and indentation
7# styles, not speaking of typos and failed uses of search and
8# replace, that an attempt in using the patch(1) tool would fail
9# miserably. This script instead is based on my rgrep from 1998.
10# Keeping it here as it may be useful to other projects under-
11# going the same pains. It is forbidden to use this script to
12# convert AGPL code back to less strict licensing. Haha, just
13# kidding.
14#
15# -symlynX
16
17use File::Find;
18$|=1;
19# Recurse into current or given directories
20find(\&wanted, $#ARGV >= 0 ? @ARGV : '.');
21print STDERR "\n";
22exit;
23
24
25sub wanted {
26 my $name = $File::Find::name;
27 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime)
28 = lstat;
29 return $File::Find::prune = 1 if /^(CVS|\.git|\.svn)$/;
30 # Nicer if you 'make distclean' first
31 return if /\.(o|pdf)$/i;
32 return if -d _ or -l _;
33 return if /afferify/; # Don't apply this to itself ;)
34 # No.. i didn't do it.. just being careful ;) ;)
35# return unless -T _; # We don't have binaries in the repo, do we?
36
37 # We need the default variable '$_' for more important duties.
38 my $f = $_;
39
40 if (sysopen(I, $f, O_RDONLY)) {
41 $_ = &slurp(*I);
42 close I;
43 # Debugging: What's inside the file we just read?
44# print STDERR '> ', $_;
45
46if (0) {
47# This code did the initial conversion. We ifdef it out.
48
49 # Good idea to have the text start with "GNUnet" rather than "This program"
50 if ( s#GNUnet is free software; you can redistribute it and/or modify it under the#GNUnet is free software: you can redistribute it and/or modify it# ) {
51 # Whoever had the idea of reformatting the GPL license text...
52 print STDERR "\nTrying wide style on $name\t";
53
54 # Most important thing to know in order to be able
55 # to read perl code: if regexps appear without any
56 # context, it means they are applied to the default
57 # variable being '$_'.
58 return unless s#terms of the GNU General Public License as published by the Free Software#under the terms of the GNU Affero General Public License as published#;
59 return unless s#^(\W*\s+)Foundation; either version \d, or \(at your option\) any later version\.#\1by the Free Software Foundation, either version 3 of the License,\n\1or (at your option) any later version.#m;
60 return unless s#GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY#GNUnet is distributed in the hope that it will be useful, but#;
61 return unless s#WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR#WITHOUT ANY WARRANTY; without even the implied warranty of#;
62 return unless s#^(\W*\s+)A PARTICULAR PURPOSE. See the GNU General Public License for more details.#\1MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n\1Affero General Public License for more details.#m;
63 return unless s#^\W*\n\W*\s+You should have received a copy of the GNU General Public License along with\n\W*\s+GNUnet. see the file COPYING\. If not, .* see\s*\W*\s+<http://www.gnu.org/licenses/>\n##m;
64 } else {
65 # If this string is not in the file, leave it alone.
66 return unless s#GNUnet is free software; you can redistribute it and/or modify#GNUnet is free software: you can redistribute it and/or modify it#;
67 print STDERR "\nTrying regular style on $name\t";
68
69 # Patterns are designed to also match some typos and substitutions.
70 return unless s#it under the terms of the GNU General Public Lice\w+ as published#under the terms of the GNU Affero General Public License as published#;
71 return unless s#by the Free Software Foundation; either version \d, or \(at your#by the Free Software Foundation, either version 3 of the License,#;
72 return unless s#option\) any later version\.#or (at your option) any later version.#;
73 return unless s#General Public Lice\w+ for more details\.#Affero General Public License for more details.#;
74 return unless s#^\W*\n\W*\s+You should have received a copy of the GNU General Public Lice\w+\n\W*\s+along with GNUnet. see the file COPYING\. If not, write to the\n\W*\s+Free Software Foundation, Inc\., (51 Franklin Street, Fifth Floor|59 Tem ?ple Place - Suite 330),\n\W*\s+Boston, MA 0211\d-130\d, USA\.\n##m;
75 }
76 print STDERR "OK";
77
78} else {
79# This is the code in actual & current use:
80
81 return unless m#GNUnet is free software: you can redistribute it and/or modify it#;
82 print STDERR "\nTrying $name\t";
83 # There was a mistake in the replacement text!
84 return unless s#under the terms of the GNU General Public License as published#under the terms of the GNU Affero General Public License as published#;
85 # Don't apply this one twice!
86# return unless s#(\n\W*)(\s+)(Affero General Public License for more details\.)#\1\2\3\1\1\2You should have received a copy of the GNU Affero General Public License\1\2along with this program. If not, see <http://www.gnu.org/licenses/>.#;
87 print STDERR "FIXED";
88}
89
90 # We directly overwrite the original file in the
91 # assumption that we're in a healthy revertible git.
92 open(O, '>', $f) or die "Cannot overwrite $f";
93 # Imagine, I could have left out $_ here... ;)
94 print O $_;
95 close O;
96 } else {
97 die "Cannot access $name";
98 }
99}
100
101# Reads a file from a stream into a variable all at once:
102sub slurp {
103 # Perl sure gets clunky here
104 local(*IN) = @_;
105 local($save) = $/;
106 undef $/;
107 local($data) = <IN>;
108 $/ = $save;
109 return $data;
110}
diff --git a/contrib/scripts/coverage.sh b/contrib/scripts/coverage.sh
new file mode 100755
index 000000000..dd6a6ab53
--- /dev/null
+++ b/contrib/scripts/coverage.sh
@@ -0,0 +1,14 @@
1#!/bin/sh
2# make sure configure was run with coverage enabled...
3lcov --directory . --zerocounters
4make check
5rm `find * -name "test_*.gc??"` `find * -name "perf_*.gc??"`
6for n in `find * -name "*.gc??" | grep libs`
7do
8 cd `dirname $n`
9 mv `basename $n` ..
10 cd -
11done
12lcov --directory . --capture --output-file app.info
13mkdir -p doc/coverage
14genhtml -o doc/coverage app.info
diff --git a/contrib/scripts/debug b/contrib/scripts/debug
new file mode 100755
index 000000000..3de2c9a14
--- /dev/null
+++ b/contrib/scripts/debug
@@ -0,0 +1,37 @@
1#!/bin/bash
2# /proc/sys/kernel/core_pattern should be core.%p.%E
3
4COREPID=$1
5
6COREFILES=`ls -1 *core.$COREPID* 2>/dev/null | wc -l`
7COREFILE=`ls -1 *core.$COREPID* 2>/dev/null | head -n 1`
8
9if [ $COREFILES -gt 1 ]; then
10 echo "Multiple files, using $COREFILE"
11fi
12
13
14if [ $COREFILES -eq 0 ]; then
15 SERVICENAME=$1
16 COREFILES=`ls -1 core.*.*$SERVICENAME 2>/dev/null | wc -l`
17 COREFILE=`ls -1 core.*.*$SERVICENAME 2>/dev/null | head -n 1`
18
19 if [ $COREFILES -gt 1 ]; then
20 echo "Multiple files, using $COREFILE"
21 fi
22fi
23
24if [ $COREFILES -eq 0 ]; then
25 echo "Core file for $1 not found"
26 exit 1
27fi
28
29echo "Using $COREFILE"
30
31EXECPATH=${COREFILE#*!}
32EXECPATH=`echo $EXECPATH | sed -e 's/!/\//g'`
33echo $EXECPATH
34echo ""
35echo ""
36
37gdb --core $COREFILE /$EXECPATH
diff --git a/contrib/scripts/documentation/gnunet-doc.scm b/contrib/scripts/documentation/gnunet-doc.scm
new file mode 100644
index 000000000..077efacad
--- /dev/null
+++ b/contrib/scripts/documentation/gnunet-doc.scm
@@ -0,0 +1,182 @@
1;;; This file is part of GNUnet.
2;;; Copyright (C) 2016, 2017 GNUnet e.V.
3;;;
4;;; GNUnet is free software: you can redistribute it and/or modify it
5;;; under the terms of the GNU Affero General Public License as published
6;;; by the Free Software Foundation, either version 3 of the License, or
7;;; (at your option) any later version.
8;;;
9;;; GNUnet is distributed in the hope that it will be useful, but
10;;; WITHOUT ANY WARRANTY; without even the implied warranty of
11;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12;;; Affero General Public License for more details.
13;;;
14;;; You should have received a copy of the GNU Affero General Public License
15;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
16;;;
17
18(use-modules
19 (ice-9 popen)
20 (ice-9 match)
21 (ice-9 rdelim)
22 (guix packages)
23 (guix build-system gnu)
24 (guix gexp)
25 ((guix build utils) #:select (with-directory-excursion))
26 (guix git-download)
27 (guix utils) ; current-source-directory
28 (gnu packages)
29 (gnu packages aidc)
30 (gnu packages autotools)
31 (gnu packages backup)
32 (gnu packages base)
33 (gnu packages compression)
34 (gnu packages curl)
35 (gnu packages databases)
36 (gnu packages file)
37 (gnu packages gettext)
38 (gnu packages glib)
39 (gnu packages gnome)
40 (gnu packages gnunet)
41 (gnu packages gnupg)
42 (gnu packages gnuzilla)
43 (gnu packages groff)
44 (gnu packages gstreamer)
45 (gnu packages gtk)
46 (gnu packages guile)
47 (gnu packages graphviz)
48 (gnu packages image)
49 (gnu packages image-viewers)
50 (gnu packages libidn)
51 (gnu packages libunistring)
52 (gnu packages linux)
53 (gnu packages maths)
54 (gnu packages multiprecision)
55 (gnu packages perl)
56 (gnu packages pkg-config)
57 (gnu packages pulseaudio)
58 (gnu packages python)
59 (gnu packages tex)
60 (gnu packages texinfo)
61 (gnu packages tex)
62 (gnu packages tls)
63 (gnu packages video)
64 (gnu packages web)
65 (gnu packages xiph)
66 ;;(gnunet packages texlive) ;GNUnet module including texlive-2012 WIP
67 ((guix licenses) #:prefix license:))
68
69;;(define %source-dir (string-append (current-source-directory)
70;; "/../../../"))
71(define %source-dir (dirname (current-filename)))
72
73(define gnunet-doc
74 (let* ((revision "2")
75 (select? (delay (or (git-predicate
76 (string-append (current-source-directory)
77 "/../../../"))
78 source-file?))))
79 (package
80 (name "gnunet-doc")
81 (version (string-append "0.10.1-" revision "." "dev"))
82 (source
83 (local-file ;;"../../.."
84 ;;%source-dir
85 ;;(string-append (getcwd) "/../../../")
86 (string-append (getcwd)) ;drrty hack and this assumes one static position FIXME!
87 #:recursive? #t))
88 ;;#:select? (git-predicate %source-dir)))
89 ;;#:select? (force select?)))
90 (build-system gnu-build-system)
91 (inputs
92 `(("glpk" ,glpk)
93 ("gnurl" ,gnurl)
94 ("gstreamer" ,gstreamer)
95 ("gst-plugins-base" ,gst-plugins-base)
96 ("gnutls/dane" ,gnutls/dane)
97 ("libextractor" ,libextractor)
98 ("libgcrypt" ,libgcrypt)
99 ("libidn" ,libidn)
100 ("libmicrohttpd" ,libmicrohttpd)
101 ("libltdl" ,libltdl)
102 ("libunistring" ,libunistring)
103 ("openssl" ,openssl)
104 ("opus" ,opus)
105 ("pulseaudio" ,pulseaudio)
106 ("sqlite" ,sqlite)
107 ("postgresql" ,postgresql)
108 ("mysql" ,mariadb)
109 ("zlib" ,zlib)
110 ("perl" ,perl)
111 ("python-2" ,python-2) ; tests and gnunet-qr
112 ("jansson" ,jansson)
113 ("nss" ,nss)
114 ("glib" ,glib "bin")
115 ("gmp" ,gmp)
116 ("bluez" ,bluez) ; for optional bluetooth feature
117 ("glib" ,glib)
118 ;;("texlive-minimal" ,texlive-minimal) ; optional.
119 ("texlive" ,texlive) ;TODO: Stabilize Texlive-2012 package
120 ("libogg" ,libogg)))
121 (native-inputs
122 `(("pkg-config" ,pkg-config)
123 ("autoconf" ,autoconf)
124 ("automake" ,automake)
125 ("gnu-gettext" ,gnu-gettext)
126 ("graphviz" ,graphviz) ; dot
127 ("texinfo-5" ,texinfo-5) ; Debian stable
128 ("which" ,which)
129 ("libtool" ,libtool)))
130 (arguments
131 `(#:configure-flags
132 (list "--enable-documentation")
133 #:tests? #f ;Don't run tests
134 #:phases
135 (modify-phases %standard-phases
136 (add-after 'unpack 'autoconf
137 (lambda _
138 (substitute* "bootstrap"
139 (("contrib/pogen.sh") "sh contrib/pogen.sh"))
140 (for-each (lambda (f) (chmod f #o755))
141 (find-files "po" ""))
142 (zero? (system* "sh" "bootstrap"))))
143 (add-after 'build 'run-gendocs
144 (lambda _
145 (chdir "doc/documentation")
146 ;;(zero? (system* "make" "dev-build"))))
147 (zero? (system* "sh" "run-gendocs.sh"))))
148 ;; (zero? (system* "make" "pdf"))
149 ;; (zero? (system* "make" "html"))
150 ;; (zero? (system* "make" "info"))))
151 ;;(zero? (system* "make" "doc-all-give-me-the-noise"))))
152 (replace 'install
153 (lambda _
154 (zero? (system* "make" "doc-gendoc-install")))))))
155 ;;(lambda* (#:key outputs #:allow-other-keys)
156 ;; (let* ((out (assoc-ref outputs "out"))
157 ;; (doc (string-append out "/share/doc/gnunet")))
158 ;; (mkdir-p doc)
159 ;; (copy-recursively "images"
160 ;; (string-append doc
161 ;; "/images"))
162 ;; (mkdir-p (string-append doc "/gnunet"))
163 ;; (install-file "gnunet.pdf" doc)
164 ;; (install-file "gnunet.info" doc)
165 ;; (install-file "gnunet.log" doc) ;TODO: Move to 'dev' output?
166 ;; (copy-recursively "gnunet"
167 ;; (string-append doc
168 ;; "/gnunet"))
169 ;; (install-file "gnunet-c-tutorial.pdf" doc)
170 ;; (install-file "gnunet-c-tutorial.info" doc)
171 ;; (install-file "gnunet-c-tutorial.log" doc) ;TODO: Move to 'dev' output?
172 ;; (copy-recursively "gnunet-c-tutorial"
173 ;; (string-append doc
174 ;; "/gnunet-c-tutorial")))
175 ;; #t)))))
176 (synopsis "Documentation of GNUnet")
177 (description
178 "GNUnet documentation build")
179 (license (list license:fdl1.3+ license:gpl3+))
180 (home-page "https://gnunet.org/"))))
181
182gnunet-doc
diff --git a/contrib/scripts/find_typedefs.py b/contrib/scripts/find_typedefs.py
new file mode 100644
index 000000000..b344cee2b
--- /dev/null
+++ b/contrib/scripts/find_typedefs.py
@@ -0,0 +1,102 @@
1# XXX (F841): local variable 'li' is assigned to but never used
2
3from __future__ import print_function
4from __future__ import unicode_literals
5import os
6import re
7import sys
8
9
10debug = False
11
12
13def get_td_from_function_signature(line, file, num):
14 left_paren = line.find('(')
15 if left_paren > 0:
16 left_paren += 1
17 li = line[left_paren:]
18 right_paren = line.find(')')
19 if right_paren > 0 and right_paren > left_paren and line[right_paren:].find('(') >= 0:
20 fname = line[:right_paren]
21 fname = fname.lstrip(' ').lstrip('*').lstrip(' ').rstrip(' ')
22 if len(fname) > 0:
23 if debug:
24 print("from {0}:{1}".format(file, num))
25 print("-T {0}".format(fname))
26
27
28def get_td_from_simple_type(line, file, num):
29 line = line.rstrip(' ').rstrip('\t').rstrip(' ').rstrip('\t')
30 right_space = line.rfind(' ')
31 right_tab = line.rfind('\t')
32 sep = right_tab if right_tab > right_space else right_space
33 sep += 1
34 tname = line[sep:]
35 tname = tname.lstrip('*')
36 if len(tname) > 0:
37 if debug:
38 print("from {0}:{1}".format(file, num))
39 print("-T {0}".format(tname))
40
41
42def find_typedefs(file):
43 with open(file, 'rb') as f:
44 td = False
45 td_struct = False
46 td_level = 0
47 td_line = []
48 data = f.read()
49 for i, l in enumerate(data.splitlines(False)):
50 # Don't try to be too smart: only count lines that begin with 'typedef '
51 l = l.rstrip(' ').rstrip('\t')
52 if len(l) == 0:
53 continue
54 if not td:
55 if l[:8] != 'typedef ':
56 continue
57 else:
58 td = True
59 if l[8:].lstrip(' ').lstrip('\t')[:6] == 'struct':
60 td_struct = True
61 if td_struct:
62 leftcbrace = l.find('{')
63 if leftcbrace >= 0:
64 if td_level == 0:
65 td_line.append(l[:leftcbrace])
66 l = l[leftcbrace + 1:]
67 td_level += 1
68 rightcbrace = l.rfind('}')
69 if rightcbrace >= 0:
70 td_level -= 1
71 if td_level == 0:
72 td_line.append(l[rightcbrace + 1:])
73 else:
74 td_line.append(l)
75 if len(l) > 0 and l[-1] == ';' and(not td_struct or td_level == 0):
76 td_line = ' '.join(td_line)
77 td_line = td_line[:-1]
78 if len(td_line) > 0:
79 if td_line[-1] == ')':
80 get_td_from_function_signature(td_line, file, i)
81 else:
82 get_td_from_simple_type(td_line, file, i)
83 td_line = []
84 td = False
85 td_struct = False
86 td_level = 0
87
88
89def scan_dir(d):
90 for dirpath, dirs, files in os.walk(d):
91 for f in files:
92 if re.match(r'(?!lt_).+\.(c|cc|h)$', f):
93 file = os.path.join(dirpath, f)
94 find_typedefs(file)
95
96
97if __name__ == '__main__':
98 if len(sys.argv[1:]) == 0:
99 arg = os.getcwd()
100 else:
101 arg = sys.argv[1]
102 scan_dir(arg)
diff --git a/contrib/scripts/gdb-iterate-dll.py b/contrib/scripts/gdb-iterate-dll.py
new file mode 100644
index 000000000..388ef6e11
--- /dev/null
+++ b/contrib/scripts/gdb-iterate-dll.py
@@ -0,0 +1,43 @@
1from __future__ import print_function
2from __future__ import unicode_literals
3from builtins import str
4from gdb import *
5
6
7def search_dll(head, field, match, pfield):
8 """
9 Search in a DLL by iterates over it.
10
11 head: name of the symbol denoting the head of the DLL
12 field: the field that should be search for match
13 match: the mathing value for field
14 pfield: the field whose value is to be printed for matched elements; None to
15 print all fields of the matched elemented
16 """
17
18 (symbol, _) = lookup_symbol(head)
19 if symbol is None:
20 print("Can't find symbol: " + head)
21 return
22 symbol_val = symbol.value()
23 while symbol_val:
24 symbol_val_def = symbol_val.dereference()
25 field_val = symbol_val_def[field]
26 if field_val.type.code == gdb.TYPE_CODE_INT:
27 val = int(field_val)
28 res = (match == val)
29 elif (field_val.type.code == gdb.TYPE_CODE_STRING) or (field_val.type.code == gdb.TYPE_CODE_ARRAY):
30 val = str(field_val)
31 res = (match == val)
32 elif (field_val.type.code == gdb.TYPE_CODE_TYPEDEF):
33 val = str(field_val)
34 res = match in val
35 else:
36 continue
37
38 if res:
39 if pfield is None:
40 print(symbol_val_def)
41 else:
42 print(symbol_val_def[pfield])
43 symbol_val = symbol_val_def["next"]
diff --git a/contrib/scripts/generate-monkey-db.sh b/contrib/scripts/generate-monkey-db.sh
new file mode 100755
index 000000000..2afe55501
--- /dev/null
+++ b/contrib/scripts/generate-monkey-db.sh
@@ -0,0 +1,17 @@
1#!/bin/sh
2
3BASEPATH="$(dirname $0)"
4OLDDIR="${pwd}"
5GN_HOME="/usr/local/bin"
6
7export CC="cparser"
8export CFLAGS="-m32 --seaspider"
9
10cd $BASEPATH/.. && ./configure --prefix=$GN_HOME --with-extractor=$GN_HOME --with-microhttpd=$GN_HOME --with-libgcrypt=$GN_HOME && make && seaspider
11if test "$?" -ne 0
12then
13 echo "FAIL: building GNUnet"
14 exit 1
15fi
16
17cd $OLDDIR
diff --git a/contrib/scripts/gnunet-bugreport b/contrib/scripts/gnunet-bugreport
new file mode 100755
index 000000000..f17cb7636
--- /dev/null
+++ b/contrib/scripts/gnunet-bugreport
@@ -0,0 +1,252 @@
1#!/bin/sh
2
3TEST=`type type|grep not`
4if test -n "$TEST"; then
5 WHICH=which
6else
7 WHICH=type
8fi
9
10echo "Please submit the following information with your bug report: "
11echo "--------------------------------------------------------------"
12OS=`uname -s 2>/dev/null`
13echo "OS : $OS"
14REL=`uname -r 2>/dev/null`
15echo "OS RELEASE : $REL"
16HW=`uname -m 2>/dev/null`
17echo "HARDWARE : $HW"
18
19TEST=`$WHICH gcc 2>/dev/null`
20if test -n "$TEST"; then
21 VERS=`gcc --version 2>/dev/null | head -n 1`
22 echo "gcc : $VERS"
23else
24 echo "gcc : Not Found";
25fi
26
27TEST=`$WHICH gmake 2>/dev/null`
28if test -n "$TEST" ; then
29 gmake --version 2>/dev/null |\
30 awk -F, '{print $1}' |\
31 awk '/GNU Make/{print "GNU gmake :",$NF}'
32else
33 TEST=`make --version 2>/dev/null`
34 if test -n "$TEST"; then
35 make --version 2>/dev/null |\
36 awk -F, '{print $1}' |\
37 awk '/GNU Make/{print "make :",$NF}'
38 else
39 echo "make : Not Found"
40 fi
41fi
42
43TEST=`$WHICH autoconf 2>/dev/null`
44if test -n "$TEST"; then
45 autoconf --version |\
46 head -n 1 |\
47 awk '{\
48 if (length($4) == 0) {\
49 print "autoconf : "$3\
50 } else {\
51 print "autoconf : "$4\
52 }}'
53else
54 echo "autoconf : Not Found"
55fi
56
57TEST=`$WHICH automake 2>/dev/null`
58if test -n "$TEST"; then
59 automake --version 2>/dev/null |\
60 head -n 1 |\
61 awk '{print "automake : "$4}'
62else
63 echo "automake : Not Found"
64fi
65
66TEST=`$WHICH libtool 2>/dev/null`
67if test -n "$TEST"; then
68 libtool --version 2>/dev/null |\
69 head -n 1 |\
70 awk '{print "libtool : "$4}'
71else
72 echo "libtool : Not Found"
73fi
74
75TEST=`$WHICH extract 2>/dev/null`
76if test -n "$TEST"; then
77 extract -v 2>/dev/null |\
78 head -n 1 |\
79 awk '{print "libextractor : "$2}'
80else
81 echo "libextractor : Not Found"
82fi
83
84if test -x gnunetd; then
85 gnunetd -v | sed -e "s/v//" 2>/dev/null |\
86 awk '{print "GNUnet 0.8 : "$2 (may conflict!)}'
87else
88 echo "GNUnet 0.8 : Not Found (good)"
89fi
90
91TEST=`$WHICH gnunet-arm 2>/dev/null`
92if test -n "$TEST"; then
93 gnunet-arm -v | sed -e "s/v//" 2>/dev/null |\
94 awk '{print "GNUnet 0.9 : "$2}'
95else
96 echo "GNUnet 0.9 : Not Found"
97fi
98
99TEST=`$WHICH libgcrypt-config 2> /dev/null`
100if test -n "$TEST"; then
101 libgcrypt-config --version 2> /dev/null | \
102 awk '{print "libgcrypt : "$1}'
103else
104 echo "libgcrypt : Not Found"
105fi
106
107TEST=`$WHICH mysql_config 2> /dev/null`
108if test -n "$TEST"; then
109 mysql_config --version 2> /dev/null | \
110 awk '{print "mysql : "$1}'
111else
112 echo "mysql : Not Found"
113fi
114
115TEST=`$WHICH pkg-config 2> /dev/null`
116if test -n "$TEST"; then
117 pkg-config --version 2> /dev/null | \
118 awk '{print "pkg-config : "$1}'
119else
120 echo "pkg-config : Not Found"
121fi
122
123TEST=`$WHICH pkg-config 2> /dev/null`
124if test -n "$TEST"; then
125 pkg-config --modversion glib-2.0 2> /dev/null | \
126 awk '{print "glib2 : "$1}'
127else
128 echo "glib2 : Not Found"
129fi
130
131TEST=`$WHICH pkg-config 2> /dev/null`
132if test -n "$TEST"; then
133 pkg-config --modversion gtk+-2.0 2> /dev/null | \
134 awk '{print "gtk2+ : "$1}'
135else
136 echo "gtk2+ : Not Found"
137fi
138
139TEST=`$WHICH dpkg 2> /dev/null`
140if test -n "$TEST"; then
141 LINES=`dpkg -s libgmp-dev | grep Version | wc -l 2> /dev/null`
142 if test "$LINES" = "1"
143 then
144 VERSION=`dpkg -s libgmp-dev | grep Version | awk '{print $2}'`
145 echo "GMP : libgmp-dev-$VERSION.deb"
146 else
147 echo "GMP : dpkg: libgmp-dev not installed"
148 fi
149else
150 TEST=`$WHICH rpm 2> /dev/null`
151 if test -n "$TEST"; then
152 rpm -q gmp | sed -e "s/gmp-//" 2> /dev/null | \
153 awk '{print "GMP : "$1.rpm}'
154 else
155 echo "GMP : Test not available"
156 fi
157fi
158
159TEST=`$WHICH dpkg 2> /dev/null`
160if test -n "$TEST"; then
161 LINES=`dpkg -s libunistring-dev | grep Version | wc -l`
162 if test "$LINES" = "1"
163 then
164 VERSION=`dpkg -s libunistring-dev | grep Version | awk '{print $2}'`
165 echo "libunistring : libunistring3-dev-$VERSION.deb"
166 else
167 echo "libunistring : dpkg: libunistring3-dev not installed"
168 fi
169else
170 TEST=`$WHICH rpm 2> /dev/null`
171 if test -n "$TEST"; then
172 rpm -q unistring | sed -e "s/unistring-//" 2> /dev/null | \
173 awk '{print "libunistring : "$1.rpm}'
174 else
175 echo "libunistring : Test not available"
176 fi
177fi
178
179TEST=`$WHICH gettext 2> /dev/null`
180if test -n "$TEST"; then
181 gettext --version | head -n1 2> /dev/null | \
182 awk '{print "GNU gettext : "$4}'
183else
184 echo "GNU gettext : Not found"
185fi
186
187
188TEST=`$WHICH curl-config 2> /dev/null`
189if test -n "$TEST"; then
190 curl-config --version | head -n1 2> /dev/null | \
191 awk '{print "libcurl : "$2}'
192else
193 echo "libcurl : Not found"
194fi
195
196TEST=`$WHICH gnurl-config 2> /dev/null`
197if test -n "$TEST"; then
198 gnurl-config --version | head -n1 2> /dev/null | \
199 awk '{print "libgnurl : "$2}'
200else
201 echo "libgnurl : Not found"
202fi
203
204echo -n "libmicrohttpd : "
205TMPFILE=`mktemp /tmp/mhd-version-testXXXXXX`
206cat - >$TMPFILE.c <<EOF
207#include <microhttpd.h>
208#include <stdio.h>
209int main()
210{
211 fprintf (stdout, "%X\n", MHD_VERSION);
212 return 0;
213}
214EOF
215
216gcc -o $TMPFILE $TMPFILE.c 2> /dev/null && $TMPFILE || echo "Not found"
217rm -f $TMPFILE $TMPFILE.bin
218
219
220echo -n "GNU GLPK : "
221TMPFILE=`mktemp /tmp/glpk-version-testXXXXXX`
222cat - >$TMPFILE.c <<EOF
223#include <glpk.h>
224#include <stdio.h>
225int main()
226{
227 fprintf (stdout, "%u.%u\n", GLP_MAJOR_VERSION, GLP_MINOR_VERSION);
228 return 0;
229}
230EOF
231
232gcc -o $TMPFILE $TMPFILE.c 2> /dev/null && $TMPFILE || echo "Not found"
233rm -f $TMPFILE $TMPFILE.bin
234
235
236echo -n "GnuTLS : "
237TMPFILE=`mktemp /tmp/gnutls-version-testXXXXXX`
238cat - >$TMPFILE.c <<EOF
239#include <gnutls/gnutls.h>
240#include <stdio.h>
241int main()
242{
243 fprintf (stdout, "%s\n", GNUTLS_VERSION);
244 return 0;
245}
246EOF
247
248gcc -o $TMPFILE $TMPFILE.c 2> /dev/null && $TMPFILE || echo "Not found"
249rm -f $TMPFILE $TMPFILE.bin
250
251
252echo "--------------------------------------------------------------"
diff --git a/contrib/scripts/gnunet-chk.py.in b/contrib/scripts/gnunet-chk.py.in
new file mode 100755
index 000000000..cabaef6c4
--- /dev/null
+++ b/contrib/scripts/gnunet-chk.py.in
@@ -0,0 +1,381 @@
1#!@PYTHON@
2# This file is part of GNUnet.
3# (C) 2013, 2018 Christian Grothoff (and other contributing authors)
4#
5# GNUnet is free software: you can redistribute it and/or modify it
6# under the terms of the GNU Affero General Public License as published
7# by the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# GNUnet is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Affero General Public License for more details.
14#
15# You should have received a copy of the GNU Affero General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17#
18# File: gnunet-chk.py
19# Brief: Computes GNUNET style Content Hash Key for a given file
20# Author: Sree Harsha Totakura
21
22from hashlib import sha512
23import logging
24import os
25import getopt
26import sys
27from Crypto.Cipher import AES
28from functools import reduce
29
30
31# Defaults
32DBLOCK_SIZE = (32 * 1024) # Data block size
33
34# Pick a multiple of 2 here to achive 8-byte alignment! We also
35# probably want DBlocks to have (roughly) the same size as IBlocks.
36# With SHA-512, the optimal value is 32768 byte / 128 byte = 256 (128
37# byte = 2 * 512 bits). DO NOT CHANGE!
38CHK_PER_INODE = 256
39
40CHK_HASH_SIZE = 64 # SHA-512 hash = 512 bits = 64 bytes
41
42CHK_QUERY_SIZE = CHK_HASH_SIZE # Again a SHA-512 hash
43
44GNUNET_FS_URI_PREFIX = "gnunet://fs/" # FS CHK URI prefix
45
46GNUNET_FS_URI_CHK_INFIX = "chk/" # FS CHK URI infix
47
48
49def encode_data_to_string(data):
50 """Returns an ASCII encoding of the given data block like
51 GNUNET_STRINGS_data_to_string() function.
52
53 data: A bytearray representing the block of data which has to be encoded
54 """
55 echart = "0123456789ABCDEFGHIJKLMNOPQRSTUV"
56 assert (None != data)
57 assert (bytearray == type(data))
58 size = len(data)
59 assert (0 != size)
60 vbit = 0
61 wpos = 0
62 rpos = 0
63 bits = 0
64 out = ""
65 while (rpos < size) or (vbit > 0):
66 if (rpos < size) and (vbit < 5):
67 bits = (bits << 8) | data[rpos] # eat 8 more bits
68 rpos += 1
69 vbit += 8
70 if (vbit < 5):
71 bits <<= (5 - vbit) # zero-padding
72 assert (vbit == ((size * 8) % 5))
73 vbit = 5
74 out += echart[(bits >> (vbit - 5)) & 31]
75 wpos += 1
76 vbit -= 5
77 assert (0 == vbit)
78 return out
79
80
81def sha512_hash(data):
82 """ Returns the sha512 hash of the given data.
83
84 data: string to hash
85 """
86 hash_obj = sha512()
87 hash_obj.update(data)
88 return hash_obj.digest()
89
90
91class AESKey:
92 """Class for AES Keys. Contains the main key and the initialization
93 vector. """
94
95 key = None # The actual AES key
96 iv = None # The initialization vector
97 cipher = None # The cipher object
98 KEY_SIZE = 32 # AES 256-bit key = 32 bytes
99 IV_SIZE = AES.block_size # Initialization vector size (= AES block size)
100
101 def __init__(self, passphrase):
102 """Creates a new AES key.
103
104 passphrase: string containing the passphrase to get the AES key and
105 initialization vector
106 """
107 passphrase = bytearray(passphrase)
108 self.key = bytearray(self.KEY_SIZE)
109 self.iv = bytearray(self.IV_SIZE)
110 if (len(passphrase) > self.KEY_SIZE):
111 self.key = passphrase[:self.KEY_SIZE]
112 passphrase = passphrase[self.KEY_SIZE:]
113 if (len(passphrase) > self.IV_SIZE):
114 self.iv = passphrase[:self.IV_SIZE]
115 else:
116 self.iv[0:len(passphrase)] = passphrase
117 else:
118 self.key[0:len(passphrase)] = passphrase
119 self.key = str(self.key)
120 self.iv = str(self.iv)
121 assert (len(self.key) == self.KEY_SIZE)
122 assert (len(self.iv) == self.IV_SIZE)
123
124
125def setup_aes_cipher_(aes_key):
126 """Initializes the AES object with settings similar to those in GNUnet.
127
128 aes_key: the AESKey object
129 Returns the newly initialized AES object
130 """
131 return AES.new(aes_key.key, AES.MODE_CFB, aes_key.iv, segment_size=128)
132
133
134def aes_pad_(data):
135 """Adds padding to the data such that the size of the data is a multiple of
136 16 bytes
137
138 data: the data string
139 Returns a tuple:(pad_len, data). pad_len denotes the number of bytes added
140 as padding; data is the new data string with padded bytes at the end
141 """
142 pad_len = len(data) % 16
143 if (0 != pad_len):
144 pad_len = 16 - pad_len
145 pad_bytes = bytearray(15)
146 data += str(pad_bytes[:pad_len])
147 return (pad_len, data)
148
149
150def aes_encrypt(aes_key, data):
151 """Encrypts the given data using AES.
152
153 aes_key: the AESKey object to use for AES encryption
154 data: the data string to encrypt
155 """
156 (pad_len, data) = aes_pad_(data)
157 cipher = setup_aes_cipher_(aes_key)
158 enc_data = cipher.encrypt(data)
159 if (0 != pad_len):
160 enc_data = enc_data[:-pad_len]
161 return enc_data
162
163
164def aes_decrypt(aes_key, data):
165 """Decrypts the given data using AES
166
167 aes_key: the AESKey object to use for AES decryption
168 data: the data string to decrypt
169 """
170 (pad_len, data) = aes_pad_(data)
171 cipher = setup_aes_cipher_(aes_key)
172 ptext = cipher.decrypt(data)
173 if (0 != pad_len):
174 ptext = ptext[:-pad_len]
175 return ptext
176
177
178class Chk:
179 """Class for the content hash key."""
180 key = None
181 query = None
182 fsize = None
183
184 def __init__(self, key, query):
185 assert (len(key) == CHK_HASH_SIZE)
186 assert (len(query) == CHK_QUERY_SIZE)
187 self.key = key
188 self.query = query
189
190 def setSize(self, size):
191 self.fsize = size
192
193 def uri(self):
194 sizestr = repr(self.fsize)
195 if isinstance(self.fsize, int):
196 sizestr = sizestr[:-1]
197 return GNUNET_FS_URI_PREFIX + GNUNET_FS_URI_CHK_INFIX + \
198 encode_data_to_string(bytearray(self.key)) + "." + \
199 encode_data_to_string(bytearray(self.query)) + "." + \
200 sizestr
201
202
203def compute_depth_(size):
204 """Computes the depth of the hash tree.
205
206 size: the size of the file whose tree's depth has to be computed
207 Returns the depth of the tree. Always > 0.
208 """
209 depth = 1
210 fl = DBLOCK_SIZE
211 while (fl < size):
212 depth += 1
213 if ((fl * CHK_PER_INODE) < fl):
214 return depth
215 fl = fl * CHK_PER_INODE
216 return depth
217
218
219def compute_tree_size_(depth):
220 """Calculate how many bytes of payload a block tree of the given depth MAY
221 correspond to at most (this function ignores the fact that some blocks will
222 only be present partially due to the total file size cutting some blocks
223 off at the end).
224
225 depth: depth of the block. depth==0 is a DBLOCK.
226 Returns the number of bytes of payload a subtree of this depth may
227 correspond to.
228 """
229 rsize = DBLOCK_SIZE
230 for cnt in range(0, depth):
231 rsize *= CHK_PER_INODE
232 return rsize
233
234
235def compute_chk_offset_(depth, end_offset):
236 """Compute the offset of the CHK for the current block in the IBlock
237 above
238
239 depth: depth of the IBlock in the tree (aka overall number of tree levels
240 minus depth); 0 == DBLOCK
241 end_offset: current offset in the overall file, at the *beginning* of the
242 block for DBLOCK (depth == 0), otherwise at the *end* of the
243 block (exclusive)
244 Returns the offset in the list of CHKs in the above IBlock
245 """
246 bds = compute_tree_size_(depth)
247 if (depth > 0):
248 end_offset -= 1
249 ret = end_offset / bds
250 return ret % CHK_PER_INODE
251
252
253def compute_iblock_size_(depth, offset):
254 """Compute the size of the current IBLOCK. The encoder is triggering the
255 calculation of the size of an IBLOCK at the *end* (hence end_offset) of its
256 construction. The IBLOCK maybe a full or a partial IBLOCK, and this
257 function is to calculate how long it should be.
258
259 depth: depth of the IBlock in the tree, 0 would be a DBLOCK, must be > 0
260 (this function is for IBLOCKs only!)
261 offset: current offset in the payload (!) of the overall file, must be > 0
262 (since this function is called at the end of a block).
263 Returns the number of elements to be in the corresponding IBlock
264 """
265 assert (depth > 0)
266 assert (offset > 0)
267 bds = compute_tree_size_(depth)
268 mod = offset % bds
269 if mod is 0:
270 ret = CHK_PER_INODE
271 else:
272 bds /= CHK_PER_INODE
273 ret = mod / bds
274 if (mod % bds) is not 0:
275 ret += 1
276 return ret
277
278
279def compute_rootchk(readin, size):
280 """Returns the content hash key after generating the hash tree for the given
281 input stream.
282
283 readin: the stream where to read data from
284 size: the size of data to be read
285 """
286 depth = compute_depth_(size)
287 current_depth = 0
288 chks = [None] * (depth * CHK_PER_INODE) # list buffer
289 read_offset = 0
290 logging.debug("Begining to calculate tree hash with depth: " + repr(depth))
291 while True:
292 if (depth == current_depth):
293 off = CHK_PER_INODE * (depth - 1)
294 assert (chks[off] is not None)
295 logging.debug("Encoding done, reading CHK `" + chks[off].query + \
296 "' from " + repr(off) + "\n")
297 uri_chk = chks[off]
298 assert (size == read_offset)
299 uri_chk.setSize(size)
300 return uri_chk
301 if (0 == current_depth):
302 pt_size = min(DBLOCK_SIZE, size - read_offset)
303 try:
304 pt_block = readin.read(pt_size)
305 except IOError:
306 logging.warning("Error reading input file stream")
307 return None
308 else:
309 pt_elements = compute_iblock_size_(current_depth, read_offset)
310 pt_block = ""
311 pt_block = \
312 reduce((lambda ba, chk:
313 ba + (chk.key + chk.query)),
314 chks[(current_depth - 1) * CHK_PER_INODE:][:pt_elements],
315 pt_block)
316 pt_size = pt_elements * (CHK_HASH_SIZE + CHK_QUERY_SIZE)
317 assert (len(pt_block) == pt_size)
318 assert (pt_size <= DBLOCK_SIZE)
319 off = compute_chk_offset_(current_depth, read_offset)
320 logging.debug("Encoding data at offset " + repr(read_offset) + \
321 " and depth " + repr(current_depth) + " with block " \
322 "size " + repr(pt_size) + " and target CHK offset " + \
323 repr(current_depth * CHK_PER_INODE))
324 pt_hash = sha512_hash(pt_block)
325 pt_aes_key = AESKey(pt_hash)
326 pt_enc = aes_encrypt(pt_aes_key, pt_block)
327 pt_enc_hash = sha512_hash(pt_enc)
328 chk = Chk(pt_hash, pt_enc_hash)
329 chks[(current_depth * CHK_PER_INODE) + off] = chk
330 if (0 == current_depth):
331 read_offset += pt_size
332 if (read_offset == size) or \
333 (0 == (read_offset % (CHK_PER_INODE * DBLOCK_SIZE))):
334 current_depth += 1
335 else:
336 if (CHK_PER_INODE == off) or (read_offset == size):
337 current_depth += 1
338 else:
339 current_depth = 0
340
341
342def chkuri_from_path(path):
343 """Returns the CHK URI of the file at the given path.
344
345 path: the path of the file whose CHK has to be calculated
346 """
347 size = os.path.getsize(path)
348 readin = open(path, "rb")
349 chk = compute_rootchk(readin, size)
350 readin.close()
351 return chk.uri()
352
353
354def usage():
355 """Prints help about using this script."""
356 print("""
357Usage: gnunet-chk.py [options] file
358Prints the Content Hash Key of given file in GNUNET-style URI.
359
360Options:
361 -h, --help : prints this message
362""")
363
364
365if '__main__' == __name__:
366 try:
367 opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
368 except getopt.GetoptError as err:
369 print(err)
370 print("Exception occured")
371 usage()
372 sys.exit(2)
373 for option, value in opts:
374 if option in("-h", "--help"):
375 usage()
376 sys.exit(0)
377 if len(args) != 1:
378 print("Incorrect number of arguments passed")
379 usage()
380 sys.exit(1)
381 print(chkuri_from_path(args[0]))
diff --git a/contrib/scripts/gnunet-logread/gnunet-logread b/contrib/scripts/gnunet-logread/gnunet-logread
new file mode 100755
index 000000000..9b1c65401
--- /dev/null
+++ b/contrib/scripts/gnunet-logread/gnunet-logread
@@ -0,0 +1,198 @@
1#!@PERL@
2# helper tool to make gnunet logs more readable
3# try 'gnunet-logread -h' for usage
4
5use strict;
6use warnings;
7my $DEFAULT_SOCKET = '/tmp/gnunet-logread-ipc.sock';
8
9print STDERR <<X if -t STDIN and $#ARGV == -1;
10*** For a usage message, try '$0 -h'.
11*** For documentation, try 'perldoc $0'.
12*** Listening for GNUNET_log events on STDIN. Type CTRL-D to terminate.
13
14X
15
16use Getopt::Std;
17my (%opts, $name, $ipc, $msg_level, $msg_regex);
18getopts ('i:x:n:s:L:m:fhq', \%opts);
19
20use Pod::Usage qw( pod2usage );
21die pod2usage if $opts{h};
22
23use POSIX qw(mkfifo);
24
25use Term::ANSIColor qw(:constants :pushpop);
26$Term::ANSIColor::AUTOLOCAL = 1;
27
28my %levels = ( NONE => 0, ERROR => 1, WARNING => 2, INFO => 4, DEBUG => 8 );
29
30# Message type numbers to names
31my %msgtypes;
32my $prefix = $ENV{GNUNET_PREFIX} || '/usr';
33my $filename = "$prefix/include/gnunet/gnunet_protocols.h";
34$ipc = $opts{s} || $DEFAULT_SOCKET;
35
36if (open HEADER, $filename)
37{
38 while (<HEADER>)
39 {
40 $msgtypes{$2} = $1 if /^\s*#define\s+GNUNET_MESSAGE_TYPE_(\w+)\s+(\d+)/i;
41 }
42 close HEADER;
43} else {
44 warn <<X;
45Could not read $filename for message codes:
46 $!.
47Please provide a \$GNUNET_PREFIX environment variable to replace "/usr".
48Try also '$0 -h' for help.
49
50X
51}
52
53die "You can't read and write the socket at the same time"
54 if exists $opts{f} and exists $opts{n};
55
56if ((exists $opts{n} or exists $opts{f}) and not -r $ipc) {
57 undef $!;
58 die "Could not mkfifo $ipc: $!" unless mkfifo $ipc, 0600;
59 system('chgrp', 'gnunet', $ipc);
60 die "Could not chgrp $ipc to 'gnunet': $!" if $!;
61 chmod 0660, $ipc;
62 die "Could not chmod $ipc to allow gnunet group writes: $!" if $!;
63}
64
65if (exists $opts{n}) {
66 $name = $opts{n};
67 $msg_level = $opts{L} && exists $levels{$opts{L}} ? $levels{$opts{L}} : 0;
68 $msg_regex = $opts{m};
69 print STDERR "RE: /$msg_regex/\n" if defined $msg_regex;
70 open O, '>', $ipc or die "Cannot write to $ipc: $!";
71}
72
73if (exists $opts{f}) {
74 open(I, $ipc) or die "Cannot read from $ipc: $!";
75 &perform while <I>;
76 close I;
77} else {
78 &perform while <>;
79}
80fileno O and close O;
81exit;
82
83
84sub perform {
85 if (fileno O) {
86 my ($time, $type, $size, $from, $to, $level, $msg);
87 if (($time, $type, $size, $from, $to) =
88 /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\ util-client-.*\b
89 (?: Received | Transmitting )\ message \b.*?\b
90 type \s+ (\d+) \b.*?\b
91 size \s+ (\d+) \b.*?\b
92 (?: from \s+ (\S+)
93 | to \s+ (\S+) ) /x)
94 {
95 $from ||= $name;
96 $to ||= $name;
97 my ($time, $type, $size, $from, $to) = ($1, $2, $3,
98 $4 || $name, $5 || $name);
99 my $msg = exists $msgtypes{$type} ? $msgtypes{$type} : $type;
100 my $ofh = select O;
101 print O "$time\t$from -> $to\t$msg ($size)\n";
102 $| = 1;
103 select $ofh;
104 }
105 if (($time, $level, $msg) =
106 /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)
107 \s+\S+\s+(\S+)\s+(.+)/x
108 and (exists $levels{$level}
109 && $levels{$level} <= $msg_level
110 && (!defined $msg_regex || $msg =~ /$msg_regex/i)))
111 {
112 print O "$time\t$name\t$level: $msg\n";
113 }
114 }
115 return if $opts{x} and /$opts{x}/io;
116 return if $opts{i} and not /$opts{i}/io;
117
118 # Timestamp (e.g. Nov 01 19:36:11-384136)
119 s/^([A-Z][a-z]{2} .[0-9] [0-9:]{8}(?:-[0-9]{6})?)/YELLOW $1/e;
120
121 # Log levels
122 s/\b(ERROR )\b/RED $1/ex;
123 s/\b(WARNING)\b/YELLOW $1/ex;
124 s/\b(INFO )\b/GREEN $1/ex;
125 s/\b(DEBUG )\b/BRIGHT_BLACK $1/ex;
126
127 # Service names
128 # TODO: might read the list from $GNUNET_PREFIX/libexec/gnunet/
129 s/\b(multicast|psyc|psycstore|social)\b/BLUE $1/gex;
130
131 # Add message type names
132 s/(\s+type\s+)(\d+)/
133 $1 . BRIGHT_CYAN (exists $msgtypes{$2} ? $msgtypes{$2} : 'UNKNOWN') .
134 CYAN " ($2)"/gei;
135
136 # logread-ipc output
137 s/(\s+)([A-Z_]+)( \(\d+\))$/$1 . BRIGHT_CYAN $2 . CYAN $3/e;
138
139 print;
140}
141
142__END__
143
144=pod
145
146=head1 NAME
147
148gnunet-logread - a GNUnet log analyzer, colorizer and aggregator
149
150=head1 SYNOPSIS
151
152 <gnunet-service> |& $0 [<options>]
153 or
154 $0 [<options>] [<logfile>]
155
156 Options:
157 -f Follow input from IPC FIFO socket.
158
159 Regular screen output options:
160 -i <regex> Include only messages that match <regex>.
161 -x <regex> Exclude all messages that match <regex>.
162 -q Quiet: Do not show usage advice to new users.
163
164 Options to forward messages to the IPC FIFO socket:
165 -n <component_name> Name of the component we are forwarding messages for.
166 -s </path/to/ipc.sock> Default = $DEFAULT_SOCKET
167 -L <LOGLEVEL> Minimum level of messages to forward:
168 Log levels: NONE, ERROR, WARNING, INFO, DEBUG.
169 -m <regex> Only forward messages matching a regular expression.
170
171 See 'perldoc gnunet-logread' for a longer explanation.
172
173=head1 MOTIVATION
174
175GNUnet debug logs are a tedious read, but given a complex system that we
176cannot run all parts of in a debugger all the time, some gathering and
177structuring of events and message passing is useful.
178
179At first, this tool simply makes logs easier to read. Both if viewed in
180real-time or taken from disk. Then it also allows to extract all message
181passing events from it and forward them to a special process that aggregates
182all message passing events and therefore helps you make sense of all the
183inter-process communication (IPC) happening between the various pieces of
184the GNUnet system beast.
185
186That master process is simply an extra gnunet-logread that you run in a
187separate window and adorn it with the '-f' flag. The submitting processes
188instead need to be given a '-n' flag. That is because from the GNUnet logs
189it isn't clear which process events belong to. For example you may be
190having events taking place in the 'util' subsystem of gnunet-psyc-service
191just as much as in the 'util' subsystem of gnunet-multicast-service. In
192order to make sense of them it is necessary to manually add that info. This
193could be remedied by extending the semantics of the GNUNET_log facility
194instead, but that is still subject to further consideration.
195
196=head1 AUTHORS
197
198tg & lynX
diff --git a/contrib/scripts/gnunet-logread/gnunet-logread-ipc b/contrib/scripts/gnunet-logread/gnunet-logread-ipc
new file mode 100755
index 000000000..72f9f47df
--- /dev/null
+++ b/contrib/scripts/gnunet-logread/gnunet-logread-ipc
@@ -0,0 +1,10 @@
1#!/bin/sh
2#
3# Usage: gnunet-logread-ipc | gnunet-logread
4#
5# ... obsoleted by gnunet-logread's new -f option that does the same thing
6
7# FIXME: Replace /tmp with our use of $TMPDIR and similar.
8ipc=${1:-/tmp/gnunet-logread-ipc.sock}
9test -e "$ipc" || mkfifo "$ipc"
10cat "$ipc"
diff --git a/contrib/scripts/gnunet-logread/gnunet-logread-ipc-sdedit b/contrib/scripts/gnunet-logread/gnunet-logread-ipc-sdedit
new file mode 100755
index 000000000..f8b7dc735
--- /dev/null
+++ b/contrib/scripts/gnunet-logread/gnunet-logread-ipc-sdedit
@@ -0,0 +1,60 @@
1#!@PERL@
2
3# 1. Start sdedit and enable 'RT diagram server' in 'Global preferences'.
4#
5# 2. Start this tool (see defaults below):
6# gnunet-logread-ipc-sdedit -n buffer-name -i /path/to/ipc.sock -h <sdedit-host> -p <sdedit-port>
7#
8# 3. Start a gnunet-logread instance for each component with the -n <component_name> option
9
10use strict;
11use warnings;
12
13use Getopt::Std;
14use IO::Socket::INET;
15use POSIX qw(mkfifo);
16
17my %opts;
18getopts ('i:n:h:p:', \%opts);
19
20my $ipc = $opts{i} || '/tmp/gnunet-logread-ipc.sock';
21my $name = $opts{n} || 'gnunet';
22my $host = $opts{h} || 'localhost';
23my $port = $opts{p} || 16001;
24my %svcs = map { $_ => 1 } @ARGV;
25
26my $sdedit = IO::Socket::INET->new(PeerAddr => $host,
27 PeerPort => $port,
28 Proto => 'tcp')
29 or die "Cannot connect to $host:$port: $!\n";
30
31print $sdedit "$name\n";
32print $sdedit "_t:time[e]\n";
33print $sdedit "$_:$_\[ap\] \"$_\"\n" for @ARGV;
34print $sdedit "_e:ext[e]\n";
35print $sdedit "\n";
36
37mkfifo $ipc, 0600 or die "$ipc: $!\n" unless -e $ipc;
38open IPC, '<', $ipc or die "$ipc: $!\n";
39$| = 1;
40while (<IPC>)
41{
42 print;
43 my ($time, $from, $to, $msg, $svc);
44 if (my ($time, $from, $to, $msg) =
45 /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\s+
46 (\S+)\s+ -> \s+(\S+)\s+ (\S+\s+ \(\d+\))/x)
47 {
48 $from = '_e' unless exists $svcs{$from};
49 $to = '_e' unless exists $svcs{$to};
50 print $sdedit "*0 _t\n$time\n*0\n", "$from:$to.$msg\n"
51 }
52 elsif (($time, $svc, $msg) =
53 /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\s+
54 (\S+)\s+(.+)/x)
55 {
56 print $sdedit "*0 _t\n$time\n*0\n", "*0 $svc\n$msg\n*0\n"
57 }
58}
59
60close IPC;
diff --git a/contrib/scripts/gnunet-suidfix b/contrib/scripts/gnunet-suidfix
new file mode 100755
index 000000000..992378966
--- /dev/null
+++ b/contrib/scripts/gnunet-suidfix
@@ -0,0 +1,27 @@
1#!/bin/sh
2#
3# "suidfix" is german and it means something like immediate suicide.
4
5# taken from dangole's lede config.. thx!
6suid_root_helpers="exit nat-server nat-client transport-bluetooth transport-wlan vpn"
7libexec="${GNUNET_PREFIX}/lib/gnunet/libexec"
8
9chmodown_execbin() {
10 if [ -x $1 ]; then
11 if [ "$3" ]; then
12 chown $3 $1 2>/dev/null && chmod $2 $1
13 else
14 chmod $2 $1
15 fi
16 ls -l $1
17 else
18 echo "Missing: $1"
19 fi
20}
21
22for helper in $suid_root_helpers; do
23 chmodown_execbin ${libexec}/gnunet-helper-$helper u+s
24done
25chmodown_execbin ${libexec}/gnunet-helper-dns 4750 root:gnunetdns
26chmodown_execbin ${libexec}/gnunet-service-dns 2750 gnunet:gnunetdns
27
diff --git a/contrib/scripts/gnunet_janitor.py.in b/contrib/scripts/gnunet_janitor.py.in
new file mode 100644
index 000000000..cbe96a8eb
--- /dev/null
+++ b/contrib/scripts/gnunet_janitor.py.in
@@ -0,0 +1,79 @@
1#!@PYTHON@
2# This file is part of GNUnet.
3# (C) 2011, 2018 Christian Grothoff (and other contributing authors)
4#
5# GNUnet is free software: you can redistribute it and/or modify it
6# under the terms of the GNU Affero General Public License as published
7# by the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# GNUnet is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Affero General Public License for more details.
14#
15# You should have received a copy of the GNU Affero General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17#
18# Finds any gnunet processes still running in the system and kills them
19#
20# gnunet janitor can be used by invoking `make' like this:
21# TESTS_ENVIRONMENT='${top_srcdir}/contrib/scripts/gnunet_janitor.py &&' make check
22
23from __future__ import print_function
24import os
25import re
26import subprocess
27import sys
28import shutil
29import time
30import signal
31import terminate
32
33if os.name == 'nt':
34 from win32com.client import GetObject
35 WMI = GetObject('winmgmts:')
36
37
38def get_process_list():
39 result = []
40 if os.name == 'nt':
41 processes = WMI.InstancesOf('Win32_Process')
42 for p in processes:
43 result.append((p.Properties_('ProcessId').Value, re.sub(r'(.+)\.exe', r'\1', p.Properties_('Name').Value)))
44 else:
45 pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]
46 for pid in pids:
47 with open(os.path.join('/proc', pid, 'cmdline'), 'rb') as p:
48 cmdline = p.read().split('\x00')
49 if len(cmdline) > 0:
50 result.append((pid, cmdline[0]))
51 return result
52
53
54def main():
55 procs = get_process_list()
56 gnunet_procs = []
57 for p in procs:
58 if re.match(r'gnunet-.+', p[1]):
59 gnunet_procs.append(p)
60 for p in gnunet_procs:
61 if re.match(r'gnunet-service-arm', p[1]):
62 print("killing arm process {0:5} {1}".format(p[0], p[1]))
63 try:
64 terminate.safe_terminate_process_by_pid(int(p[0]), 1)
65 except OSError as e:
66 print("failed: {0}".format(e))
67 pass
68 for p in gnunet_procs:
69 if not re.match(r'gnunet-service-arm', p[1]):
70 print("killing non-arm process {0:5} {1}".format(p[0], p[1]))
71 try:
72 terminate.safe_terminate_process_by_pid(int(p[0]), 1)
73 except OSError as e:
74 print("failed: {0}".format(e))
75 pass
76
77
78if __name__ == '__main__':
79 sys.exit(main())
diff --git a/contrib/scripts/gnunet_pyexpect.py.in b/contrib/scripts/gnunet_pyexpect.py.in
new file mode 100644
index 000000000..f155db5be
--- /dev/null
+++ b/contrib/scripts/gnunet_pyexpect.py.in
@@ -0,0 +1,82 @@
1#!@PYTHON@
2# This file is part of GNUnet.
3# (C) 2010, 2018 Christian Grothoff (and other contributing authors)
4#
5# GNUnet is free software: you can redistribute it and/or modify it
6# under the terms of the GNU Affero General Public License as published
7# by the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# GNUnet is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Affero General Public License for more details.
14#
15# You should have received a copy of the GNU Affero General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17#
18# Testcase for gnunet-peerinfo
19from __future__ import print_function
20import os
21import re
22import subprocess
23import sys
24import shutil
25import time
26
27
28class pexpect (object):
29 def __init__(self):
30 super(pexpect, self).__init__()
31
32 def spawn(self, stdin, arglist, *pargs, **kwargs):
33 env = kwargs.pop('env', None)
34 if env is None:
35 env = os.environ.copy()
36 # This messes up some testcases, disable log redirection
37 env.pop('GNUNET_FORCE_LOGFILE', None)
38 self.proc = subprocess.Popen(arglist, *pargs, env=env, **kwargs)
39 if self.proc is None:
40 print("Failed to spawn a process {0}".format(arglist))
41 sys.exit(1)
42 if stdin is not None:
43 self.stdo, self.stde = self.proc.communicate(stdin)
44 else:
45 self.stdo, self.stde = self.proc.communicate()
46 return self.proc
47
48 def expect(self, s, r, flags=0):
49 stream = self.stdo if s == 'stdout' else self.stde
50 if isinstance(r, str):
51 if r == "EOF":
52 if len(stream) == 0:
53 return True
54 else:
55 print("Failed to find `{1}' in {0}, which is `{2}' ({3})".format(s, r, stream, len(stream)))
56 sys.exit(2)
57 raise ValueError("Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'".format(r))
58 m = r.search(stream.decode(), flags)
59 if not m:
60 print("Failed to find `{1}' in {0}, which is is `{2}'".format(s, r.pattern, stream))
61 sys.exit(2)
62 stream = stream[m.end():]
63 if s == 'stdout':
64 self.stdo = stream
65 else:
66 self.stde = stream
67 return m
68
69 def read(self, s, size=-1):
70 stream = self.stdo if s == 'stdout' else self.stde
71 result = ""
72 if size < 0:
73 result = stream
74 new_stream = ""
75 else:
76 result = stream[0:size]
77 new_stream = stream[size:]
78 if s == 'stdout':
79 self.stdo = new_stream
80 else:
81 self.stde = new_stream
82 return result
diff --git a/contrib/scripts/lint-python.sh b/contrib/scripts/lint-python.sh
new file mode 100755
index 000000000..9f7e0462d
--- /dev/null
+++ b/contrib/scripts/lint-python.sh
@@ -0,0 +1,24 @@
1#!/bin/sh
2# check python style (and 2 to 3 migration)
3
4rm python-lint.log
5
6if [ -e "python" ]
7then
8 python --version >> python-lint.log
9fi
10
11if [ -e "python2" ]
12then
13 python2 --version >> python-lint.log
14fi
15
16if [ -e "python3" ]
17then
18 python3 --version >> python-lint.log
19fi
20
21flake8 >> python-lint.log
22
232to3 -v -d . >> python-lint.log
242to3 -v -p . >> python-lint.log
diff --git a/contrib/scripts/process_log.sh b/contrib/scripts/process_log.sh
new file mode 100755
index 000000000..c25c515c2
--- /dev/null
+++ b/contrib/scripts/process_log.sh
@@ -0,0 +1,30 @@
1#!/bin/bash
2
3# Usage: service should print "STARTING SERVICE (srvc) for peer [PEER]" where:
4# - "srvc" is the service name (in lowercase, as in the log output).
5# It cannot contain parenthesis in its name.
6# - "PEER" is the peer ID. Should be 4 alfanumeric characters
7
8grep "STARTING SERVICE " log > __tmp_peers
9
10SED_EXPR=""
11while read -r line; do
12 SRVC=`echo "$line" | sed -e 's/.*(\([^)]*\)).*/\1/'`
13 PEER=`echo "$line" | sed -e 's/.*\[\(....\)\].*/\1/'`
14 PID=`echo "$line" | sed -e "s/.*$SRVC-\([0-9]*\).*/\1/"`
15 echo "$SRVC $PID => $PEER"
16
17 SED_EXPR="${SED_EXPR}s/$SRVC-\([a-z2]*\)-$PID/$SRVC \1 $PEER/;"
18 SED_EXPR="${SED_EXPR}s/$SRVC-$PID/$SRVC XXX $PEER/;"
19 SED_EXPR="${SED_EXPR}s/$SRVC-api-[0-9]/$SRVC-api- /;"
20done < __tmp_peers
21rm __tmp_peers
22
23sed -e "$SED_EXPR" log > .log
24echo "$0 sed regex: $SED_EXPR" >> .log
25
26SIZE=`stat -c%s .log`
27
28if [[ "`ps aux | grep "kwrite .lo[g]"`" = "" && "$SIZE" < 10000000 ]]; then
29 kwrite .log --geometry 960x1140-960 &
30fi
diff --git a/contrib/scripts/pydiffer.py.in b/contrib/scripts/pydiffer.py.in
new file mode 100644
index 000000000..10145371c
--- /dev/null
+++ b/contrib/scripts/pydiffer.py.in
@@ -0,0 +1,44 @@
1#!@PYTHON@
2import os
3import sys
4import difflib
5import filecmp
6
7
8def getdiff(old, new):
9 diff = []
10 with open(old) as a:
11 with open(new) as b:
12 for l in difflib.unified_diff(a.read().splitlines(), b.read().splitlines()):
13 diff.append(l)
14 return diff
15
16
17def dc_getdiff(dc, old, new):
18 diff = []
19 for f in dc.left_only:
20 diff.append("Only in {}: {}".format(old, f))
21 for f in dc.right_only:
22 diff.append("Only in {}: {}".format(new, f))
23 for f in dc.diff_files:
24 r = getdiff(os.path.join(old, f), os.path.join(new, f))
25 diff.extend(r)
26 for dn, dc in dc.subdirs.items():
27 r = dc_getdiff(dc, os.path.join(old, dn), os.path.join(new, dn))
28 diff.extend(r)
29 return diff
30
31
32def dcdiff(old, new):
33 dc = filecmp.dircmp(old, new)
34 diff = dc_getdiff(dc, old, new)
35 return diff
36
37
38def main():
39 for l in dcdiff(sys.argv[1], sys.argv[2]):
40 print(l)
41
42
43if __name__ == '__main__':
44 main()
diff --git a/contrib/scripts/pydmesg b/contrib/scripts/pydmesg
new file mode 100755
index 000000000..d60e08fe3
--- /dev/null
+++ b/contrib/scripts/pydmesg
@@ -0,0 +1,75 @@
1#!/usr/bin/env python
2# coding=utf8
3
4# Copyright (C) 2010 Saúl ibarra Corretgé <saghul@gmail.com>
5#
6
7"""
8pydmesg: dmesg with human-readable timestamps
9"""
10
11from __future__ import with_statement
12
13import re
14import subprocess
15import sys
16
17from datetime import datetime, timedelta
18
19
20_datetime_format = "%Y-%m-%d %H:%M:%S"
21_dmesg_line_regex = re.compile("^\[(?P<time>\d+\.\d+)\](?P<line>.*)$")
22
23def exec_process(cmdline, silent, input=None, **kwargs):
24 """Execute a subprocess and returns the returncode, stdout buffer and stderr buffer.
25 Optionally prints stdout and stderr while running."""
26 try:
27 sub = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
28 stdout, stderr = sub.communicate(input=input)
29 returncode = sub.returncode
30 if not silent:
31 sys.stdout.write(stdout)
32 sys.stderr.write(stderr)
33 except OSError,e:
34 if e.errno == 2:
35 raise RuntimeError('"%s" is not present on this system' % cmdline[0])
36 else:
37 raise
38 if returncode != 0:
39 raise RuntimeError('Got return value %d while executing "%s", stderr output was:\n%s' % (returncode, " ".join(cmdline), stderr.rstrip("\n")))
40 return stdout
41
42def human_dmesg():
43 now = datetime.now()
44 uptime_diff = None
45 try:
46 with open('/proc/uptime') as f:
47 uptime_diff = f.read().strip().split()[0]
48 except IndexError:
49 return
50 else:
51 try:
52 uptime = now - timedelta(seconds=int(uptime_diff.split('.')[0]), microseconds=int(uptime_diff.split('.')[1]))
53 except IndexError:
54 return
55
56 dmesg_data = exec_process(['dmesg'], True)
57 for line in dmesg_data.split('\n'):
58 if not line:
59 continue
60 match = _dmesg_line_regex.match(line)
61 if match:
62 try:
63 seconds = int(match.groupdict().get('time', '').split('.')[0])
64 nanoseconds = int(match.groupdict().get('time', '').split('.')[1])
65 microseconds = int(round(nanoseconds * 0.001))
66 line = match.groupdict().get('line', '')
67 t = uptime + timedelta(seconds=seconds, microseconds=microseconds)
68 except IndexError:
69 pass
70 else:
71 print "[%s]%s" % (t.strftime(_datetime_format), line)
72
73
74if __name__ == '__main__':
75 human_dmesg()
diff --git a/contrib/scripts/regression.sh b/contrib/scripts/regression.sh
new file mode 100755
index 000000000..1f799797a
--- /dev/null
+++ b/contrib/scripts/regression.sh
@@ -0,0 +1,54 @@
1#!/bin/sh
2cd
3cd gnunet
4svn up > /dev/null
5H=`hostname`
6echo "================START===================" >> regression.$H
7RUN=`date +%0y%0m%0d%0k%0M`
8uname -a >> regression.$H
9date >> regression.$H
10echo "Run $RUN" >> regression.$H
11svn up >> regression.$H
12export GNUNET_PREFIX=$HOME
13export PATH=$HOME/bin:$PATH
14./bootstrap >> regression.$H.$RUN 2>&1
15./configure --prefix=$HOME --with-extractor=$HOME --with-microhttpd=$HOME >> regression.$H.$RUN 2>&1
16if [ $? != 0 ]
17then
18 echo configure failed >> regression.$H
19 exit
20fi
21KEEP=0
22make clean >> regression.$H.$RUN 2>&1
23make install >> regression.$H.$RUN 2>&1
24cd src
25for n in `ls --hide "Makefile*"`
26do
27 cd $n
28 if [ -f Makefile ]
29 then
30 make check >> ../regression.$H.$RUN.$n 2>&1
31 if [ $? != 0 ]
32 then
33 echo Tests for $n failed >> ../regression.$H
34 echo "--------- Details for $n -----------" >> ../regression.$H
35 cat regression.$H.$RUN.$n >> ../regression.$H
36 echo "----- End of Details for $n --------" >> ../regression.$H
37 KEEP=1
38 else
39 echo Tests for $n succeeded >> ../regression.$H
40 fi
41 fi
42 cd ..
43done
44echo "================END====================" >> regression.$H
45
46if [ $KEEP == 0]
47then
48 rm regression.$H.$RUN*
49 rm regression.$H
50else
51 svn add regression.$H > /dev/null
52 svn commit -m "Regression in tests on $H" regression.$H
53fi
54
diff --git a/contrib/scripts/removetrailingwhitespace.py.in b/contrib/scripts/removetrailingwhitespace.py.in
new file mode 100755
index 000000000..5824fb591
--- /dev/null
+++ b/contrib/scripts/removetrailingwhitespace.py.in
@@ -0,0 +1,15 @@
1#!@PYTHON@
2
3import sys
4import re
5
6
7for fileName in sys.argv[1:]:
8 f = open(fileName, 'r+')
9 fileString = f.read()
10
11 fileString = re.sub(r'[ ]+\n', r'\n', fileString)
12 fileString = re.sub(r'\r', r'', fileString)
13 f.seek(0)
14 f.write(fileString)
15 f.truncate(len(fileString))
diff --git a/contrib/scripts/revisionary.sh b/contrib/scripts/revisionary.sh
new file mode 100755
index 000000000..5778cf148
--- /dev/null
+++ b/contrib/scripts/revisionary.sh
@@ -0,0 +1,98 @@
1#!/usr/local/bin/bash
2
3STARTREVISION=14033
4ENDREVISION=15268
5CURRENTREVISION=$STARTREVISION
6HOME_DIR='/home/gnunet/FreeBSD7-AMD64-wachs/freebsd7-amd64-wachs/build'
7
8
9CMD_UPDATE="svn up --force --accept theirs-full -r"
10CMD_CLEANUP="killall -s 31 -r gnunet-*; make distclean;"
11CMD_PREPARATION="./bootstrap; ./configure --prefix=/tmp/gnb --with-extractor=/usr/local"
12CMD_BUILD="make all"
13CMD_TEST="cd src/transport ; make test_transport_api_tcp; ./test_transport_api_tcp"
14
15#LOGGING=""
16LOGGING=" 1> /dev/null 2> errors.txt"
17LOGFILE="log.txt"
18
19function output ()
20{
21 eval echo $1
22 eval echo $1 >> $LOGFILE
23}
24
25
26while [ $CURRENTREVISION -le $ENDREVISION ]; do
27 output 'Testing revision $CURRENTREVISION'
28# updating
29 output ' -> updating '
30 eval cd $HOME_DIR
31 CMD="$CMD_UPDATE $CURRENTREVISION $LOGGING"
32 eval $CMD
33 result=$?
34 if [ $result -eq 0 ]; then
35 output " updating OK"
36 else
37 output " updating FAILED"
38 (( CURRENTREVISION++ ))
39 continue
40 fi
41
42# clean up
43 output " -> cleanup "
44 CMD="$CMD_CLEANUP $LOGGING"
45 eval $CMD
46 result=$?
47 if [ $result -eq 0 ]; then
48 output " cleanup OK"
49 else
50 output " cleanup FAILED"
51 (( CURRENTREVISION++ ))
52 continue
53 fi
54# preparing
55 output " -> preparation "
56 CMD="$CMD_PREPARATION $LOGGING"
57 #echo $CMD
58 eval $CMD
59 result=$?
60 if [ $result -eq 0 ]; then
61 output " preparation OK"
62 else
63 output " preparation FAILED"
64 (( CURRENTREVISION++ ))
65 continue
66 fi
67# building
68 output " -> building "
69 CMD="$CMD_BUILD $LOGGING"
70 #echo $CMD
71 eval $CMD
72 result=$?
73 if [ $result -eq 0 ]; then
74 output " building OK"
75 else
76 output " building FAILED"
77 (( CURRENTREVISION++ ))
78 continue
79 fi
80# testing
81 output " -> testing "
82 CMD="$CMD_TEST $LOGGING"
83 #echo $CMD
84 eval $CMD
85 result=$?
86 testresult=result
87 if [ $result -eq 0 ]; then
88 output " testing OK"
89 else
90 output " testing FAILED"
91 output 'Revision $CURRENTREVISION FAILED'
92 fi
93 (( CURRENTREVISION++ ))
94done
95
96exit
97
98
diff --git a/contrib/scripts/terminate.py.in b/contrib/scripts/terminate.py.in
new file mode 100644
index 000000000..30f5dc97f
--- /dev/null
+++ b/contrib/scripts/terminate.py.in
@@ -0,0 +1,66 @@
1#!@PYTHON@
2# This file is part of GNUnet.
3# (C) 2011, 2018 Christian Grothoff (and other contributing authors)
4#
5# GNUnet is free software: you can redistribute it and/or modify it
6# under the terms of the GNU Affero General Public License as published
7# by the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# GNUnet is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Affero General Public License for more details.
14#
15# You should have received a copy of the GNU Affero General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17#
18# Utility module that implements safe process termination for W32.
19# For other platforms it's equivalent to Popen.kill ()
20# Requires pywin32 on W32.
21
22import sys
23import subprocess
24import os
25if os.name == 'nt':
26 import win32api
27 import win32process
28
29
30class dummyobj (object):
31 pass
32
33
34def safe_terminate_process_by_pid(pid, code):
35 if os.name == 'nt':
36 p = dummyobj()
37 p._handle = win32api.OpenProcess(2 | 1024 | 8 | 32 | 16, 0, pid)
38 result = safe_terminate_process(p, code)
39 win32api.CloseHandle(p._handle)
40 return result
41 else:
42 # XXX (F821): Undefined name 'SIGKILL'
43 return os.kill(int(pid), SIGKILL)
44
45
46def safe_terminate_process(proc, code):
47 if os.name == 'nt':
48 cp = win32api.GetCurrentProcess()
49 result = False
50 dupproc = win32api.DuplicateHandle(cp, proc._handle, cp, 2 | 1024 | 8 | 32 | 16, 0, 0)
51 try:
52 exitcode = win32process.GetExitCodeProcess(dupproc)
53 if exitcode == 0x103:
54 kernel32 = win32api.GetModuleHandle("kernel32")
55 exitprocess = win32api.GetProcAddress(kernel32, "ExitProcess")
56 th, tid = win32process.CreateRemoteThread(dupproc, None, 0, exitprocess, code, 0)
57 win32api.CloseHandle(th)
58 result = True
59 else:
60 result = True
61 # except failed to get exit code? failed to get module handle?
62 finally:
63 win32api.CloseHandle(dupproc)
64 return result
65 else:
66 return proc.kill()
diff --git a/contrib/scripts/testbed_cleanup.sh b/contrib/scripts/testbed_cleanup.sh
new file mode 100755
index 000000000..57413fba0
--- /dev/null
+++ b/contrib/scripts/testbed_cleanup.sh
@@ -0,0 +1,14 @@
1#!/bin/bash
2
3###################################################################################
4# Script to clean a previous run of testbed which has crashed. This scripts kills #
5# the peers and cleans the temporary files created for those peers #
6# #
7# Author: Sree Harsha Totakura #
8###################################################################################
9
10for host in `cut -d : -f 1 < infiniband_cluster.hosts | cut -d @ -f 2`
11do
12 echo "ssh --> $host"
13 ssh $host 'pkill -SIGKILL gnunet; rm -rf /tmp/gnunet-pipe*; rm -rf /tmp/testbed*'
14done
diff --git a/contrib/scripts/texinfo-hacks.el b/contrib/scripts/texinfo-hacks.el
new file mode 100644
index 000000000..bfb5c98fa
--- /dev/null
+++ b/contrib/scripts/texinfo-hacks.el
@@ -0,0 +1,18 @@
1;;;; hacks.el --- a few functions to help me work on the manual
2;;;; Jim Blandy <jimb@red-bean.com> --- October 1998
3;;;; -- imported from https://git.savannah.gnu.org/cgit/guile.git/tree/doc/hacks.el
4;;;; This code should be covered by the same license as GNU Guile (GPL3).
5
6(defun jh-exemplify-region (start end)
7 (interactive "r")
8 (save-excursion
9 (save-restriction
10 (narrow-to-region start end)
11
12 ;; Texinfo doesn't handle tabs well.
13 (untabify (point-min) (point-max))
14
15 ;; Quote any characters special to texinfo.
16 (goto-char (point-min))
17 (while (re-search-forward "[{}@]" nil t)
18 (replace-match "@\\&")))))
diff --git a/contrib/scripts/visualize_stats.sh b/contrib/scripts/visualize_stats.sh
new file mode 100755
index 000000000..aaa5e657b
--- /dev/null
+++ b/contrib/scripts/visualize_stats.sh
@@ -0,0 +1,86 @@
1#!/bin/bash
2#
3# This script polls gnunet-stats repeatedly to create statistics plots.
4# Use 'collect' to collect statistics and 'plot' to plot whats been
5# collected. All plots will be written to $STATDIR as separate .png files.
6#
7# WARNING: calling 'collect' will delete all files in $STATDIR.
8#
9# Requires: gnuplot
10#
11# Note: gnuplot syntax has changed across versions. This
12# script perhaps will not produce color images with older gnuplots.
13# The script should work atleast with gnuplot 3.8k patchlevel 1.
14#
15
16SLEEP=120
17GNUNET=$HOME/
18STATDIR=$GNUNET/stats
19IMAGEVIEWER='display'
20TMP=/tmp/.gnuplot_error
21
22##########################################################################
23
24mkdir -p $STATDIR
25
26case "$1" in
27 collect)
28 rm -f $STATDIR/*
29
30 STARTTIME=`date +%s`
31 IFS=":"
32
33 while true; do
34 NOW=`date +%s`
35 RELAT=$[$NOW-$STARTTIME]
36 gnunet-statistics | while read KEY VALUE; do
37 KEY=`echo $KEY | tr / .`
38 # Collect stats of previous round
39 if [ -e "$STATDIR/$KEY.dat" ]; then
40 PREV=`tail --lines=1 "$STATDIR/$KEY.dat" | sed -e "s/.* //g"`
41 else
42 PREV=$VALUE
43 fi
44
45 # Write new stats
46 echo $RELAT $VALUE >>"$STATDIR/$KEY.dat"
47 echo $RELAT $PREV $VALUE >>"$STATDIR/$KEY.diff"
48
49 done
50 sleep $SLEEP
51 done
52 ;;
53 plot)
54 # Plot incremental
55 ls -1 $STATDIR/*.dat | while read FILENAME; do
56 BASENAME=`basename "$FILENAME" | sed -e "s/ *\..*//g"`
57 echo "set terminal png;set output '$FILENAME.png';set title '$BASENAME - incr';plot '$FILENAME' using (\$1/60):(\$2) title '' with lines;" | nice gnuplot 2> $TMP
58 EC=`cat $TMP | grep "empty" | grep "Warning" | wc -l`
59 if test $EC -ge 1
60 then
61 rm "$FILENAME.png"
62 fi
63 done
64
65 # Plot diff
66 ls -1 $STATDIR/*.diff | while read FILENAME; do
67 BASENAME=`basename "$FILENAME" | sed -e "s/ *\..*//g"`
68 echo "set terminal png;set output '$FILENAME.png';set title '$BASENAME - diff';plot '$FILENAME' using (\$1/60):(\$3-\$2) title '' with lines;" | nice gnuplot 2> $TMP
69 EC=`cat $TMP | grep "empty" | grep "Warning" | wc -l`
70 if test $EC -ge 1
71 then
72 rm "$FILENAME.png"
73 fi
74
75 done
76 ;;
77 view)
78 $IMAGEVIEWER $STATDIR/*.png
79 ;;
80 *)
81 echo $"Usage: $0 {collect|plot|view}"
82 exit 1
83
84esac
85
86
diff --git a/contrib/scripts/zonewalk-to-types.sh b/contrib/scripts/zonewalk-to-types.sh
new file mode 100755
index 000000000..dfe15a8e3
--- /dev/null
+++ b/contrib/scripts/zonewalk-to-types.sh
@@ -0,0 +1,35 @@
1#!/bin/sh
2# This script is in the public domain.
3# Converts the output of gnunet-zonewalk (DNS resolutions)
4# into a proper input for gnunet-gns-benchmark.
5
6NUM_CLIENTS=3
7# How many different groups of names should we
8# create? 1/N will be in the 'shared' group.
9
10# FILE ($1) contains results from DNS lookup; strip
11# everything but the hostnames, remove duplicates
12# and then randomize the order.
13cat $1 | grep -v SOA | awk '{print $1}' | sort | uniq | shuf > $1.tmp
14TOTAL=`cat $1.tmp | wc -l`
15GROUP_SIZE=`expr $TOTAL / \( $NUM_CLIENTS + 1 \)`
16echo "Creating $NUM_CLIENTS benchmark sets with 2x $GROUP_SIZE entries each."
17# First group (0) is to be shared among all clients
18for i in `seq 1 $NUM_CLIENTS`
19do
20 cat $1.tmp | head -n $GROUP_SIZE | awk "{print 0 \" \" \$1}" > $1.$i.tmp
21done
22
23# Second group (1) is unique per client
24OFF=$GROUP_SIZE
25for i in `seq 1 $NUM_CLIENTS`
26do
27 END=`expr $OFF + $GROUP_SIZE`
28 cat $1.tmp | head -n $END | tail -n $GROUP_SIZE | awk "{print 1 \" \" \$1}" >> $1.$i.tmp
29# Shuffle again, so we mix the different request categories in terms of
30# when we issue the queries.
31 cat $1.$i.tmp | shuf > $1.$i
32 OFF="$END"
33 rm $1.$i.tmp
34done
35rm $1.tmp