summaryrefslogtreecommitdiff
path: root/other/mixminion
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2005-04-11 21:16:38 +0000
committerPeter Palfrader <peter@palfrader.org>2005-04-11 21:16:38 +0000
commitc4cbd290c89d38687dc4f523fb8b44851066975d (patch)
tree9f3056e9dc01109100b36914557b0af4137d5c51 /other/mixminion
parent31c579ec715796afbdd176227ec4bc2fb6cc96fa (diff)
Add tor and mixminion
Diffstat (limited to 'other/mixminion')
-rw-r--r--other/mixminion/Makefile21
-rwxr-xr-xother/mixminion/bin/rrd-graph103
-rwxr-xr-xother/mixminion/bin/rrd-update147
3 files changed, 271 insertions, 0 deletions
diff --git a/other/mixminion/Makefile b/other/mixminion/Makefile
new file mode 100644
index 0000000..78706a5
--- /dev/null
+++ b/other/mixminion/Makefile
@@ -0,0 +1,21 @@
+TODAY=`TZ=UTC date +'%Y-%m-%d_%H:%M:%S'`
+WGET=wget --cache=off
+OUTDIR=mixminion-directory
+SOURCE=http://mixminion.net/directory/Directory.gz
+TMPFILE=download.tmp
+LAST_NAME=dir.last
+
+all:
+ rm -f $(TMPFILE)
+ $(WGET) -q -O $(TMPFILE) $(SOURCE)
+ NAME=directory-$(TODAY).gz; \
+ if [ -e $(LAST_NAME) ] && diff -q $(TMPFILE) $(OUTDIR)/`cat $(LAST_NAME)` >/dev/null ; then \
+ ln $(OUTDIR)/`cat $(LAST_NAME)` $(OUTDIR)/$$NAME; \
+ else \
+ mv $(TMPFILE) $(OUTDIR)/$$NAME; \
+ echo "$$NAME" > $(LAST_NAME); \
+ fi; \
+ bin/rrd-update $$NAME
+ rm -rf result
+ mkdir result
+ bin/rrd-graph
diff --git a/other/mixminion/bin/rrd-graph b/other/mixminion/bin/rrd-graph
new file mode 100755
index 0000000..269a2ad
--- /dev/null
+++ b/other/mixminion/bin/rrd-graph
@@ -0,0 +1,103 @@
+#!/usr/bin/perl -w
+
+use strict;
+use RRDs;
+use BER;
+
+my $HOSTNAME = `hostname`;
+
+#my $IMG_URL = 'http://images.noreply.org/mixminion-nodes/';
+my $IMG_URL = '';
+my $NOW = time;
+my $GMTIME = gmtime($NOW);
+my $START_AT = $NOW-9*30*24*3600;
+my $RRD = '/home/weasel/www/www.noreply.org/Build/other/mixminion/rrd/nodes.rrd';
+my $RRD_DIR = '/home/weasel/www/www.noreply.org/Build/other/mixminion/rrd/nodes';
+
+opendir(D,$RRD_DIR) or die ("Cannot opendir .: $!\n");
+my @SOURCES = sort { lc($a) cmp lc($b)} grep { /\.rrd$/ } readdir(D);
+@SOURCES = grep {
+ my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
+ $atime,$mtime,$ctime,$blksize,$blocks) = stat($RRD_DIR.'/'.$_);
+ $mtime >= $START_AT;
+ } @SOURCES;
+closedir(D);
+
+my @params = qw{result/total.png};
+push @params, sprintf('-s %s', $START_AT);
+#push @params, sprintf('-e %s', $NOW- 2*24*3600);
+push @params, sprintf('-t %s', "Mixminion nodes");
+push @params, sprintf('-v %s', "# nodes");
+#push @params, sprintf('-w %d', 600);
+#push @params, sprintf('-h %d', 400);
+
+push @params, sprintf('DEF:%s=%s:%s:%s', 'd_inDirectory' , $RRD, 'inDirectory', 'AVERAGE');
+push @params, sprintf('CDEF:%s=%s' , 'c_inDirectory' , 'd_inDirectory');
+push @params, sprintf('%s:%s#%s:%s' , 'LINE2' , 'c_inDirectory' , 'FF77FF', '# in directory');
+
+push @params, sprintf('DEF:%s=%s:%s:%s', 'd_recommended' , $RRD, 'recommended', 'AVERAGE');
+push @params, sprintf('CDEF:%s=%s' , 'c_recommended' , 'd_recommended');
+push @params, sprintf('%s:%s#%s:%s' , 'LINE3' , 'c_recommended' , '7777FF', '# recommended' );
+
+push @params, sprintf('CDEF:%s=d_inDirectory,0,*,%s,+' , 'zeroline' , '0');
+push @params, sprintf('%s:%s' , 'LINE1' , 'zeroline' );
+
+
+my $body;
+my $index;
+
+for my $source (@SOURCES) {
+ my $def = $source;
+ $def =~ s/\.rrd$//;
+ my $cdef = 'c_'.$def;
+ my $label = $def;
+
+ $source = $RRD_DIR .'/'. $source;
+
+ my @this;
+ push @this, sprintf('result/node-%s.png', $def);
+ push @this, sprintf('-s %s', $START_AT);
+ push @this, sprintf('-t %s', "$def");
+ push @this, sprintf('-v %s', "#");
+ #push @this, sprintf('-w %d', 150);
+ #push @this, sprintf('-h %d', 50);
+
+ push @this, sprintf('DEF:%s=%s:%s:%s', 'd_inDirectory' , $source, 'inDirectory', 'AVERAGE');
+ push @this, sprintf('CDEF:%s=%s' , 'c_inDirectory' , 'd_inDirectory');
+ push @this, sprintf('%s:%s#%s:%s' , 'AREA' , 'c_inDirectory' , 'FF77FF', '# in directory');
+
+ push @this, sprintf('DEF:%s=%s:%s:%s', 'd_recommended' , $source, 'recommended', 'AVERAGE');
+ push @this, sprintf('CDEF:%s=%s' , 'c_recommended' , 'd_recommended');
+ push @this, sprintf('%s:%s#%s:%s' , 'AREA' , 'c_recommended' , '7777FF', '# recommended' );
+
+ push @this, sprintf('CDEF:%s=d_inDirectory,0,*,%s,+' , 'zeroline' , '0');
+ push @this, sprintf('%s:%s' , 'LINE1' , 'zeroline' );
+
+
+ my ($averages,$xsize,$ysize) = RRDs::graph @this;
+ warn RRDs::error if RRDs::error;
+
+ $body .= "<h2><a name=\"$def\">$def</a></h2><p><a href=\"#_top\">top</a><p><img width=\"$xsize\" height=\"$ysize\" alt=\"$def running\" src=\"$IMG_URL"."node-$def.png\"></p>\n";
+ $index .= "<li><a href=\"#$def\">$def</a></li>\n";
+}
+
+my ($averages,$xsize,$ysize) = RRDs::graph @params;
+die RRDs::error if RRDs::error;
+
+my $html = "<html><head><title>Number of Mixminion Nodes</title></head><body>";
+$html .= "<h1><a name=\"_top\">Number of Mixminion Nodes</a></h1>";
+$html .= "<a href=\"../\">..</a><br>\n";
+$html .= "<p><img width=\"$xsize\" height=\"$ysize\" src=\"$IMG_URL"."total.png\"></p>";
+$html .= "<h1>Nodes</h1>";
+$html .= "<ul>".$index."</ul>";
+$html .= $body;
+$html .= "<br><br><br>\n";
+$html .= 'Images created with Tobi Oetiker\'s <a href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/">rrdtool</a>'."\n";
+$html .= "<hr>\nBuilt at $GMTIME on $HOSTNAME<br>\n";
+$html .= "<a href=\"mailto:web\@palfrader.org\">Peter Palfrader &lt;web\@palfrader.org&gt;</a>\n";
+$html .= "</body></html>\n";
+
+open (F, ">result/index.html") or die ("Cannot open index.html: $!\n");
+print F $html;
+close F;
+
diff --git a/other/mixminion/bin/rrd-update b/other/mixminion/bin/rrd-update
new file mode 100755
index 0000000..29d0c17
--- /dev/null
+++ b/other/mixminion/bin/rrd-update
@@ -0,0 +1,147 @@
+#!/usr/bin/perl -w
+
+use strict;
+use RRDs;
+use BER;
+use Time::ParseDate;
+use Compress::Zlib;
+
+my $NOW = time;
+my $VERBOSE = 0;
+my $RRD = '/home/weasel/www/www.noreply.org/Build/other/mixminion/rrd/nodes.rrd';
+my $RRD_DIR = '/home/weasel/www/www.noreply.org/Build/other/mixminion/rrd/nodes';
+my $DIR_DIR = '/home/weasel/www/www.noreply.org/Build/other/mixminion/mixminion-directory';
+
+sub check_exists($) {
+ my ($rrd) = @_;
+ return if (-e $rrd);
+ my @params = ($rrd);
+ push @params, '-b', 'now - 1 year',
+ qw{ --step 14400
+ DS:inDirectory:GAUGE:172800:U:U
+ DS:recommended:GAUGE:172800:U:U
+ RRA:AVERAGE:0.5:1:21900
+ };
+ print "Creating rrd: $rrd...\n" if $VERBOSE;
+ RRDs::create @params;
+ my $err=RRDs::error;
+ warn "ERROR while creating $rrd: $err\n" if $err;
+}
+sub get_last($) {
+ my ($rrd) = @_;
+ my $last = 0;
+ if ( -e $rrd) {
+ $last = RRDs::last($rrd);
+ my $err = RRDs::error;
+ warn "ERROR while getting last for $rrd: $err\n" if $err;
+ };
+ return $last;
+};
+
+check_exists($RRD);
+my $last = get_last($RRD);
+
+opendir(DIR, $RRD_DIR) || die ("Cannot opendir $RRD_DIR: $!\n");
+my @rrdfiles = grep { /\.rrd$/ } readdir (DIR);
+closedir(DIR);
+my %last_node;
+for my $rrdfile (@rrdfiles) {
+ my $nodename = $rrdfile;
+ $nodename =~ s/\.rrd$//;
+ $last_node{$nodename} = get_last($RRD_DIR.'/'.$rrdfile);
+}
+
+my @dirfiles;
+if (scalar @ARGV) {
+ @dirfiles = @ARGV;
+} else {
+ opendir(DIR, $DIR_DIR) || die ("Cannot opendir $DIR_DIR: $!\n");
+ @dirfiles = sort { ($a cmp $b) } grep { /^directory-/ } readdir (DIR);
+ closedir(DIR);
+};
+
+my @updateGlobal;
+my %updates;
+for my $dir (@dirfiles) {
+ print "Doing $dir\n" if $VERBOSE;
+ open (DIRECTORY, $DIR_DIR.'/'.$dir) || die ("Cannot open $DIR_DIR/$dir: $!\n");
+ my $compressed_dir = join '', <DIRECTORY>;
+ close (DIRECTORY);
+
+ my $directory = Compress::Zlib::memGunzip($compressed_dir);
+
+ my $published = undef;
+ my $recommended_servers = undef;
+ my %in_directory;
+ my %is_recommended;
+ my $section = '' ;
+ for my $line (split /\r?\n/, $directory) {
+ chomp $line;
+ if ($line =~ /^\[(.*)\]\s*$/) {
+ $section = $1;
+ };
+ if ($section eq 'Directory' && $line =~ /^Published: (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})$/) {
+ my $date = $1;
+ print "Found published: $date\n" if ($VERBOSE >= 3);
+ $date =~ s#/#-#g;
+ $published = parsedate($date);
+ print "Parsed as $published (".(gmtime $published).")\n" if ($VERBOSE >= 4);
+ };
+ if ($section eq 'Directory' && $line =~ m#^Published: (\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2})$#) {
+ my $date = $1;
+ print "Found published: $date\n" if ($VERBOSE >= 3);
+ $date =~ s#/#-#g;
+ $published = parsedate($date);
+ print "Parsed as $published (".(gmtime $published).")\n" if ($VERBOSE >= 4);
+ };
+ if ($section eq 'Directory' && $line =~ /^Recommended-Servers: \s*(.*?)\s*$/) {
+ $recommended_servers = $1
+ };
+ if ($section eq 'Server' && $line =~ /Nickname: ([a-zA-Z0-9_-]+)\s*$/) {
+ $in_directory{$1} = 1;
+ };
+ }
+ close (DIRECTORY);
+ my @recommended_servers = split /,?\s*\s+/, $recommended_servers;
+ for my $node (@recommended_servers) {
+ $is_recommended{$node} = 1;
+ }
+
+ if ($published > $last) {
+ push @updateGlobal, $published.':'.(scalar keys %in_directory).':'.(scalar @recommended_servers);
+ $last = $published;
+ print "at ".(gmtime $published)." there are ".(scalar keys %in_directory).' in the directory and '.(scalar @recommended_servers)." recommended servers\n" if ($VERBOSE >= 3);
+ } else {
+ print "ignoring data at ".(gmtime $published)." because it's older than ".(gmtime $last)."\n" if ($VERBOSE >= 3);
+ };
+ for my $node (keys %in_directory) {
+ if (!defined $last_node{$node} || $published > $last_node{$node}) {
+ push @{$updates{$node}}, $published.':1:'.( defined $is_recommended{$node} ? '1' : '0' );
+ $last_node{$node} = $published;
+ }
+ delete $is_recommended{$node};
+ }
+ if (scalar keys %is_recommended) {
+ my $nodes = join ', ', keys %is_recommended;
+ warn ("$nodes recommended but not in directory.\n");
+ }
+};
+
+if (scalar @updateGlobal != 0) {
+ check_exists($RRD);
+ RRDs::update( $RRD, @updateGlobal );
+ my $err=RRDs::error;
+ warn "ERROR while updating $RRD: $err\n" if $err;
+};
+
+for my $node (keys %updates) {
+ if ($node =~ /[^a-zA-Z0-9_-]/) {
+ warn ("Illegal characters in node name '$node'\n");
+ next;
+ };
+ my $rrd = $RRD_DIR.'/'.$node.'.rrd';
+ check_exists($rrd);
+ RRDs::update( $rrd, @{$updates{$node}} );
+ my $err=RRDs::error;
+ warn "ERROR while updating $rrd: $err\n" if $err;
+};