0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 04:10:24 +00:00

Cleanup logs

This commit is contained in:
Loïc Hoguin 2025-06-06 14:27:58 +02:00
parent ee6ef37643
commit a8cc1d8144
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764

View file

@ -9,7 +9,15 @@
-export([webtransport_info/2]). -export([webtransport_info/2]).
-export([terminate/3]). -export([terminate/3]).
%% -define(DEBUG, 1).
-ifdef(DEBUG).
-define(LOG(Fmt, Args), ct:pal(Fmt, Args)).
-else.
-define(LOG(Fmt, Args), _ = Fmt, _ = Args, ok).
-endif.
init(Req0, _) -> init(Req0, _) ->
?LOG("WT init ~p~n", [Req0]),
Req = case cowboy_req:parse_header(<<"wt-available-protocols">>, Req0) of Req = case cowboy_req:parse_header(<<"wt-available-protocols">>, Req0) of
undefined -> undefined ->
Req0; Req0;
@ -21,16 +29,16 @@ init(Req0, _) ->
%% @todo WT handle {stream_open,4,bidi} %% @todo WT handle {stream_open,4,bidi}
webtransport_handle(Event = {stream_open, StreamID, bidi}, Streams) -> webtransport_handle(Event = {stream_open, StreamID, bidi}, Streams) ->
ct:pal("WT handle ~p~n", [Event]), ?LOG("WT handle ~p~n", [Event]),
{[], Streams#{StreamID => bidi}}; {[], Streams#{StreamID => bidi}};
webtransport_handle(Event = {stream_open, StreamID, unidi}, Streams) -> webtransport_handle(Event = {stream_open, StreamID, unidi}, Streams) ->
ct:pal("WT handle ~p~n", [Event]), ?LOG("WT handle ~p~n", [Event]),
OpenStreamRef = make_ref(), OpenStreamRef = make_ref(),
{[{open_stream, OpenStreamRef, unidi, <<>>}], Streams#{ {[{open_stream, OpenStreamRef, unidi, <<>>}], Streams#{
StreamID => {unidi_remote, OpenStreamRef}, StreamID => {unidi_remote, OpenStreamRef},
OpenStreamRef => {unidi_local, StreamID}}}; OpenStreamRef => {unidi_local, StreamID}}};
webtransport_handle(Event = {opened_stream_id, OpenStreamRef, OpenStreamID}, Streams) -> webtransport_handle(Event = {opened_stream_id, OpenStreamRef, OpenStreamID}, Streams) ->
ct:pal("WT handle ~p~n", [Event]), ?LOG("WT handle ~p~n", [Event]),
case Streams of case Streams of
#{OpenStreamRef := bidi} -> #{OpenStreamRef := bidi} ->
{[], maps:remove(OpenStreamRef, Streams#{ {[], maps:remove(OpenStreamRef, Streams#{
@ -44,7 +52,7 @@ webtransport_handle(Event = {opened_stream_id, OpenStreamRef, OpenStreamID}, Str
})} })}
end; end;
webtransport_handle(Event = {stream_data, StreamID, _IsFin, <<"TEST:", Test/bits>>}, Streams) -> webtransport_handle(Event = {stream_data, StreamID, _IsFin, <<"TEST:", Test/bits>>}, Streams) ->
ct:pal("WT handle ~p~n", [Event]), ?LOG("WT handle ~p~n", [Event]),
case Test of case Test of
<<"open_bidi">> -> <<"open_bidi">> ->
OpenStreamRef = make_ref(), OpenStreamRef = make_ref(),
@ -63,7 +71,7 @@ webtransport_handle(Event = {stream_data, StreamID, _IsFin, <<"TEST:", Test/bits
Streams#{event_pid => binary_to_term(EventPidBin)}} Streams#{event_pid => binary_to_term(EventPidBin)}}
end; end;
webtransport_handle(Event = {stream_data, StreamID, IsFin, Data}, Streams) -> webtransport_handle(Event = {stream_data, StreamID, IsFin, Data}, Streams) ->
ct:pal("WT handle ~p~n", [Event]), ?LOG("WT handle ~p~n", [Event]),
case Streams of case Streams of
#{StreamID := bidi} -> #{StreamID := bidi} ->
{[{send, StreamID, IsFin, Data}], Streams}; {[{send, StreamID, IsFin, Data}], Streams};
@ -75,23 +83,23 @@ webtransport_handle(Event = {stream_data, StreamID, IsFin, Data}, Streams) ->
{[{send, LocalStreamID, IsFin, Data}], Streams} {[{send, LocalStreamID, IsFin, Data}], Streams}
end; end;
webtransport_handle(Event = {datagram, Data}, Streams) -> webtransport_handle(Event = {datagram, Data}, Streams) ->
ct:pal("WT handle ~p~n", [Event]), ?LOG("WT handle ~p~n", [Event]),
{[{send, datagram, Data}], Streams}; {[{send, datagram, Data}], Streams};
webtransport_handle(Event = close_initiated, Streams) -> webtransport_handle(Event = close_initiated, Streams) ->
ct:pal("WT handle ~p~n", [Event]), ?LOG("WT handle ~p~n", [Event]),
{[{send, datagram, <<"TEST:close_initiated">>}], Streams}; {[{send, datagram, <<"TEST:close_initiated">>}], Streams};
webtransport_handle(Event, Streams) -> webtransport_handle(Event, Streams) ->
ct:pal("WT handle ignore ~p~n", [Event]), ?LOG("WT handle ignore ~p~n", [Event]),
{[], Streams}. {[], Streams}.
webtransport_info({try_again, Event}, Streams) -> webtransport_info({try_again, Event}, Streams) ->
ct:pal("try_again ~p", [Event]), ?LOG("WT try_again ~p", [Event]),
webtransport_handle(Event, Streams). webtransport_handle(Event, Streams).
terminate(Reason, Req, State=#{event_pid := EventPid}) -> terminate(Reason, Req, State=#{event_pid := EventPid}) ->
ct:pal("terminate ~p ~p ~p", [Reason, Req, State]), ?LOG("WT terminate ~p ~p ~p", [Reason, Req, State]),
EventPid ! {'$wt_echo_h', terminate, Reason, Req, State}, EventPid ! {'$wt_echo_h', terminate, Reason, Req, State},
ok; ok;
terminate(Reason, Req, State) -> terminate(Reason, Req, State) ->
ct:pal("terminate ~p ~p ~p", [Reason, Req, State]), ?LOG("WT terminate ~p ~p ~p", [Reason, Req, State]),
ok. ok.