View Source edb_node_monitor (edb_core v0.4.0)

Summary

Types

action/0

-type action() :: {state_timeout, timeout(), Content :: term()}.

action/1

-type action(A) :: {reply, gen_statem:from(), A}.

actions/1

-type actions(A) :: action(A) | [action() | action(A)].

call_request/0

-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()}.

cast_request/0

-type cast_request() :: {try_attach, node()}.

data/0

-type data() :: #{event_subscribers := edb_events:subscribers()}.

info_message/0

-type info_message() ::
          {nodedown, node(), #{node_type := hidden | visible, nodedown_reason := term()}} |
          {nodeup, node(), #{node_type := hidden | visible}} |
          {'DOWN', MonitorRef :: reference(), process, pid(), Info :: term()}.

no_reply/0

-type no_reply() ::
          keep_state_and_data |
          {keep_state, data()} |
          {next_state, state(), data()} |
          {next_state, state(), data(), action()}.

reply/1

-type reply(A) ::
          {keep_state_and_data, actions(A)} |
          {keep_state, data(), {reply, gen_statem:from(), A}} |
          {next_state, state(), data(), actions(A)}.

start_opts/0

-type start_opts() :: [].

state/0

-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

attach(Node, Timeout)

-spec attach(Node, Timeout) -> ok | {error, Reason}
                when
                    Node :: node(),
                    Timeout :: timeout(),
                    Reason ::
                        attachment_in_progress | nodedown | {bootstrap_failed, edb:bootstrap_failure()}.

attached_node()

-spec attached_node() -> node().

callback_mode()

-spec callback_mode() -> handle_event_function.

detach()

-spec detach() -> ok.

expect_reverse_attach(Id, NotificationRef, Timeout)

-spec expect_reverse_attach(Id, NotificationRef, Timeout) -> ok | {error, Reason}
                               when
                                   Id :: edb_gatekeeper:id(),
                                   NotificationRef :: reference(),
                                   Timeout :: timeout(),
                                   Reason :: attachment_in_progress.

handle_event(_, _, State0, Data0)

init(_)

-spec init(start_opts()) -> {ok, state(), data()}.

reverse_attach_notification(Id, Node)

-spec reverse_attach_notification(Id, Node) -> ok | {error, edb:bootstrap_failure()}
                                     when Id :: edb_gatekeeper:id(), Node :: node().

safe_sname_hostname()

-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.

start_link()

-spec start_link() -> gen_statem:start_ret().

subscribe()

-spec subscribe() -> {ok, edb:event_subscription()}.

unsubscribe(Subscription)

-spec unsubscribe(Subscription) -> ok when Subscription :: edb:event_subscription().