/[echolot]/trunk/pingd
ViewVC logotype

Diff of /trunk/pingd

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 53 by weasel, Thu Jun 13 16:49:02 2002 UTC revision 54 by weasel, Thu Jun 20 04:30:04 2002 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -wT  #!/usr/bin/perl -wT
2    
3  # (c) 2002 Peter Palfrader <peter@palfrader.org>  # (c) 2002 Peter Palfrader <peter@palfrader.org>
4  # $Id: pingd,v 1.4 2002/06/13 16:49:02 weasel Exp $  # $Id: pingd,v 1.5 2002/06/20 04:30:04 weasel Exp $
5  #  #
6    
7    =pod
8    
9    =head1 NAME
10    
11    pingd - echolot ping daemon
12    
13    =head1 SYNOPSIS
14    
15    =over
16    
17    =item B<pingd> B<start>
18    
19    =item B<pingd> B<stop>
20    
21    =item B<pingd> B<add> I<address>
22    
23    =back
24    
25    =head1 DESCRIPTION
26    
27    pingd is a the heart of echolot. Echolot is a pinger for anonymous remailers.
28    
29    A Pinger in the context of anonymous remailers is a program that regularily
30    sends messages through remailers to check their reliability. It then calculates
31    reliability statistics which are used by remailer clients to choose the chain
32    of remailers to use.
33    
34    Additionally it collects configuration parameters and keys of all remailers and
35    offers them in a format readable by remailer clients.
36    
37    When called without parameters pingd schedules tasks like sending pings,
38    processing incoming mail and requesting remailer-xxx data and runs them in
39    configurable intervalls.
40    
41    =head1 COMMANDS
42    
43    =over
44    
45    =item B<start>
46    
47    Start the ping daemon.
48    
49    =item B<stop>
50    
51    Send the running pingd process a SIGTERM.
52    
53    =item B<add> I<address>
54    
55    Add I<address> to the list of remailers to query for
56    keys and confs.
57    
58    =head1 OPTIONS
59    
60    none
61    
62    =back
63    
64    =head1 FILES
65    
66    F<pingd.conf>
67    
68    =head1 AUTHOR
69    
70    Peter Palfrader E<lt>pp@3node.com<gt>
71    
72    =head1 SEE ALSO
73    
74    echolot Documentation
75    
76    =head1 BUGS
77    
78    Please report them at <lt>URL:http://savannah.gnu.org/bugs/?group=echolot<gt>
79    
80    =cut
81    
82  use strict;  use strict;
83  use XML::Parser;  use XML::Parser;
84  use XML::Dumper;  use XML::Dumper;
85  use Getopt::Long;  use Getopt::Long;
86    use English;
87  use lib qw{ . lib };  use lib qw{ . lib };
88  use Echolot::Config;  use Echolot::Config;
89  use Echolot::Globals;  use Echolot::Globals;
# Line 17  use Echolot::Conf; Line 93  use Echolot::Conf;
93  use Echolot::Mailin;  use Echolot::Mailin;
94  use Echolot::Pinger;  use Echolot::Pinger;
95  use Echolot::Stats;  use Echolot::Stats;
96    use Echolot::Commands;
97    
98  $ENV{'PATH'} = '/bin:/usr/bin';  $ENV{'PATH'} = '/bin:/usr/bin';
99  delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};  delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
100    
101  $SIG{'INT'} = sub {  
102          print "Got SIGINT. committ()ing\n";  my $scheduler;
103          Echolot::Globals::get()->{'storage'}->commit();  
104          Echolot::Globals::get()->{'storage'}->finish();  sub setSigHandlers() {
105          exit 0;          $SIG{'HUP'} = sub {
106                    print "Got SIGINT. scheduling readcommands\n";
107                    $scheduler->schedule('readcommands', time() );
108            };
109            $SIG{'INT'} = sub {
110                    print "Got SIGINT. scheduling exit\n";
111                    $scheduler->schedule('exit', time() );
112            };
113            $SIG{'QUIT'} = sub {
114                    print "Got SIGQUIT. scheduling exit\n";
115                    $scheduler->schedule('exit', time() );
116            };
117            $SIG{'TERM'} = sub {
118                    print "Got SIGTERM. scheduling exit\n";
119                    $scheduler->schedule('exit', time() );
120            };
121  };  };
122  $SIG{'QUIT'} = sub {  
123          print "Got SIGQUIT. committ()ing\n";  sub commit_prospective_address() {
124          Echolot::Globals::get()->{'storage'}->commit();          Echolot::Globals::get()->{'storage'}->commit_prospective_address();
         Echolot::Globals::get()->{'storage'}->finish();  
         exit 0;  
125  };  };
126  $SIG{'TERM'} = sub {  
127          print "Got SIGTERM. committ()ing\n";  
128          Echolot::Globals::get()->{'storage'}->commit();  
129          Echolot::Globals::get()->{'storage'}->finish();  
130          exit 0;  #Echolot::Mailin::process();
131    #Echolot::Pinger::send_pings();
132    #Echolot::Mailin::process();
133    #Echolot::Conf::send_requests();
134    #Echolot::Stats::build();
135    
136    
137    
138    my $params;
139    Getopt::Long::config('bundling');
140    if (!GetOptions (
141            'help'    =>  \$params->{'help'},
142            'verbose' =>  \$params->{'verbose'}
143            )) {
144            die ("$PROGRAM_NAME: Usage: $PROGRAM_NAME [-fwhv]\n");
145  };  };
146    if ($params->{'help'}) {
147        print ("Usage: $PROGRAM_NAME [options]\n"); #FIXME
148        exit 0;
149    };
150    
151    my $COMMAND = shift @ARGV;
152    die ("command required\n") unless defined $COMMAND;
153    
154    
155  Echolot::Config::init();  Echolot::Config::init();
156    chdir( Echolot::Config::get()->{'homedir'} );
157  Echolot::Globals::init();  Echolot::Globals::init();
158    
 my $scheduler = new Echolot::Scheduler;  
