Commit 1961b3fd authored by Joseph Noir's avatar Joseph Noir

Reworkign UDP handshake

parent e6a8e04f
......@@ -203,7 +203,8 @@ public:
/// Answer client handshake ... TODO
void write_udp_server_handshake(execution_unit* ctx, buffer_type& buf,
const node_id& remote_side);
const node_id& remote_side,
optional<uint16_t> port);
/// Writes an `announce_proxy` to `buf`.
void write_announce_proxy(execution_unit* ctx, buffer_type& buf,
......
......@@ -154,7 +154,7 @@ public:
expected<ActorHandle> remote_actor(uri u) {
CAF_LOG_TRACE(CAF_ARG(u));
detail::type_list<ActorHandle> tk;
auto x = remote_actor(system().message_types(tk), u);
auto x = remote_actor(system().message_types(tk), std::move(u));
if (!x)
return x.error();
CAF_ASSERT(x && *x);
......
......@@ -585,7 +585,6 @@ behavior basp_broker::make_behavior() {
// received from underlying broker implementation
[=](new_datagram_msg& msg) {
CAF_LOG_TRACE(CAF_ARG(msg.handle));
CAF_LOG_DEBUG("Received new_datagram_msg: " << CAF_ARG(msg));
state.set_context(msg.handle);
auto& ctx = *state.this_context;
// TODO: ordering
......@@ -603,7 +602,7 @@ behavior basp_broker::make_behavior() {
// TODO: if callback available, handle that
}
// TODO: Is there configuration necessary?
// configure_datagram_size(...);
configure_datagram_size(msg.handle, 1500);
}
},
// received from proxy instances
......@@ -682,24 +681,19 @@ behavior basp_broker::make_behavior() {
// received from underlying broker implementation
[=](const acceptor_closed_msg& msg) {
CAF_LOG_TRACE("");
std::cerr << "[BB] Received acceptor closed msg" << std::endl;
auto port = local_port(msg.handle);
state.instance.remove_published_actor(port);
},
// received from underlying broker implementation
[=](const new_endpoint_msg& msg) {
CAF_LOG_TRACE(CAF_ARG(msg.handle));
std::cerr << "[BB] new endpoint msg received" << std::endl;
//auto& bi = state.instance;
//bi.write_server_handshake(context(), wr_buf(msg.handle),
// local_port(msg.source));
static_cast<void>(msg);
// flush(msg.handle);
// TODO: is this right?
// TODO: Do I need this or does the handshake procedure handle things?
},
/*
[=](const dgram_delegate_msg&) {
CAF_LOG_TRACE(CAF_ARG(msg.handle));
// TODO: Remove msg type?
},
*/
// received from underlying broker implementation
......@@ -717,7 +711,6 @@ behavior basp_broker::make_behavior() {
},
[=](const dgram_doorman_closed_msg& msg) {
CAF_LOG_TRACE(CAF_ARG(msg.handle));
std::cerr << "[BB] Received dgram_doorman_closed_msg" << std::endl;
auto port = local_port(msg.handle);
state.instance.remove_published_actor(port);
},
......@@ -777,8 +770,6 @@ behavior basp_broker::make_behavior() {
[=](connect_atom, dgram_scribe_handle hdl,
const std::string& host, uint16_t port) {
CAF_LOG_TRACE(CAF_ARG(hdl.id()));
std::cerr << "[BB] \"connect\" for dgram to "
<< host << ":" << port << std::endl;
auto rp = make_response_promise();
auto res = assign_dgram_scribe(hdl, host, port);
if (res) {
......@@ -787,8 +778,6 @@ behavior basp_broker::make_behavior() {
ctx.remote_port = port;
ctx.callback = rp;
auto& bi = state.instance;
// bi.write_server_handshake(context(), wr_buf(hdl), port);
// bi.write_client_handshake(context(), wr_buf(hdl), local_port(hdl));
bi.write_udp_client_handshake(context(), wr_buf(hdl));
flush(hdl);
configure_datagram_size(hdl, 1500);
......
......@@ -1254,6 +1254,7 @@ bool send_datagram(size_t& result, native_socket fd, void* buf, size_t buf_len,
auto sres = ::sendto(fd, reinterpret_cast<socket_send_ptr>(buf), buf_len,
no_sigpipe_flag, reinterpret_cast<sockaddr*>(&sa),
sa_len);
/*
{
std::string host;
uint16_t port;
......@@ -1261,6 +1262,7 @@ bool send_datagram(size_t& result, native_socket fd, void* buf, size_t buf_len,
std::cerr << "[SD] Sent " << sres << " bytes to "
<< host << ":" << port << std::endl;
}
*/
if (is_error(sres, true)) {
CAF_LOG_ERROR("sendto returned" << CAF_ARG(sres));
return false;
......@@ -1276,13 +1278,15 @@ bool receive_datagram(size_t& result, native_socket fd, void* buf, size_t len,
auto sres = ::recvfrom(fd, buf, len, 0,
reinterpret_cast<struct sockaddr *>(&sa),
&sa_len);
/*
{
std::string host;
uint16_t port;
std::tie(host,port) = sender_from_sockaddr(sa, sa_len);
std::cerr << "[SD] Received " << sres << " bytes from "
std::cerr << "[RD] Received " << sres << " bytes from "
<< host << ":" << port << std::endl;
}
*/
// TODO: Check if sres > len and do some error handling ...
if (is_error(sres, true)) {
CAF_LOG_ERROR("recvfrom returned" << CAF_ARG(sres));
......@@ -1665,7 +1669,7 @@ void dgram_communicator::handle_event(operation op) {
passivate();
return;
}
std::cerr << "[C] Received " << rb << " bytes" << std::endl;
//std::cerr << "[C] Received " << rb << " bytes" << std::endl;
// currently handles the change from acceptor
// to communicator, TODO: Find a better solution
// Either keep sending to the same endpoint,
......@@ -1675,7 +1679,9 @@ void dgram_communicator::handle_event(operation op) {
std::tie(host_, port_) = sender_from_sockaddr(sockaddr_, sockaddr_len_);
remote_endpoint_addr_ = std::move(sockaddr_);
remote_endpoint_addr_len_ = sockaddr_len_;
sockaddr_len_ = 0;
sockaddr_len_ = 0;
//std::cerr << "[C] Adapted new endpoint: " << host_ << ":" << port_
// << std::endl;
}
if (rb > 0) {
auto res = reader_->consume(&backend(), rd_buf_.data(), rb);
......@@ -1695,6 +1701,8 @@ void dgram_communicator::handle_event(operation op) {
writer_->io_failure(&backend(), operation::write);
backend().del(operation::write, fd(), this);
} else if (wb > 0) {
//std::cerr << "[C] Sent " << wb << " bytes to "
// << host_ << ":" << port_ << std::endl;
CAF_ASSERT(wb == wr_buf_.size());
if (ack_writes_)
writer_->datagram_sent(&backend(), wb);
......@@ -1736,9 +1744,10 @@ void dgram_communicator::prepare_next_read() {
void dgram_communicator::set_endpoint_addr(const sockaddr_storage& sa,
size_t len,
bool is_tmp_endpoint) {
waiting_for_remote_endpoint = !is_tmp_endpoint;
waiting_for_remote_endpoint = is_tmp_endpoint;
remote_endpoint_addr_ = sa;
remote_endpoint_addr_len_ = len;
std::tie(host_, port_) = sender_from_sockaddr(sa, len);
}
dgram_acceptor::dgram_acceptor(default_multiplexer& backend_ref,
......@@ -1787,16 +1796,14 @@ void dgram_acceptor::handle_event(operation op) {
// --> create a new dgram_scribe
// TODO: some idenfification to prevent arbitrary
// message from creating endpoints?
rd_buf_.clear();
rd_buf_.resize(dgram_size_);
size_t rb;
memset(&sockaddr_,0, sockaddr_len_);
if (!receive_datagram(rb, fd(), rd_buf_.data(), rd_buf_.size(),
sockaddr_, sockaddr_len_)) {
mgr_->io_failure(&backend(), operation::read);
passivate();
return;
}
//std::cerr << "[A] Received message with " << rb << " bytes" << std::endl;
bytes_read_ = rb;
if (rb > 0) {
std::tie(host_,port_) = sender_from_sockaddr(sockaddr_, sockaddr_len_);
......
......@@ -91,14 +91,15 @@ bool udp_server_handshake_valid(const header& hdr) {
return valid(hdr.source_node)
&& valid(hdr.dest_node)
&& hdr.source_node != hdr.dest_node
&& zero(hdr.source_actor)
//&& zero(hdr.source_actor)
&& zero(hdr.dest_actor)
&& zero(hdr.operation_data);
&& !zero(hdr.operation_data);
}
bool udp_client_handshake_valid(const header& hdr) {
return valid(hdr.source_node)
&& !valid(hdr.dest_node)
&& zero(hdr.source_actor)
&& zero(hdr.dest_actor)
&& !zero(hdr.operation_data);
}
......
This diff is collapsed.
......@@ -33,7 +33,9 @@ const char* message_type_strings[] = {
"dispatch_message",
"announce_proxy_instance",
"kill_proxy_instance",
"heartbeat"
"heartbeat",
"udp_client_handshake",
"udp_server_handshake"
};
} // namespace <anonymous>
......
......@@ -196,12 +196,15 @@ expected<strong_actor_ptr> middleman::remote_actor(std::set<std::string> ifs,
uri u) {
CAF_LOG_TRACE(CAF_ARG(ifs) << CAF_ARG(u));
auto f = make_function_view(actor_handle());
auto res = f(connect_atom::value, std::move(u));
auto res = f(connect_atom::value, u);
if (!res)
return std::move(res.error());
strong_actor_ptr ptr = std::move(std::get<1>(*res));
if (!ptr)
if (!ptr) {
std::cerr << "[remote_actor] no actor published on port " << u.port_as_int()
<< std::endl;
return make_error(sec::no_actor_published_at_port, u.port_as_int());
}
if (!system().assignable(std::get<2>(*res), ifs))
return make_error(sec::unexpected_actor_messaging_interface, std::move(ifs),
std::move(std::get<2>(*res)));
......
......@@ -108,7 +108,7 @@ public:
mpi_set sigs;
return put(u, whom, sigs, reuse);
},
[=](connect_atom, uri& u) -> get_res {
[=](connect_atom, uri u) -> get_res {
CAF_LOG_TRACE(CAF_ARG(u));
auto rp = make_response_promise();
std::string host(u.host().first, u.host().second);
......
......@@ -122,12 +122,12 @@ CAF_TEST(test_datagram_remote_actor) {
auto res3 = io::uri::make(string(uri_no_port) + ":" + to_string(*res2));
CAF_CHECK(res3);
CAF_MESSAGE("Published pong on: " + to_string(*res3) + ".");
/*
CAF_SET_LOGGER_SYS(&server_side);
//CAF_MESSAGE("Local call to remote actor should acquire the actor.");
//auto res4 = server_side_mm.remote_actor(*res3);
//CAF_CHECK(res4);
CAF_MESSAGE("Local call to remote actor should acquire the actor.");
auto res4 = server_side_mm.remote_actor(*res3);
CAF_CHECK(res4);
*/
CAF_MESSAGE("Checking from different actor system next.");
auto res5 = client_side_mm.remote_actor(*res3);
CAF_CHECK(res5);
......
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