Skip to content

Commit

Permalink
ssl: Shortcut data path
Browse files Browse the repository at this point in the history
Avoid several external calls for every data package.

Remove debug code for application data, i.e. fast path.
  • Loading branch information
dgud committed Jan 16, 2025
1 parent e24acbf commit 20612c9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/ssl/src/tls_client_connection_1_3.erl
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ wait_finished(Type, Msg, State) ->
term(), #state{}) ->
gen_statem:state_function_result().
%%--------------------------------------------------------------------
connection(info, Msg, State) ->
tls_gen_connection:handle_info(Msg, connection, State);
connection(Type, Msg, State) ->
tls_gen_connection_1_3:connection(Type, Msg, State).

Expand Down
13 changes: 11 additions & 2 deletions lib/ssl/src/tls_gen_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ handle_info(Msg, StateName, State) ->
%%====================================================================
%% State transition handling
%%====================================================================

next_event(connection, #ssl_tls{} = Record, State) ->
handle_protocol_record(Record, connection, State);
next_event(StateName, Record, State) ->
next_event(StateName, Record, State, []).

Expand Down Expand Up @@ -404,7 +407,7 @@ handle_protocol_record(#ssl_tls{type = ?APPLICATION_DATA, fragment = Data}, Stat
TimerAction = [{{timeout, recv}, infinity, timeout}],
next_event(StateName, Record, State, TimerAction);
{Record, State} ->
next_event(StateName, Record, State, [])
next_event(StateName, Record, State)
end;
handle_protocol_record(#ssl_tls{type = ?APPLICATION_DATA, fragment = Data}, StateName, State0) ->
case ssl_gen_statem:read_application_data(Data, State0) of
Expand Down Expand Up @@ -622,10 +625,16 @@ next_tls_record(Data, StateName,
end,
MaxFragLen = maps:get(max_fragment_length, State#state.connection_states, undefined),
case tls_record:get_tls_records(Data, Versions, Buf0, MaxFragLen, Downgrade) of
{Records, Buf1} ->
{Records, Buf1} when StateName == connection ->
CT1 = CT0 ++ Records,
next_record(StateName, Buffers#protocol_buffers{tls_record_buffer = Buf1,
tls_cipher_texts = CT1}, State);
{Records, Buf1} ->
CT1 = CT0 ++ Records,
[ssl_logger:debug(get(log_level), inbound, 'record', Record) || Record <- Records],
next_record(StateName, Buffers#protocol_buffers{tls_record_buffer = Buf1,
tls_cipher_texts = CT1}, State);

#alert{} = Alert ->
handle_record_alert(Alert, State)
end.
Expand Down
1 change: 0 additions & 1 deletion lib/ssl/src/tls_record.erl
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,6 @@ validate_tls_record_length(Versions, {_,Size0,_} = Q0, MaxFragLen,
%% Complete record
{Fragment, Q} = binary_from_front(Length, Q0),
Record = #ssl_tls{type = Type, version = Version, fragment = Fragment},
ssl_logger:debug(get(log_level), inbound, 'record', Record),
case Downgrade of
{_Pid, _From} ->
%% parse only single record for downgrade scenario, buffer remaining data
Expand Down
2 changes: 0 additions & 2 deletions lib/ssl/src/tls_sender.erl
Original file line number Diff line number Diff line change
Expand Up @@ -488,14 +488,12 @@ send_application_data(Data, From, StateName,
{Msgs, ConnStates} = tls_record:encode_data(Data, Version, ConnStates0),
case tls_socket:send(Transport, Socket, Msgs) of
ok when From =:= dist_data ->
ssl_logger:debug(get(log_level), outbound, 'record', Msgs),
StateData = StateData0#data{bytes_sent = BytesSent, connection_states = ConnStates},
hibernate_after(StateName, StateData, []);
Reason when From =:= dist_data ->
StateData = StateData0#data{connection_states = ConnStates},
death_row_shutdown(Reason, StateData);
ok ->
ssl_logger:debug(get(log_level), outbound, 'record', Msgs),
gen_statem:reply(From, ok),
StateData = StateData0#data{bytes_sent = BytesSent, connection_states = ConnStates},
hibernate_after(StateName, StateData, []);
Expand Down
2 changes: 2 additions & 0 deletions lib/ssl/src/tls_server_connection_1_3.erl
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ wait_eoed(Type, Msg, State) ->
term(), #state{}) ->
gen_statem:state_function_result().
%%--------------------------------------------------------------------
connection(info, Msg, State) ->
tls_gen_connection:handle_info(Msg, connection, State);
connection(Type, Msg, State) ->
tls_gen_connection_1_3:connection(Type, Msg, State).

Expand Down

0 comments on commit 20612c9

Please sign in to comment.