159    
160  $scheduler->add('processmail' ,     60                                      , 0, \&Echolot::Mailin::process );  if ($COMMAND eq 'add') {
161  $scheduler->add('getkeyconf'  ,   3*60                                      , 0, \&Echolot::Conf::send_requests );          my $address = shift @ARGV;
162  $scheduler->add('ping'        ,  Echolot::Config::get()->{'pinger_interval'}, 0, \&Echolot::Pinger::send_pings );          die ("add requires argument <address>\n") unless defined $address;
163  $scheduler->add('buildstats'  ,     60                                      , 0, \&Echolot::Stats::build );          die ("argument <address> is not a valid email address\n") unless ($address =~ /^[a-zA-Z0-9+.-]+\@[a-zA-Z0-9+.-]+$/ );
164            Echolot::Commands::addCommand("add $address");
165            # FIXME send hup
166    } elsif ($COMMAND eq 'stop') {
167            die ("stop not implemented yet");
168    } elsif ($COMMAND eq 'start') {
169            setSigHandlers();
170            Echolot::Globals::initStorage();
171    
172            $scheduler = new Echolot::Scheduler;
173            $scheduler->add('exit'               ,      -1                                      , 0, 'exit' );
174            $scheduler->add('readcommands'        ,     -1                                      , 0, \&Echolot::Commands::processCommands );
175    
176            $scheduler->add('processmail'         ,     60                                      , 0, \&Echolot::Mailin::process );
177            $scheduler->add('ping'                ,  Echolot::Config::get()->{'pinger_interval'}, 0, \&Echolot::Pinger::send_pings );
178            $scheduler->add('buildstats'          ,     60                                      , 0, \&Echolot::Stats::build );
179    
180  $scheduler->run();          $scheduler->add('commitprospectives'  ,   30*60                                     ,240, \&commit_prospective_address );
181  #Echolot::Mailin::process();          $scheduler->add('getkeyconf'          ,   60*60                                     , 0, \&Echolot::Conf::send_requests );
182  #Echolot::Conf::send_requests();  
183  #Echolot::Stats::build();          $scheduler->run();
184    
185            Echolot::Globals::get()->{'storage'}->commit();
186            Echolot::Globals::get()->{'storage'}->finish();
187    } else {
188            die ("Command $COMMAND unknown");
189    };
190    
 Echolot::Globals::get()->{'storage'}->commit();  
 Echolot::Globals::get()->{'storage'}->finish();  
191  exit 0;  exit 0;
192    
193  # vim: set ts=4 shiftwidth=4:  # vim: set ts=4 shiftwidth=4:

Legend:
Removed from v.53  
changed lines
  Added in v.54

  ViewVC Help
Powered by ViewVC 1.1.5