Commit 9b5e6cdd authored by Dominik Charousset's avatar Dominik Charousset

Maintain a last-seen time for connected BASP nodes

(cherry picked from commit b00983e6)
parent d14154c0
......@@ -6,14 +6,14 @@
#include <unordered_map>
#include "caf/response_promise.hpp"
#include "caf/variant.hpp"
#include "caf/io/connection_handle.hpp"
#include "caf/io/datagram_handle.hpp"
#include "caf/actor_clock.hpp"
#include "caf/io/basp/connection_state.hpp"
#include "caf/io/basp/header.hpp"
#include "caf/io/connection_handle.hpp"
#include "caf/io/datagram_handle.hpp"
#include "caf/response_promise.hpp"
#include "caf/timestamp.hpp"
#include "caf/variant.hpp"
namespace caf::io::basp {
......@@ -32,6 +32,8 @@ struct endpoint_context {
uint16_t local_port;
// pending operations to be performed after handshake completed
optional<response_promise> callback;
// keeps track of when we've last received a message from this endpoint
actor_clock::time_point last_seen;
};
} // namespace caf::io::basp
......@@ -97,6 +97,7 @@ public:
void learned_new_node(const node_id& nid);
/// Sets `this_context` by either creating or accessing state for `hdl`.
/// Automatically sets `endpoint_context::last_seen` to `clock().now()`.
void set_context(connection_handle hdl);
/// Cleans up any state for `hdl`.
......
......@@ -587,6 +587,7 @@ void basp_broker::learned_new_node_indirectly(const node_id& nid) {
void basp_broker::set_context(connection_handle hdl) {
CAF_LOG_TRACE(CAF_ARG(hdl));
auto now = clock().now();
auto i = ctx.find(hdl);
if (i == ctx.end()) {
CAF_LOG_DEBUG("create new BASP context:" << CAF_ARG(hdl));
......@@ -598,8 +599,10 @@ void basp_broker::set_context(connection_handle hdl) {
invalid_actor_id};
i = ctx
.emplace(hdl, basp::endpoint_context{basp::await_header, hdr, hdl,
node_id{}, 0, 0, none})
node_id{}, 0, 0, none, now})
.first;
} else {
i->second.last_seen = now;
}
this_context = &i->second;
t_last_hop = &i->second.id;
......
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