summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2002-06-11 09:53:35 +0000
committerPeter Palfrader <peter@palfrader.org>2002-06-11 09:53:35 +0000
commit7a234c06420ece9f0f100107b05cd061b0471b5b (patch)
tree17246819ec7c1bcb6bba844df1421d9099e456e1
parenta71fb93482962a7c49d088a233c7c8496c3e2f66 (diff)
Initial Import
-rw-r--r--Echolot/Pinger.pm133
-rw-r--r--Echolot/Pinger/Mix.pm49
2 files changed, 182 insertions, 0 deletions
diff --git a/Echolot/Pinger.pm b/Echolot/Pinger.pm
new file mode 100644
index 0000000..0585ef8
--- /dev/null
+++ b/Echolot/Pinger.pm
@@ -0,0 +1,133 @@
+package Echolot::Pinger;
+
+# (c) 2002 Peter Palfrader <peter@palfrader.org>
+# $Id: Pinger.pm,v 1.1 2002/06/11 09:53:35 weasel Exp $
+#
+
+=pod
+
+=head1 Name
+
+Echolot::Pinger - actual sending and receiving of Pings.
+
+=head1 DESCRIPTION
+
+This package provides functions for sending out and receiving pings.
+
+=cut
+
+use strict;
+use warnings;
+use Carp qw{cluck};
+use English;
+use Echolot::Pinger::Mix;
+
+sub makeHash($) {
+ my ($text) = @_;
+ my $sum = 0;
+ for (my $i=0; $i < length($text); $i++) {
+ $sum += ord( substr($text, $i, 1) )
+ };
+ return $sum;
+};
+
+sub do_mix_ping($$$$$) {
+ my ($address, $keyid, $time, $to, $body) = @_;
+
+ my %key = Echolot::Globals::get()->{'storage'}->get_key($address, 'mix', $keyid);
+ Echolot::Pinger::Mix::ping(
+ $body,
+ $to,
+ $key{'nick'},
+ { $keyid => \%key } ) or
+ return 0;
+
+ return 1;
+};
+
+sub do_ping($$$) {
+ my ($type, $address, $key) = @_;
+
+ my $now = time();
+ my $token = $address.':'.$type.':'.$key.':'.$now;
+ my $mac = Echolot::Tools::make_mac($token);
+ my $body = "remailer: $address\n".
+ "type: $type\n".
+ "key: $key\n".
+ "sent: $now\n".
+ "mac: $mac\n";
+
+ my $to = Echolot::Tools::make_address('ping');
+ if ($type eq 'mix') {
+ do_mix_ping($address, $key, $now, $to, $body);
+ } else {
+ cluck ("Don't know how to handle ping type $type");
+ return 0;
+ };
+
+ Echolot::Globals::get()->{'storage'}->register_pingout($address, $type, $key, $now);
+ return 1;
+};
+
+sub send_pings($$) {
+ my ($call_intervall, $send_every_n_calls) = @_;
+
+ my $now = time();
+
+ my @remailers = Echolot::Globals::get()->{'storage'}->get_remailers();
+ for my $remailer (@remailers) {
+ my $timemod = ($now / $call_intervall);
+ my $this_call_id = $timemod % $send_every_n_calls;
+
+ my $this_remailer_id = makeHash($remailer) % $send_every_n_calls;
+
+ next unless ($this_call_id eq $this_remailer_id);
+
+ for my $type (Echolot::Globals::get()->{'storage'}->get_types($remailer)) {
+ print "y: $type\n";
+ for my $key (Echolot::Globals::get()->{'storage'}->get_keys($remailer, $type)) {
+ print "k: $key\n";
+ do_ping($type, $remailer, $key);
+ }
+ };
+ };
+ return 1;
+};
+
+
+sub receive($$$) {
+ my ($body, $token, $timestamp) = @_;
+
+ my $now = time();
+
+ my ($addr) = $body =~ /^remailer: (.*)$/m;
+ my ($type) = $body =~ /^type: (.*)$/m;
+ my ($key) = $body =~ /^key: (.*)$/m;
+ my ($sent) = $body =~ /^sent: (.*)$/m;
+ my ($mac) = $body =~ /^mac: (.*)$/m;
+
+ my $cleanstring = (defined $addr ? $addr : 'undef') . ':' .
+ (defined $type ? $type : 'undef') . ':' .
+ (defined $key ? $key : 'undef') . ':' .
+ (defined $sent ? $sent : 'undef') . ':' .
+ (defined $mac ? $mac : 'undef') . ':';
+
+ print "Foo\n";
+ (defined $addr && defined $type && defined $key && defined $sent && defined $mac) or
+ warn ("Received ping at $timestamp has undefined values: $cleanstring\n"), #FIXME: logging
+ return 0;
+
+ print "Foo\n";
+ Echolot::Tools::verify_mac($addr.':'.$type.':'.$key.':'.$sent, $mac) or
+ warn ("Received ping at $timestamp has wrong mac; $cleanstring\n"), #FIXME: logging
+ return 0;
+
+ print "Foo\n";
+ Echolot::Globals::get()->{'storage'}->register_pingdone($addr, $type, $key, $sent, $now - $sent) or
+ return 0;
+
+ return 1;
+};
+
+1;
+# vim: set ts=4 shiftwidth=4:
diff --git a/Echolot/Pinger/Mix.pm b/Echolot/Pinger/Mix.pm
new file mode 100644
index 0000000..afe957f
--- /dev/null
+++ b/Echolot/Pinger/Mix.pm
@@ -0,0 +1,49 @@
+package Echolot::Pinger::Mix;
+
+# (c) 2002 Peter Palfrader <peter@palfrader.org>
+# $Id: Mix.pm,v 1.1 2002/06/11 09:53:35 weasel Exp $
+#
+
+=pod
+
+=head1 Name
+
+Echolot::Pinger::Mix - send mix pings
+
+=head1 DESCRIPTION
+
+This package provides functions for sending mixmaster (type II) pings.
+
+=cut
+
+use strict;
+use warnings;
+use Carp qw{cluck};
+use English;
+
+sub ping($$$$) {
+ my ($body, $to, $chain, $keys) = @_;
+
+ my $keyring = Echolot::Config::get()->{'Pinger::Mix'}->{'mixdir'}.'/pubring.mix';
+ open (F, '>'.$keyring) or
+ cluck("Cannot open $keyring for writing: $!"),
+ return 0;
+ for my $keyid (keys %$keys) {
+ print (F $keys->{$keyid}->{'summary'}, "\n\n");
+ print (F $keys->{$keyid}->{'key'},"\n\n");
+ };
+ close (F) or
+ cluck("Cannot close $keyring"),
+ return 0;
+
+ open(MIX, "|".Echolot::Config::get()->{'Pinger::Mix'}->{'mix'}." -m -S -l $chain") or
+ cluck("Cannot exec mixpinger: $!"),
+ return 0;
+ print MIX "To: $to\n\n$body";
+ close (MIX);
+
+ return 1;
+};
+
+1;
+# vim: set ts=4 shiftwidth=4: