summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@gmail.com>2021-12-06 17:21:09 -0500
committerNick Vatamaniuc <vatamane@apache.org>2021-12-07 01:10:17 -0500
commite57f9ef1eb63c3f660a986b08e3465b8aabd4504 (patch)
tree179f47da25fcb1fdcd7426a8c21ac85b16598891
parent86facac5004d813cdd561ecac24c621800a51687 (diff)
downloadcouchdb-fix-couch-dist-for-erlang-20.tar.gz
Fix TLS custom (couch) dist for Erlang 20fix-couch-dist-for-erlang-20
* Fix quoting so that it works with all OTP versions 20 through 24 [1]. * Dist API in 20 [2] did not have a `listen/2` [3] callback. Implement `listen/1` so we're compatible with all the supported OTP versions. [1] https://github.com/apache/couchdb/issues/3821#issuecomment-985089867 [2] https://github.com/erlang/otp/blob/maint-20/lib/kernel/src/inet_tcp_dist.erl#L71-L72 [3] https://github.com/erlang/otp/blob/master/lib/kernel/src/inet_tcp_dist.erl#L79-L80
-rw-r--r--rel/overlay/etc/vm.args2
-rw-r--r--src/couch_dist/src/couch_dist.erl43
2 files changed, 44 insertions, 1 deletions
diff --git a/rel/overlay/etc/vm.args b/rel/overlay/etc/vm.args
index 805e9ec22..8da600bc3 100644
--- a/rel/overlay/etc/vm.args
+++ b/rel/overlay/etc/vm.args
@@ -91,5 +91,5 @@
## Don't forget to override the paths to point to your certificate(s) and key(s)!
##
#-proto_dist couch
-#-couch_dist no_tls \"clouseau@127.0.0.1\"
+#-couch_dist no_tls '"clouseau@127.0.0.1"'
#-ssl_dist_optfile <path/to/couch_ssl_dist.conf>
diff --git a/src/couch_dist/src/couch_dist.erl b/src/couch_dist/src/couch_dist.erl
index 9a6b26d07..a0922ebc5 100644
--- a/src/couch_dist/src/couch_dist.erl
+++ b/src/couch_dist/src/couch_dist.erl
@@ -14,6 +14,7 @@
-export([
childspecs/0,
+ listen/1,
listen/2,
accept/1,
accept_connection/5,
@@ -33,6 +34,16 @@ childspecs() ->
]}
]}.
+listen(Name) ->
+ NodeName =
+ case is_atom(Name) of
+ true -> atom_to_list(Name);
+ false -> Name
+ end,
+ Host = get_node_host(),
+ Mod = inet_dist(NodeName ++ "@" ++ Host),
+ Mod:listen(NodeName).
+
listen(Name, Host) ->
NodeName =
case is_atom(Name) of
@@ -66,6 +77,38 @@ is_node_name(Node) ->
get_init_args() ->
init:get_argument(couch_dist).
+get_node_host() ->
+ % Cannot use `node()` since distribution hasn't started yet. Use
+ % similar logic as erl_distribition and net_kernel to parse it
+ % from the arguments list
+ case {init:get_argument(sname), init:get_argument(name)} of
+ {{ok, [[SName]]}, _} ->
+ case split_host(SName) of
+ [$@ | Host] when length(Host) > 0 ->
+ Host;
+ _ ->
+ inet_db:gethostname()
+ end;
+ {error, {ok, [[Name]]}} ->
+ case split_host(Name) of
+ [$@ | Host] when length(Host) > 0 ->
+ Host;
+ _ ->
+ OwnHost = inet_db:gethostname(),
+ case inet_db:res_option(domain) of
+ Domain when is_list(Domain), length(Domain) > 0 ->
+ OwnHost ++ "." ++ Domain;
+ _ ->
+ OwnHost
+ end
+ end
+ end.
+
+split_host(Name) ->
+ % Copied from net_kernel. Modifed to return Host only
+ {_, Host} = lists:splitwith(fun(C) -> C =/= $@ end, Name),
+ Host.
+
inet_dist(Node) ->
case no_tls(Node) of
true -> inet_tcp_dist;