Net-IMP
view release on metacpan or search on metacpan
Contrary to stream types a rule must match whole packet, no more and no less.
Configuration keys allow_dup and allow_reorder for unreliable packet
transports like UDP.
0.622 2013/09/16
- Bugfix Cascade
0.621 2013/07/16
- rewrite of Net::IMP::Cascade for hopefully less bugs and better design
0.620 2013/07/03
- don't call callback with no results
0.619 2013/06/28
- with analyzer->busy(dir,busy) the data provider might notify the analyzer,
that it is busy at the moment, mostly because forwarding data is stalled.
0.618 2013/06/27
- added IMP_REPLACE_LATER as a promise to replace a range of data later and
thus let the data provider save space. Added way to not send optional
returns types like IMP_PAUSE, IMP_REPLACE_LATER if data provider does not
provide them
0.617 2013/06/24
- added IMP_FATAL return value to let analyzer propagate internal problems.
Added support in bin/* data providers
0.616 2013/06/21
- added IMP_DATA_TYPES function to Net::IMP to get all registered data types
lib/Net/IMP.pm view on Meta::CPAN
use constant IMP_PASS_PATTERN => dualvar(0x1002,"pass_pattern");
use constant IMP_PREPASS => dualvar(0x1003,"prepass");
### change data
use constant IMP_TOSENDER => dualvar(0x1010,"tosender");
use constant IMP_REPLACE => dualvar(0x1011,"replace");
### affect whole connection
use constant IMP_DENY => dualvar(0x1100,"deny");
use constant IMP_DROP => dualvar(0x1101,"drop");
use constant IMP_FATAL => dualvar(0x1102,"fatal");
# these return values still get sent if the data provider is busy
# the most important are on top
use constant IMP_PASS_IF_BUSY => [
IMP_FATAL,
IMP_DENY,
IMP_DROP,
IMP_PAUSE,
IMP_CONTINUE,
IMP_ACCTFIELD
];
lib/Net/IMP.pm view on Meta::CPAN
Also only streaming data of the same type can be concatenated and
analyzed together.
Results will be delivered through the callback or via C<poll_results>.
=item $analyzer->poll_results => @results
Returns outstanding results.
If a callback is attached, no results will be delivered this way.
=item $analyzer->busy($dir,0|1)
Reports to the analyzer if the data provider is busy and cannot process all
requests. This is usually the case, if the upstream cannot keep up with the
data, so sending gets stalled.
While the data provider is busy the analyzer might still send return values,
which might resolve the busy state, like IMP_DENY, IMP_FATAL etc
=item Net::IMP->set_debug
This is just a convenient way to call C<< Net::IMP::Debug->set_debug >>.
See L<Net::IMP::Debug> for more information.
=back
=head1 TODO
lib/Net/IMP/Base.pm view on Meta::CPAN
use Carp 'croak';
use fields (
'factory_args', # arguments given to new_factory
'meta', # hash with meta data given to new_analyzer
'analyzer_cb', # callback, set from new_analyzer or with set_callback
'analyzer_rv', # collected results for polling or callback, set
# from add_results
'ignore_rv', # hash with return values like IMP_PAUSE or
# IMP_REPLACE_LATER which are unsupported by the data
# provider and can be ignored
'busy', # if data provider is busy
);
use Net::IMP::Debug;
############################################################################
# API plugin methods
############################################################################
# creates new factory
lib/Net/IMP/Base.pm view on Meta::CPAN
sub new_analyzer {
my Net::IMP::Base $factory = shift;
my %args = @_;
my $cb = delete $args{cb};
my $analyzer = fields::new(ref($factory));
%$analyzer = (
%$factory, # common properties of all analyzers
%args, # properties of this analyzer
analyzer_rv => [], # reset queued return values
busy => undef, # busy per dir
);
$analyzer->set_callback(@$cb) if $cb;
return $analyzer;
}
# get available interfaces
# returns factory for the given interface
# might be a new one or same as called on
sub set_interface {
my Net::IMP::Base $factory = shift;
lib/Net/IMP/Base.pm view on Meta::CPAN
# return queued results
sub poll_results {
my Net::IMP::Base $analyzer = shift;
my $rv = $analyzer->{analyzer_rv};
$analyzer->{analyzer_rv} = [];
return @$rv;
}
sub data { die "needs to be implemented" }
sub busy {
my Net::IMP::Base $analyzer = shift;
my ($dir,$busy) = @_;
if ( $busy ) {
return if $analyzer->{busy}
&& $analyzer->{busy}[$dir]; # no change - stay busy
$analyzer->{busy}[$dir] = 1; # unbusy -> busy
} elsif ( ! $analyzer->{busy}
|| ! $analyzer->{busy}[$dir] ) {
return; # no change - stay not busy
} else {
# set to no busy on $dir, maybe no busy at all
$analyzer->{busy}[$dir] = 0; # busy -> unbusy
if ( ! grep { $_ } @{$analyzer->{busy}} ) {
# all dir are not busy anymore
$analyzer->{busy} = undef;
}
}
# run callback, either for important stuff on busy or for
# all stuff if not busy
$analyzer->run_callback;
}
############################################################################
# internal analyzer methods
############################################################################
sub add_results {
my Net::IMP::Base $analyzer = shift;
lib/Net/IMP/Base.pm view on Meta::CPAN
if (@_) {
# add more results
if ( my $ignore = $analyzer->{ignore_rv} ) {
push @$rv, grep { ! $ignore->{$_->[0]+0} } @_;
} else {
push @$rv,@_;
}
}
if ( my $cb = $analyzer->{analyzer_cb} ) {
my ($sub,@args) = @$cb;
if ( my $busy = $analyzer->{busy} ) {
# at least one dir is busy
my (@important,@nobusy,@busy);
for( @$rv ) {
if ( my $lvl = $important{ $_->[0]+0 } ) {
push @important,[ $_, $lvl ]
} elsif ( $busy->[$_->[1]] ) {
push @busy,$_
} else {
push @nobusy,$_
}
}
# sort by importance
@important =
map { $_->[0] } sort { $a->[1] <=> $b->[1] } @important
if @important;
if (@nobusy || @important) {
$analyzer->{analyzer_rv} = \@busy;
$sub->(@args,@important,@nobusy);
} else {
# nothing important enough to call back
}
} elsif (@$rv) {
$analyzer->{analyzer_rv} = []; # reset
$sub->(@args,@$rv); # and call back
}
}
}
}
lib/Net/IMP/Base.pm view on Meta::CPAN
This will return the current C<@results> and remove them from collected
results.
It will only be used from the caller of the analyzer if no callback is set.
=item $analyzer->data($dir,$data,$offset,$dtype)
This method should be defined for all analyzers.
The implementation in this package will just croak.
=item $analyzer->busy($dir,0|1)
This method sets direction $dir to busy.
The analyzer should not propagate results for this direction until it gets
unbusy again (e.g. will accumulate results for later).
The exception are results which might help to solve the busy state, like
IMP_DENY. Also, results not specific for this dir should still be delivered.
=back
Also the following methods are defined for analyzers and can be used inside
your own analyzer.
=over 4
=item $analyzer->add_results(@results)
( run in 0.294 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )