IS2 parameter setting: Provide reply messages and test them + sequence number
This commit is contained in:
parent
f9c6b77aa1
commit
4288769228
|
|
@ -501,20 +501,31 @@ static int is2_in_parameter(struct worker_t *self, struct client_t *c, IS2Messag
|
|||
goto done;
|
||||
}
|
||||
|
||||
hlog(LOG_INFO, "%s/%s: IS2: Parameter set received: request_id %ul",
|
||||
c->addr_rem, c->username, par->request_id);
|
||||
hlog(LOG_INFO, "%s/%s: IS2: Parameter set received: request_id %d%s",
|
||||
c->addr_rem, c->username, par->request_id,
|
||||
(par->filter_string) ? "filter_string" : "");
|
||||
|
||||
/* prepare reply message */
|
||||
IS2Parameter prep = IS2_PARAMETER__INIT;
|
||||
prep.type = IS2_PARAMETER__TYPE__PARAMETER_FAILED;
|
||||
prep.has_request_id = par->has_request_id;
|
||||
if (prep.has_request_id)
|
||||
prep.request_id = par->request_id;
|
||||
IS2Message rm = IS2_MESSAGE__INIT;
|
||||
rm.type = IS2_MESSAGE__TYPE__PARAMETER;
|
||||
rm.parameter = &prep;
|
||||
|
||||
if (par->filter_string) {
|
||||
filter_set(c, par->filter_string, strlen(par->filter_string));
|
||||
|
||||
prep.type = IS2_PARAMETER__TYPE__PARAMETER_APPLIED;
|
||||
prep.filter_string = c->filter_s;
|
||||
} else {
|
||||
hlog(LOG_WARNING, "%s/%s: IS2: PARAMETER_SET: No parameters found for setting",
|
||||
c->addr_rem, c->username);
|
||||
}
|
||||
|
||||
/*
|
||||
if (ping->ping_type == KEEPALIVE_PING__PING_TYPE__REQUEST) {
|
||||
ping->ping_type = KEEPALIVE_PING__PING_TYPE__REPLY;
|
||||
|
||||
r = is2_write_message(self, c, m);
|
||||
}
|
||||
*/
|
||||
r = is2_write_message(self, c, &rm);
|
||||
|
||||
done:
|
||||
is2_message__free_unpacked(m, NULL);
|
||||
|
|
|
|||
|
|
@ -356,11 +356,13 @@ sub set_filter($$)
|
|||
{
|
||||
my($self, $filter) = @_;
|
||||
|
||||
my $reqid = int(rand(2**30));
|
||||
|
||||
my $im = IS2Message->new({
|
||||
'type' => IS2Message::Type::PARAMETER(),
|
||||
'parameter' => IS2Parameter->new({
|
||||
'type' => IS2Parameter::Type::PARAMETER_SET(),
|
||||
'request_id' => 1, # todo: sequential
|
||||
'request_id' => $reqid, # todo: sequential
|
||||
'filter_string' => $filter
|
||||
})
|
||||
});
|
||||
|
|
@ -369,7 +371,40 @@ sub set_filter($$)
|
|||
$self->is2_frame_out($im->encode);
|
||||
$self->{'sock'}->blocking(0);
|
||||
|
||||
return 1;
|
||||
my $t = time();
|
||||
while (my $l = $self->is2_frame_in()) {
|
||||
my $rep = $l->parameter;
|
||||
if ($l->type == IS2Message::Type::PARAMETER()) {
|
||||
if (!$rep) {
|
||||
$self->{'error'} = "PARAMETER type, but no parameter message";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($rep->request_id != $reqid) {
|
||||
$self->{'error'} = "PARAMETER reply, wrong request id " . $rep->request_id . ", expected $reqid";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($rep->type != IS2Parameter::Type::PARAMETER_APPLIED()) {
|
||||
$self->{'error'} = sprintf("filter set reply: not applied");
|
||||
return 0;
|
||||
}
|
||||
|
||||
# todo: check sequence
|
||||
return 1;
|
||||
} else {
|
||||
$self->{'error'} = "Wrong type of response received for PARAMETER_SET: " . $l->type;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (time() - $t > 5) {
|
||||
$self->{'error'} = "parameter command timed out";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
$self->{'error'} = "No PARAMETER_APPLIED received";
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub is2_frame_out($$)
|
||||
|
|
|
|||
Loading…
Reference in New Issue