Commit b00983e6 authored by Dominik Charousset's avatar Dominik Charousset

Maintain a last-seen time for connected BASP nodes

parent 3ca105e2
...@@ -20,14 +20,14 @@ ...@@ -20,14 +20,14 @@
#include <unordered_map> #include <unordered_map>
#include "caf/variant.hpp" #include "caf/actor_clock.hpp"
#include "caf/response_promise.hpp"
#include "caf/io/datagram_handle.hpp"
#include "caf/io/connection_handle.hpp"
#include "caf/io/basp/header.hpp"
#include "caf/io/basp/connection_state.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 { namespace caf {
namespace io { namespace io {
...@@ -48,6 +48,8 @@ struct endpoint_context { ...@@ -48,6 +48,8 @@ struct endpoint_context {
uint16_t local_port; uint16_t local_port;
// pending operations to be performed after handshake completed // pending operations to be performed after handshake completed
optional<response_promise> callback; optional<response_promise> callback;
// keeps track of when we've last received a message from this endpoint
actor_clock::time_point last_seen;
}; };
} // namespace basp } // namespace basp
......
...@@ -18,24 +18,23 @@ ...@@ -18,24 +18,23 @@
#pragma once #pragma once
#include <future>
#include <map> #include <map>
#include <set> #include <set>
#include <stack> #include <stack>
#include <string> #include <string>
#include <future>
#include <vector>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include <vector>
#include "caf/stateful_actor.hpp"
#include "caf/proxy_registry.hpp"
#include "caf/binary_serializer.hpp"
#include "caf/binary_deserializer.hpp" #include "caf/binary_deserializer.hpp"
#include "caf/binary_serializer.hpp"
#include "caf/forwarding_actor_proxy.hpp" #include "caf/forwarding_actor_proxy.hpp"
#include "caf/io/basp/all.hpp" #include "caf/io/basp/all.hpp"
#include "caf/io/broker.hpp" #include "caf/io/broker.hpp"
#include "caf/io/typed_broker.hpp" #include "caf/io/typed_broker.hpp"
#include "caf/proxy_registry.hpp"
#include "caf/stateful_actor.hpp"
namespace caf { namespace caf {
namespace io { namespace io {
...@@ -108,6 +107,7 @@ public: ...@@ -108,6 +107,7 @@ public:
void learned_new_node(const node_id& nid); void learned_new_node(const node_id& nid);
/// Sets `this_context` by either creating or accessing state for `hdl`. /// 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); void set_context(connection_handle hdl);
/// Cleans up any state for `hdl`. /// Cleans up any state for `hdl`.
......
...@@ -548,6 +548,7 @@ void basp_broker::learned_new_node_indirectly(const node_id& nid) { ...@@ -548,6 +548,7 @@ void basp_broker::learned_new_node_indirectly(const node_id& nid) {
void basp_broker::set_context(connection_handle hdl) { void basp_broker::set_context(connection_handle hdl) {
CAF_LOG_TRACE(CAF_ARG(hdl)); CAF_LOG_TRACE(CAF_ARG(hdl));
auto now = clock().now();
auto i = ctx.find(hdl); auto i = ctx.find(hdl);
if (i == ctx.end()) { if (i == ctx.end()) {
CAF_LOG_DEBUG("create new BASP context:" << CAF_ARG(hdl)); CAF_LOG_DEBUG("create new BASP context:" << CAF_ARG(hdl));
...@@ -559,8 +560,10 @@ void basp_broker::set_context(connection_handle hdl) { ...@@ -559,8 +560,10 @@ void basp_broker::set_context(connection_handle hdl) {
invalid_actor_id}; invalid_actor_id};
i = ctx i = ctx
.emplace(hdl, basp::endpoint_context{basp::await_header, hdr, hdl, .emplace(hdl, basp::endpoint_context{basp::await_header, hdr, hdl,
node_id{}, 0, 0, none}) node_id{}, 0, 0, none, now})
.first; .first;
} else {
i->second.last_seen = now;
} }
this_context = &i->second; this_context = &i->second;
t_last_hop = &i->second.id; 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