Skip to content

Commit

Permalink
Merge pull request #2 from nhs-riak/nhse-d34-nhscore.i11-options
Browse files Browse the repository at this point in the history
Nhse d34 nhscore.i11 options
  • Loading branch information
martinsumner authored Sep 23, 2024
2 parents e4eaa15 + e6b86f9 commit e1c5f1e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 20 deletions.
43 changes: 25 additions & 18 deletions src/riak_core_connection_mgr.erl
Original file line number Diff line number Diff line change
Expand Up @@ -433,32 +433,39 @@ disconnect_from_target(Target, State = #state{pending = Pending}) ->
Req ->
case get_cancellation_interval() of
undefined ->
?LOG_WARNING("Cancelled connection ~p will not be removed because
cm_cancellation_interval is set to undefined", [Req#req.target]);
?LOG_WARNING(
"Cancelled connection ~p will not be removed because"
"cm_cancellation_interval is set to undefined",
[Req#req.target]
);
Interval when is_integer(Interval) ->
erlang:send_after(Interval,self(),{remove_cancelled_connection,Req#req.ref});
erlang:send_after(
Interval,
self(),
{remove_cancelled_connection, Req}
);
Error ->
?LOG_ERROR("Unsupported cm_cancellation_interval: ~p", [Error])
?LOG_ERROR(
"Unsupported cm_cancellation_interval: ~p",
[Error]
)
end,
%% The helper process will discover the cancellation when it asks if it
%% should connect to an endpoint.
State#state{pending = lists:keystore(Req#req.ref, #req.ref, Pending,
Req#req{state = cancelled})}
State#state{
pending =
lists:keystore(
Req#req.ref,
#req.ref,
Pending,
Req#req{state = cancelled}
)
}
end.

%% @doc remove pending connection from state for supplied Ref.
remove_cancelled_connection(Ref, State = #state{pending = Pending}) ->
case lists:keytake(Ref, #req.ref, Pending) of
false ->
State;
{value, Req, Pending2} ->
case Req#req.state of
cancelled ->
State#state{pending=Pending2};
_ ->
State
end
end.
remove_cancelled_connection(Req, State) ->
fail_request(cancelled, Req, State).

%% schedule a retry to occur after Interval milliseconds.
%% do not clear the pid from pending. the exit handler will do that.
Expand Down
2 changes: 1 addition & 1 deletion src/riak_repl_tcp_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ send_peerinfo(#state{transport=Transport, socket=Socket, sitename=SiteName} = St
OurNode ->
_ = erlang:cancel_timer(State#state.election_timeout),
%% are we configured to upgrade to ssl?
case {riak_repl_util:maybe_use_ssl(), Transport:name()} of
case {riak_repl_util:maybe_server_use_ssl(), Transport:name()} of
{B, T} when B == false; T == ssl ->
%% if there's no valid ssl config or we've already
%% upgraded
Expand Down
25 changes: 24 additions & 1 deletion src/riak_repl_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
normalize_ip/1,
format_socketaddrs/2,
maybe_use_ssl/0,
maybe_server_use_ssl/0,
upgrade_client_to_ssl/1,
choose_strategy/2,
strategy_module/2,
Expand Down Expand Up @@ -471,12 +472,34 @@ validate_ssl_config(true, [{cacerts, CACerts}|Rest]) ->
validate_ssl_config(true, [_|Rest]) ->
validate_ssl_config(true, Rest).

client_only_options() ->
[server_name_indication].

server_only_options() ->
[fail_if_no_peer_cert].

deduct_options(StandardOptions, SpecificOptions) ->
lists:foldl(
fun(K, CfgAcc) ->
lists:keydelete(K, 1, CfgAcc)
end,
StandardOptions,
SpecificOptions).

upgrade_client_to_ssl(Socket) ->
case maybe_use_ssl() of
false ->
{error, no_ssl_config};
Config ->
ssl:connect(Socket, Config)
ssl:connect(Socket, deduct_options(Config, server_only_options()))
end.

maybe_server_use_ssl() ->
case maybe_use_ssl() of
false ->
false;
Config ->
deduct_options(Config, client_only_options())
end.

load_certs(undefined) ->
Expand Down

0 comments on commit e1c5f1e

Please sign in to comment.