diff options
Diffstat (limited to 'contrib/scripts/gnunet-logread/gnunet-logread-ipc-sdedit')
-rwxr-xr-x | contrib/scripts/gnunet-logread/gnunet-logread-ipc-sdedit | 60 |
1 files changed, 60 insertions, 0 deletions
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 | |||
10 | use strict; | ||
11 | use warnings; | ||
12 | |||
13 | use Getopt::Std; | ||
14 | use IO::Socket::INET; | ||
15 | use POSIX qw(mkfifo); | ||
16 | |||
17 | my %opts; | ||
18 | getopts ('i:n:h:p:', \%opts); | ||
19 | |||
20 | my $ipc = $opts{i} || '/tmp/gnunet-logread-ipc.sock'; | ||
21 | my $name = $opts{n} || 'gnunet'; | ||
22 | my $host = $opts{h} || 'localhost'; | ||
23 | my $port = $opts{p} || 16001; | ||
24 | my %svcs = map { $_ => 1 } @ARGV; | ||
25 | |||
26 | my $sdedit = IO::Socket::INET->new(PeerAddr => $host, | ||
27 | PeerPort => $port, | ||
28 | Proto => 'tcp') | ||
29 | or die "Cannot connect to $host:$port: $!\n"; | ||
30 | |||
31 | print $sdedit "$name\n"; | ||
32 | print $sdedit "_t:time[e]\n"; | ||
33 | print $sdedit "$_:$_\[ap\] \"$_\"\n" for @ARGV; | ||
34 | print $sdedit "_e:ext[e]\n"; | ||
35 | print $sdedit "\n"; | ||
36 | |||
37 | mkfifo $ipc, 0600 or die "$ipc: $!\n" unless -e $ipc; | ||
38 | open IPC, '<', $ipc or die "$ipc: $!\n"; | ||
39 | $| = 1; | ||
40 | while (<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 | |||
60 | close IPC; | ||