From 17549c9ea3cf38b21bfbd36082c7e0b7969e6ce2 Mon Sep 17 00:00:00 2001 From: William Yang Date: Mon, 18 Sep 2023 15:50:50 +0200 Subject: [PATCH] feat(conn): peer_needs_streams of msquic2.2 --- c_src/quicer_connection.c | 14 +++----------- docs/messages_to_owner.md | 2 +- src/quicer_connection.erl | 2 +- src/quicer_server_conn_callback.erl | 2 +- test/example_server_connection.erl | 7 ++++--- test/quicer_snb_SUITE.erl | 14 ++++---------- 6 files changed, 14 insertions(+), 27 deletions(-) diff --git a/c_src/quicer_connection.c b/c_src/quicer_connection.c index 2d516f27..40697ae1 100644 --- a/c_src/quicer_connection.c +++ b/c_src/quicer_connection.c @@ -1355,20 +1355,12 @@ handle_connection_event_peer_needs_streams( assert(QUIC_CONNECTION_EVENT_PEER_NEEDS_STREAMS == Event->Type); assert(c_ctx->Connection); ErlNifEnv *env = c_ctx->env; - /* reserved for the future upgrade - ERL_NIF_TERM props_name[] = { Event->PEER_NEEDS_STREAMS.Bidirectional ? - ATOM_BIDI_STREAMS : ATOM_UNIDI_STREAMS }; ERL_NIF_TERM props_value[] = { - enif_make_uint64(env, Event->PEER_NEEDS_STREAMS.StreamLimit) }; ERL_NIF_TERM - report = make_event_with_props(env, ATOM_PEER_NEEDS_STREAMS, - enif_make_resource(env, c_ctx), - props_name, - props_value, - 1); - */ ERL_NIF_TERM report = make_event(env, ATOM_PEER_NEEDS_STREAMS, enif_make_resource(env, c_ctx), - ATOM_UNDEFINED); + Event->PEER_NEEDS_STREAMS.Bidirectional + ? ATOM_BIDI_STREAMS + : ATOM_UNIDI_STREAMS); enif_send(NULL, &(c_ctx->owner->Pid), NULL, report); return QUIC_STATUS_SUCCESS; diff --git a/docs/messages_to_owner.md b/docs/messages_to_owner.md index 0aaf72e0..86ed61cb 100644 --- a/docs/messages_to_owner.md +++ b/docs/messages_to_owner.md @@ -296,7 +296,7 @@ More streams are available due to flow control from the peer. Peer wants to open more streams but cannot due to flow control ```erlang -{quic, peer_needs_streams, connection_handle(), undefined} +{quic, peer_needs_streams, connection_handle(), unidi_streams | bidi_streams} ``` ### Ideal processor changed diff --git a/src/quicer_connection.erl b/src/quicer_connection.erl index 2d0560fc..92d6a1fe 100644 --- a/src/quicer_connection.erl +++ b/src/quicer_connection.erl @@ -395,7 +395,7 @@ handle_info({quic, peer_needs_streams, C, Needs}, #{ conn := C , callback := M , callback_state := CbState} = State) -> - ?tp_ignore_side_effects_in_prod(debug, #{module => ?MODULE, conn => C, event => peer_needs_streams}), + ?tp_ignore_side_effects_in_prod(debug, #{module => ?MODULE, conn => C, event => peer_needs_streams, needs => Needs}), default_cb_ret(M:peer_needs_streams(C, Needs, CbState), State); handle_info({quic, connection_resumed, C, ResumeData}, diff --git a/src/quicer_server_conn_callback.erl b/src/quicer_server_conn_callback.erl index 5b72ab50..62d0abfd 100644 --- a/src/quicer_server_conn_callback.erl +++ b/src/quicer_server_conn_callback.erl @@ -105,7 +105,7 @@ streams_available(_C, {BidirCnt, UnidirCnt}, S) -> , peer_bidi_stream_count => BidirCnt}}. %% @doc May integrate with App flow control -peer_needs_streams(_C, undefined, S) -> +peer_needs_streams(_C, _UnidiOrBidi, S) -> {ok, S}. connected(Conn, _Flags, #{ slow_start := false, stream_opts := SOpts diff --git a/test/example_server_connection.erl b/test/example_server_connection.erl index a5bcf9ab..a1c6dc94 100644 --- a/test/example_server_connection.erl +++ b/test/example_server_connection.erl @@ -113,11 +113,12 @@ local_address_changed(_C, _NewAddr, S) -> streams_available(_C, {_BidirCnt, _UnidirCnt}, S) -> {ok, S}. -peer_needs_streams(C, #{unidi_streams := Current}, S) -> +peer_needs_streams(C, unidi_streams, S) -> + {ok, Current} = quicer:getopt(C, param_conn_local_unidi_stream_count), ok = quicer:setopt(C, param_conn_settings, #{peer_unidi_stream_count => Current + 1}), {ok, S}; -peer_needs_streams(C, #{bidi_streams := Current}, S) -> - ok = quicer:setopt(C, param_conn_settings, #{peer_bidi_stream_count => Current + 1}), +peer_needs_streams(_C, bidi_streams, S) -> + %% leave it for test case to unblock it, see tc_multi_streams_example_server_3 {ok, S}; %% for https://github.com/microsoft/msquic/issues/3120 peer_needs_streams(_C, undefined, S) -> diff --git a/test/quicer_snb_SUITE.erl b/test/quicer_snb_SUITE.erl index f6e3fcea..f4ab9ba3 100644 --- a/test/quicer_snb_SUITE.erl +++ b/test/quicer_snb_SUITE.erl @@ -1996,20 +1996,14 @@ tc_multi_streams_example_server_1(Config) -> true = quicer:is_unidirectional(Flag), Incoming after 1000 -> - %%ct:fail("no incoming stream") - %% reenable the check when it is fixed. - %% https://github.com/microsoft/msquic/issues/3120 - ok + ct:fail("no incoming stream") end, receive {quic, Data, Stm3In, DFlag} -> ct:pal("~p is received from ~p with flag: ~p", [Data, Stm3In, DFlag]), ?assertEqual(Data, <<"ping3">>) after 1000 -> - %% ct:fail("no incoming data") - %% reenable the check when it is fixed. - %% https://github.com/microsoft/msquic/issues/3120 - ok + ct:fail("no incoming data") end, quicer:async_shutdown_connection(Conn, ?QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, 0), receive @@ -2020,7 +2014,7 @@ tc_multi_streams_example_server_1(Config) -> end, fun(_Result, Trace) -> ct:pal("Trace is ~p", [Trace]), - ?assertMatch([{pair, _, _}], + ?assertMatch([{pair, _, _}, {pair, _, _}], ?find_pairs( #{ ?snk_kind := debug , event := handoff_stream @@ -2033,7 +2027,7 @@ tc_multi_streams_example_server_1(Config) -> , stream := _STREAM0 }, Trace)), - ?assertMatch([{pair, _, _}], + ?assertMatch([{pair, _, _}, {pair, _, _}], ?find_pairs( #{ ?snk_kind := debug , event := handoff_stream , module := quicer