View Source edb_node_monitor (edb_core v0.4.0)
Summary
Functions
Returns a host that is safe to use as a node shortname.
Types
-type action(A) :: {reply, gen_statem:from(), A}.
-type call_request() :: {attach, node(), timeout()} | {expect_reverse_attach, edb_gatekeeper:id(), reference(), timeout()} | {reverse_attach_notification, edb_gatekeeper:id(), node()} | detach | {subscribe_to_events, pid()} | {remove_event_subscription, edb:event_subscription()}.
-type cast_request() :: {try_attach, node()}.
-type data() :: #{event_subscribers := edb_events:subscribers()}.
-type start_opts() :: [].
-type state() :: #{state := not_attached} | #{state := attachment_in_progress, type := attach, node := node(), caller := gen_statem:from()} | #{state := attachment_in_progress, type := reverse_attach, gatekeeper := edb_gatekeeper:id(), notification_ref => reference(), caller_pid := pid()} | #{state := up, node := node()} | #{state := down, node := node()}.
Functions
-spec attach(Node, Timeout) -> ok | {error, Reason} when Node :: node(), Timeout :: timeout(), Reason :: attachment_in_progress | nodedown | {bootstrap_failed, edb:bootstrap_failure()}.
-spec attached_node() -> node().
-spec callback_mode() -> handle_event_function.
-spec detach() -> ok.
-spec expect_reverse_attach(Id, NotificationRef, Timeout) -> ok | {error, Reason} when Id :: edb_gatekeeper:id(), NotificationRef :: reference(), Timeout :: timeout(), Reason :: attachment_in_progress.
-spec handle_event(cast, cast_request(), state(), data()) -> gen_statem:event_handler_result(state(), data()); ({call, gen_statem:from()}, call_request(), state(), data()) -> gen_statem:event_handler_result(state(), data()); (info, info_message(), state(), data()) -> gen_statem:event_handler_result(state(), data()).
-spec init(start_opts()) -> {ok, state(), data()}.
-spec reverse_attach_notification(Id, Node) -> ok | {error, edb:bootstrap_failure()} when Id :: edb_gatekeeper:id(), Node :: node().
-spec safe_sname_hostname() -> atom().
Returns a host that is safe to use as a node shortname.
Normally, net_kernel uses inet:gethostname/0 to get the hostname, when building an sname. This is problematic in cases where you have a fleet of hosts and the naming convention is nnn.my.fleet.net where nnn is an integer. In this case, inet:gethostname/0 will return nnn, so you get a node name like foo@nnn, but if you then try to connect to this node, inet_tcp_dist will end up calling inet:getaddr/2 on nnn, which will incorrectly interpret nnn as an IP address and the connection will of course fail.
So let's try a couple of options and validate that they can be resolved properly.
-spec start_link() -> gen_statem:start_ret().
-spec subscribe() -> {ok, edb:event_subscription()}.
-spec unsubscribe(Subscription) -> ok when Subscription :: edb:event_subscription().