Skip to content

Commit

Permalink
Merge pull request #134 from qzhuyan/dev/william/quicer-0.0.8
Browse files Browse the repository at this point in the history
feat: bump to quicer 0.0.8
  • Loading branch information
qzhuyan authored Aug 26, 2021
2 parents 321a676 + f33585b commit 25892ef
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
[{test,
[{deps,
[{meck, "0.9.2"},
{emqx, {git_subdir, "https://github.com/emqx/emqx", {branch, "master"}, "apps/emqx"}},
{emqx, {git_subdir, "https://github.com/qzhuyan/emqx", {branch, "dev/william/5.0-quic-support-2"}, "apps/emqx"}},
{emqx_ct_helpers, {git, "https://github.com/emqx/emqx-ct-helpers", {branch, "hocon"}}}
]},
{erl_opts, [debug_info]},
Expand Down
2 changes: 1 addition & 1 deletion rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Profiles1 = lists:keystore(emqtt, 1, Profiles, {emqtt, NewRelx(emqtt, Profiles)}
Profiles2 = lists:keystore(emqtt_pkg, 1, Profiles1, {emqtt_pkg, NewRelx(emqtt_pkg, Profiles1)}),
NewConfig = lists:keystore(profiles, 1, CONFIG, {profiles, Profiles2}),

Quicer = {quicer, {git, "https://github.com/emqx/quic.git", {tag, "0.0.6"}}},
Quicer = {quicer, {git, "https://github.com/emqx/quic.git", {tag, "0.0.8"}}},
ExtraDeps = fun(C) ->
{deps, Deps0} = lists:keyfind(deps, 1, C),
Deps = Deps0 ++
Expand Down
9 changes: 8 additions & 1 deletion src/emqtt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1067,11 +1067,18 @@ code_change(_Vsn, State, Data, _Extra) ->
%%--------------------------------------------------------------------
%% Internal functions
%%--------------------------------------------------------------------
should_ping(emqtt_quic, Sock) ->
case emqtt_quic:getstat(Sock, [send_cnt]) of
{ok, [{send_cnt, V}]} ->
V == put(quic_send_cnt, V) orelse V == undefined;
Err ->
Err
end;

should_ping(ConnMod, Sock) ->
case ConnMod:getstat(Sock, [send_oct]) of
{ok, [{send_oct, Val}]} ->
OldVal = get(send_oct), put(send_oct, Val),
OldVal = put(send_oct, Val),
OldVal == undefined orelse OldVal == Val;
Error = {error, _Reason} ->
Error
Expand Down
5 changes: 3 additions & 2 deletions src/emqtt_quic.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
]).

connect(Host, Port, Opts, Timeout) ->
KeepAlive = proplists:get_value(keepalive, Opts, 60),
ConnOpts = [ {alpn, ["mqtt"]}
, {idle_timeout_ms, 60000}
, {idle_timeout_ms, timer:seconds(KeepAlive * 3)}
, {peer_unidi_stream_count, 1}
, {peer_bidi_stream_count, 10}
| Opts],
Expand Down Expand Up @@ -58,7 +59,7 @@ setopts(Stream, Opts) ->
ok.

close(Stream) ->
quicer:async_close_stream(Stream).
quicer:close_stream(Stream, 1000).

sockname(H) ->
quicer:sockname(H).
31 changes: 17 additions & 14 deletions test/emqtt_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ groups() ->
[basic_test_v3]},
{mqttv4, [non_parallel_tests],
[basic_test_v4,
anonymous_test,
%% anonymous_test,
retry_interval_test,
will_message_test,
will_retain_message_test,
Expand Down Expand Up @@ -321,21 +321,24 @@ basic_test_v3(_Config) ->
basic_test_v4(_Config) ->
basic_test([{proto_ver, v4}]).

anonymous_test(_Config) ->
application:set_env(emqx, allow_anonymous, false),

process_flag(trap_exit, true),
{ok, C1} = emqtt:start_link(),
{_,{unauthorized_client,_}} = emqtt:connect(C1),
receive {'EXIT', _, _} -> ok
after 500 -> error("allow_anonymous")
end,
process_flag(trap_exit, false),
%%$ NOTE, Mask the test anonymous_test for emqx 5.0 since `auth' is moved out of emqx core app

application:set_env(emqx, allow_anonymous, true),
{ok, C2} = emqtt:start_link([{username, <<"test">>}, {password, <<"password">>}]),
{ok, _} = emqtt:connect(C2),
ok = emqtt:disconnect(C2).
%% anonymous_test(_Config) ->
%% application:set_env(emqx, allow_anonymous, false),

%% process_flag(trap_exit, true),
%% {ok, C1} = emqtt:start_link(),
%% {_,{unauthorized_client,_}} = emqtt:connect(C1),
%% receive {'EXIT', _, _} -> ok
%% after 500 -> error("allow_anonymous")
%% end,
%% process_flag(trap_exit, false),

%% application:set_env(emqx, allow_anonymous, true),
%% {ok, C2} = emqtt:start_link([{username, <<"test">>}, {password, <<"password">>}]),
%% {ok, _} = emqtt:connect(C2),
%% ok = emqtt:disconnect(C2).

retry_interval_test(_Config) ->
{ok, Pub} = emqtt:start_link([{clean_start, true}, {retry_interval, 1}]),
Expand Down
1 change: 1 addition & 0 deletions test/quic_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ server_loop(L) ->
after 0 ->
case quicer:accept(L, [], 30000) of
{ok, Conn} ->
{ok, Conn} = quicer:handshake(Conn, 1000),
{ok, Stm} = quicer:accept_stream(Conn, []),
receive
{quic, <<"ping">>, _, _, _, _} ->
Expand Down

0 comments on commit 25892ef

Please sign in to comment.