|
47 | 47 | -export([with_user/2, with_vhost/2, with_user_and_vhost/3]). |
48 | 48 | -export([execute_mnesia_transaction/1]). |
49 | 49 | -export([ensure_ok/2]). |
50 | | --export([localnode/1, tcp_name/3]). |
| 50 | +-export([localnode/1, nodehost/1, cookie_hash/0, tcp_name/3]). |
51 | 51 | -export([intersperse/2, upmap/2, map_in_order/2]). |
52 | 52 | -export([table_foreach/2]). |
53 | 53 | -export([dirty_read_all/1, dirty_foreach_key/2, dirty_dump_log/1]). |
|
106 | 106 | -spec(execute_mnesia_transaction/1 :: (thunk(A)) -> A). |
107 | 107 | -spec(ensure_ok/2 :: (ok_or_error(), atom()) -> 'ok'). |
108 | 108 | -spec(localnode/1 :: (atom()) -> erlang_node()). |
| 109 | +-spec(nodehost/1 :: (erlang_node()) -> string()). |
| 110 | +-spec(cookie_hash/0 :: () -> string()). |
109 | 111 | -spec(tcp_name/3 :: (atom(), ip_address(), ip_port()) -> atom()). |
110 | 112 | -spec(intersperse/2 :: (A, [A]) -> [A]). |
111 | 113 | -spec(upmap/2 :: (fun ((A) -> B), [A]) -> [B]). |
@@ -307,11 +309,15 @@ ensure_ok(ok, _) -> ok; |
307 | 309 | ensure_ok({error, Reason}, ErrorTag) -> throw({error, {ErrorTag, Reason}}). |
308 | 310 |
|
309 | 311 | localnode(Name) -> |
| 312 | + list_to_atom(lists:append([atom_to_list(Name), "@", nodehost(node())])). |
| 313 | + |
| 314 | +nodehost(Node) -> |
310 | 315 | %% This is horrible, but there doesn't seem to be a way to split a |
311 | 316 | %% nodename into its constituent parts. |
312 | | - list_to_atom(lists:append(atom_to_list(Name), |
313 | | - lists:dropwhile(fun (E) -> E =/= $@ end, |
314 | | - atom_to_list(node())))). |
| 317 | + tl(lists:dropwhile(fun (E) -> E =/= $@ end, atom_to_list(Node))). |
| 318 | + |
| 319 | +cookie_hash() -> |
| 320 | + ssl_base64:encode(erlang:md5(atom_to_list(erlang:get_cookie()))). |
315 | 321 |
|
316 | 322 | tcp_name(Prefix, IPAddress, Port) |
317 | 323 | when is_atom(Prefix) andalso is_number(Port) -> |
|
0 commit comments