Skip to content

Commit

Permalink
Drop messages from blacklisted paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Neverlord committed Apr 27, 2020
1 parent c1ae1c9 commit 9640781
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
16 changes: 11 additions & 5 deletions include/broker/alm/peer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ public:
publish(content);
}

/// Checks whether a path and its associated vector timestamp are non-empty
/// and loop-free.
/// Checks whether a path and its associated vector timestamp are non-empty,
/// loop-free and not blacklisted.
bool valid (peer_id_list& path, vector_timestamp path_ts) {
// Drop if empty or if path and path_ts have different sizes.
if (path.empty()) {
Expand All @@ -228,6 +228,11 @@ public:
BROKER_DEBUG("drop message: path contains a loop");
return false;
}
// Drop all messages that arrive after blacklisting a path.
if (blacklisted(path, path_ts, blacklist_)) {
BROKER_DEBUG("drop message from a blacklisted path");
return false;
}
return true;
}

Expand All @@ -240,17 +245,18 @@ public:
std::pair<std::vector<peer_id_type>, bool>
handle_update(peer_id_list& path, vector_timestamp path_ts,
const filter_type& filter) {
// The reverse path leads to the sender.
std::vector<peer_id_type> new_peers;
// Extract new peers from the path.
auto is_new = [this](const auto& id) { return !reachable(tbl_, id); };
for (const auto& id : path)
if (is_new(id))
new_peers.emplace_back(id);
// Update the routing table.
auto added_tbl_entry = add_or_update_path(
tbl_, path[0], peer_id_list{path.rbegin(), path.rend()},
vector_timestamp{path_ts.rbegin(), path_ts.rend()});
BROKER_ASSERT(new_peers.empty() || added_tbl_entry);
// We increase our own timestamp only if we have changed the routing table .
// Increase local time, but only if we have changed the routing table.
// Otherwise, we would cause infinite flooding, because the peers would
// never agree on a vector time.
if (added_tbl_entry) {
Expand All @@ -267,7 +273,7 @@ public:
void handle_filter_update(peer_id_list& path, vector_timestamp path_ts,
const filter_type& filter) {
BROKER_TRACE(BROKER_ARG(path) << BROKER_ARG(path_ts) << BROKER_ARG(filter));
// Handle message content (drop nonsense messages).
// Handle message content (drop nonsense messages and blacklisted paths).
if (!valid(path, path_ts))
return;
auto new_peers = std::move(handle_update(path, path_ts, filter).first);
Expand Down
16 changes: 14 additions & 2 deletions include/broker/alm/routing_table.hh
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,20 @@ bool blacklisted(const std::vector<PeerId>& path,
template <class PeerId>
bool blacklisted(const std::vector<PeerId>& path, const vector_timestamp& ts,
const blacklist_entry<PeerId>& entry) {
return blacklisted(path, ts, entry.revoker, entry.timestamp,
entry.revoked_hop);
return blacklisted(path, ts, entry.revoker, entry.ts, entry.hop);
}

/// Checks whether `path` is blacklisted by any entry in `entries`.
template <class PeerId, class Container>
std::enable_if_t<
std::is_same<typename Container::value_type, blacklist_entry<PeerId>>::value,
bool>
blacklisted(const std::vector<PeerId>& path, const vector_timestamp& ts,
const Container& entries) {
for (const auto& entry : entries)
if (blacklisted(path, ts, entry))
return true;
return false;
}

/// Removes all entries form `tbl` where `blacklisted` returns true for given
Expand Down

0 comments on commit 9640781

Please sign in to comment.