aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/doc/src/net_kernel.xml
blob: 97b20fe94f8f8af7474d6db226c0872190d329eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>1996</year><year>2016</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
 
          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    
    </legalnotice>

    <title>net_kernel</title>
    <prepared>Claes Wikstrom</prepared>
    <docno>1</docno>
    <date>96-09-10</date>
    <rev>A</rev>
  </header>
  <module>net_kernel</module>
  <modulesummary>Erlang Networking Kernel</modulesummary>
  <description>
    <p>The net kernel is a system process, registered as
      <c>net_kernel</c>, which must be running for distributed Erlang
      to work. The purpose of this process is to implement parts of
      the BIFs <c>spawn/4</c> and <c>spawn_link/4</c>, and to provide 
      monitoring of the network.</p>
    <p>An Erlang node is started using the command line flag
      <c>-name</c> or <c>-sname</c>:</p>
<pre>$ <input>erl -sname foobar</input></pre>
    <p>It is also possible to call <c>net_kernel:start([foobar])</c>
      directly from the normal Erlang shell prompt:</p>
<pre>1> <input>net_kernel:start([foobar, shortnames]).</input>
{ok,&lt;0.64.0>}
(foobar@gringotts)2></pre>
    <p>If the node is started with the command line flag <c>-sname</c>,
      the node name will be <c>foobar@Host</c>, where <c>Host</c> is
      the short name of the host (not the fully qualified domain name).
      If started with the <c>-name</c> flag, <c>Host</c> is the fully
      qualified domain name. See <c>erl(1)</c>.</p>
    <p>Normally, connections are established automatically when
      another node is referenced. This functionality can be disabled
      by setting the Kernel configuration parameter
      <c>dist_auto_connect</c> to <c>false</c>, see
      <seealso marker="kernel_app">kernel(6)</seealso>. In this case,
      connections must be established explicitly by calling
      <c>net_kernel:connect_node/1</c>.</p>
    <p>Which nodes are allowed to communicate with each other is handled
      by the magic cookie system, see
      <seealso marker="doc/reference_manual:distributed">Distributed Erlang</seealso> in the Erlang Reference Manual.</p>
  </description>
  <funcs>
    <func>
      <name name="allow" arity="1"/>
      <fsummary>Permit access to a specified set of nodes</fsummary>
      <desc>
        <p>Permits access to the specified set of nodes.</p>
        <p>Before the first call to <c>allow/1</c>, any node with the correct
          cookie can be connected. When <c>allow/1</c> is called, a list
          of allowed nodes is established. Any access attempts made from (or to)
          nodes not in that list will be rejected.</p>
        <p>Subsequent calls to <c>allow/1</c> will add the specified nodes
          to the list of allowed nodes. It is not possible to remove nodes
          from the list.</p>
        <p>Returns <c>error</c> if any element in <c><anno>Nodes</anno></c> is not
          an atom.</p>
      </desc>
    </func>
    <func>
      <name name="connect_node" arity="1"/>
      <fsummary>Establish a connection to a node</fsummary>
      <desc>
        <p>Establishes a connection to <c><anno>Node</anno></c>. Returns <c>true</c>
          if successful, <c>false</c> if not, and <c>ignored</c> if
          the local node is not alive.</p>
      </desc>
    </func>
    <func>
      <name name="monitor_nodes" arity="1"/>
      <name name="monitor_nodes" arity="2"/>
      <fsummary>Subscribe to node status change messages</fsummary>
      <desc>
        <p>The calling process subscribes or unsubscribes to node
          status change messages. A <c>nodeup</c> message is delivered
          to all subscribing process when a new node is connected, and
          a <c>nodedown</c> message is delivered when a node is
          disconnected.</p>
        <p>If <c><anno>Flag</anno></c> is <c>true</c>, a new subscription is started.
          If <c><anno>Flag</anno></c> is <c>false</c>, all previous subscriptions --
          started with the same <c><anno>Options</anno></c> -- are stopped. Two
          option lists are considered the same if they contain the same
          set of options.</p>
        <p>As of <c>kernel</c> version 2.11.4, and <c>erts</c> version
          5.5.4, the following is guaranteed:</p>
        <list type="bulleted">
          <item><c>nodeup</c> messages will be delivered before delivery
           of any message from the remote node passed through the
           newly established connection.</item>
          <item><c>nodedown</c> messages will not be delivered until all
           messages from the remote node that have been passed
           through the connection have been delivered.</item>
        </list>
        <p>Note, that this is <em>not</em> guaranteed for <c>kernel</c>
          versions before 2.11.4.</p>
        <p>As of <c>kernel</c> version 2.11.4 subscriptions can also be
          made before the <c>net_kernel</c> server has been started,
          i.e., <c>net_kernel:monitor_nodes/[1,2]</c> does not return
          <c>ignored</c>.</p>
        <p>As of <c>kernel</c> version 2.13, and <c>erts</c> version
          5.7, the following is guaranteed:</p>
        <list type="bulleted">
          <item><c>nodeup</c> messages will be delivered after the
	  corresponding node appears in results from
	  <c>erlang:nodes/X</c>.</item>
          <item><c>nodedown</c> messages will be delivered after the
	  corresponding node has disappeared in results from
	  <c>erlang:nodes/X</c>.</item>
        </list>
        <p>Note, that this is <em>not</em> guaranteed for <c>kernel</c>
          versions before 2.13.</p>
        <p>The format of the node status change messages depends on
          <c><anno>Options</anno></c>. If <c><anno>Options</anno></c> is [], which is the default,
          the format is:</p>
        <code type="none">
{nodeup, Node} | {nodedown, Node}
  Node = node()</code>
        <p>If <c><anno>Options</anno> /= []</c>, the format is:</p>
        <code type="none">
{nodeup, Node, InfoList} | {nodedown, Node, InfoList}
  Node = node()
  InfoList = [{Tag, Val}]</code>
        <p><c>InfoList</c> is a list of tuples. Its contents depends on
          <c><anno>Options</anno></c>, see below.</p>
        <p>Also, when <c>OptionList == []</c> only visible nodes, that
          is, nodes that appear in the result of
          <seealso marker="erts:erlang#nodes/0">nodes/0</seealso>, are
          monitored.</p>
        <p><c><anno>Option</anno></c> can be any of the following:</p>
        <taglist>
          <tag><c>{node_type, NodeType}</c></tag>
          <item>
            <p>Currently valid values for <c>NodeType</c> are:</p>
            <taglist>
              <tag><c>visible</c></tag>
              <item>Subscribe to node status change messages for visible
               nodes only. The tuple <c>{node_type, visible}</c> is
               included in <c>InfoList</c>.</item>
              <tag><c>hidden</c></tag>
              <item>Subscribe to node status change messages for hidden
               nodes only. The tuple <c>{node_type, hidden}</c> is
               included in <c>InfoList</c>.</item>
              <tag><c>all</c></tag>
              <item>Subscribe to node status change messages for both
               visible and hidden nodes. The tuple
              <c>{node_type, visible | hidden}</c> is included in
              <c>InfoList</c>.</item>
            </taglist>
          </item>
          <tag><c>nodedown_reason</c></tag>
          <item>
            <p>The tuple <c>{nodedown_reason, Reason}</c> is included in
              <c>InfoList</c> in <c>nodedown</c> messages. <c>Reason</c>
              can be:</p>
            <taglist>
              <tag><c>connection_setup_failed</c></tag>
              <item>The connection setup failed (after <c>nodeup</c>
               messages had been sent).</item>
              <tag><c>no_network</c></tag>
              <item>No network available.</item>
              <tag><c>net_kernel_terminated</c></tag>
              <item>The <c>net_kernel</c> process terminated.</item>
              <tag><c>shutdown</c></tag>
              <item>Unspecified connection shutdown.</item>
              <tag><c>connection_closed</c></tag>
              <item>The connection was closed.</item>
              <tag><c>disconnect</c></tag>
              <item>The connection was disconnected (forced from the
               current node).</item>
              <tag><c>net_tick_timeout</c></tag>
              <item>Net tick timeout.</item>
              <tag><c>send_net_tick_failed</c></tag>
              <item>Failed to send net tick over the connection.</item>
              <tag><c>get_status_failed</c></tag>
              <item>Status information retrieval from the <c>Port</c>
               holding the connection failed.</item>
            </taglist>
          </item>
        </taglist>
      </desc>
    </func>
    <func>
      <name name="get_net_ticktime" arity="0"/>
      <fsummary>Get <c>net_ticktime</c></fsummary>
      <desc>
        <p>Gets <c>net_ticktime</c> (see
          <seealso marker="kernel_app">kernel(6)</seealso>).</p>
        <p>Currently defined return values (<c><anno>Res</anno></c>):</p>
        <taglist>
          <tag><c><anno>NetTicktime</anno></c></tag>
          <item>
            <p><c>net_ticktime</c> is <c><anno>NetTicktime</anno></c> seconds.</p>
          </item>
          <tag><c>{ongoing_change_to, <anno>NetTicktime</anno>}</c></tag>
          <item>
            <p><c>net_kernel</c> is currently changing
              <c>net_ticktime</c> to <c><anno>NetTicktime</anno></c> seconds.</p>
          </item>
          <tag><c>ignored</c></tag>
          <item>
            <p>The local node is not alive.</p>
          </item>
        </taglist>
      </desc>
    </func>
    <func>
      <name name="set_net_ticktime" arity="1"/>
      <name name="set_net_ticktime" arity="2"/>
      <fsummary>Set <c>net_ticktime</c></fsummary>
      <desc>
        <p>Sets <c>net_ticktime</c> (see
          <seealso marker="kernel_app">kernel(6)</seealso>) to
          <c><anno>NetTicktime</anno></c> seconds. <c><anno>TransitionPeriod</anno></c> defaults
          to 60.</p>
        <p>Some definitions:</p>
        <taglist>
          <tag>The minimum transition traffic interval (<c>MTTI</c>)</tag>
          <item>
            <p><c>minimum(<anno>NetTicktime</anno>, PreviousNetTicktime)*1000 div 4</c> milliseconds.</p>
          </item>
          <tag>The transition period</tag>
          <item>
            <p>The time of the least number of consecutive <c>MTTI</c>s
              to cover <c><anno>TransitionPeriod</anno></c> seconds following
              the call to <c>set_net_ticktime/2</c> (i.e.
              ((<c><anno>TransitionPeriod</anno>*1000 - 1) div MTTI + 1)*MTTI</c>
              milliseconds).</p>
          </item>
        </taglist>
        <p>If <c><![CDATA[<anno>NetTicktime</anno> < PreviousNetTicktime]]></c>, the actual
          <c>net_ticktime</c> change will be done at the end of
          the transition period; otherwise, at the beginning. During
          the transition period, <c>net_kernel</c> will ensure that
          there will be outgoing traffic on all connections at least
          every <c>MTTI</c> millisecond.</p>
        <note>
          <p>The <c>net_ticktime</c> changes have to be initiated on all
            nodes in the network (with the same <c><anno>NetTicktime</anno></c>)
            before the end of any transition period on any node;
            otherwise, connections may erroneously be disconnected.</p>
        </note>
        <p>Returns one of the following:</p>
        <taglist>
          <tag><c>unchanged</c></tag>
          <item>
            <p><c>net_ticktime</c> already had the value of
              <c><anno>NetTicktime</anno></c> and was left unchanged.</p>
          </item>
          <tag><c>change_initiated</c></tag>
          <item>
            <p><c>net_kernel</c> has initiated the change of
              <c>net_ticktime</c> to <c><anno>NetTicktime</anno></c> seconds.</p>
          </item>
          <tag><c>{ongoing_change_to, <anno>NewNetTicktime</anno>}</c></tag>
          <item>
            <p>The request was <em>ignored</em>; because,
              <c>net_kernel</c> was busy changing <c>net_ticktime</c> to
              <c><anno>NewNetTicktime</anno></c> seconds.</p>
          </item>
        </taglist>
      </desc>
    </func>
    <func>
      <name>start([Name]) -> {ok, pid()} | {error, Reason}</name>
      <name>start([Name, NameType]) -> {ok, pid()} | {error, Reason}</name>
      <name>start([Name, NameType, Ticktime]) -> {ok, pid()} | {error, Reason}</name>
      <fsummary>Turn an Erlang runtime system into a distributed node</fsummary>
      <type>
        <v>Name = atom()</v>
        <v>NameType = shortnames | longnames</v>
        <v>Reason = {already_started, pid()} | term()</v>
      </type>
      <desc>
        <p>Note that the argument is a list with exactly one, two or
          three arguments. <c>NameType</c> defaults to <c>longnames</c>
          and <c>Ticktime</c> to 15000.</p>
        <p>Turns a non-distributed node into a distributed node by
          starting <c>net_kernel</c> and other necessary processes.</p>
      </desc>
    </func>
    <func>
      <name name="stop" arity="0"/>
      <fsummary>Turn a node into a non-distributed Erlang runtime system</fsummary>
      <desc>
        <p>Turns a distributed node into a non-distributed node. For
          other nodes in the network, this is the same as the node
          going down. Only possible when the net kernel was started
          using <c>start/1</c>, otherwise returns
          <c>{error, not_allowed}</c>. Returns <c>{error, not_found}</c>
          if the local node is not alive.</p>
      </desc>
    </func>
  </funcs>
</erlref>