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
e327c64e
Commit
e327c64e
authored
Nov 15, 2016
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP Intergrating datagrams into the basp broker
parent
1fc1d5e5
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
118 additions
and
48 deletions
+118
-48
libcaf_io/caf/io/basp/instance.hpp
libcaf_io/caf/io/basp/instance.hpp
+5
-2
libcaf_io/caf/io/basp_broker.hpp
libcaf_io/caf/io/basp_broker.hpp
+17
-22
libcaf_io/caf/io/connection_handle.hpp
libcaf_io/caf/io/connection_handle.hpp
+1
-1
libcaf_io/caf/io/system_messages.hpp
libcaf_io/caf/io/system_messages.hpp
+16
-3
libcaf_io/src/basp_broker.cpp
libcaf_io/src/basp_broker.cpp
+71
-19
libcaf_io/src/dgram_doorman.cpp
libcaf_io/src/dgram_doorman.cpp
+1
-1
libcaf_io/src/instance.cpp
libcaf_io/src/instance.cpp
+7
-0
No files found.
libcaf_io/caf/io/basp/instance.hpp
View file @
e327c64e
...
@@ -116,8 +116,11 @@ public:
...
@@ -116,8 +116,11 @@ public:
/// Handles received data and returns a config for receiving the
/// Handles received data and returns a config for receiving the
/// next data or `none` if an error occured.
/// next data or `none` if an error occured.
connection_state
handle
(
execution_unit
*
ctx
,
connection_state
handle
(
execution_unit
*
ctx
,
new_data_msg
&
dm
,
header
&
hdr
,
new_data_msg
&
dm
,
header
&
hdr
,
bool
is_payload
);
bool
is_payload
);
/// Handles a received datagram
bool
handle
(
execution_unit
*
ctx
,
new_datagram_msg
&
dm
,
header
&
hdr
);
/// Sends heartbeat messages to all valid nodes those are directly connected.
/// Sends heartbeat messages to all valid nodes those are directly connected.
void
handle_heartbeat
(
execution_unit
*
ctx
);
void
handle_heartbeat
(
execution_unit
*
ctx
);
...
...
libcaf_io/caf/io/basp_broker.hpp
View file @
e327c64e
...
@@ -42,6 +42,7 @@ namespace caf {
...
@@ -42,6 +42,7 @@ namespace caf {
namespace
io
{
namespace
io
{
struct
basp_broker_state
:
proxy_registry
::
backend
,
basp
::
instance
::
callee
{
struct
basp_broker_state
:
proxy_registry
::
backend
,
basp
::
instance
::
callee
{
basp_broker_state
(
broker
*
self
);
basp_broker_state
(
broker
*
self
);
~
basp_broker_state
();
~
basp_broker_state
();
...
@@ -94,31 +95,17 @@ struct basp_broker_state : proxy_registry::backend, basp::instance::callee {
...
@@ -94,31 +95,17 @@ struct basp_broker_state : proxy_registry::backend, basp::instance::callee {
// nop
// nop
}
}
// stores meta information for
open connection
s
// stores meta information for
active endpoint
s
struct
connection
_context
{
struct
endpoint
_context
{
// denotes what message we expect from the remote node next
// denotes what message we expect from the remote node next
basp
::
connection_state
cstate
;
basp
::
connection_state
cstate
;
// our currently processed BASP header
// our currently processed BASP header
basp
::
header
hdr
;
basp
::
header
hdr
;
// the
connection
handle for I/O operations
// the handle for I/O operations
connection_handle
hdl
;
variant
<
connection_handle
,
dgram_scribe_handle
>
hdl
;
// network-agnostic node identifier
// network-agnostic node identifier
node_id
id
;
node_id
id
;
// connected port
// port
uint16_t
remote_port
;
// pending operations to be performed after handshake completed
optional
<
response_promise
>
callback
;
};
// stores meta information for dgram endpoints
struct
endpoint_context
{
// our current processed BSAP header
basp
::
header
hdr
;
// local source
dgram_scribe_handle
hdl
;
// network-agnositc node identifier
node_id
id
;
// ports
uint16_t
remote_port
;
uint16_t
remote_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
;
...
@@ -127,6 +114,15 @@ struct basp_broker_state : proxy_registry::backend, basp::instance::callee {
...
@@ -127,6 +114,15 @@ struct basp_broker_state : proxy_registry::backend, basp::instance::callee {
};
};
void
set_context
(
connection_handle
hdl
);
void
set_context
(
connection_handle
hdl
);
void
set_context
(
dgram_scribe_handle
hdl
);
struct
wr_buf_visitor
{
wr_buf_visitor
(
broker
*
ptr
)
:
ptr
{
ptr
}
{
/* nop */
}
using
result_type
=
std
::
vector
<
char
>&
;
result_type
operator
()(
connection_handle
hdl
)
{
return
ptr
->
wr_buf
(
hdl
);
}
result_type
operator
()(
dgram_scribe_handle
hdl
)
{
return
ptr
->
wr_buf
(
hdl
);
}
broker
*
ptr
;
}
wr_buf_of_hdl
;
// pointer to ourselves
// pointer to ourselves
broker
*
self
;
broker
*
self
;
...
@@ -135,12 +131,11 @@ struct basp_broker_state : proxy_registry::backend, basp::instance::callee {
...
@@ -135,12 +131,11 @@ struct basp_broker_state : proxy_registry::backend, basp::instance::callee {
basp
::
instance
instance
;
basp
::
instance
instance
;
// keeps context information for all open connections
// keeps context information for all open connections
std
::
unordered_map
<
connection_handle
,
connection
_context
>
tcp_ctx
;
std
::
unordered_map
<
connection_handle
,
endpoint
_context
>
tcp_ctx
;
std
::
unordered_map
<
dgram_scribe_handle
,
endpoint_context
>
udp_ctx
;
std
::
unordered_map
<
dgram_scribe_handle
,
endpoint_context
>
udp_ctx
;
// points to the current context for callbacks such as `make_proxy`
// points to the current context for callbacks such as `make_proxy`
connection_context
*
this_context
=
nullptr
;
endpoint_context
*
this_context
=
nullptr
;
endpoint_context
*
current_context
=
nullptr
;
// stores handles to spawn servers for other nodes; these servers
// stores handles to spawn servers for other nodes; these servers
// are spawned whenever the broker learns a new node ID and try to
// are spawned whenever the broker learns a new node ID and try to
...
...
libcaf_io/caf/io/connection_handle.hpp
View file @
e327c64e
...
@@ -71,7 +71,7 @@ public:
...
@@ -71,7 +71,7 @@ public:
}
// namespace io
}
// namespace io
}
// namespace caf
}
// namespace caf
namespace
std
{
namespace
std
{
template
<
>
template
<
>
struct
hash
<
caf
::
io
::
connection_handle
>
{
struct
hash
<
caf
::
io
::
connection_handle
>
{
...
...
libcaf_io/caf/io/system_messages.hpp
View file @
e327c64e
...
@@ -140,6 +140,19 @@ inspect(Inspector& f, dgram_scribe_closed_msg& x) {
...
@@ -140,6 +140,19 @@ inspect(Inspector& f, dgram_scribe_closed_msg& x) {
return
f
(
meta
::
type_name
(
"dgram_scribe_closed_msg"
),
x
.
handle
);
return
f
(
meta
::
type_name
(
"dgram_scribe_closed_msg"
),
x
.
handle
);
}
}
/// Signalizes that a {@link broker} dgram_acceptor has been closed.
struct
dgram_acceptor_closed_msg
{
/// Handle to the closed connection.
dgram_doorman_handle
handle
;
};
/// @relates connection_closed_msg
template
<
class
Inspector
>
typename
Inspector
::
result_type
inspect
(
Inspector
&
f
,
dgram_acceptor_closed_msg
&
x
)
{
return
f
(
meta
::
type_name
(
"dgram_acceptor_closed_msg"
),
x
.
handle
);
}
/// Signalizes that a {@link broker} datagram source was closed.
/// Signalizes that a {@link broker} datagram source was closed.
struct
dgram_doorman_closed_msg
{
struct
dgram_doorman_closed_msg
{
dgram_doorman_handle
handle
;
dgram_doorman_handle
handle
;
...
@@ -155,17 +168,17 @@ inspect(Inspector& f, dgram_doorman_closed_msg& x) {
...
@@ -155,17 +168,17 @@ inspect(Inspector& f, dgram_doorman_closed_msg& x) {
/// Signalizes newly arrived datagram for a {@link broker}.
/// Signalizes newly arrived datagram for a {@link broker}.
struct
new_endpoint_msg
{
struct
new_endpoint_msg
{
/// Handle to the related datagram endpoint.
/// Handle to the related datagram endpoint.
dgram_doorman_handle
handl
e
;
dgram_doorman_handle
sourc
e
;
// Buffer containing the received data.
// Buffer containing the received data.
// std::vector<char> buf;
// std::vector<char> buf;
/// Handle to new dgram_scribe
/// Handle to new dgram_scribe
dgram_scribe_handle
endpoint
;
dgram_scribe_handle
handle
;
};
};
/// @relates new_endpoint_msg
/// @relates new_endpoint_msg
template
<
class
Inspector
>
template
<
class
Inspector
>
typename
Inspector
::
result_type
inspect
(
Inspector
&
f
,
new_endpoint_msg
&
x
)
{
typename
Inspector
::
result_type
inspect
(
Inspector
&
f
,
new_endpoint_msg
&
x
)
{
return
f
(
meta
::
type_name
(
"new_endpoint_msg"
),
x
.
handle
,
x
.
endpoint
);
return
f
(
meta
::
type_name
(
"new_endpoint_msg"
),
x
.
source
,
x
.
handle
);
}
}
/// Signalizes that a datagram with a certain size has been sent.
/// Signalizes that a datagram with a certain size has been sent.
...
...
libcaf_io/src/basp_broker.cpp
View file @
e327c64e
...
@@ -50,6 +50,7 @@ const char* basp_broker_state::name = "basp_broker";
...
@@ -50,6 +50,7 @@ const char* basp_broker_state::name = "basp_broker";
basp_broker_state
::
basp_broker_state
(
broker
*
selfptr
)
basp_broker_state
::
basp_broker_state
(
broker
*
selfptr
)
:
basp
::
instance
::
callee
(
selfptr
->
system
(),
:
basp
::
instance
::
callee
(
selfptr
->
system
(),
static_cast
<
proxy_registry
::
backend
&>
(
*
this
)),
static_cast
<
proxy_registry
::
backend
&>
(
*
this
)),
wr_buf_of_hdl
(
selfptr
),
self
(
selfptr
),
self
(
selfptr
),
instance
(
selfptr
,
*
this
)
{
instance
(
selfptr
,
*
this
)
{
CAF_ASSERT
(
this_node
()
!=
none
);
CAF_ASSERT
(
this_node
()
!=
none
);
...
@@ -105,7 +106,9 @@ strong_actor_ptr basp_broker_state::make_proxy(node_id nid, actor_id aid) {
...
@@ -105,7 +106,9 @@ strong_actor_ptr basp_broker_state::make_proxy(node_id nid, actor_id aid) {
<<
CAF_ARG
(
nid
)
<<
CAF_ARG
(
aid
));
<<
CAF_ARG
(
nid
)
<<
CAF_ARG
(
aid
));
// tell remote side we are monitoring this actor now
// tell remote side we are monitoring this actor now
instance
.
write_announce_proxy
(
self
->
context
(),
instance
.
write_announce_proxy
(
self
->
context
(),
self
->
wr_buf
(
this_context
->
hdl
),
nid
,
aid
);
apply_visitor
(
wr_buf_of_hdl
,
this_context
->
hdl
),
nid
,
aid
);
instance
.
tbl
().
flush
(
*
path
);
instance
.
tbl
().
flush
(
*
path
);
mm
->
notify
<
hook
::
new_remote_actor
>
(
res
);
mm
->
notify
<
hook
::
new_remote_actor
>
(
res
);
return
res
;
return
res
;
...
@@ -451,18 +454,39 @@ void basp_broker_state::set_context(connection_handle hdl) {
...
@@ -451,18 +454,39 @@ void basp_broker_state::set_context(connection_handle hdl) {
auto
i
=
tcp_ctx
.
find
(
hdl
);
auto
i
=
tcp_ctx
.
find
(
hdl
);
if
(
i
==
tcp_ctx
.
end
())
{
if
(
i
==
tcp_ctx
.
end
())
{
CAF_LOG_INFO
(
"create new BASP context:"
<<
CAF_ARG
(
hdl
));
CAF_LOG_INFO
(
"create new BASP context:"
<<
CAF_ARG
(
hdl
));
i
=
tcp_ctx
.
emplace
(
hdl
,
i
=
tcp_ctx
.
emplace
(
connection_context
{
hdl
,
endpoint_context
{
basp
::
await_header
,
basp
::
await_header
,
basp
::
header
{
basp
::
message_type
::
server_handshake
,
0
,
basp
::
header
{
basp
::
message_type
::
server_handshake
,
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
}
).
first
;
}
this_context
=
&
i
->
second
;
}
void
basp_broker_state
::
set_context
(
dgram_scribe_handle
hdl
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
hdl
));
auto
i
=
udp_ctx
.
find
(
hdl
);
if
(
i
==
udp_ctx
.
end
())
{
CAF_LOG_INFO
(
"create new BASP context:"
<<
CAF_ARG
(
hdl
));
i
=
udp_ctx
.
emplace
(
hdl
,
hdl
,
none
,
endpoint_context
{
0
,
basp
::
await_header
,
none
}).
first
;
basp
::
header
{
basp
::
message_type
::
client_handshake
,
0
,
0
,
0
,
none
,
none
,
invalid_actor_id
,
invalid_actor_id
},
hdl
,
none
,
0
,
none
}
).
first
;
}
}
this_context
=
&
i
->
second
;
this_context
=
&
i
->
second
;
}
}
/******************************************************************************
/******************************************************************************
...
@@ -525,14 +549,21 @@ behavior basp_broker::make_behavior() {
...
@@ -525,14 +549,21 @@ behavior basp_broker::make_behavior() {
[
=
](
new_datagram_msg
&
msg
)
{
[
=
](
new_datagram_msg
&
msg
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
msg
.
handle
));
CAF_LOG_TRACE
(
CAF_ARG
(
msg
.
handle
));
CAF_LOG_DEBUG
(
"Received new_datagram_msg: "
<<
CAF_ARG
(
msg
));
CAF_LOG_DEBUG
(
"Received new_datagram_msg: "
<<
CAF_ARG
(
msg
));
static_cast
<
void
>
(
msg
);
state
.
set_context
(
msg
.
handle
);
// state.set_context(msg.handle);
auto
&
ctx
=
*
state
.
this_context
;
// auto& ctx = *state.udp_context;
// TODO: ordering
//auto next = state.instance.handle(context(), msg, ctx.hdr, ...);
// TODO: reliability?
// TODO: implement this
auto
is_open
=
state
.
instance
.
handle
(
context
(),
msg
,
ctx
.
hdr
);
// look for existing context or create a new one
if
(
!
is_open
)
{
// handle messge
if
(
ctx
.
callback
)
{
static_cast
<
void
>
(
msg
);
CAF_LOG_WARNING
(
"failed to handshake with remote node"
<<
CAF_ARG
(
msg
.
handle
));
ctx
.
callback
->
deliver
(
make_error
(
sec
::
disconnect_during_handshake
));
}
}
else
{
// TODO: Is there configuration necessary?
// configure_datagram_size(...);
}
},
},
// received from proxy instances
// received from proxy instances
[
=
](
forward_atom
,
strong_actor_ptr
&
src
,
[
=
](
forward_atom
,
strong_actor_ptr
&
src
,
...
@@ -613,6 +644,27 @@ behavior basp_broker::make_behavior() {
...
@@ -613,6 +644,27 @@ behavior basp_broker::make_behavior() {
auto
port
=
local_port
(
msg
.
handle
);
auto
port
=
local_port
(
msg
.
handle
);
state
.
instance
.
remove_published_actor
(
port
);
state
.
instance
.
remove_published_actor
(
port
);
},
},
// received from underlying broker implementation
[
=
](
const
new_endpoint_msg
&
msg
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
msg
.
handle
));
auto
&
bi
=
state
.
instance
;
bi
.
write_server_handshake
(
context
(),
wr_buf
(
msg
.
handle
),
local_port
(
msg
.
source
));
// flush(msg.handle);
// TODO: is this right?
},
// received from underlying broker implementation
[
=
](
const
dgram_scribe_closed_msg
&
msg
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
msg
.
handle
));
// TODO: dgram_scribe_closed_msg
static_cast
<
void
>
(
msg
);
},
// received from underlying broker implementation
[
=
](
const
dgram_acceptor_closed_msg
&
msg
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
msg
.
handle
));
// TODO: dgram_acceptor_closed_msg
static_cast
<
void
>
(
msg
);
},
// received from middleman actor
// received from middleman actor
[
=
](
publish_atom
,
accept_handle
hdl
,
uint16_t
port
,
[
=
](
publish_atom
,
accept_handle
hdl
,
uint16_t
port
,
const
strong_actor_ptr
&
whom
,
std
::
set
<
std
::
string
>&
sigs
)
{
const
strong_actor_ptr
&
whom
,
std
::
set
<
std
::
string
>&
sigs
)
{
...
...
libcaf_io/src/dgram_doorman.cpp
View file @
e327c64e
...
@@ -48,7 +48,7 @@ void dgram_doorman::io_failure(execution_unit* ctx, network::operation op) {
...
@@ -48,7 +48,7 @@ void dgram_doorman::io_failure(execution_unit* ctx, network::operation op) {
// size_t besize) {
// size_t besize) {
bool
dgram_doorman
::
new_endpoint
(
execution_unit
*
ctx
,
bool
dgram_doorman
::
new_endpoint
(
execution_unit
*
ctx
,
dgram_scribe_handle
endpoint
)
{
dgram_scribe_handle
endpoint
)
{
msg
().
endpoint
=
endpoint
;
msg
().
handle
=
endpoint
;
return
invoke_mailbox_element
(
ctx
);
return
invoke_mailbox_element
(
ctx
);
}
}
...
...
libcaf_io/src/instance.cpp
View file @
e327c64e
...
@@ -252,6 +252,13 @@ connection_state instance::handle(execution_unit* ctx,
...
@@ -252,6 +252,13 @@ connection_state instance::handle(execution_unit* ctx,
return
await_header
;
return
await_header
;
}
}
bool
instance
::
handle
(
execution_unit
*
ctx
,
new_datagram_msg
&
dm
,
header
&
hdr
)
{
static_cast
<
void
>
(
ctx
);
static_cast
<
void
>
(
dm
);
static_cast
<
void
>
(
hdr
);
return
false
;
};
void
instance
::
handle_heartbeat
(
execution_unit
*
ctx
)
{
void
instance
::
handle_heartbeat
(
execution_unit
*
ctx
)
{
CAF_LOG_TRACE
(
""
);
CAF_LOG_TRACE
(
""
);
for
(
auto
&
kvp
:
tbl_
.
direct_by_hdl_
)
{
for
(
auto
&
kvp
:
tbl_
.
direct_by_hdl_
)
{
...
...
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