tresor: better handling of hash mismatches

Instead of throwing an uncaught exception, the corresponding request is marked
failed.

Ref #4819
This commit is contained in:
Martin Stein 2023-06-01 10:48:05 +02:00 committed by Norman Feske
parent 7c5c92351e
commit 03d7258d33
4 changed files with 41 additions and 13 deletions

View File

@ -684,6 +684,26 @@ void Free_tree::_execute_update(Channel &chan,
}
void Free_tree::_mark_req_failed(Channel &chan,
bool &progress,
char const *str)
{
error(chan._request.type_name(), " request failed, reason: \"", str, "\"");
chan._request._success = false;
chan._state = Channel::COMPLETE;
progress = true;
}
void Free_tree::_mark_req_successful(Channel &channel,
bool &progress)
{
channel._request._success = true;
channel._state = Channel::COMPLETE;
progress = true;
}
void Free_tree::_execute(Channel &chan,
Snapshots const &active_snaps,
Generation last_secured_gen,
@ -711,19 +731,16 @@ void Free_tree::_execute(Channel &chan,
_execute_update(chan, active_snaps, last_secured_gen, progress);
break;
case Channel::UPDATE_COMPLETE:
chan._request._success = true;
chan._state = Channel::COMPLETE;
_mark_req_successful(chan, progress);
break;
case Channel::COMPLETE:
break;
case Channel::NOT_ENOUGH_FREE_BLOCKS:
chan._request._success = false;
chan._state = Channel::COMPLETE;
progress = true;
_mark_req_failed(chan, progress, "not enough free blocks");
break;
case Channel::TREE_HASH_MISMATCH:
class Exception_1 { };
throw Exception_1 { };
_mark_req_failed(chan, progress, "node hash mismatch");
break;
}
}

View File

@ -110,6 +110,8 @@ class Tresor::Free_tree_request : public Module_request
static char const *type_to_string(Type type);
char const *type_name() const { return type_to_string(_type); }
/********************
** Module_request **
@ -395,6 +397,13 @@ class Tresor::Free_tree : public Module
Block const &block_data,
Type_1_node_block &entries);
void _mark_req_failed(Channel &chan,
bool &progress,
char const *str);
void _mark_req_successful(Channel &chan,
bool &progress);
void
_exchange_type_2_leaves(Generation free_gen,
Tree_level_index max_level,

View File

@ -78,6 +78,8 @@ class Tresor::Meta_tree_request : public Module_request
static char const *type_to_string(Type type);
char const *type_name() const { return type_to_string(_type); }
/********************
** Module_request **

View File

@ -225,13 +225,13 @@ void Meta_tree::generated_request_complete(Module_request &mod_req)
}
void Meta_tree::_mark_req_failed(Channel &channel,
void Meta_tree::_mark_req_failed(Channel &chan,
bool &progress,
char const *str)
{
error("request failed: failed to ", str);
channel._request._success = false;
channel._state = Channel::COMPLETE;
error(chan._request.type_name(), " request failed, reason: \"", str, "\"");
chan._request._success = false;
chan._state = Channel::COMPLETE;
progress = true;
}
@ -464,8 +464,8 @@ void Meta_tree::execute(bool &progress)
case Channel::COMPLETE:
break;
case Channel::TREE_HASH_MISMATCH:
class Exception_1 { };
throw Exception_1 { };
_mark_req_failed(channel, progress, "node hash mismatch");
break;
}
}
}