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
d718796c
Commit
d718796c
authored
Jul 28, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Streamline `instance::handle`
parent
243e9b68
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
48 deletions
+19
-48
libcaf_io/caf/io/basp.hpp
libcaf_io/caf/io/basp.hpp
+1
-1
libcaf_io/src/basp.cpp
libcaf_io/src/basp.cpp
+18
-47
No files found.
libcaf_io/caf/io/basp.hpp
View file @
d718796c
...
@@ -423,7 +423,7 @@ public:
...
@@ -423,7 +423,7 @@ public:
const
node_id
&
dest_node
,
const
node_id
&
dest_node
,
error
error_code
,
error
error_code
,
const
header
&
original_hdr
,
const
header
&
original_hdr
,
const
buffer_type
&
payload
);
const
buffer_type
*
payload
);
/// Writes a `kill_proxy_instance` to `buf`.
/// Writes a `kill_proxy_instance` to `buf`.
void
write_kill_proxy_instance
(
buffer_type
&
buf
,
void
write_kill_proxy_instance
(
buffer_type
&
buf
,
...
...
libcaf_io/src/basp.cpp
View file @
d718796c
...
@@ -336,10 +336,10 @@ connection_state instance::handle(const new_data_msg& dm, header& hdr,
...
@@ -336,10 +336,10 @@ connection_state instance::handle(const new_data_msg& dm, header& hdr,
if
(
!
is_handshake
(
hdr
)
&&
hdr
.
dest_node
!=
this_node_
)
{
if
(
!
is_handshake
(
hdr
)
&&
hdr
.
dest_node
!=
this_node_
)
{
auto
path
=
lookup
(
hdr
.
dest_node
);
auto
path
=
lookup
(
hdr
.
dest_node
);
if
(
path
)
{
if
(
path
)
{
auto
&
wr_buf
=
path
->
wr_buf
;
binary_serializer
bs
{
std
::
back_inserter
(
path
->
wr_buf
),
&
get_namespace
()};
binary_serializer
bs
{
std
::
back_inserter
(
wr_buf
),
&
get_namespace
()};
write_hdr
(
bs
,
hdr
);
write_hdr
(
bs
,
hdr
);
wr_buf
.
insert
(
wr_buf
.
end
(),
payload
->
begin
(),
payload
->
end
());
if
(
payload
)
bs
.
write_raw
(
payload
->
size
(),
payload
->
data
());
tbl_
.
flush
(
*
path
);
tbl_
.
flush
(
*
path
);
}
else
{
}
else
{
CAF_LOG_INFO
(
"cannot forward message, no route to destination"
);
CAF_LOG_INFO
(
"cannot forward message, no route to destination"
);
...
@@ -353,7 +353,7 @@ connection_state instance::handle(const new_data_msg& dm, header& hdr,
...
@@ -353,7 +353,7 @@ connection_state instance::handle(const new_data_msg& dm, header& hdr,
hdr
.
source_node
,
hdr
.
source_node
,
error
::
no_route_to_destination
,
error
::
no_route_to_destination
,
hdr
,
hdr
,
*
payload
);
payload
);
}
}
}
else
{
}
else
{
CAF_LOG_WARNING
(
"lost packet with probably spoofed source"
);
CAF_LOG_WARNING
(
"lost packet with probably spoofed source"
);
...
@@ -361,8 +361,15 @@ connection_state instance::handle(const new_data_msg& dm, header& hdr,
...
@@ -361,8 +361,15 @@ connection_state instance::handle(const new_data_msg& dm, header& hdr,
}
}
return
await_header
;
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
switch
(
hdr
.
operation
)
{
switch
(
hdr
.
operation
)
{
case
message_type
:
:
server_handshake
:
{
case
message_type
:
:
server_handshake
:
{
if
(
!
payload_valid
())
return
err
();
binary_deserializer
bd
{
payload
->
data
(),
payload
->
size
(),
binary_deserializer
bd
{
payload
->
data
(),
payload
->
size
(),
&
get_namespace
()};
&
get_namespace
()};
actor_id
aid
;
actor_id
aid
;
...
@@ -409,7 +416,8 @@ connection_state instance::handle(const new_data_msg& dm, header& hdr,
...
@@ -409,7 +416,8 @@ connection_state instance::handle(const new_data_msg& dm, header& hdr,
tbl_
.
add_direct
(
dm
.
handle
,
hdr
.
source_node
);
tbl_
.
add_direct
(
dm
.
handle
,
hdr
.
source_node
);
break
;
break
;
case
message_type
:
:
dispatch_message
:
{
case
message_type
:
:
dispatch_message
:
{
// message is addressed to us
if
(
!
payload_valid
())
return
err
();
binary_deserializer
bd
{
payload
->
data
(),
payload
->
size
(),
binary_deserializer
bd
{
payload
->
data
(),
payload
->
size
(),
&
get_namespace
()};
&
get_namespace
()};
message
msg
;
message
msg
;
...
@@ -420,49 +428,11 @@ connection_state instance::handle(const new_data_msg& dm, header& hdr,
...
@@ -420,49 +428,11 @@ connection_state instance::handle(const new_data_msg& dm, header& hdr,
break
;
break
;
}
}
case
message_type
:
:
dispatch_error
:
case
message_type
:
:
dispatch_error
:
// needs forwarding?
if
(
hdr
.
dest_node
!=
this_node_
)
{
auto
path
=
lookup
(
hdr
.
dest_node
);
if
(
!
path
)
{
CAF_LOG_ERROR
(
"cannot forward dispatch error message: "
"no route to destination!"
);
}
else
{
CAF_LOG_DEBUG
(
"forwarded error message"
);
auto
&
wr_buf
=
path
->
wr_buf
;
binary_serializer
bs
{
std
::
back_inserter
(
path
->
wr_buf
),
&
get_namespace
()};
write_hdr
(
bs
,
hdr
);
wr_buf
.
insert
(
wr_buf
.
end
(),
payload
->
begin
(),
payload
->
end
());
tbl_
.
flush
(
*
path
);
}
return
await_header
;
}
switch
(
static_cast
<
error
>
(
hdr
.
operation_data
))
{
switch
(
static_cast
<
error
>
(
hdr
.
operation_data
))
{
case
error
:
:
loop_detected
:
case
error
:
:
loop_detected
:
case
error
:
:
no_route_to_destination
:
case
error
:
:
no_route_to_destination
:
// TODO: do some better error handling for detected loops
// TODO: do some actual error handling
binary_deserializer
bd
{
payload
->
data
(),
payload
->
size
(),
CAF_LOG_ERROR
(
"a message got lost"
);
&
get_namespace
()};
header
original_hdr
;
read_hdr
(
bd
,
original_hdr
);
message
original_msg
;
auto
msg_size
=
bd
.
read
<
uint32_t
>
();
original_msg
.
deserialize
(
bd
);
node_id
first_hop
;
first_hop
.
deserialize
(
bd
);
tbl_
.
blacklist
(
first_hop
,
original_hdr
.
dest_node
);
// try re-sending message (without forwarding hops)
auto
path
=
tbl_
.
lookup
(
original_hdr
.
dest_node
);
if
(
path
)
{
binary_serializer
bs
{
std
::
back_inserter
(
path
->
wr_buf
),
&
get_namespace
()};
write_hdr
(
bs
,
original_hdr
);
bs
.
write_raw
(
header_size
+
sizeof
(
uint32_t
)
+
msg_size
,
payload
->
data
());
tbl_
.
flush
(
*
path
);
}
else
{
CAF_LOG_WARNING
(
"message was lost"
);
}
break
;
break
;
}
}
break
;
break
;
...
@@ -656,10 +626,11 @@ void instance::write_dispatch_error(buffer_type& buf,
...
@@ -656,10 +626,11 @@ void instance::write_dispatch_error(buffer_type& buf,
const
node_id
&
dest_node
,
const
node_id
&
dest_node
,
error
error_code
,
error
error_code
,
const
header
&
original_hdr
,
const
header
&
original_hdr
,
const
buffer_type
&
payload
)
{
const
buffer_type
*
payload
)
{
auto
writer
=
make_callback
([
&
](
serializer
&
sink
)
{
auto
writer
=
make_callback
([
&
](
serializer
&
sink
)
{
write_hdr
(
sink
,
original_hdr
);
write_hdr
(
sink
,
original_hdr
);
sink
.
write_raw
(
payload
.
size
(),
payload
.
data
());
if
(
payload
)
sink
.
write_raw
(
payload
->
size
(),
payload
->
data
());
});
});
header
hdr
{
message_type
::
kill_proxy_instance
,
0
,
header
hdr
{
message_type
::
kill_proxy_instance
,
0
,
static_cast
<
uint64_t
>
(
error_code
),
static_cast
<
uint64_t
>
(
error_code
),
...
...
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