Commit 0b186219 authored by Dominik Charousset's avatar Dominik Charousset

Catch repeated handshakes

parent 7545d114
...@@ -36,6 +36,7 @@ enum class ec : uint8_t { ...@@ -36,6 +36,7 @@ enum class ec : uint8_t {
illegal_state, illegal_state,
invalid_handshake, invalid_handshake,
missing_handshake, missing_handshake,
unexpected_handshake,
version_mismatch, version_mismatch,
unimplemented, unimplemented,
app_identifiers_mismatch, app_identifiers_mismatch,
......
...@@ -102,6 +102,8 @@ error application::handle(span<const byte> bytes) { ...@@ -102,6 +102,8 @@ error application::handle(span<const byte> bytes) {
error application::handle(header hdr, span<const byte>) { error application::handle(header hdr, span<const byte>) {
switch (hdr.type) { switch (hdr.type) {
case message_type::handshake:
return ec::unexpected_handshake;
case message_type::heartbeat: case message_type::heartbeat:
return none; return none;
default: default:
......
...@@ -158,6 +158,20 @@ CAF_TEST(app identifier mismatch) { ...@@ -158,6 +158,20 @@ CAF_TEST(app identifier mismatch) {
basp::ec::app_identifiers_mismatch); basp::ec::app_identifiers_mismatch);
} }
CAF_TEST(repeated handshake) {
handle_handshake();
consume_handshake();
CAF_CHECK_EQUAL(app.state(), basp::connection_state::await_header);
node_id no_nid;
std::vector<std::string> no_ids;
auto payload = to_buf(no_nid, no_ids);
set_input(basp::header{basp::message_type::handshake,
static_cast<uint32_t>(payload.size()), basp::version});
CAF_CHECK_EQUAL(app.handle_data(*this, input), none);
CAF_CHECK_EQUAL(app.handle_data(*this, payload),
basp::ec::unexpected_handshake);
}
CAF_TEST(heartbeat message) { CAF_TEST(heartbeat message) {
handle_handshake(); handle_handshake();
consume_handshake(); consume_handshake();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment