gnunet-logread-ipc-sdedit.in 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!@PERLEXE@
  2. # 1. Start sdedit and enable 'RT diagram server' in 'Global preferences'.
  3. #
  4. # 2. Start this tool (see defaults below):
  5. # gnunet-logread-ipc-sdedit -n buffer-name -i /path/to/ipc.sock -h <sdedit-host> -p <sdedit-port>
  6. #
  7. # 3. Start a gnunet-logread instance for each component with the -n <component_name> option
  8. use strict;
  9. use warnings;
  10. use Getopt::Std;
  11. use IO::Socket::INET;
  12. use POSIX qw(mkfifo);
  13. my %opts;
  14. getopts ('i:n:h:p:', \%opts);
  15. my $ipc = $opts{i} || '/tmp/gnunet-logread-ipc.sock';
  16. my $name = $opts{n} || 'gnunet';
  17. my $host = $opts{h} || 'localhost';
  18. my $port = $opts{p} || 16001;
  19. my %svcs = map { $_ => 1 } @ARGV;
  20. my $sdedit = IO::Socket::INET->new(PeerAddr => $host,
  21. PeerPort => $port,
  22. Proto => 'tcp')
  23. or die "Cannot connect to $host:$port: $!\n";
  24. print $sdedit "$name\n";
  25. print $sdedit "_t:time[e]\n";
  26. print $sdedit "$_:$_\[ap\] \"$_\"\n" for @ARGV;
  27. print $sdedit "_e:ext[e]\n";
  28. print $sdedit "\n";
  29. mkfifo $ipc, 0600 or die "$ipc: $!\n" unless -e $ipc;
  30. open IPC, '<', $ipc or die "$ipc: $!\n";
  31. $| = 1;
  32. while (<IPC>)
  33. {
  34. print;
  35. my ($time, $from, $to, $msg, $svc);
  36. if (my ($time, $from, $to, $msg) =
  37. /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\s+
  38. (\S+)\s+ -> \s+(\S+)\s+ (\S+\s+ \(\d+\))/x)
  39. {
  40. $from = '_e' unless exists $svcs{$from};
  41. $to = '_e' unless exists $svcs{$to};
  42. print $sdedit "*0 _t\n$time\n*0\n", "$from:$to.$msg\n"
  43. }
  44. elsif (($time, $svc, $msg) =
  45. /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\s+
  46. (\S+)\s+(.+)/x)
  47. {
  48. print $sdedit "*0 _t\n$time\n*0\n", "*0 $svc\n$msg\n*0\n"
  49. }
  50. }
  51. close IPC;