Commit 67b7161c authored by Dominik Charousset's avatar Dominik Charousset

Remove message forwarding

In our BASP redesign, we have decided to remove the (broken) overlay
aspect. Instead, we enable automatic connections per default and require
CAF nodes to establish connections before exchanging messages.
parent fac1cc62
...@@ -22,13 +22,10 @@ ...@@ -22,13 +22,10 @@
#include <cstdint> #include <cstdint>
#include "caf/error.hpp" #include "caf/error.hpp"
#include "caf/node_id.hpp" #include "caf/io/basp/message_type.hpp"
#include "caf/meta/omittable.hpp" #include "caf/meta/omittable.hpp"
#include "caf/meta/type_name.hpp" #include "caf/meta/type_name.hpp"
#include "caf/io/basp/message_type.hpp"
namespace caf { namespace caf {
namespace io { namespace io {
namespace basp { namespace basp {
...@@ -46,20 +43,16 @@ struct header { ...@@ -46,20 +43,16 @@ struct header {
uint8_t flags; uint8_t flags;
uint32_t payload_len; uint32_t payload_len;
uint64_t operation_data; uint64_t operation_data;
node_id source_node;
node_id dest_node;
actor_id source_actor; actor_id source_actor;
actor_id dest_actor; actor_id dest_actor;
header(message_type m_operation, uint8_t m_flags, uint32_t m_payload_len, header(message_type m_operation, uint8_t m_flags, uint32_t m_payload_len,
uint64_t m_operation_data, node_id m_source_node, node_id m_dest_node, uint64_t m_operation_data, actor_id m_source_actor,
actor_id m_source_actor, actor_id m_dest_actor) actor_id m_dest_actor)
: operation(m_operation), : operation(m_operation),
flags(m_flags), flags(m_flags),
payload_len(m_payload_len), payload_len(m_payload_len),
operation_data(m_operation_data), operation_data(m_operation_data),
source_node(std::move(m_source_node)),
dest_node(std::move(m_dest_node)),
source_actor(m_source_actor), source_actor(m_source_actor),
dest_actor(m_dest_actor) { dest_actor(m_dest_actor) {
// nop // nop
...@@ -80,13 +73,9 @@ struct header { ...@@ -80,13 +73,9 @@ struct header {
template <class Inspector> template <class Inspector>
typename Inspector::result_type inspect(Inspector& f, header& hdr) { typename Inspector::result_type inspect(Inspector& f, header& hdr) {
uint8_t pad = 0; uint8_t pad = 0;
return f(meta::type_name("header"), return f(meta::type_name("header"), hdr.operation, meta::omittable(), pad,
hdr.operation, meta::omittable(), pad, hdr.flags, hdr.payload_len,
meta::omittable(), pad, hdr.operation_data, hdr.source_actor, hdr.dest_actor);
meta::omittable(), pad,
hdr.flags, hdr.payload_len, hdr.operation_data,
hdr.source_node, hdr.dest_node,
hdr.source_actor, hdr.dest_actor);
} }
/// @relates header /// @relates header
...@@ -113,8 +102,7 @@ inline bool is_heartbeat(const header& hdr) { ...@@ -113,8 +102,7 @@ inline bool is_heartbeat(const header& hdr) {
bool valid(const header& hdr); bool valid(const header& hdr);
/// Size of a BASP header in serialized form /// Size of a BASP header in serialized form
constexpr size_t header_size = node_id::serialized_size * 2 constexpr size_t header_size = sizeof(actor_id) * 2
+ sizeof(actor_id) * 2
+ sizeof(uint32_t) * 2 + sizeof(uint32_t) * 2
+ sizeof(uint64_t); + sizeof(uint64_t);
......
...@@ -200,15 +200,12 @@ public: ...@@ -200,15 +200,12 @@ public:
buffer_type& out_buf, optional<uint16_t> port); buffer_type& out_buf, optional<uint16_t> port);
/// Writes the client handshake to `buf`. /// Writes the client handshake to `buf`.
static void write_client_handshake(execution_unit* ctx, static void write_client_handshake(execution_unit* ctx, buffer_type& buf,
buffer_type& buf,
const node_id& remote_side,
const node_id& this_node, const node_id& this_node,
const std::string& app_identifier); const std::string& app_identifier);
/// Writes the client handshake to `buf`. /// Writes the client handshake to `buf`.
void write_client_handshake(execution_unit* ctx, void write_client_handshake(execution_unit* ctx, buffer_type& buf);
buffer_type& buf, const node_id& remote_side);
/// Writes an `announce_proxy` to `buf`. /// Writes an `announce_proxy` to `buf`.
void write_announce_proxy(execution_unit* ctx, buffer_type& buf, void write_announce_proxy(execution_unit* ctx, buffer_type& buf,
...@@ -220,8 +217,7 @@ public: ...@@ -220,8 +217,7 @@ public:
const error& rsn); const error& rsn);
/// Writes a `heartbeat` to `buf`. /// Writes a `heartbeat` to `buf`.
void write_heartbeat(execution_unit* ctx, buffer_type& buf, void write_heartbeat(execution_unit* ctx, buffer_type& buf);
const node_id& remote_side);
const node_id& this_node() const { const node_id& this_node() const {
return this_node_; return this_node_;
......
...@@ -338,9 +338,9 @@ void basp_broker_state::learned_new_node(const node_id& nid) { ...@@ -338,9 +338,9 @@ void basp_broker_state::learned_new_node(const node_id& nid) {
} }
// send message to SpawnServ of remote node // send message to SpawnServ of remote node
basp::header hdr{basp::message_type::dispatch_message, basp::header hdr{basp::message_type::dispatch_message,
basp::header::named_receiver_flag, basp::header::named_receiver_flag, 0,
0, make_message_id().integer_value(), this_node(), nid, make_message_id().integer_value(), tmp.id(),
tmp.id(), invalid_actor_id}; invalid_actor_id};
// writing std::numeric_limits<actor_id>::max() is a hack to get // writing std::numeric_limits<actor_id>::max() is a hack to get
// this send-to-named-actor feature working with older CAF releases // this send-to-named-actor feature working with older CAF releases
instance.write(self->context(), get_buffer(path->hdl), instance.write(self->context(), get_buffer(path->hdl),
...@@ -388,9 +388,9 @@ void basp_broker_state::learned_new_node_indirectly(const node_id& nid) { ...@@ -388,9 +388,9 @@ void basp_broker_state::learned_new_node_indirectly(const node_id& nid) {
return sink(name_atm, stages, msg); return sink(name_atm, stages, msg);
}); });
basp::header hdr{basp::message_type::dispatch_message, basp::header hdr{basp::message_type::dispatch_message,
basp::header::named_receiver_flag, basp::header::named_receiver_flag, 0,
0, make_message_id().integer_value(), this_node(), nid, make_message_id().integer_value(), tmp.id(),
tmp.id(), invalid_actor_id}; invalid_actor_id};
instance.write(self->context(), get_buffer(path->hdl), instance.write(self->context(), get_buffer(path->hdl),
hdr, &writer); hdr, &writer);
instance.flush(*path); instance.flush(*path);
...@@ -403,7 +403,7 @@ void basp_broker_state::set_context(connection_handle hdl) { ...@@ -403,7 +403,7 @@ void basp_broker_state::set_context(connection_handle hdl) {
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));
basp::header hdr{basp::message_type::server_handshake, 0, 0, 0, none, none, basp::header hdr{basp::message_type::server_handshake, 0, 0, 0,
invalid_actor_id, invalid_actor_id}; 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,
...@@ -544,9 +544,8 @@ behavior basp_broker::make_behavior() { ...@@ -544,9 +544,8 @@ behavior basp_broker::make_behavior() {
return sink(dest_name, cme->stages, const_cast<message&>(msg)); return sink(dest_name, cme->stages, const_cast<message&>(msg));
}); });
basp::header hdr{basp::message_type::dispatch_message, basp::header hdr{basp::message_type::dispatch_message,
basp::header::named_receiver_flag, basp::header::named_receiver_flag, 0,
0, cme->mid.integer_value(), state.this_node(), cme->mid.integer_value(), src->id(), invalid_actor_id};
dest_node, src->id(), invalid_actor_id};
state.instance.write(context(), state.get_buffer(path->hdl), state.instance.write(context(), state.get_buffer(path->hdl),
hdr, &writer); hdr, &writer);
state.instance.flush(*path); state.instance.flush(*path);
......
...@@ -48,8 +48,7 @@ behavior datagram_connection_broker(broker* self, uint16_t port, ...@@ -48,8 +48,7 @@ behavior datagram_connection_broker(broker* self, uint16_t port,
auto hdl = (*eptr)->hdl(); auto hdl = (*eptr)->hdl();
self->add_datagram_servant(std::move(*eptr)); self->add_datagram_servant(std::move(*eptr));
basp::instance::write_client_handshake(self->context(), basp::instance::write_client_handshake(self->context(),
self->wr_buf(hdl), self->wr_buf(hdl), this_node,
none, this_node,
app_id); app_id);
} }
} }
......
...@@ -40,8 +40,6 @@ std::string to_string(const header &hdr) { ...@@ -40,8 +40,6 @@ std::string to_string(const header &hdr) {
<< to_bin(hdr.flags) << ", " << to_bin(hdr.flags) << ", "
<< hdr.payload_len << ", " << hdr.payload_len << ", "
<< hdr.operation_data << ", " << hdr.operation_data << ", "
<< to_string(hdr.source_node) << ", "
<< to_string(hdr.dest_node) << ", "
<< hdr.source_actor << ", " << hdr.source_actor << ", "
<< hdr.dest_actor << hdr.dest_actor
<< "}"; << "}";
...@@ -53,69 +51,42 @@ bool operator==(const header& lhs, const header& rhs) { ...@@ -53,69 +51,42 @@ bool operator==(const header& lhs, const header& rhs) {
&& lhs.flags == rhs.flags && lhs.flags == rhs.flags
&& lhs.payload_len == rhs.payload_len && lhs.payload_len == rhs.payload_len
&& lhs.operation_data == rhs.operation_data && lhs.operation_data == rhs.operation_data
&& lhs.source_node == rhs.source_node
&& lhs.dest_node == rhs.dest_node
&& lhs.source_actor == rhs.source_actor && lhs.source_actor == rhs.source_actor
&& lhs.dest_actor == rhs.dest_actor; && lhs.dest_actor == rhs.dest_actor;
} }
namespace { namespace {
bool valid(const node_id& val) {
return val != none;
}
template <class T> template <class T>
bool zero(T val) { bool zero(T val) {
return val == 0; return val == 0;
} }
bool server_handshake_valid(const header& hdr) { bool server_handshake_valid(const header& hdr) {
return valid(hdr.source_node) return !zero(hdr.operation_data);
&& zero(hdr.dest_actor)
&& !zero(hdr.operation_data);
} }
bool client_handshake_valid(const header& hdr) { bool client_handshake_valid(const header& hdr) {
return valid(hdr.source_node) return zero(hdr.source_actor) && zero(hdr.dest_actor);
&& hdr.source_node != hdr.dest_node
&& zero(hdr.source_actor)
&& zero(hdr.dest_actor);
} }
bool dispatch_message_valid(const header& hdr) { bool dispatch_message_valid(const header& hdr) {
return valid(hdr.dest_node) return (!zero(hdr.dest_actor) || hdr.has(header::named_receiver_flag))
&& (!zero(hdr.dest_actor) || hdr.has(header::named_receiver_flag))
&& !zero(hdr.payload_len); && !zero(hdr.payload_len);
} }
bool announce_proxy_instance_valid(const header& hdr) { bool announce_proxy_instance_valid(const header& hdr) {
return valid(hdr.source_node) return zero(hdr.source_actor) && !zero(hdr.dest_actor)
&& valid(hdr.dest_node) && zero(hdr.payload_len) && zero(hdr.operation_data);
&& hdr.source_node != hdr.dest_node
&& zero(hdr.source_actor)
&& !zero(hdr.dest_actor)
&& zero(hdr.payload_len)
&& zero(hdr.operation_data);
} }
bool kill_proxy_instance_valid(const header& hdr) { bool kill_proxy_instance_valid(const header& hdr) {
return valid(hdr.source_node) return !zero(hdr.source_actor) && zero(hdr.dest_actor)
&& valid(hdr.dest_node) && !zero(hdr.payload_len) && zero(hdr.operation_data);
&& hdr.source_node != hdr.dest_node
&& !zero(hdr.source_actor)
&& zero(hdr.dest_actor)
&& !zero(hdr.payload_len)
&& zero(hdr.operation_data);
} }
bool heartbeat_valid(const header& hdr) { bool heartbeat_valid(const header& hdr) {
return valid(hdr.source_node) return zero(hdr.source_actor) && zero(hdr.dest_actor) && zero(hdr.payload_len)
&& valid(hdr.dest_node)
&& hdr.source_node != hdr.dest_node
&& zero(hdr.source_actor)
&& zero(hdr.dest_actor)
&& zero(hdr.payload_len)
&& zero(hdr.operation_data); && zero(hdr.operation_data);
} }
......
This diff is collapsed.
This diff is collapsed.
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