earlytalker: check connection note for wait length

Issue #58
reputation databases can set $connection->notes(earlytalker_wait)
This commit is contained in:
Matt Simerson 2014-09-12 13:30:56 -07:00
parent 96ff5746bd
commit a53c692c7b
2 changed files with 12 additions and 8 deletions

View File

@ -126,6 +126,14 @@ sub register {
}; };
} }
sub wait_length {
my ($self) = @_;
if ($self->connection->notes('earlytalker_wait')) {
return $self->connection->notes('earlytalker_wait');
}
return $self->{_args}{wait};
};
sub apr_connect_handler { sub apr_connect_handler {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
@ -134,7 +142,7 @@ sub apr_connect_handler {
my $c = $self->qp->{conn} or return DECLINED; my $c = $self->qp->{conn} or return DECLINED;
my $socket = $c->client_socket or return DECLINED; my $socket = $c->client_socket or return DECLINED;
my $timeout = $self->{_args}{'wait'} * 1_000_000; my $timeout = $self->wait_length() * 1_000_000;
my $rc = $socket->poll($c->pool, $timeout, APR::Const::POLLIN()); my $rc = $socket->poll($c->pool, $timeout, APR::Const::POLLIN());
if ($rc == APR::Const::SUCCESS()) { if ($rc == APR::Const::SUCCESS()) {
@ -155,7 +163,7 @@ sub apr_data_handler {
my $c = $self->qp->{conn} or return DECLINED; my $c = $self->qp->{conn} or return DECLINED;
my $socket = $c->client_socket or return DECLINED; my $socket = $c->client_socket or return DECLINED;
my $timeout = $self->{_args}{wait} * 1_000_000; my $timeout = $self->wait_length() * 1_000_000;
my $rc = $socket->poll($c->pool, $timeout, APR::Const::POLLIN()); my $rc = $socket->poll($c->pool, $timeout, APR::Const::POLLIN());
if ($rc == APR::Const::SUCCESS()) { if ($rc == APR::Const::SUCCESS()) {
@ -179,7 +187,7 @@ sub connect_handler {
my $in = new IO::Select; my $in = new IO::Select;
$in->add(\*STDIN) or return DECLINED; $in->add(\*STDIN) or return DECLINED;
if (!$in->can_read($self->{_args}{wait})) { if (!$in->can_read($self->wait_length())) {
return $self->log_and_pass(); return $self->log_and_pass();
} }
@ -200,7 +208,7 @@ sub data_handler {
return DECLINED if $self->is_immune(); return DECLINED if $self->is_immune();
$in->add(\*STDIN) or return DECLINED; $in->add(\*STDIN) or return DECLINED;
if (!$in->can_read($self->{_args}{wait})) { if (!$in->can_read($self->wait_length())) {
return $self->log_and_pass(); return $self->log_and_pass();
} }
@ -209,7 +217,6 @@ sub data_handler {
sub log_and_pass { sub log_and_pass {
my $self = shift; my $self = shift;
my $ip = $self->qp->connection->remote_ip || 'remote host';
$self->log(LOGINFO, "pass, not spontaneous"); $self->log(LOGINFO, "pass, not spontaneous");
return DECLINED; return DECLINED;
} }
@ -217,8 +224,6 @@ sub log_and_pass {
sub log_and_deny { sub log_and_deny {
my $self = shift; my $self = shift;
my $ip = $self->qp->connection->remote_ip || 'remote host';
$self->connection->notes('earlytalker', 1); $self->connection->notes('earlytalker', 1);
$self->adjust_karma(-1); $self->adjust_karma(-1);

View File

@ -144,4 +144,3 @@ sub test_reject_type {
$self->{_args}{reject_type} = 'disconnect'; $self->{_args}{reject_type} = 'disconnect';
cmp_ok( $self->get_reject_type(), '==', DENY_DISCONNECT, "disconnect"); cmp_ok( $self->get_reject_type(), '==', DENY_DISCONNECT, "disconnect");
}; };