Skip to content

Commit

Permalink
Merge branch 'maint'
Browse files Browse the repository at this point in the history
* maint:
  Add read_concurrency to ssl_otp_cacertificate_db
  Optimize pkix_db cert selection
  • Loading branch information
dgud committed Dec 5, 2023
2 parents 20c7a33 + 82424cc commit ad49d5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 1 addition & 6 deletions lib/ssl/src/ssl_handshake.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2011,12 +2011,7 @@ supported_cert_type_or_empty(Algo, Type) ->
end.

certificate_authorities_from_db(CertDbHandle, CertDbRef) when is_reference(CertDbRef) ->
ConnectionCerts = fun({{Ref, _, _}, Cert}, Acc) when Ref == CertDbRef ->
[Cert | Acc];
(_, Acc) ->
Acc
end,
ssl_pkix_db:foldl(ConnectionCerts, [], CertDbHandle);
ssl_pkix_db:select_certs_by_ref(CertDbRef, CertDbHandle);
certificate_authorities_from_db(_CertDbHandle, {extracted, CertDbData}) ->
%% Cache disabled, Ref contains data
lists:foldl(fun({decoded, {_Key,Cert}}, Acc) -> [Cert | Acc] end,
Expand Down
12 changes: 10 additions & 2 deletions lib/ssl/src/ssl_pkix_db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
extract_trusted_certs/1,
remove_trusted_certs/2, insert/3, remove/2, clear/1, db_size/1,
ref_count/3, lookup_trusted_cert/4, foldl/3, select_certentries_by_ref/2,
decode_pem_file/1, lookup/2]).
select_certs_by_ref/2, decode_pem_file/1, lookup/2]).

%%====================================================================
%% Internal application API
Expand All @@ -53,7 +53,7 @@ create(PEMCacheName) ->
[%% Let connection process delete trusted certs
%% that can only belong to one connection. (Supplied directly
%% on DER format to ssl:connect/listen.)
ets:new(ssl_otp_cacertificate_db, [set, public]),
ets:new(ssl_otp_cacertificate_db, [set, public, {read_concurrency, true}]),
%% Let connection processes call ref_count/3 directly
{ets:new(ssl_otp_ca_file_ref, [set, public]),
ets:new(ssl_otp_ca_ref_file_mapping, [set, protected])
Expand Down Expand Up @@ -251,6 +251,14 @@ foldl(Fun, Acc0, Cache) ->
select_certentries_by_ref(Ref, Cache) ->
ets:select(Cache, [{{{Ref,'_', '_'}, '_'},[],['$_']}]).

%%--------------------------------------------------------------------
-spec select_certs_by_ref(reference(), db_handle()) -> term().
%%
%% Description: Select certs originating from same source
%%--------------------------------------------------------------------
select_certs_by_ref(Ref, Cache) ->
ets:select(Cache, [{{{Ref,'_','_'},'$1'},[],['$1']}]).

%%--------------------------------------------------------------------
-spec ref_count(term(), db_handle(), integer()) -> integer().
%%
Expand Down

0 comments on commit ad49d5d

Please sign in to comment.