-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add dgram recv callback #247
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -462,6 +462,86 @@ tc_conn_client_bad_cert(Config) -> | |
ct:fail({run_error, Error}) | ||
end. | ||
|
||
tc_datagram_disallowed(Config) -> | ||
Port = select_port(), | ||
ServerConnCallback = example_server_connection, | ||
ServerStreamCallback = example_server_stream, | ||
ListenerOpts = [{conn_acceptors, 4} | default_listen_opts(Config)], | ||
ConnectionOpts = [ {conn_callback, ServerConnCallback} | ||
, {stream_acceptors, 2} | ||
| default_conn_opts()], | ||
StreamOpts = [ {stream_callback, ServerStreamCallback} | ||
, {disable_fpbuffer, true} | ||
| default_stream_opts() ], | ||
%% GIVEN: A listener with datagram_receive_enabled = false | ||
Comment on lines
+474
to
+476
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: should |
||
Options = {ListenerOpts, ConnectionOpts, StreamOpts}, | ||
|
||
{ok, _} = quicer:spawn_listener(mqtt, Port, Options), | ||
%% WHEN: Client send dgram data | ||
{ok, Conn} = quicer:connect("localhost", Port, default_conn_opts(), 5000), | ||
%% THEN: It get an error | ||
?assertEqual({error, dgram_send_error, invalid_state}, quicer:send_dgram(Conn, <<"dg_ping">>)), | ||
quicer:shutdown_connection(Conn), | ||
ok. | ||
|
||
tc_datagram_peer_allowed(Config) -> | ||
Port = select_port(), | ||
ServerConnCallback = example_server_connection, | ||
ServerStreamCallback = example_server_stream, | ||
%% GIVEN: A listener with datagram_receive_enabled = 1 (true) | ||
ListenerOpts = [{conn_acceptors, 4}, {datagram_receive_enabled, 1} | default_listen_opts(Config)], | ||
ConnectionOpts = [ {conn_callback, ServerConnCallback} | ||
, {stream_acceptors, 2} | ||
| default_conn_opts()], | ||
StreamOpts = [ {stream_callback, ServerStreamCallback} | ||
, {disable_fpbuffer, true} | ||
| default_stream_opts() ], | ||
Options = {ListenerOpts, ConnectionOpts, StreamOpts}, | ||
|
||
{ok, _} = quicer:spawn_listener(mqtt, Port, Options), | ||
%% WHEN: A client send_dgram | ||
{ok, Conn} = quicer:connect("localhost", Port, default_conn_opts(), 5000), | ||
%% THEN: It should success | ||
?assertEqual({ok, 7}, quicer:send_dgram(Conn, <<"dg_ping">>)), | ||
|
||
receive | ||
%% THEN: the client should not recv dgram from peer as the receiving is disabled | ||
{quic, Data, _Conn, _Flag} when is_binary(Data) -> | ||
ct:fail("client side dgram recv timeout") | ||
after 500 -> | ||
ok | ||
end, | ||
quicer:shutdown_connection(Conn), | ||
ok. | ||
|
||
tc_datagram_local_peer_allowed(Config) -> | ||
Port = select_port(), | ||
ServerConnCallback = example_server_connection, | ||
ServerStreamCallback = example_server_stream, | ||
%% GIVEN: A listener with datagram_receive_enabled = 1 (true) | ||
ListenerOpts = [{conn_acceptors, 4}, {datagram_receive_enabled, 1} | default_listen_opts(Config)], | ||
ConnectionOpts = [ {conn_callback, ServerConnCallback} | ||
, {stream_acceptors, 2} | ||
| default_conn_opts()], | ||
StreamOpts = [ {stream_callback, ServerStreamCallback} | ||
, {disable_fpbuffer, true} | ||
| default_stream_opts() ], | ||
Options = {ListenerOpts, ConnectionOpts, StreamOpts}, | ||
|
||
{ok, _} = quicer:spawn_listener(mqtt, Port, Options), | ||
%% WHEN: Client connect with datagram_receive_enabled = 1 (true) | ||
{ok, Conn} = quicer:connect("localhost", Port, [{datagram_receive_enabled, 1} | default_conn_opts()], 5000), | ||
?assertEqual({ok, 7}, quicer:send_dgram(Conn, <<"dg_ping">>)), | ||
receive | ||
%% THEN: the client is able to receive the dgram from server | ||
{quic, <<"dg_ping">>, Conn, Flag} -> | ||
?assertEqual(0, Flag) | ||
after 1000 -> | ||
ct:fail("client side dgram recv timeout") | ||
end, | ||
quicer:shutdown_connection(Conn), | ||
ok. | ||
|
||
run_tc_conn_client_bad_cert(Config)-> | ||
Port = select_port(), | ||
Owner = self(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will format the code with erlfmt in the next PR.