Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
1961b3fd
Commit
1961b3fd
authored
Nov 20, 2016
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reworkign UDP handshake
parent
e6a8e04f
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
278 additions
and
308 deletions
+278
-308
libcaf_io/caf/io/basp/instance.hpp
libcaf_io/caf/io/basp/instance.hpp
+2
-1
libcaf_io/caf/io/middleman.hpp
libcaf_io/caf/io/middleman.hpp
+1
-1
libcaf_io/src/basp_broker.cpp
libcaf_io/src/basp_broker.cpp
+3
-14
libcaf_io/src/default_multiplexer.cpp
libcaf_io/src/default_multiplexer.cpp
+14
-7
libcaf_io/src/header.cpp
libcaf_io/src/header.cpp
+3
-2
libcaf_io/src/instance.cpp
libcaf_io/src/instance.cpp
+241
-274
libcaf_io/src/message_type.cpp
libcaf_io/src/message_type.cpp
+3
-1
libcaf_io/src/middleman.cpp
libcaf_io/src/middleman.cpp
+5
-2
libcaf_io/src/middleman_actor.cpp
libcaf_io/src/middleman_actor.cpp
+1
-1
libcaf_io/test/datagram.cpp
libcaf_io/test/datagram.cpp
+5
-5
No files found.
libcaf_io/caf/io/basp/instance.hpp
View file @
1961b3fd
...
...
@@ -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
,
...
...
libcaf_io/caf/io/middleman.hpp
View file @
1961b3fd
...
...
@@ -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
);
...
...
libcaf_io/src/basp_broker.cpp
View file @
1961b3fd
...
...
@@ -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
);
...
...
libcaf_io/src/default_multiplexer.cpp
View file @
1961b3fd
...
...
@@ -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
<<
"[
S
D] Received "
<<
sres
<<
" bytes from "
std::cerr << "[
R
D] 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,
...
...
@@ -1676,6 +1680,8 @@ void dgram_communicator::handle_event(operation op) {
remote_endpoint_addr_
=
std
::
move
(
sockaddr_
);
remote_endpoint_addr_len_
=
sockaddr_len_
;
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_
);
...
...
libcaf_io/src/header.cpp
View file @
1961b3fd
...
...
@@ -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
);
}
...
...
libcaf_io/src/instance.cpp
View file @
1961b3fd
...
...
@@ -17,6 +17,8 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include <iterator>
#include "caf/io/basp/instance.hpp"
#include "caf/streambuf.hpp"
...
...
@@ -258,6 +260,8 @@ connection_state instance::handle(execution_unit* ctx,
}
bool
instance
::
handle
(
execution_unit
*
ctx
,
new_datagram_msg
&
dm
,
header
&
hdr
)
{
using
itr_t
=
std
::
vector
<
char
>::
iterator
;
// Call in case of an error
auto
err
=
[
&
]()
->
bool
{
auto
cb
=
make_callback
([
&
](
const
node_id
&
nid
)
->
error
{
callee_
.
purge_state
(
nid
);
...
...
@@ -266,14 +270,15 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) {
tbl_
.
erase
(
dm
.
handle
,
cb
);
return
false
;
};
std
::
cerr
<<
"New datagram received!"
<<
std
::
endl
;
static_cast
<
void
>
(
ctx
);
static_cast
<
void
>
(
dm
);
static_cast
<
void
>
(
hdr
);
std
::
vector
<
char
>
hdr_buf
{
std
::
begin
(
dm
.
buf
),
std
::
begin
(
dm
.
buf
)
+
basp
::
header_size
};
std
::
vector
<
char
>
pl_buf
{
std
::
begin
(
dm
.
buf
)
+
basp
::
header_size
,
std
::
end
(
dm
.
buf
)};
// Split message into hdr and payload
auto
dgram_itr
=
dm
.
buf
.
begin
();
do
{
// extract header
std
::
vector
<
char
>
hdr_buf
{
std
::
move_iterator
<
itr_t
>
(
dgram_itr
),
std
::
move_iterator
<
itr_t
>
(
dgram_itr
+
basp
::
header_size
)};
dgram_itr
+=
basp
::
header_size
;
// deserialize header
binary_deserializer
bd
{
ctx
,
hdr_buf
};
auto
e
=
bd
(
hdr
);
if
(
e
||
!
valid
(
hdr
))
{
...
...
@@ -282,66 +287,37 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) {
return
err
();
}
CAF_LOG_DEBUG
(
CAF_ARG
(
hdr
));
// extract payload
std
::
vector
<
char
>
pl_buf
{
std
::
move_iterator
<
itr_t
>
(
dgram_itr
),
std
::
move_iterator
<
itr_t
>
(
dgram_itr
+
hdr
.
payload_len
)};
dgram_itr
+=
hdr
.
payload_len
;
// deserialize handshake
std
::
vector
<
char
>*
payload
=
nullptr
;
if
(
hdr
.
payload_len
>
0
)
{
payload
=
&
pl_buf
;
if
(
payload
->
size
()
!=
hdr
.
payload_len
)
{
CAF_LOG_WARNING
(
"received invalid payload"
);
std
::
cerr
<<
"Received invalid payload"
<<
std
::
endl
;
return
err
();
}
std
::
cerr
<<
"Received "
<<
payload
->
size
()
<<
" bytes payload."
<<
std
::
endl
;
//
if (payload->size() != hdr.payload_len) {
//
CAF_LOG_WARNING("received invalid payload");
// // TODO: This kind of should not happen ...
// std::cerr << "Received invalid payload with size " << payload->size()
// << " although header says " << hdr.payload_len << std::endl;
// return err();
//}
}
// TODO: handle payload
// needs forwarding?
if
(
!
is_handshake
(
hdr
)
&&
!
is_heartbeat
(
hdr
)
&&
hdr
.
dest_node
!=
this_node_
)
{
std
::
cerr
<<
"[I] Needs forwarding?"
<<
std
::
endl
;
/*
CAF_LOG_DEBUG("forward message");
auto path = lookup(hdr.dest_node);
if (path) {
binary_serializer bs{ctx, path->wr_buf};
auto e = bs(hdr);
if (e)
// TODO: anything to do here? (i.e., do we still need forwarding?)
return
err
();
if (payload)
bs.apply_raw(payload->size(), payload->data());
tbl_.flush(*path);
notify<hook::message_forwarded>(hdr, payload);
} else {
CAF_LOG_INFO("cannot forward message, no route to destination");
if (hdr.source_node != this_node_) {
// TODO: signalize error back to sending node
auto reverse_path = lookup(hdr.source_node);
if (!reverse_path) {
CAF_LOG_WARNING("cannot send error message: no route to source");
} else {
CAF_LOG_WARNING("not implemented yet: signalize forward failure");
}
} else {
CAF_LOG_WARNING("lost packet with probably spoofed source");
}
notify<hook::message_forwarding_failed>(hdr, payload);
}
return await_header;
*/
}
// function object for checking payload validity
auto
payload_valid
=
[
&
]()
->
bool
{
return
payload
!=
nullptr
&&
payload
->
size
()
==
hdr
.
payload_len
;
};
// handle message to
ourselves
// handle message
ourselves
switch
(
hdr
.
operation
)
{
case
message_type
:
:
udp_server_handshake
:
{
std
::
cerr
<<
"[I] Received UDP server handshake"
<<
std
::
endl
;
break
;
}
case
message_type
:
:
udp_client_handshake
:
{
std
::
cerr
<<
"[I] Received UDP client handshake"
<<
std
::
endl
;
// udp scribes start with a client handshake when sending the first
// message, should be answered by a server handshake!
actor_id
aid
=
invalid_actor_id
;
std
::
set
<
std
::
string
>
sigs
;
if
(
payload_valid
())
{
...
...
@@ -350,9 +326,9 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) {
auto
e
=
bd
(
remote_appid
);
if
(
e
)
return
err
();
if
(
remote_appid
!=
callee_
.
system
().
config
().
middleman_app_identifier
)
{
if
(
remote_appid
!=
callee_
.
system
().
config
().
middleman_app_identifier
)
{
CAF_LOG_ERROR
(
"app identifier mismatch"
);
std
::
cerr
<<
"app identifier mismatch"
<<
std
::
endl
;
return
err
();
}
e
=
bd
(
aid
,
sigs
);
...
...
@@ -360,13 +336,11 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) {
return
err
();
}
else
{
CAF_LOG_ERROR
(
"fail to receive the app identifier"
);
std
::
cerr
<<
"fail to receive the app identifier"
<<
std
::
endl
;
return
err
();
}
// close self connection after handshake is done
if
(
hdr
.
source_node
==
this_node_
)
{
CAF_LOG_INFO
(
"close connection to self immediately"
);
std
::
cerr
<<
"close connection to self immediately"
<<
std
::
endl
;
callee_
.
finalize_handshake
(
hdr
.
source_node
,
aid
,
sigs
);
return
err
();
}
...
...
@@ -374,16 +348,11 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) {
if
(
tbl_
.
lookup_hdl
(
hdr
.
source_node
))
{
CAF_LOG_INFO
(
"close connection since we already have a "
"direct connection: "
<<
CAF_ARG
(
hdr
.
source_node
));
std
::
cerr
<<
"close connection since we already have a "
"direct connection: "
<<
to_string
(
hdr
.
source_node
)
<<
std
::
endl
;
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
));
std
::
cerr
<<
"new direct connection: "
<<
to_string
(
hdr
.
source_node
)
<<
std
::
endl
;
tbl_
.
add
(
dm
.
handle
,
hdr
.
source_node
);
// auto was_indirect = tbl_.erase_indirect(hdr.source_node);
// write handshake as client in response
...
...
@@ -392,97 +361,60 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) {
CAF_LOG_ERROR
(
"no route to host after server handshake"
);
return
err
();
}
write_udp_server
_handshake
(
ctx
,
path
->
wr_buf
,
hdr
.
source_node
);
write_client
_handshake
(
ctx
,
path
->
wr_buf
,
hdr
.
source_node
);
callee_
.
learned_new_node_directly
(
hdr
.
source_node
);
std
::
cerr
<<
"[I] Before finalize handshake"
<<
std
::
endl
;
callee_
.
finalize_handshake
(
hdr
.
source_node
,
aid
,
sigs
);
std
::
cerr
<<
"[I] After finalize handshake"
<<
std
::
endl
;
flush
(
*
path
);
break
;
}
case
message_type
:
:
server_handshake
:
{
std
::
cerr
<<
"[I] message_type::server_handshake"
<<
std
::
endl
;
/*
actor_id aid = invalid_actor_id;
std::set<std::string> sigs;
case
message_type
:
:
udp_client_handshake
:
{
std
::
cerr
<<
"[I] Received UDP client handshake"
<<
std
::
endl
;
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) {
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
// 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_client_handshake(ctx, path->wr_buf, hdr.source_node);
write_udp_server_handshake
(
ctx
,
path
->
wr_buf
,
hdr
.
source_node
,
none
);
// auto was_indirect = tbl_.erase_indirect(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
:
{
std
::
cerr
<<
"[I] message_type::client_handshake"
<<
std
::
endl
;
/*
if (tbl_.lookup_hdl(hdr.source_node)) {
CAF_LOG_INFO("received second client handshake:"
<< CAF_ARG(hdr.source_node));
case
message_type
:
:
server_handshake
:
{
std
::
cerr
<<
"[I] message_type::server_handshake"
<<
std
::
endl
;
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);
*/
case
message_type
:
:
client_handshake
:
{
std
::
cerr
<<
"[I] Received TCP client handshake"
<<
std
::
endl
;
break
;
}
case
message_type
:
:
dispatch_message
:
{
std
::
cerr
<<
"[I] message_type::dispatch_message"
<<
std
::
endl
;
/*
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,
...
...
@@ -518,19 +450,15 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) {
callee_
.
deliver
(
hdr
.
source_node
,
hdr
.
source_actor
,
hdr
.
dest_actor
,
message_id
::
from_integer_value
(
hdr
.
operation_data
),
forwarding_stack
,
msg
);
*/
return
err
();
//return err();
break
;
}
case
message_type
:
:
announce_proxy
:
std
::
cerr
<<
"[I] message_type::announce_proxy"
<<
std
::
endl
;
/*
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
};
...
...
@@ -539,26 +467,25 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) {
if
(
e
)
return
err
();
callee_
.
kill_proxy
(
hdr
.
source_node
,
hdr
.
source_actor
,
fail_state
);
*/
break
;
}
case
message_type
:
:
heartbeat
:
{
std
::
cerr
<<
"[I] message_type::heartbeat"
<<
std
::
endl
;
/*
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
);
*/
return
true
;
//return true;
break
;
}
default:
CAF_LOG_ERROR
(
"invalid operation"
);
std
::
cerr
<<
"[I] Invalid operation"
<<
std
::
endl
;
return
err
();
}
}
while
(
dgram_itr
!=
dm
.
buf
.
end
());
// TODO: Is this reachable?
return
err
()
;
return
true
;
};
void
instance
::
handle_heartbeat
(
execution_unit
*
ctx
)
{
...
...
@@ -679,9 +606,11 @@ bool instance::dispatch(execution_unit* ctx, const strong_actor_ptr& sender,
void
instance
::
write
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
header
&
hdr
,
payload_writer
*
pw
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
hdr
));
std
::
cerr
<<
"In instance::write"
<<
std
::
endl
;
//std::cerr << "[W] Writing " << buf.size() << " bytes in "
// << to_string(hdr.operation) << " message" << std::endl;
error
err
;
if
(
pw
)
{
//std::cerr << "[W] Has payload writer" << std::endl;
auto
pos
=
buf
.
size
();
// write payload first (skip first 72 bytes and write header later)
char
placeholder
[
basp
::
header_size
];
...
...
@@ -715,11 +644,6 @@ void instance::write_server_handshake(execution_unit* ctx,
pa
=
&
i
->
second
;
}
CAF_LOG_DEBUG_IF
(
!
pa
&&
port
,
"no actor published"
);
if
(
!
pa
&&
port
)
{
std
::
cerr
<<
"No actor published."
<<
std
::
endl
;
}
else
{
std
::
cerr
<<
"Found locally published actor."
<<
std
::
endl
;
}
auto
writer
=
make_callback
([
&
](
serializer
&
sink
)
->
error
{
auto
&
ref
=
callee_
.
system
().
config
().
middleman_app_identifier
;
auto
e
=
sink
(
const_cast
<
std
::
string
&>
(
ref
));
...
...
@@ -757,6 +681,13 @@ void instance::write_client_handshake(execution_unit* ctx,
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
);
/*
CAF_LOG_TRACE(CAF_ARG(port));
using namespace detail;
...
...
@@ -772,7 +703,6 @@ void instance::write_udp_client_handshake(execution_unit* ctx,
} else {
std::cerr << "Found locally published actor." << std::endl;
}
*/
auto writer = make_callback([&](serializer& sink) -> error {
auto& ref = callee_.system().config().middleman_app_identifier;
auto e = sink(const_cast<std::string&>(ref));
...
...
@@ -790,11 +720,47 @@ void instance::write_udp_client_handshake(execution_unit* ctx,
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
)
{
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"
);
if
(
!
pa
&&
port
)
{
std
::
cerr
<<
"No actor published."
<<
std
::
endl
;
}
else
{
std
::
cerr
<<
"Found locally published actor."
<<
std
::
endl
;
}
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
);
/*
CAF_LOG_TRACE(CAF_ARG(remote_side));
auto writer = make_callback([&](serializer& sink) -> error {
auto& str = callee_.system().config().middleman_app_identifier;
...
...
@@ -803,6 +769,7 @@ void instance::write_udp_server_handshake(execution_unit* ctx,
header hdr{message_type::udp_server_handshake, 0, 0, 0,
this_node_, remote_side, invalid_actor_id, invalid_actor_id};
write(ctx, buf, hdr, &writer);
*/
}
void
instance
::
write_announce_proxy
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
...
...
libcaf_io/src/message_type.cpp
View file @
1961b3fd
...
...
@@ -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>
...
...
libcaf_io/src/middleman.cpp
View file @
1961b3fd
...
...
@@ -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
)));
...
...
libcaf_io/src/middleman_actor.cpp
View file @
1961b3fd
...
...
@@ -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
);
...
...
libcaf_io/test/datagram.cpp
View file @
1961b3fd
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment