Commit 38892b14 authored by Joseph Noir's avatar Joseph Noir

Fix UDP actor handshake & buffer handling

parent bd9f84ce
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "caf/error.hpp" #include "caf/error.hpp"
#include "caf/actor_system_config.hpp" #include "caf/actor_system_config.hpp"
#include "caf/binary_deserializer.hpp" // --- #include "caf/binary_deserializer.hpp"
#include "caf/io/hook.hpp" #include "caf/io/hook.hpp"
#include "caf/io/middleman.hpp" #include "caf/io/middleman.hpp"
...@@ -200,14 +200,6 @@ public: ...@@ -200,14 +200,6 @@ public:
void write_client_handshake(execution_unit* ctx, void write_client_handshake(execution_unit* ctx,
buffer_type& buf, const node_id& remote_side); buffer_type& buf, const node_id& remote_side);
/// Start handshake ... TODO
//void write_udp_client_handshake(execution_unit* ctx, buffer_type& buf);
/// Answer client handshake ... TODO
//void write_udp_server_handshake(execution_unit* ctx, buffer_type& buf,
// const node_id& remote_side,
// optional<uint16_t> port);
/// 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,
const node_id& dest_node, actor_id aid); const node_id& dest_node, actor_id aid);
...@@ -239,7 +231,8 @@ public: ...@@ -239,7 +231,8 @@ public:
bool handle_msg(execution_unit* ctx, const Handle& hdl, header& hdr, bool handle_msg(execution_unit* ctx, const Handle& hdl, header& hdr,
std::vector<char>* payload, bool tcp_based, std::vector<char>* payload, bool tcp_based,
optional<uint16_t> port) { optional<uint16_t> port) {
std::cerr << "Handling " << to_string(hdr.operation) << " msg" << std::endl; // std::cerr << "[MSG] From " << hdl.id() << " (" << to_string(hdr.operation)
// << ")" << std::endl;
auto payload_valid = [&]() -> bool { auto payload_valid = [&]() -> bool {
return payload != nullptr && payload->size() == hdr.payload_len; return payload != nullptr && payload->size() == hdr.payload_len;
}; };
...@@ -321,18 +314,14 @@ public: ...@@ -321,18 +314,14 @@ public:
CAF_LOG_INFO("new direct connection:" << CAF_ARG(hdr.source_node)); CAF_LOG_INFO("new direct connection:" << CAF_ARG(hdr.source_node));
tbl_.add(hdl, hdr.source_node); tbl_.add(hdl, hdr.source_node);
} }
auto path = tbl_.lookup(hdr.source_node); if (!tcp_based) {
if (!path) { write_server_handshake(ctx, wr_buf_.ptr->wr_buf(hdl), port);
CAF_LOG_ERROR("no route to host after server handshake"); wr_buf_.ptr->flush(hdl);
return false;
} }
if (!tcp_based)
write_server_handshake(ctx, path->wr_buf, port);
if (!is_known_node) { if (!is_known_node) {
//auto was_indirect = tbl_.erase_indirect(hdr.source_node); //auto was_indirect = tbl_.erase_indirect(hdr.source_node);
callee_.learned_new_node_directly(hdr.source_node); callee_.learned_new_node_directly(hdr.source_node);
} }
flush(*path);
break; break;
} }
case message_type::dispatch_message: { case message_type::dispatch_message: {
......
...@@ -652,6 +652,7 @@ private: ...@@ -652,6 +652,7 @@ private:
// state for writing // state for writing
manager_ptr writer_; manager_ptr writer_;
bool ack_writes_; bool ack_writes_;
bool writing_;
buffer_type wr_buf_; buffer_type wr_buf_;
buffer_type wr_offline_buf_; buffer_type wr_offline_buf_;
......
...@@ -127,8 +127,9 @@ void basp_broker_state::finalize_handshake(const node_id& nid, actor_id aid, ...@@ -127,8 +127,9 @@ void basp_broker_state::finalize_handshake(const node_id& nid, actor_id aid,
CAF_ASSERT(this_context != nullptr); CAF_ASSERT(this_context != nullptr);
this_context->id = nid; this_context->id = nid;
auto& cb = this_context->callback; auto& cb = this_context->callback;
if (!cb) if (!cb) {
return; return;
}
auto cleanup = detail::make_scope_guard([&] { auto cleanup = detail::make_scope_guard([&] {
cb = none; cb = none;
}); });
...@@ -155,17 +156,6 @@ void basp_broker_state::purge_state(const node_id& nid) { ...@@ -155,17 +156,6 @@ void basp_broker_state::purge_state(const node_id& nid) {
auto hdl = instance.tbl().lookup_hdl(nid); auto hdl = instance.tbl().lookup_hdl(nid);
if (!hdl) if (!hdl)
return; return;
/*
auto i = tcp_ctx.find(hdl);
if (i != tcp_ctx.end()) {
auto& ref = i->second;
if (ref.callback) {
CAF_LOG_DEBUG("connection closed during handshake");
ref.callback->deliver(sec::disconnect_during_handshake);
}
tcp_ctx.erase(i);
}
*/
apply_visitor(purge_state_vis, *hdl); apply_visitor(purge_state_vis, *hdl);
proxies().erase(nid); proxies().erase(nid);
} }
...@@ -487,7 +477,7 @@ void basp_broker_state::set_context(dgram_scribe_handle hdl) { ...@@ -487,7 +477,7 @@ void basp_broker_state::set_context(dgram_scribe_handle hdl) {
hdl, hdl,
endpoint_context{ endpoint_context{
basp::await_header, basp::await_header,
basp::header{basp::message_type::client_handshake, basp::header{basp::message_type::server_handshake,
0, 0, 0, none, none, 0, 0, 0, none, none,
invalid_actor_id, invalid_actor_id}, invalid_actor_id, invalid_actor_id},
hdl, none, 0, none hdl, none, 0, none
......
...@@ -1008,14 +1008,24 @@ default_multiplexer::add_dgram_doorman(abstract_broker* self, ...@@ -1008,14 +1008,24 @@ default_multiplexer::add_dgram_doorman(abstract_broker* self,
// further activities for the broker // further activities for the broker
return false; return false;
auto& dm = acceptor_.backend(); auto& dm = acceptor_.backend();
auto endpoint_info = acceptor_.last_sender();
auto fd = new_dgram_scribe_impl(acceptor_.host(), auto fd = new_dgram_scribe_impl(acceptor_.host(),
acceptor_.port()); acceptor_.port());
{
std::string host;
uint16_t port;
std::tie(host,port) = sender_from_sockaddr(endpoint_info.first,
endpoint_info.second);
// std::cerr << "[DDM] New scribe with " << fd << " for " << host << ":" << port
// << "(or " << acceptor_.host() << ":" << acceptor_.port() << ")"
// << std::endl;
}
if (!fd) { if (!fd) {
CAF_LOG_ERROR(CAF_ARG(fd.error())); CAF_LOG_ERROR(CAF_ARG(fd.error()));
return false; return false;
// return std::move(fd.error()); // return std::move(fd.error());
} }
auto endpoint_info = acceptor_.last_sender(); // auto endpoint_info = acceptor_.last_sender();
auto hdl = dm.add_dgram_scribe(parent(), *fd, auto hdl = dm.add_dgram_scribe(parent(), *fd,
endpoint_info.first, endpoint_info.second, endpoint_info.first, endpoint_info.second,
false); false);
...@@ -1605,6 +1615,7 @@ dgram_communicator::dgram_communicator(default_multiplexer& backend_ref, ...@@ -1605,6 +1615,7 @@ dgram_communicator::dgram_communicator(default_multiplexer& backend_ref,
: event_handler(backend_ref, sockfd), : event_handler(backend_ref, sockfd),
dgram_size_(0), dgram_size_(0),
ack_writes_(false), ack_writes_(false),
writing_(false),
waiting_for_remote_endpoint(true) { waiting_for_remote_endpoint(true) {
// TODO: Set some reasonable default. // TODO: Set some reasonable default.
configure_datagram_size(1500); configure_datagram_size(1500);
...@@ -1641,9 +1652,10 @@ void dgram_communicator::write(const void* buf, size_t num_bytes) { ...@@ -1641,9 +1652,10 @@ void dgram_communicator::write(const void* buf, size_t num_bytes) {
void dgram_communicator::flush(const manager_ptr& mgr) { void dgram_communicator::flush(const manager_ptr& mgr) {
CAF_ASSERT(mgr != nullptr); CAF_ASSERT(mgr != nullptr);
CAF_LOG_TRACE(CAF_ARG(wr_offline_buf_.size())); CAF_LOG_TRACE(CAF_ARG(wr_offline_buf_.size()));
if (!wr_offline_buf_.empty()) { if (!wr_offline_buf_.empty() && !writing_) {
backend().add(operation::write, fd(), this); backend().add(operation::write, fd(), this);
writer_ = mgr; writer_ = mgr;
writing_ = true;
prepare_next_write(); prepare_next_write();
} }
} }
...@@ -1675,7 +1687,13 @@ void dgram_communicator::handle_event(operation op) { ...@@ -1675,7 +1687,13 @@ void dgram_communicator::handle_event(operation op) {
passivate(); passivate();
return; return;
} }
//std::cerr << "[C] Received " << rb << " bytes" << std::endl; // {
// std::string host;
// uint16_t port;
// std::tie(host, port) = sender_from_sockaddr(sockaddr_, sockaddr_len_);
// std::cerr << "[COM] " << fd() << " received " << rb << " bytes from "
// << host << ":" << port << std::endl;
// }
// currently handles the change from acceptor // currently handles the change from acceptor
// to communicator, TODO: Find a better solution // to communicator, TODO: Find a better solution
// Either keep sending to the same endpoint, // Either keep sending to the same endpoint,
...@@ -1686,8 +1704,8 @@ void dgram_communicator::handle_event(operation op) { ...@@ -1686,8 +1704,8 @@ void dgram_communicator::handle_event(operation op) {
remote_endpoint_addr_ = std::move(sockaddr_); remote_endpoint_addr_ = std::move(sockaddr_);
remote_endpoint_addr_len_ = sockaddr_len_; remote_endpoint_addr_len_ = sockaddr_len_;
sockaddr_len_ = 0; sockaddr_len_ = 0;
//std::cerr << "[C] Adapted new endpoint: " << host_ << ":" << port_ // std::cerr << "[COM] Adapted new endpoint: " << host_ << ":" << port_
// << std::endl; // << std::endl;
} }
if (rb > 0) { if (rb > 0) {
auto res = reader_->consume(&backend(), rd_buf_.data(), rb); auto res = reader_->consume(&backend(), rd_buf_.data(), rb);
...@@ -1707,8 +1725,8 @@ void dgram_communicator::handle_event(operation op) { ...@@ -1707,8 +1725,8 @@ void dgram_communicator::handle_event(operation op) {
writer_->io_failure(&backend(), operation::write); writer_->io_failure(&backend(), operation::write);
backend().del(operation::write, fd(), this); backend().del(operation::write, fd(), this);
} else if (wb > 0) { } else if (wb > 0) {
//std::cerr << "[C] Sent " << wb << " bytes to " // std::cerr << "[COM] " << fd() << " sent " << wb << " bytes to "
// << host_ << ":" << port_ << std::endl; // << host_ << ":" << port_ << std::endl;
CAF_ASSERT(wb == wr_buf_.size()); CAF_ASSERT(wb == wr_buf_.size());
if (ack_writes_) if (ack_writes_)
writer_->datagram_sent(&backend(), wb); writer_->datagram_sent(&backend(), wb);
...@@ -1716,8 +1734,8 @@ void dgram_communicator::handle_event(operation op) { ...@@ -1716,8 +1734,8 @@ void dgram_communicator::handle_event(operation op) {
} else { } else {
// TODO: remove this if sure that datagrams are either written // TODO: remove this if sure that datagrams are either written
// as a whole or not at all // as a whole or not at all
std::cerr << "[DC] Partial datagram wrtten: " << wb // std::cerr << "[DC] Partial datagram wrtten: " << wb
<< " of " << wr_buf_.size() << std::endl; // << " of " << wr_buf_.size() << std::endl;
if (writer_) if (writer_)
writer_->io_failure(&backend(), operation::write); writer_->io_failure(&backend(), operation::write);
} }
...@@ -1736,6 +1754,7 @@ void dgram_communicator::prepare_next_write() { ...@@ -1736,6 +1754,7 @@ void dgram_communicator::prepare_next_write() {
CAF_LOG_TRACE(CAF_ARG(wr_buf_.size()) << CAF_ARG(wr_offline_buf_.size())); CAF_LOG_TRACE(CAF_ARG(wr_buf_.size()) << CAF_ARG(wr_offline_buf_.size()));
wr_buf_.clear(); wr_buf_.clear();
if (wr_offline_buf_.empty()) { if (wr_offline_buf_.empty()) {
writing_ = false;
backend().del(operation::write, fd(), this); backend().del(operation::write, fd(), this);
} else { } else {
wr_buf_.swap(wr_offline_buf_); wr_buf_.swap(wr_offline_buf_);
...@@ -1809,7 +1828,14 @@ void dgram_acceptor::handle_event(operation op) { ...@@ -1809,7 +1828,14 @@ void dgram_acceptor::handle_event(operation op) {
passivate(); passivate();
return; return;
} }
//std::cerr << "[A] Received message with " << rb << " bytes" << std::endl; {
std::string host;
uint16_t port;
std::tie(host, port) = sender_from_sockaddr(sockaddr_, sockaddr_len_);
// std::cerr << "[ACC] " << fd() << " received message with " << rb
// << " bytes from " << host << ":" << port << std::endl;
}
bytes_read_ = rb; bytes_read_ = rb;
if (rb > 0) { if (rb > 0) {
std::tie(host_,port_) = sender_from_sockaddr(sockaddr_, sockaddr_len_); std::tie(host_,port_) = sender_from_sockaddr(sockaddr_, sockaddr_len_);
...@@ -1818,8 +1844,8 @@ void dgram_acceptor::handle_event(operation op) { ...@@ -1818,8 +1844,8 @@ void dgram_acceptor::handle_event(operation op) {
if (!res) { if (!res) {
// What is the right way to propagate this? // What is the right way to propagate this?
CAF_LOG_DEBUG("Failure during creation of new udp endpoint"); CAF_LOG_DEBUG("Failure during creation of new udp endpoint");
std::cerr << "[DA] Failure during creation of new udp endpoint" // std::cerr << "[DA] Failure during creation of new udp endpoint"
<< std::endl;; // << std::endl;;
} }
} }
prepare_next_read(); prepare_next_read();
......
...@@ -115,150 +115,6 @@ connection_state instance::handle(execution_unit* ctx, ...@@ -115,150 +115,6 @@ connection_state instance::handle(execution_unit* ctx,
} }
if (!handle_msg(ctx, dm.handle, hdr, payload, true, none)) if (!handle_msg(ctx, dm.handle, hdr, payload, true, none))
return err(); return err();
/*
// function object for checking payload validity
auto payload_valid = [&]() -> bool {
return payload != nullptr && payload->size() == hdr.payload_len;
};
// handle message to ourselves
switch (hdr.operation) {
case message_type::server_handshake: {
actor_id aid = invalid_actor_id;
std::set<std::string> sigs;
if (payload_valid()) {
binary_deserializer bd{ctx, *payload};
std::string remote_appid;
auto e = bd(remote_appid);
if (e)
return err();
if (remote_appid != callee_.system().config().middleman_app_identifier) {
CAF_LOG_ERROR("app identifier mismatch");
return err();
}
e = bd(aid, sigs);
if (e)
return err();
} else {
CAF_LOG_ERROR("fail to receive the app identifier");
return err();
}
// close self connection after handshake is done
if (hdr.source_node == this_node_) {
CAF_LOG_INFO("close connection to self immediately");
callee_.finalize_handshake(hdr.source_node, aid, sigs);
return err();
}
// close this connection if we already have a direct connection
if (tbl_.lookup_hdl(hdr.source_node)) {
CAF_LOG_INFO("close connection since we already have a "
"direct connection: " << CAF_ARG(hdr.source_node));
callee_.finalize_handshake(hdr.source_node, aid, sigs);
return err();
}
// add direct route to this node and remove any indirect entry
CAF_LOG_INFO("new direct connection:" << CAF_ARG(hdr.source_node));
tbl_.add(dm.handle, hdr.source_node);
// auto was_indirect = tbl_.erase_indirect(hdr.source_node);
// write handshake as client in response
auto path = tbl_.lookup(hdr.source_node);
if (!path) {
CAF_LOG_ERROR("no route to host after server handshake");
return err();
}
write_client_handshake(ctx, path->wr_buf, hdr.source_node);
callee_.learned_new_node_directly(hdr.source_node);
callee_.finalize_handshake(hdr.source_node, aid, sigs);
flush(*path);
break;
}
case message_type::client_handshake: {
if (tbl_.lookup_hdl(hdr.source_node)) {
CAF_LOG_INFO("received second client handshake:"
<< CAF_ARG(hdr.source_node));
break;
}
if (payload_valid()) {
binary_deserializer bd{ctx, *payload};
std::string remote_appid;
auto e = bd(remote_appid);
if (e)
return err();
if (remote_appid != callee_.system().config().middleman_app_identifier) {
CAF_LOG_ERROR("app identifier mismatch");
return err();
}
} else {
CAF_LOG_ERROR("fail to receive the app identifier");
return err();
}
// add direct route to this node and remove any indirect entry
CAF_LOG_INFO("new direct connection:" << CAF_ARG(hdr.source_node));
tbl_.add(dm.handle, hdr.source_node);
// auto was_indirect = tbl_.erase_indirect(hdr.source_node);
callee_.learned_new_node_directly(hdr.source_node);
break;
}
case message_type::dispatch_message: {
if (!payload_valid())
return err();
// in case the sender of this message was received via a third node,
// we assume that that node to offers a route to the original source
//auto last_hop = tbl_.lookup_node(dm.handle);
// TODO: if we don't need this anymore, what does the rest do here?
//if (hdr.source_node != none
// && hdr.source_node != this_node_
// && last_hop != hdr.source_node
// && tbl_.lookup_hdl(hdr.source_node))
// && tbl_.add_indirect(last_hop, hdr.source_node))
// callee_.learned_new_node_indirectly(hdr.source_node);
binary_deserializer bd{ctx, *payload};
auto receiver_name = static_cast<atom_value>(0);
std::vector<strong_actor_ptr> forwarding_stack;
message msg;
if (hdr.has(header::named_receiver_flag)) {
auto e = bd(receiver_name);
if (e)
return err();
}
auto e = bd(forwarding_stack, msg);
if (e)
return err();
CAF_LOG_DEBUG(CAF_ARG(forwarding_stack) << CAF_ARG(msg));
if (hdr.has(header::named_receiver_flag))
callee_.deliver(hdr.source_node, hdr.source_actor, receiver_name,
message_id::from_integer_value(hdr.operation_data),
forwarding_stack, msg);
else
callee_.deliver(hdr.source_node, hdr.source_actor, hdr.dest_actor,
message_id::from_integer_value(hdr.operation_data),
forwarding_stack, msg);
break;
}
case message_type::announce_proxy:
callee_.proxy_announced(hdr.source_node, hdr.dest_actor);
break;
case message_type::kill_proxy: {
if (!payload_valid())
return err();
binary_deserializer bd{ctx, *payload};
error fail_state;
auto e = bd(fail_state);
if (e)
return err();
callee_.kill_proxy(hdr.source_node, hdr.source_actor, fail_state);
break;
}
case message_type::heartbeat: {
CAF_LOG_TRACE("received heartbeat: " << CAF_ARG(hdr.source_node));
callee_.handle_heartbeat(hdr.source_node);
break;
}
default:
CAF_LOG_ERROR("invalid operation");
std::cerr << "[I] Invalid message type" << std::endl;
return err();
}
*/
return await_header; return await_header;
} }
...@@ -309,177 +165,6 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) { ...@@ -309,177 +165,6 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) {
} }
if (!handle_msg(ctx, dm.handle, hdr, payload, false, dm.port)) if (!handle_msg(ctx, dm.handle, hdr, payload, false, dm.port))
return err(); return err();
/*
// function object for checking payload validity
auto payload_valid = [&]() -> bool {
return payload != nullptr && payload->size() == hdr.payload_len;
};
// handle message ourselves
switch (hdr.operation) {
case message_type::server_handshake: {
std::cerr << "[I] Received UDP server handshake" << std::endl;
// TODO: test if this is the second time the handshake takes place ...
//if (tbl_.lookup(hdr.source_node)) {
// std::cerr << "[I] Second handshake received from node" << std::endl;
// break;
//}
actor_id aid = invalid_actor_id;
std::set<std::string> sigs;
if (payload_valid()) {
binary_deserializer bd{ctx, *payload};
std::string remote_appid;
auto e = bd(remote_appid);
if (e)
return err();
if (remote_appid !=
callee_.system().config().middleman_app_identifier) {
CAF_LOG_ERROR("app identifier mismatch");
return err();
}
e = bd(aid, sigs);
if (e)
return err();
} else {
CAF_LOG_ERROR("fail to receive the app identifier");
return err();
}
// close self connection after handshake is done
if (hdr.source_node == this_node_) {
CAF_LOG_INFO("close connection to self immediately");
callee_.finalize_handshake(hdr.source_node, aid, sigs);
return err();
}
// close this connection if we already have a direct connection
if (tbl_.lookup_hdl(hdr.source_node)) {
CAF_LOG_INFO("close connection since we already have a "
"direct connection: " << CAF_ARG(hdr.source_node));
callee_.finalize_handshake(hdr.source_node, aid, sigs);
return err();
}
// add direct route to this node and remove any indirect entry
CAF_LOG_INFO("new direct connection:" << CAF_ARG(hdr.source_node));
tbl_.add(dm.handle, hdr.source_node);
// auto was_indirect = tbl_.erase_indirect(hdr.source_node);
// write handshake as client in response
auto path = tbl_.lookup(hdr.source_node);
if (!path) {
CAF_LOG_ERROR("no route to host after server handshake");
return err();
}
callee_.learned_new_node_directly(hdr.source_node);
callee_.finalize_handshake(hdr.source_node, aid, sigs);
flush(*path);
break;
}
case message_type::client_handshake: {
std::cerr << "[I] Received UDP client handshake" << std::endl;
if (!tbl_.lookup_hdl(hdr.source_node)) {
std::cerr << "[I] Node not found, is a new client" << std::endl;
if (payload_valid()) {
std::cerr << "[I] Has valid payload of " << hdr.payload_len
<< " bytes" << std::endl;
binary_deserializer bd{ctx, *payload};
std::string remote_appid;
auto e = bd(remote_appid);
if (e)
return err();
if (remote_appid !=
callee_.system().config().middleman_app_identifier) {
CAF_LOG_ERROR("app identifier mismatch");
std::cerr << "[I] App identifier mismatch" << std::endl;
return err();
}
} else {
CAF_LOG_ERROR("failed to receive the app identifier");
std::cerr << "[I] Failed to receive the app identifier" << std::endl;
return err();
}
// add direct route to this node and remove any indirect entry
CAF_LOG_INFO("new direct connection:" << CAF_ARG(hdr.source_node));
tbl_.add(dm.handle, hdr.source_node);
// auto was_indirect = tbl_.erase_indirect(hdr.source_node);
callee_.learned_new_node_directly(hdr.source_node);
}
// write handshake as server in response
auto path = tbl_.lookup(hdr.source_node);
if (!path) {
CAF_LOG_ERROR("no route to host after server handshake");
return err();
}
write_server_handshake(ctx, path->wr_buf, dm.port);
break;
}
case message_type::dispatch_message: {
std::cerr << "[I] Received dispatch message" << std::endl;
if (!payload_valid())
return err();
// in case the sender of this message was received via a third node,
// we assume that that node to offers a route to the original source
//auto last_hop = tbl_.lookup_node(dm.handle);
// TODO: if we don't need this anymore, what does the rest do here?
//if (hdr.source_node != none
// && hdr.source_node != this_node_
// && last_hop != hdr.source_node
// && tbl_.lookup_hdl(hdr.source_node))
// && tbl_.add_indirect(last_hop, hdr.source_node))
// callee_.learned_new_node_indirectly(hdr.source_node);
binary_deserializer bd{ctx, *payload};
auto receiver_name = static_cast<atom_value>(0);
std::vector<strong_actor_ptr> forwarding_stack;
message msg;
if (hdr.has(header::named_receiver_flag)) {
auto e = bd(receiver_name);
if (e)
return err();
}
auto e = bd(forwarding_stack, msg);
if (e)
return err();
CAF_LOG_DEBUG(CAF_ARG(forwarding_stack) << CAF_ARG(msg));
if (hdr.has(header::named_receiver_flag)) {
callee_.deliver(hdr.source_node, hdr.source_actor, receiver_name,
message_id::from_integer_value(hdr.operation_data),
forwarding_stack, msg);
} else {
callee_.deliver(hdr.source_node, hdr.source_actor, hdr.dest_actor,
message_id::from_integer_value(hdr.operation_data),
forwarding_stack, msg);
}
break;
}
case message_type::announce_proxy:
std::cerr << "[I] Received announce proxy message" << std::endl;
callee_.proxy_announced(hdr.source_node, hdr.dest_actor);
break;
case message_type::kill_proxy: {
std::cerr << "[I] message_type::kill_proxy" << std::endl;
if (!payload_valid())
return err();
binary_deserializer bd{ctx, *payload};
error fail_state;
auto e = bd(fail_state);
if (e)
return err();
callee_.kill_proxy(hdr.source_node, hdr.source_actor, fail_state);
break;
}
case message_type::heartbeat: {
std::cerr << "[I] Received heartbeat message" << std::endl;
CAF_LOG_TRACE("received heartbeat: " << CAF_ARG(hdr.source_node));
std::cerr << "[I] Received hearbeat: " << to_string(hdr.source_node)
<< std::endl;
callee_.handle_heartbeat(hdr.source_node);
break;
}
default:
CAF_LOG_ERROR("invalid operation");
std::cerr << "[I] Invalid operation" << std::endl;
return err();
}
*/
} while (dgram_itr != dm.buf.end()); } while (dgram_itr != dm.buf.end());
return true; return true;
}; };
...@@ -605,7 +290,6 @@ void instance::write(execution_unit* ctx, buffer_type& buf, ...@@ -605,7 +290,6 @@ void instance::write(execution_unit* ctx, buffer_type& buf,
// << to_string(hdr.operation) << " message" << std::endl; // << to_string(hdr.operation) << " message" << std::endl;
error err; error err;
if (pw) { if (pw) {
//std::cerr << "[W] Has payload writer" << std::endl;
auto pos = buf.size(); auto pos = buf.size();
// write payload first (skip first 72 bytes and write header later) // write payload first (skip first 72 bytes and write header later)
char placeholder[basp::header_size]; char placeholder[basp::header_size];
...@@ -617,6 +301,8 @@ void instance::write(execution_unit* ctx, buffer_type& buf, ...@@ -617,6 +301,8 @@ void instance::write(execution_unit* ctx, buffer_type& buf,
hdr.payload_len = static_cast<uint32_t>(plen); hdr.payload_len = static_cast<uint32_t>(plen);
stream_serializer<charbuf> out{ctx, buf.data() + pos, basp::header_size}; stream_serializer<charbuf> out{ctx, buf.data() + pos, basp::header_size};
err = out(hdr); err = out(hdr);
// std::cerr << "Wrote " << to_string(hdr.operation) << " with " << basp::header_size
// << " + " << hdr.payload_len << " bytes" << std::endl;
} else { } else {
binary_serializer bs{ctx, buf}; binary_serializer bs{ctx, buf};
err = bs(hdr); err = bs(hdr);
...@@ -656,6 +342,8 @@ void instance::write_server_handshake(execution_unit* ctx, buffer_type& buf, ...@@ -656,6 +342,8 @@ void instance::write_server_handshake(execution_unit* ctx, buffer_type& buf,
this_node_, none, this_node_, none,
pa && pa->first ? pa->first->id() : invalid_actor_id, pa && pa->first ? pa->first->id() : invalid_actor_id,
invalid_actor_id}; invalid_actor_id};
// std::cerr << "Writing server handshake, published actor "
// << (pa ? "found" : "unknwon") << std::endl;
write(ctx, buf, hdr, &writer); write(ctx, buf, hdr, &writer);
} }
...@@ -671,54 +359,6 @@ void instance::write_client_handshake(execution_unit* ctx, buffer_type& buf, ...@@ -671,54 +359,6 @@ void instance::write_client_handshake(execution_unit* ctx, buffer_type& buf,
write(ctx, buf, hdr, &writer); write(ctx, buf, hdr, &writer);
} }
/*
void instance::write_udp_client_handshake(execution_unit* ctx,
buffer_type& buf) {
CAF_LOG_TRACE("");
auto writer = make_callback([&](serializer& sink) -> error {
auto& str = callee_.system().config().middleman_app_identifier;
return sink(const_cast<std::string&>(str));
});
header hdr{message_type::udp_client_handshake, 0, 0, version,
this_node_, none, invalid_actor_id, invalid_actor_id};
write(ctx, buf, hdr, &writer);
}
void instance::write_udp_server_handshake(execution_unit* ctx,
buffer_type& buf,
const node_id& remote_side,
optional<uint16_t> port) {
CAF_LOG_TRACE(CAF_ARG(port));
using namespace detail;
published_actor* pa = nullptr;
if (port) {
auto i = published_actors_.find(*port);
if (i != published_actors_.end())
pa = &i->second;
}
CAF_LOG_DEBUG_IF(!pa && port, "no actor published");
auto writer = make_callback([&](serializer& sink) -> error {
auto& ref = callee_.system().config().middleman_app_identifier;
auto e = sink(const_cast<std::string&>(ref));
if (e)
return e;
if (pa) {
auto i = pa->first ? pa->first->id() : invalid_actor_id;
return sink(i, pa->second);
} else {
auto aid = invalid_actor_id;
std::set<std::string> tmp;
return sink(aid, tmp);
}
});
header hdr{message_type::udp_server_handshake, 0, 0, version,
this_node_, remote_side,
pa && pa->first ? pa->first->id() : invalid_actor_id,
invalid_actor_id};
write(ctx, buf, hdr, &writer);
}
*/
void instance::write_announce_proxy(execution_unit* ctx, buffer_type& buf, void instance::write_announce_proxy(execution_unit* ctx, buffer_type& buf,
const node_id& dest_node, actor_id aid) { const node_id& dest_node, actor_id aid) {
CAF_LOG_TRACE(CAF_ARG(dest_node) << CAF_ARG(aid)); CAF_LOG_TRACE(CAF_ARG(dest_node) << CAF_ARG(aid));
......
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