Ereshkigal
view release on metacpan or search on metacpan
lib/Ereshkigal/Kur.pm view on Meta::CPAN
return $self->_cmd_cidr_unban($request);
},
'banned' => sub {
return $self->_cmd_banned;
},
'status' => sub {
return $self->_cmd_status;
},
'flush' => sub {
return $self->_cmd_flush;
},
're_init' => sub {
return $self->_cmd_re_init;
},
'checkpoint' => sub {
return $self->_cmd_checkpoint;
},
'clear_retries' => sub {
my ( undef, $request ) = @_;
return $self->_cmd_clear_retries($request);
},
'stop' => sub {
my ( undef, undef, $ctx ) = @_;
return $self->_cmd_stop($ctx);
},
},
);
$self->{server} = $server;
$self->{started} = time;
# the ban sweeper... a self-rescheduling one second alarm that expires
# timed bans and handles the periodic checkpoint... it stops
# rescheduling once stop has been requested so the session ends and the
# kernel can exit... it also watches for TERM/INT so a signaled kur
# still checkpoints and tears the backend down rather than dying with
# the firewall state dangling
POE::Session->create(
'inline_states' => {
'_start' => sub {
$_[KERNEL]->sig( 'TERM', 'sig_shutdown' );
$_[KERNEL]->sig( 'INT', 'sig_shutdown' );
$_[KERNEL]->delay( 'sweep', 1 );
},
'sweep' => sub {
if ( $self->{stopping} ) {
return;
}
$self->_tick;
$_[KERNEL]->delay( 'sweep', 1 );
},
'sig_shutdown' => sub {
my $signal = $_[ARG0];
$_[KERNEL]->sig_handled;
if ( $self->{stopping} ) {
return;
}
log_drek( 'info', 'SIG' . $signal . ' received, tearing the backend down', undef, $ident );
$self->_stop_guts;
# _stop_guts set stopping, so the pending sweep alarm is the
# only thing keeping this session alive... clear it and fire
# the server session's shutdown so the kernel can exit
$_[KERNEL]->delay('sweep');
$_[KERNEL]->post( $ident, 'shutdown' );
},
},
);
log_drek( 'info', 'started... socket=' . $self->socket_path . ' backend=' . $self->{backend}, undef, $ident );
$poe_kernel->run;
log_drek( 'info', 'stopped', undef, $ident );
return;
} ## end sub start_server
# The single choke point for every call into the Net::Firewall::BlockerHelper
# frontend held in $self->{backend_obj}. It exists because that frontend has
# two ways of failing and only one of them is a die... depending on the
# Error::Helper fatality settings in play a failure may instead just warn and
# leave the error flag set, which a bare method call would sail straight past.
# Everything in this module goes through here so both look the same to the
# caller, which is why none of the command handlers check errors themselves.
#
# The method is called on the frontend inside an eval. A die is rethrown as
# is, and if the call survived but left the frontend's error flag set, the
# frontend's errorString is thrown instead.
#
# Args, the first required and the rest optional...
#
# $method :: The name of the method to call on the frontend, as a plain
# string, called as a method so it may be any of the frontend's
# public API... 'ban', 'unban', 'ban_cidr', 'unban_cidr',
# 'list', 'list_cidr', 'check', 'flush', 're_init', or
# 'teardown'. Not validated here, so a name the frontend does
# not implement dies with the usual can't locate object method.
# %args :: The remaining pairs, passed through to that method verbatim.
# In practice this is either empty, for the ones taking no
# arguments, or a single ban => $entry pair for the ban and
# unban family.
#
# Returns whatever the method returned, as a list, propagated unchanged. For
# list and list_cidr that is the entries the firewall is carrying; for check
# it is a single true or false healthy value, which is why callers of that
# assign it as ($healthy); for the rest it is generally empty and ignored.
#
# Dies with either the frontend's own exception or its errorString, neither
# carrying a trailing newline, so a caller wanting to report it cleanly has
# to trim it.
#
# my @banned = $self->_backend_do('list');
#
# $self->_backend_do( 'unban', ban => '1.2.3.4' );
#
# my ($healthy) = $self->_backend_do('check');
sub _backend_do {
my ( $self, $method, %args ) = @_;
my @results;
eval { @results = $self->{backend_obj}->$method(%args); };
( run in 1.042 second using v1.01-cache-2.11-cpan-a49fcb8fa48 )