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
0a9ae8a2
Commit
0a9ae8a2
authored
Jun 30, 2023
by
Samir Halilcevic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integrate review feedback
parent
ef0d2b4c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
39 deletions
+24
-39
libcaf_net/caf/net/web_socket/framing.hpp
libcaf_net/caf/net/web_socket/framing.hpp
+6
-1
libcaf_net/src/net/web_socket/framing.cpp
libcaf_net/src/net/web_socket/framing.cpp
+17
-37
libcaf_net/test/net/web_socket/framing.cpp
libcaf_net/test/net/web_socket/framing.cpp
+1
-1
No files found.
libcaf_net/caf/net/web_socket/framing.hpp
View file @
0a9ae8a2
...
...
@@ -144,7 +144,12 @@ private:
// Signal abort to the upper layer and shutdown to the lower layer,
// with closing message
void
abort_and_close_connection
(
sec
reason
,
std
::
string_view
msg
);
template
<
class
...
Ts
>
void
abort_and_shutdown
(
sec
reason
,
Ts
&&
...
xs
)
{
auto
err
=
make_error
(
reason
,
std
::
forward
<
Ts
>
(
xs
)...);
up_
->
abort
(
err
);
shutdown
(
err
);
}
// -- member variables -------------------------------------------------------
...
...
libcaf_net/src/net/web_socket/framing.cpp
View file @
0a9ae8a2
...
...
@@ -30,8 +30,8 @@ ptrdiff_t framing::consume(byte_span buffer, byte_span) {
auto
hdr_bytes
=
detail
::
rfc6455
::
decode_header
(
buffer
,
hdr
);
if
(
hdr_bytes
<
0
)
{
CAF_LOG_DEBUG
(
"decoded malformed data: hdr_bytes < 0"
);
abort_and_
close_connectio
n
(
sec
::
protocol_error
,
"negative header size on WebSocket connection"
);
abort_and_
shutdow
n
(
sec
::
protocol_error
,
"negative header size on WebSocket connection"
);
return
-
1
;
}
if
(
hdr_bytes
==
0
)
{
...
...
@@ -41,8 +41,7 @@ ptrdiff_t framing::consume(byte_span buffer, byte_span) {
// Make sure the entire frame (including header) fits into max_frame_size.
if
(
hdr
.
payload_len
>=
(
max_frame_size
-
static_cast
<
size_t
>
(
hdr_bytes
)))
{
CAF_LOG_DEBUG
(
"WebSocket frame too large"
);
abort_and_close_connection
(
sec
::
protocol_error
,
"WebSocket frame too large"
);
abort_and_shutdown
(
sec
::
protocol_error
,
"WebSocket frame too large"
);
return
-
1
;
}
// Wait for more data if necessary.
...
...
@@ -61,27 +60,24 @@ ptrdiff_t framing::consume(byte_span buffer, byte_span) {
if
(
opcode_
==
nil_code
)
{
// Call upper layer.
if
(
hdr
.
opcode
==
detail
::
rfc6455
::
connection_close
)
{
// TODO
abort_and_close_connection
(
sec
::
connection_closed
,
""
);
abort_and_shutdown
(
sec
::
connection_closed
);
return
-
1
;
}
else
if
(
!
handle
(
hdr
.
opcode
,
payload
))
{
return
-
1
;
}
}
else
if
(
hdr
.
opcode
!=
detail
::
rfc6455
::
continuation_frame
)
{
CAF_LOG_DEBUG
(
"expected a WebSocket continuation_frame"
);
abort_and_
close_connectio
n
(
sec
::
protocol_error
,
"expected a WebSocket continuation_frame"
);
abort_and_
shutdow
n
(
sec
::
protocol_error
,
"expected a WebSocket continuation_frame"
);
return
-
1
;
}
else
if
(
payload_buf_
.
size
()
+
payload_len
>
max_frame_size
)
{
CAF_LOG_DEBUG
(
"fragmented WebSocket payload exceeds maximum size"
);
abort_and_close_connection
(
sec
::
protocol_error
,
"fragmented WebSocket payload "
"exceeds maximum size"
);
abort_and_shutdown
(
sec
::
protocol_error
,
"fragmented WebSocket payload "
"exceeds maximum size"
);
return
-
1
;
}
else
{
if
(
hdr
.
opcode
==
detail
::
rfc6455
::
connection_close
)
{
// TODO
abort_and_close_connection
(
sec
::
connection_closed
,
""
);
abort_and_shutdown
(
sec
::
connection_closed
);
return
-
1
;
}
else
{
// End of fragmented input.
...
...
@@ -100,23 +96,21 @@ ptrdiff_t framing::consume(byte_span buffer, byte_span) {
if
(
hdr
.
opcode
==
detail
::
rfc6455
::
continuation_frame
)
{
CAF_LOG_DEBUG
(
"received WebSocket continuation "
"frame without prior opcode"
);
abort_and_
close_connectio
n
(
sec
::
protocol_error
,
"received WebSocket continuation "
"frame without prior opcode"
);
abort_and_
shutdow
n
(
sec
::
protocol_error
,
"received WebSocket continuation "
"frame without prior opcode"
);
return
-
1
;
}
opcode_
=
hdr
.
opcode
;
}
else
if
(
hdr
.
opcode
!=
detail
::
rfc6455
::
continuation_frame
)
{
CAF_LOG_DEBUG
(
"expected a continuation frame"
);
abort_and_close_connection
(
sec
::
protocol_error
,
"expected a continuation frame"
);
abort_and_shutdown
(
sec
::
protocol_error
,
"expected a continuation frame"
);
return
-
1
;
}
else
if
(
payload_buf_
.
size
()
+
payload_len
>
max_frame_size
)
{
// Reject assembled payloads that exceed max_frame_size.
CAF_LOG_DEBUG
(
"fragmented WebSocket payload exceeds maximum size"
);
abort_and_close_connection
(
sec
::
protocol_error
,
"fragmented WebSocket payload "
"exceeds maximum size"
);
abort_and_shutdown
(
sec
::
protocol_error
,
"fragmented WebSocket payload "
"exceeds maximum size"
);
return
-
1
;
}
payload_buf_
.
insert
(
payload_buf_
.
end
(),
payload
.
begin
(),
payload
.
end
());
...
...
@@ -247,8 +241,8 @@ void framing::ship_closing_message(status code, std::string_view msg) {
payload
.
reserve
(
msg
.
size
()
+
2
);
payload
.
push_back
(
static_cast
<
std
::
byte
>
((
code_val
&
0xFF00
)
>>
8
));
payload
.
push_back
(
static_cast
<
std
::
byte
>
(
code_val
&
0x00FF
));
for
(
auto
c
:
msg
)
payload
.
push_back
(
static_cast
<
std
::
byte
>
(
c
));
auto
*
first
=
reinterpret_cast
<
const
std
::
byte
*>
(
msg
.
data
());
payload
.
insert
(
payload
.
end
(),
first
,
first
+
msg
.
size
(
));
if
(
mask_outgoing_frames
)
{
mask_key
=
static_cast
<
uint32_t
>
(
rng_
());
detail
::
rfc6455
::
mask_data
(
mask_key
,
payload
);
...
...
@@ -259,18 +253,4 @@ void framing::ship_closing_message(status code, std::string_view msg) {
down_
->
end_output
();
}
void
framing
::
abort_and_close_connection
(
sec
reason
,
std
::
string_view
msg
)
{
if
(
msg
.
empty
())
up_
->
abort
(
make_error
(
reason
));
else
up_
->
abort
(
make_error
(
reason
,
std
::
string
(
msg
)));
status
code
=
status
::
unexpected_condition
;
if
(
reason
==
sec
::
connection_closed
)
code
=
status
::
normal_close
;
else
if
(
reason
==
sec
::
protocol_error
)
code
=
status
::
protocol_error
;
ship_closing_message
(
code
,
to_string
(
reason
));
down_
->
shutdown
();
}
}
// namespace caf::net::web_socket
libcaf_net/test/net/web_socket/framing.cpp
View file @
0a9ae8a2
...
...
@@ -144,7 +144,7 @@ SCENARIO("the client closes the connection with a closing handshake") {
make_test_data
(
0
),
handshake
);
transport
->
push
(
handshake
);
}
THEN
(
"the server closes the connection
with a closing handshak
e"
)
{
THEN
(
"the server closes the connection
after sending a close fram
e"
)
{
transport
->
handle_input
();
detail
::
rfc6455
::
header
hdr
;
auto
hdr_length
...
...
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