Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
4297-Implement-set_cookie-1-and-get_cookie-1.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 4297-Implement-set_cookie-1-and-get_cookie-1.patch of Package erlang
From e45dd2fb07463596c456a041fde693548f8c77d2 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen <raimo@erlang.org> Date: Mon, 16 Aug 2021 15:38:23 +0200 Subject: [PATCH 7/9] Implement set_cookie/1 and get_cookie/1 Clarify the documentation further regarding to these functions. --- erts/doc/src/erlang.xml | 37 ++++++++++++++++--- erts/emulator/test/exception_SUITE.erl | 7 +++- erts/preloaded/src/erlang.erl | 41 +++++++++++++-------- lib/kernel/src/erl_erts_errors.erl | 14 ++++++- lib/kernel/test/erl_distribution_SUITE.erl | 6 ++- system/doc/reference_manual/distributed.xml | 37 ++++++++++++------- 6 files changed, 103 insertions(+), 39 deletions(-) diff --git a/erts/doc/src/erlang.xml b/erts/doc/src/erlang.xml index 7b614832b0..4367f6f757 100644 --- a/erts/doc/src/erlang.xml +++ b/erts/doc/src/erlang.xml @@ -2500,6 +2500,16 @@ uncompiled code with the same arity are mapped to the same list by </desc> </func> + <func> + <name name="get_cookie" arity="1" since="OTP 24.1"/> + <fsummary>Get the magic cookie for a node.</fsummary> + <desc> + <p>Returns the magic cookie for node <c><anno>Node</anno></c> + if the local node is alive, + otherwise the atom <c>nocookie</c>.</p> + </desc> + </func> + <func> <name name="get_keys" arity="0" since="OTP 18.0"/> <fsummary>Return a list of all keys from the process dictionary. @@ -6931,14 +6941,31 @@ true</pre> </desc> </func> + <func> + <name name="set_cookie" arity="1" since="OTP 24.1"/> + <fsummary>Set the magic cookie of the local node.</fsummary> + <desc> + <p>Sets the magic cookie of the local node to the atom + <c><anno>Cookie</anno></c>, which is also + the cookie for all nodes that have no explicit cookie set with + <seemfa marker="#set_cookie/2"><c>set_cookie/2</c></seemfa> + <c><anno>Cookie</anno></c> (see section + <seeguide marker="system/reference_manual:distributed"> + Distributed Erlang</seeguide> + in the Erlang Reference Manual in System Documentation).</p> + <p>Failure: <c>function_clause</c> if the local node is not + alive.</p> + </desc> + </func> + <func> <name name="set_cookie" arity="2" since=""/> - <fsummary>Set the magic cookie of a node.</fsummary> + <fsummary>Set the magic cookie for a node.</fsummary> <desc> - <p>Sets the magic cookie of <c><anno>Node</anno></c> to the atom + <p>Sets the magic cookie for <c><anno>Node</anno></c> to the atom <c><anno>Cookie</anno></c>. If <c><anno>Node</anno></c> is the - local node, the function - also sets the cookie of all other unknown nodes to + local node, the function sets the cookie of all other nodes + (that have no explicit cookie set with this function) to <c><anno>Cookie</anno></c> (see section <seeguide marker="system/reference_manual:distributed"> Distributed Erlang</seeguide> diff --git a/erts/preloaded/src/erlang.erl b/erts/preloaded/src/erlang.erl index 7f23c21d45..b9196448fe 100644 --- a/erts/preloaded/src/erlang.erl +++ b/erts/preloaded/src/erlang.erl @@ -35,7 +35,7 @@ -export([min/2, max/2]). -export([dmonitor_node/3]). -export([delay_trap/2]). --export([set_cookie/2, get_cookie/0]). +-export([set_cookie/1, set_cookie/2, get_cookie/0, get_cookie/1]). -export([nodes/0]). -export([integer_to_list/2]). @@ -3779,29 +3779,38 @@ dmonitor_node(Node, Flag, Opts) -> delay_trap(Result, 0) -> erlang:yield(), Result; delay_trap(Result, Timeout) -> receive after Timeout -> Result end. -%% -%% The business with different in and out cookies represented -%% everywhere is discarded. -%% A node has a cookie, connections/messages to that node use that cookie. -%% Messages to us use our cookie. IF we change our cookie, other nodes -%% have to reflect that, which we cannot forsee. -%% + +-spec erlang:set_cookie(Cookie) -> true when + Cookie :: atom(). +set_cookie(C) when erlang:is_atom(C) -> + auth:set_cookie(C); +set_cookie(C) -> + erlang:error(badarg, [C]). + -spec erlang:set_cookie(Node, Cookie) -> true when Node :: node(), Cookie :: atom(). -set_cookie(Node, C) when Node =/= nonode@nohost, erlang:is_atom(Node) -> - case erlang:is_atom(C) of - true -> - auth:set_cookie(Node, C); - false -> - erlang:error(badarg) - end. +set_cookie(Node, C) + when Node =/= nonode@nohost, erlang:is_atom(Node), erlang:is_atom(C) -> + auth:set_cookie(Node, C); +set_cookie(Node, C) -> + erlang:error(badarg, [Node, C]). + -spec erlang:get_cookie() -> Cookie | nocookie when Cookie :: atom(). get_cookie() -> auth:get_cookie(). +-spec erlang:get_cookie(Node) -> Cookie | nocookie when + Node :: node(), + Cookie :: atom(). +get_cookie(Node) when erlang:is_atom(Node) -> + auth:get_cookie(Node); +get_cookie(Node) -> + erlang:error(badarg, [Node]). + + -spec integer_to_list(Integer, Base) -> string() when Integer :: integer(), Base :: 2..36. diff --git a/lib/kernel/test/erl_distribution_SUITE.erl b/lib/kernel/test/erl_distribution_SUITE.erl index bb7b813239..6443189a7c 100644 --- a/lib/kernel/test/erl_distribution_SUITE.erl +++ b/lib/kernel/test/erl_distribution_SUITE.erl @@ -2085,7 +2085,6 @@ cmdline_setcookie_2(Config) when is_list(Config) -> { ok, NodeA } = start_node( "-hidden", NodeAName, - "-setcookie "++NodeACookieL++" " "-setcookie "++NodeL++" "++NodeCookieL ), try @@ -2093,6 +2092,9 @@ cmdline_setcookie_2(Config) when is_list(Config) -> %% Verify the cluster [ NodeA ] = nodes(hidden), [ Node ] = rpc:call( NodeA, erlang, nodes, [hidden] ), + NodeCookie = rpc:call( NodeA, erlang, get_cookie, []), + + true = rpc:call( NodeA, erlang, set_cookie, [NodeACookie] ), %% Start node B with different cookie %% and cookie configuration of mother node and node A @@ -2166,7 +2168,7 @@ connection_cookie(Config) when is_list(Config) -> [ Node ] = rpc:call( NodeA, erlang, nodes, [] ), NodeACookie = rpc:call( NodeA, erlang, get_cookie, []), ConnectionCookie = rpc:call( NodeA, auth, get_cookie, [Node]), - ConnectionCookie = auth:get_cookie(NodeA) + ConnectionCookie = erlang:get_cookie( NodeA ) after _ = stop_node(NodeA) diff --git a/system/doc/reference_manual/distributed.xml b/system/doc/reference_manual/distributed.xml index 0ef5d3edc3..043f6e6734 100644 --- a/system/doc/reference_manual/distributed.xml +++ b/system/doc/reference_manual/distributed.xml @@ -186,15 +186,14 @@ dilbert@uab</pre> 400 (read-only by user) and its content is a random string. An atom <c>Cookie</c> is created from the contents of the file and the cookie of the local node is set to this using - <c>erlang:set_cookie(node(), Cookie)</c>. This is - the default cookie that the local node will use towards - all other nodes.</p> + <c>erlang:set_cookie(Cookie)</c>. This sets the default cookie + that the local node will use for all other nodes.</p> <p>Thus, groups of users with identical cookie files get Erlang - nodes that can communicate freely since they have the same + nodes that can communicate freely since they use the same magic cookie. Users who want to run nodes where the cookie files are on different file systems must make certain that their cookie files are identical.</p> - <p>For a node <c>Node1</c> with magic cookie <c>Cookie</c> to be + <p>For a node <c>Node1</c> using magic cookie <c>Cookie</c> to be able to connect to, and to accept a connection from, another node <c>Node2</c> that uses a different cookie <c>DiffCookie</c>, the function <c>erlang:set_cookie(Node2, DiffCookie)</c> must @@ -203,7 +202,7 @@ dilbert@uab</pre> can be handled in this way.</p> <note> <p>With this setup <c>Node1</c> and <c>Node2</c> agree - on which cookie to use: <c>Node1</c> uses its explicitly + on which cookie to use: <c>Node1</c> uses its explicitly configured <c>DiffCookie</c> for <c>Node2</c>, and <c>Node2</c> uses its default cookie <c>DiffCookie</c>.</p> <p>You can also use a <c>DiffCookie</c> that neither @@ -211,8 +210,8 @@ dilbert@uab</pre> if you also call <c>erlang:set_cookie(Node1, DiffCookie)</c> in <c>Node2</c> before establishing connection</p> <p>Because node names are exchanged during connection setup - before cookies are selected, the setup works regardless - of which node that initiates the connection</p> + before cookies are selected, connection setup works regardless + of which node that initiates it.</p> <p>Note that to configure <c>Node1</c> to use <c>Node2</c>'s default cookie when communicating with <c>Node2</c>, <em>and vice versa</em> results in a broken configuration @@ -228,7 +227,7 @@ dilbert@uab</pre> and the command-line flag <c>-connect_all false</c> must be set, see the <seecom marker="erts:erl">erl(1)</seecom> manual page in ERTS.</p> - <p>The magic cookie of the local node is retrieved by calling + <p>The magic cookie of the local node can be retrieved by calling <c>erlang:get_cookie()</c>.</p> </section> @@ -250,6 +249,11 @@ dilbert@uab</pre> <cell align="left" valign="middle"><c>erlang:get_cookie()</c></cell> <cell align="left" valign="middle">Returns the magic cookie of the current node.</cell> </row> + <row> + <cell align="left" valign="middle"><c>erlang:get_cookie(Node)</c></cell> + <cell align="left" valign="middle">Returns the magic cookie + for node <c>Node</c>.</cell> + </row> <row> <cell align="left" valign="middle"><c>is_alive()</c></cell> <cell align="left" valign="middle">Returns <c>true</c> if the runtime system is a node and can connect to other nodes, <c>false</c> otherwise.</cell> @@ -278,12 +282,19 @@ dilbert@uab</pre> this function can return a list not only of visible nodes, but also hidden nodes and previously known nodes, and so on.</cell> </row> + <row> + <cell align="left" valign="middle"><c>erlang:set_cookie(Cookie)</c></cell> + <cell align="left" valign="middle">Sets the magic cookie, + <c>Cookie</c> to use when connecting all nodes + that have no explicit cookie set with + <c>erlang:set_cookie/2</c>.</cell> + </row> <row> <cell align="left" valign="middle"><c>erlang:set_cookie(Node, Cookie)</c></cell> <cell align="left" valign="middle">Sets the magic cookie used - when connecting to <c>Node</c>. If <c>Node</c> is the - current node, <c>Cookie</c> is used when connecting to - all new nodes.</cell> + when connecting <c>Node</c>. If <c>Node</c> is the + current node, <c>Cookie</c> is used when connecting + all nodes that have no explicit cookie set with this function.</cell> </row> <row> <cell align="left" valign="middle"><c>spawn[_link|_opt](Node, Fun)</c></cell> @@ -322,7 +333,7 @@ dilbert@uab</pre> </row> <row> <cell align="left" valign="middle"><c>-setcookie Cookie</c></cell> - <cell align="left" valign="middle">Same as calling <c>erlang:set_cookie(node(), Cookie)</c>.</cell> + <cell align="left" valign="middle">Same as calling <c>erlang:set_cookie(Cookie)</c>.</cell> </row> <row> <cell align="left" valign="middle"><c>-setcookie Node Cookie</c></cell> -- 2.31.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor