summaryrefslogtreecommitdiff
path: root/erts/doc/src/erl_dist_protocol.xml
blob: ae3de0a31c47ef90b1f98209c79b00c7232c79fe (plain)
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">

<chapter>
  <header>
    <copyright>
      <year>2007</year>
      <year>2020</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.

  The Initial Developer of the Original Code is Ericsson AB.
    </legalnotice>

    <title>Distribution Protocol</title>
    <prepared></prepared>
    <docno></docno>
    <date>2007-09-21</date>
    <rev>PA1</rev>
    <file>erl_dist_protocol.xml</file>
  </header>

  <p>This description is far from complete. It will be updated if the
    protocol is updated. However, the protocols, both from Erlang
    nodes to the Erlang Port Mapper Daemon (EPMD) and between Erlang nodes
    are stable since many years.</p>

  <p>The distribution protocol can be divided into four parts:</p>

  <list type="bulleted">
    <item>
      <p>Low-level socket connection (1)</p>
    </item>
    <item>
      <p>Handshake, interchange node name, and authenticate (2)</p>
    </item>
    <item>
      <p>Authentication (done by <seeerl marker="kernel:net_kernel">
        <c>net_kernel(3)</c></seeerl>) (3)</p>
    </item>
    <item>
      <p>Connected (4)</p> 
    </item>
  </list>

  <p>A node fetches the port number of another node through the EPMD (at the
    other host) to initiate a connection request.</p>

  <p>For each host, where a distributed Erlang node is running, also an EPMD
    is to be running. The EPMD can be started explicitly or automatically
    as a result of the Erlang node startup.</p>

  <p>By default the EPMD listens on port 4369.</p>

  <p>(3) and (4) above are performed at the same level but the <c>net_kernel</c>
    disconnects the other node if it communicates using an invalid cookie (after
    1 second).</p>

  <p>The integers in all multibyte fields are in big-endian order.</p>

  <warning>
    <p>
      The Erlang Distribution protocol is not by itself secure and does not
      aim to be so. In order to get secure distribution the distributed nodes
      should be configured to use distribution over tls.
      See the <seeguide marker="ssl:ssl_distribution">
      Using SSL for Erlang Distribution</seeguide> User's Guide
      for details on how to setup a secure distributed node.
    </p>
  </warning>

  <section>
    <title>EPMD Protocol</title>
    <p>The requests served by the EPMD are summarized in the following
      figure.</p>

    <image file="erl_ext_fig.gif">
      <icaption>Summary of EPMD Requests</icaption>
    </image>

    <p>Each request <c>*_REQ</c> is preceded by a 2 byte length field.
      Thus, the overall request format is as follows:</p>

    <table align="left">
      <row>
        <cell align="center">2</cell>
        <cell align="center">n</cell>
      </row>
      <row>
        <cell align="center"><c>Length</c></cell>
        <cell align="center"><c>Request</c></cell>
      </row>
      <tcaption>Request Format</tcaption>
    </table>

    <section>
      <title>Register a Node in EPMD</title>
      <p>When a distributed node is started it registers itself in the EPMD.
        The message <c>ALIVE2_REQ</c> described below is sent from the node to
        the EPMD. The response from the EPMD is <c>ALIVE2_X_RESP</c> (or
        <c>ALIVE2_RESP</c>).</p>

      <table align="left">
        <row>
          <cell align="center">1</cell>
          <cell align="center">2</cell>
          <cell align="center">1</cell>
          <cell align="center">1</cell>
          <cell align="center">2</cell>
          <cell align="center">2</cell>
          <cell align="center">2</cell>
          <cell align="center">Nlen</cell>
          <cell align="center">2</cell>
          <cell align="center">Elen</cell>
        </row>
        <row>
          <cell align="center"><c>120</c></cell>
          <cell align="center"><c>PortNo</c></cell>
          <cell align="center"><c>NodeType</c></cell>
          <cell align="center"><c>Protocol</c></cell>
          <cell align="center"><c>HighestVersion</c></cell>
          <cell align="center"><c>LowestVersion</c></cell>
          <cell align="center"><c>Nlen</c></cell>
          <cell align="center"><c>NodeName</c></cell>
          <cell align="center"><c>Elen</c></cell>
          <cell align="center"><c>Extra</c></cell>
        </row>
        <tcaption>ALIVE2_REQ (120)</tcaption>
      </table>

      <taglist>
        <tag><c>PortNo</c></tag>
        <item>
          <p>The port number on which the node accept connection requests.</p>
        </item>
        <tag><c>NodeType</c></tag>
        <item>
          <p>77 = normal Erlang node, 72 = hidden node (C-node), ...</p>
        </item>
        <tag><c>Protocol</c></tag>
        <item>
          <p>0 = TCP/IPv4, ...</p>
        </item>
        <tag><c>HighestVersion</c></tag>
        <item>
          <p>The highest distribution protocol version this node can handle.
            The value in OTP 23 and later is 6. Older nodes only support version 5.</p>
        </item>
        <tag><c>LowestVersion</c></tag>
        <item>
          <p>The lowest distribution version that this node can handle.
            Should be 5 to support connections to nodes older than OTP 23.</p>
        </item>
        <tag><c>Nlen</c></tag>
        <item>
          <p>The length (in bytes) of field <c>NodeName</c>.</p>
        </item>
        <tag><c>NodeName</c></tag>
        <item>
          <p>The node name as an UTF-8 encoded string of <c>Nlen</c> bytes.</p>
        </item>
        <tag><c>Elen</c></tag>
        <item>
          <p>The length of field <c>Extra</c>.</p>
        </item>
        <tag><c>Extra</c></tag>
        <item>
          <p>Extra field of <c>Elen</c> bytes.</p>
        </item>
      </taglist>

      <p>The connection created to the EPMD must be kept as long as the
        node is a distributed node. When the connection is closed,
        the node is automatically unregistered from the EPMD.</p>

      <p>The response message is either <c>ALIVE2_X_RESP</c> or
        <c>ALIVE2_RESP</c> depending on distribution version. If both the node
        and EPMD support distribution version 6 then the response is
        <c>ALIVE2_X_RESP</c> otherwise it is the older <c>ALIVE2_RESP</c>:</p>

      <table align="left">
        <row>
          <cell align="center">1</cell>
          <cell align="center">1</cell>
          <cell align="center">4</cell>
        </row>
        <row>
          <cell align="center"><c>118</c></cell>
          <cell align="center"><c>Result</c></cell>
          <cell align="center"><c>Creation</c></cell>
        </row>
        <tcaption>ALIVE2_X_RESP (118) with 32 bit creation</tcaption>
      </table>

      <table align="left">
        <row>
          <cell align="center">1</cell>
          <cell align="center">1</cell>
          <cell align="center">2</cell>
        </row>
        <row>
          <cell align="center"><c>121</c></cell>
          <cell align="center"><c>Result</c></cell>
          <cell align="center"><c>Creation</c></cell>
        </row>
        <tcaption>ALIVE2_RESP (121) with 16-bit creation</tcaption>
      </table>

      <p>Result = 0 -> ok, result &gt; 0 -> error.</p>
    </section>

    <section>
      <title>Unregister a Node from EPMD</title>
      <p>A node unregisters itself from the EPMD by closing the TCP
        connection to EPMD established when the node was registered.</p>
    </section>

    <section>
      <title>Get the Distribution Port of Another Node</title>
      <p>When one node wants to connect to another node it starts with
        a <c>PORT_PLEASE2_REQ</c> request to the EPMD on the host where the
        node resides to get the distribution port that the node listens to.</p>

      <table align="left">
        <row>
          <cell align="center">1</cell>
          <cell align="center">N</cell>
        </row>
        <row>
          <cell align="center"><c>122</c></cell>
          <cell align="center"><c>NodeName</c></cell>
        </row>
        <tcaption>PORT_PLEASE2_REQ (122)</tcaption>
      </table>

      <p>where N = <c>Length</c> - 1.</p>

      <table align="left">
        <row>
          <cell align="center">1</cell>
          <cell align="center">1</cell>
        </row>
        <row>
          <cell align="center"><c>119</c></cell>
          <cell align="center"><c>Result</c></cell>
        </row>
        <tcaption>PORT2_RESP (119) Response Indicating Error, Result &gt; 0
        </tcaption>
      </table>

      <p>or</p>

      <table align="left">
        <row>
          <cell align="center">1</cell>
          <cell align="center">1</cell>
          <cell align="center">2</cell>
          <cell align="center">1</cell>
          <cell align="center">1</cell>
          <cell align="center">2</cell>
          <cell align="center">2</cell>
          <cell align="center">2</cell>
          <cell align="center">Nlen</cell>
          <cell align="center">2</cell>
          <cell align="center">Elen</cell>
        </row>
        <row>
          <cell align="center"><c>119</c></cell>
          <cell align="center"><c>Result</c></cell>
          <cell align="center"><c>PortNo</c></cell>
          <cell align="center"><c>NodeType</c></cell>
          <cell align="center"><c>Protocol</c></cell>
          <cell align="center"><c>HighestVersion</c></cell>
          <cell align="center"><c>LowestVersion</c></cell>
          <cell align="center"><c>Nlen</c></cell>
          <cell align="center"><c>NodeName</c></cell>
          <cell align="center"><c>Elen</c></cell>
          <cell align="center">><c>Extra</c></cell>
        </row>
        <tcaption>PORT2_RESP, Result = 0</tcaption>
      </table>

      <p>If <c>Result</c> &gt; 0, the packet only consists of
        <c>[119, Result]</c>.</p>

      <p>The EPMD closes the socket when it has sent the information.</p>
    </section>

    <section>
      <title>Get All Registered Names from EPMD</title>
      <p>This request is used through the Erlang function
        <seemfa marker="kernel:net_adm#names/1">
        <c>net_adm:names/1,2</c></seemfa>. A TCP connection is opened
        to the  EPMD and this request is sent.</p>

      <table align="left">
        <row>
          <cell align="center">1</cell>
        </row>
        <row>
          <cell align="center"><c>110</c></cell>
        </row>
        <tcaption>NAMES_REQ (110)</tcaption>
      </table>	

      <p>The response for a <c>NAMES_REQ</c> is as follows:</p>

      <table align="left">
        <row>
          <cell align="center">4</cell>
          <cell align="center">&nbsp;</cell>
        </row>
        <row>
          <cell align="center"><c>EPMDPortNo</c></cell>
          <cell align="center"><c>NodeInfo*</c></cell>
        </row>
        <tcaption>NAMES_RESP</tcaption>
      </table>

      <p><c>NodeInfo</c> is a string written for each active node.
        When all <c>NodeInfo</c> has been written the connection is
        closed by the EPMD.</p>

      <p><c>NodeInfo</c> is, as expressed in Erlang:</p>

      <code>
io:format("name ~ts at port ~p~n", [NodeName, Port]).</code>
    </section>

    <section>
      <title>Dump All Data from EPMD</title>
      <p>This request is not really used, it is to be regarded as a debug
        feature.</p>

      <table align="left">
        <row>
          <cell align="center">1</cell>
        </row>
        <row>
          <cell align="center"><c>100</c></cell>
        </row>
        <tcaption>DUMP_REQ</tcaption>
      </table>

      <p>The response for a <c>DUMP_REQ</c> is as follows:</p>

      <table align="left">
        <row>
          <cell align="center">4</cell>
          <cell align="center">&nbsp;</cell>
        </row>
        <row>
          <cell align="center"><c>EPMDPortNo</c></cell>
          <cell align="center"><c>NodeInfo*</c></cell>
        </row>
        <tcaption>DUMP_RESP</tcaption>
      </table>

      <p><c>NodeInfo</c> is a string written for each node kept in the EPMD.
        When all <c>NodeInfo</c> has been written the connection is
        closed by the EPMD.</p>

      <p><c>NodeInfo</c> is, as expressed in Erlang:</p>

      <code>
io:format("active name     ~ts at port ~p, fd = ~p~n",
          [NodeName, Port, Fd]).</code>

      <p>or</p>

      <code>
io:format("old/unused name ~ts at port ~p, fd = ~p ~n",
          [NodeName, Port, Fd]).</code>
    </section>

    <section>
      <title>Kill EPMD</title>
      <p>This request kills the running EPMD. It is almost never used.</p>

      <table align="left">
        <row>
          <cell align="center">1</cell>
        </row>
        <row>
          <cell align="center"><c>107</c></cell>
        </row>
        <tcaption>KILL_REQ</tcaption>
      </table>

      <p>The response for a <c>KILL_REQ</c> is as follows:</p>

      <table align="left">
        <row>
          <cell align="center">2</cell>
        </row>
        <row>
          <cell align="center"><c>OKString</c></cell>
        </row>
        <tcaption>KILL_RESP</tcaption>
      </table>

      <p>where <c>OKString</c> is "OK".</p>
    </section>

    <section>
      <title>STOP_REQ  (Not Used)</title>
      <table align="left">
        <row>
          <cell align="center">1</cell>
          <cell align="center">n</cell>
        </row>
        <row>
          <cell align="center"><c>115</c></cell>
          <cell align="center"><c>NodeName</c></cell>
        </row>
        <tcaption>STOP_REQ</tcaption>
      </table>

      <p>where n = <c>Length</c> - 1.</p>

      <p>The response for a <c>STOP_REQ</c> is as follows:</p>

      <table align="left">
        <row>
          <cell align="center">7</cell>
        </row>
        <row>
          <cell align="center"><c>OKString</c></cell>
        </row>
        <tcaption>STOP_RESP</tcaption>
      </table>

      <p>where <c>OKString</c> is "STOPPED".</p>

      <p>A negative response can look as follows:</p>

      <table align="left">
        <row>
          <cell align="center">7</cell>
        </row>
        <row>
          <cell align="center"><c>NOKString</c></cell>
        </row>
        <tcaption>STOP_NOTOK_RESP</tcaption>
      </table>

      <p>where <c>NOKString</c> is "NOEXIST".</p>
    </section>
<!--
    <section>
      <title>ALIVE_REQ (97)</title>
      <table align="left">
        <row>
          <cell align="center">1</cell>
          <cell align="center">2</cell>
          <cell align="center">n</cell>
        </row>
        <row>
          <cell align="center"><c>97</c></cell>
          <cell align="center"><c>PortNo</c></cell>
          <cell align="center"><c>NodeName</c></cell>
        </row>
        <tcaption></tcaption>
      </table>

      <p>where n = <c>Length</c> - 3.</p>

      <p>The connection created to the EPMD must be kept until the node is
        not a distributed node any longer.</p>
    </section>

    <section>
      <title>ALIVE_OK_RESP (89)</title>
      <table align="left">
        <row>
          <cell align="center">1</cell>
          <cell align="center">2</cell>
        </row>
        <row>
          <cell align="center"><c>89</c></cell>
          <cell align="center"><c>Creation</c></cell>
        </row>
        <tcaption></tcaption>
      </table>
    </section>

    <section>
      <title>ALIVE_NOTOK_RESP ()</title>
      <p>The EPMD closed the connection.</p>
    </section>

    <section>
      <title>PORT_PLEASE_REQ (112)</title>
      <table align="left">
        <row>
          <cell align="center">1</cell>
          <cell align="center">n</cell>
        </row>
        <row>
          <cell align="center"><c>112</c></cell>
          <cell align="center"><c>NodeName</c></cell>
        </row>
        <tcaption></tcaption>
      </table>

      <p>where n = <c>Length</c> - 1.</p>
    </section>

    <section>
      <title>PORT_OK_RESP ()</title>
      <table align="left">
        <row>
          <cell align="center">2</cell>
        </row>
        <row>
          <cell align="center"><c>PortNo</c></cell>
        </row>
        <tcaption></tcaption>
      </table>
    </section>

    <section>
      <title>PORT_NOTOK_RESP ()</title>
      <p>The EPMD closed the connection.</p>
    </section>

    <section>
      <title>PORT_NOTOK_RESP ()</title>
      <p>The EPMD closed the connection.</p>
    </section>
-->
  </section>

  <section>
    <marker id="distribution_handshake"/>
    <title>Distribution Handshake</title>
    <p>
      This section describes the distribution handshake protocol used between
      nodes to establishing a connection. The protocol was introduced in
      Erlang/OTP R6 and has remained unchanged until OTP 23. The changes made in
      OTP 23 were designed to be compatible with the older protocol
      version. That is an old node can still connect toward a new node and vice
      versa.
    </p>

    <section>
      <title>General</title>
      <p>The TCP/IP distribution uses a handshake that expects a
        connection-based protocol, that is, the protocol does not include any
        authentication after the handshake procedure.</p>

      <p>This is not entirely safe, as it is vulnerable against takeover
        attacks, but it is a tradeoff between fair safety and performance.</p>

      <p>The cookies are never sent in cleartext and the handshake procedure
        expects the client (called <c>A</c>) to be the first one to prove that
        it can generate a sufficient digest. The digest is generated with the
        MD5 message digest algorithm and the challenges are expected to be
        random numbers.</p>
    </section>

    <section>
      <title>Definitions</title>
      <p>A challenge is a 32-bit integer in big-endian order. Below the function
        <c>gen_challenge()</c> returns a random 32-bit integer used as a
        challenge.</p>

      <p>A digest is a (16 bytes) MD5 hash of the challenge (as text)
        concatenated with the cookie (as text). Below, the function
        <c>gen_digest(Challenge, Cookie)</c> generates a digest as described
        above.</p>

      <p>An <c>out_cookie</c> is the cookie used in outgoing communication to a
        certain node, so that <c>A</c>'s <c>out_cookie</c> for <c>B</c> is to
        correspond with <c>B</c>'s <c>in_cookie</c> for <c>A</c> and conversely.
        <c>A</c>'s <c>out_cookie</c> for <c>B</c> and <c>A</c>'s
        <c>in_cookie</c> for <c>B</c> need <em>not</em> be the same. Below the
        function <c>out_cookie(Node)</c> returns the current node's
        <c>out_cookie</c> for <c>Node</c>.</p>

      <p>An <c>in_cookie</c> is the cookie expected to be used by another node
        when communicating with us, so that <c>A</c>'s <c>in_cookie</c> for
        <c>B</c> corresponds with <c>B</c>'s <c>out_cookie</c> for <c>A</c>.
        Below the function <c>in_cookie(Node)</c> returns the current node's
        <c>in_cookie</c> for <c>Node</c>.</p>

      <p>The cookies are text strings that can be viewed as passwords.</p>

      <p>Every message in the handshake starts with a 16-bit big-endian integer,
        which contains the message length (not counting the two initial bytes).
        In Erlang this corresponds to option <c>{packet, 2}</c> in
        <seeerl marker="kernel:gen_tcp"><c>gen_tcp(3)</c></seeerl>.
        Notice that after the handshake, the distribution switches to 4 byte
        packet headers.</p>
    </section>

    <section>
      <title>The Handshake in Detail</title>
      <p>Imagine two nodes, <c>A</c> that initiates the handshake and <c>B</c>
        that accepts the connection.</p>

      <taglist>
      <tag>1) connect/accept</tag>
        <item>
          <p><c>A</c> connects to <c>B</c> through TCP/IP and <c>B</c> accepts
            the connection.</p>
        </item>
        <tag>2) <c>send_name</c>/<c>receive_name</c></tag>
        <item>
          <p><c>A</c> sends an initial identification to <c>B</c>, which
            receives the message. The message can have two different formats
	    which looks as follows (the packet headers are removed):
	  </p>
	  <table align="left">
            <row>
              <cell align="center">1</cell>
              <cell align="center">2</cell>
              <cell align="center">4</cell>
	      <cell align="center">Nlen</cell>
            </row>
            <row>
              <cell align="center"><c>'n'</c></cell>
              <cell align="center"><c>Version=5</c></cell>
              <cell align="center"><c>Flags</c></cell>
	      <cell align="center"><c>Name</c></cell>
            </row>
            <tcaption>Old send_name ('n') for protocol version 5</tcaption>
	  </table>

	  <table align="left">
            <row>
              <cell align="center">1</cell>
              <cell align="center">8</cell>
              <cell align="center">4</cell>
	      <cell align="center">2</cell>
	      <cell align="center">Nlen</cell>
            </row>
            <row>
              <cell align="center"><c>'N'</c></cell>
              <cell align="center"><c>Flags</c></cell>
	      <cell align="center"><c>Creation</c></cell>
	      <cell align="center"><c>Nlen</c></cell>
	      <cell align="center"><c>Name</c></cell>
            </row>
            <tcaption>New send_name ('N') for protocol version 6</tcaption>
	  </table>

	  <p>
	    The old <c>send_name</c> format is sent from nodes only supporting version 5
            or to nodes that might only support version 5. The <c>Version</c> is
	    a 16-bit big endian integer and <em>must</em> always have the value 5, even
	    if node <c>A</c> supports version 6. <c>Flags</c> are the
	    <seeguide marker="#dflags">capability flags</seeguide>
	    of node <c>A</c> in 32-bit big endian. The flag bit
	    <seeguide marker="#DFLAG_HANDSHAKE_23"><c>DFLAG_HANDSHAKE_23</c></seeguide>
	    should be set if node <c>A</c> supports version 6.
	    <c>Name</c> is the full node name of <c>A</c>, as a string of bytes
	    (the packet length denotes how long it is).
	  </p>
	  <p>
	    The new <c>send_name</c> is only sent from nodes supporting version 6 to
	    nodes known to support version 6. <c>Flags</c> are the
	    <seeguide marker="#dflags">capability flags</seeguide> of node
	    <c>A</c> in 64-bit big endian. The flag bit
	    <seeguide marker="#DFLAG_HANDSHAKE_23"><c>DFLAG_HANDSHAKE_23</c></seeguide>
            must always be set. <c>Creation</c> is the node incarnation
	    identifier used by node <c>A</c> to create its pids, ports and
	    references. <c>Name</c> is the full node name of <c>A</c>, as a
	    string of bytes. <c>Nlen</c> is the byte length of the node name in
	    16-bit big endian. Any extra data after the node <c>Name</c> must be
	    accepted and ignored.
	  </p>
        </item>
        <tag>3) <c>recv_status</c>/<c>send_status</c></tag>
        <item>
          <p>
	    <c>B</c> sends a status message to <c>A</c>, which indicates if the
            connection is allowed.
	  </p>
	  <table align="left">
            <row>
              <cell align="center">1</cell>
	      <cell align="center">Slen</cell>
            </row>
            <row>
              <cell align="center"><c>'s'</c></cell>
	      <cell align="center"><c>Status</c></cell>
            </row>
            <tcaption>The format of the status message</tcaption>
	  </table>
          <p>
	    's' is the message tag. <c>Status</c> is the status code as a
            string (not null terminated). The following status codes are
	    defined:
	  </p>
          <taglist>
            <tag><c>ok</c></tag>
            <item>
              <p>The handshake will continue.</p>
            </item>
            <tag><c>ok_simultaneous</c></tag>
            <item>
              <p>The handshake will continue, but <c>A</c> is informed that
                <c>B</c> has another ongoing connection attempt that will be
                shut down (simultaneous connect where <c>A</c>'s name is
                greater than <c>B</c>'s name, compared literally).</p>
            </item>
            <tag><c>nok</c></tag>
            <item>
              <p>The handshake will not continue, as <c>B</c> already has an
                ongoing handshake, which it itself has initiated (simultaneous
                connect where <c>B</c>'s name is greater than <c>A</c>'s).</p>
            </item>
            <tag><c>not_allowed</c></tag>
            <item>
              <p>The connection is disallowed for some (unspecified) security
                reason.</p>
            </item>
            <tag><c>alive</c></tag>
            <item>
              <p>A connection to the node is already active, which either means
                that node <c>A</c> is confused or that the TCP connection
                breakdown of a previous node with this name has not yet reached
                node <c>B</c>. See step 3B below.</p>
            </item>
	    <tag><c>named:</c></tag>
            <item><p>
	      The handshake willl continue, but <c>A</c> requested a dynamic
	      node name by setting flag <seeguide marker="#DFLAG_NAME_ME">
	      <c>DFLAG_NAME_ME</c></seeguide>. The dynamic node name of
	      <c>A</c> is supplied at the end of the status message from
	      <c>B</c>.</p>
            </item>
          </taglist>
	  <table align="left">
            <row>
              <cell align="center">1</cell>
	      <cell align="center">Slen=6</cell>
	      <cell align="center">2</cell>
	      <cell align="center">Nlen</cell>
            </row>
            <row>
              <cell align="center"><c>'s'</c></cell>
	      <cell align="center"><c>Status='named:'</c></cell>
	      <cell align="center"><c>Nlen</c></cell>
	      <cell align="center"><c>Name</c></cell>
            </row>
            <tcaption>The format of the 'named:' status message</tcaption>
	  </table>
	  <p>
	    <c>Name</c> is the full dynamic node name of <c>A</c>, as a
	    string of bytes. <c>Nlen</c> is the byte length of the node name in
	    16-bit big endian. Any extra data after the node <c>Name</c> must be
	    accepted and ignored.
	  </p>
          </item>
        <tag>3B) <c>send_status</c>/<c>recv_status</c></tag>
        <item>
          <p>If status was <c>alive</c>, node <c>A</c> answers with another
            status message containing either <c>true</c>, which means that the
            connection is to continue (the old connection from this node is
            broken), or <c>false</c>, which means that the connection is to be
            closed (the connection attempt was a mistake.</p>
        </item>
        <tag>4) <c>recv_challenge</c>/<c>send_challenge</c></tag>
        <item>
          <p>If the status was <c>ok</c> or <c>ok_simultaneous</c>, the
            handshake continues with <c>B</c> sending <c>A</c> another message,
            the challenge. The challenge contains the same type of information
            as the "name" message initially sent from <c>A</c> to <c>B</c>, plus
            a 32-bit challenge. The challenge message can have two different
	    formats:
	  </p>
	  <table align="left">
            <row>
              <cell align="center">1</cell>
	      <cell align="center">2</cell>
	      <cell align="center">4</cell>
	      <cell align="center">4</cell>
	      <cell align="center">Nlen</cell>
            </row>
            <row>
              <cell align="center"><c>'n'</c></cell>
	      <cell align="center"><c>Version=5</c></cell>
	      <cell align="center"><c>Flags</c></cell>
	      <cell align="center"><c>Challenge</c></cell>
	      <cell align="center"><c>Name</c></cell>
            </row>
            <tcaption>The old challenge message format (version 5)</tcaption>
	  </table>
	  <table align="left">
            <row>
              <cell align="center">1</cell>
	      <cell align="center">8</cell>
	      <cell align="center">4</cell>
	      <cell align="center">4</cell>
	      <cell align="center">2</cell>
	      <cell align="center">Nlen</cell>
            </row>
            <row>
              <cell align="center"><c>'N'</c></cell>
	      <cell align="center"><c>Flags</c></cell>
	      <cell align="center"><c>Challenge</c></cell>
	      <cell align="center"><c>Creation</c></cell>
	      <cell align="center"><c>Nlen</c></cell>
	      <cell align="center"><c>Name</c></cell>
            </row>
            <tcaption>The new challenge message format (version 6)</tcaption>
	  </table>
	  <p>
	    The old challenge message is sent from old <c>B</c> nodes
	    (supporting only version 5) or if node <c>A</c> had not capability flag
	    <seeguide marker="#DFLAG_HANDSHAKE_23"><c>DFLAG_HANDSHAKE_23</c></seeguide>
	    set. The <c>Version</c> is a 16-bit big endian integer and
	    <c>must</c> always have the value 5.
	  </p>
	  <p>
	    The new challenge message is sent from new <c>B</c> nodes if node
	    <c>A</c> had capability flag <seeguide marker="#DFLAG_HANDSHAKE_23">
	    <c>DFLAG_HANDSHAKE_23</c></seeguide> set. Any extra data after the
	    node <c>Name</c> must be accepted and ignored.
	  </p>
          <p>
	    <c>Challenge</c> is a 32-bit big-endian integer. The other fields
	    are node <c>B</c>'s flags, creation and full node name, similar to
	    the <c>send_name</c> message.
	  </p>
        </item>

        <tag>4B) <c>send_complement</c>/<c>recv_complement</c></tag>
        <item>
          <p>
	    The complement message, from <c>A</c> to <c>B</c>, is only sent if
	    node <c>A</c> initially sent an old name message and received back a
	    new challenge message from node <c>B</c>. It contains complementary
	    information missing in the initial old name message from node <c>A</c>.
	  </p>
	  <table align="left">
            <row>
              <cell align="center">1</cell>
	      <cell align="center">4</cell>
	      <cell align="center">4</cell>
            </row>
            <row>
              <cell align="center"><c>'c'</c></cell>
	      <cell align="center"><c>FlagsHigh</c></cell>
	      <cell align="center"><c>Creation</c></cell>
            </row>
            <tcaption>The complement message</tcaption>
	  </table>
	  <p>
	    <c>FlagsHigh</c> are the high capability flags (bit 33-64) of node
	    <c>A</c> as a 32-bit big endian integer. <c>Creation</c> is the
	    incarnation identifier of node <c>A</c>.
	  </p>
        </item>

        <tag>5) <c>send_challenge_reply</c>/<c>recv_challenge_reply</c></tag>
        <item>
          <p>Now <c>A</c> has generated a digest and its own challenge. Those
            are sent together in a package to <c>B</c>:</p>
	  <table align="left">
            <row>
              <cell align="center">1</cell>
	      <cell align="center">4</cell>
	      <cell align="center">16</cell>
            </row>
            <row>
              <cell align="center"><c>'r'</c></cell>
	      <cell align="center"><c>Challenge</c></cell>
	      <cell align="center"><c>Digest</c></cell>
            </row>
            <tcaption>The challenge_reply message</tcaption>
	  </table>
          <p>
	    <c>Challenge</c> is <c>A</c>'s challenge for <c>B</c> to
	    handle. <c>Digest</c> is the MD5 digest that <c>A</c> constructed
	    from the challenge <c>B</c> sent in the previous step.
	  </p>
        </item>
        <tag>6) <c>recv_challenge_ack</c>/<c>send_challenge_ack</c></tag>
        <item>
          <p><c>B</c> checks that the digest received from <c>A</c> is correct
            and generates a digest from the challenge received from <c>A</c>.
            The digest is then sent to <c>A</c>. The message is as follows:</p>
	  <table align="left">
            <row>
              <cell align="center">1</cell>
	      <cell align="center">16</cell>
            </row>
            <row>
              <cell align="center"><c>'a'</c></cell>
	      <cell align="center"><c>Digest</c></cell>
            </row>
            <tcaption>The challenge_ack message</tcaption>
	  </table>
          <p>
	    <c>Digest</c> is the digest calculated by <c>B</c> for <c>A</c>'s
	    challenge.
	  </p>
        </item>
        <tag>7) check</tag>
        <item>
          <p><c>A</c> checks the digest from <c>B</c> and the connection is
            up.</p>
        </item>
      </taglist>
    </section>

    <section>
      <title>Semigraphic View</title>
      <pre>
A (initiator)                                      B (acceptor)

TCP connect ------------------------------------&gt;
                                                   TCP accept

send_name --------------------------------------&gt;
                                                   recv_name

  &lt;---------------------------------------------- send_status
recv_status
(if status was 'alive'
 send_status - - - - - - - - - - - - - - - - - -&gt;
                                                   recv_status)

                          (ChB)                      ChB = gen_challenge()
  &lt;---------------------------------------------- send_challenge
recv_challenge

(if old send_name and new recv_challenge
 send_complement - - - - - - - - - - - - - - - -&gt;
                                                   recv_complement)

ChA = gen_challenge(),
OCA = out_cookie(B),
DiA = gen_digest(ChB, OCA)
                          (ChA, DiA)
send_challenge_reply ---------------------------&gt;
                                                   recv_challenge_reply
                                                   ICB = in_cookie(A),
                                                   check:
                                                   DiA == gen_digest (ChB, ICB)?
                                                   - if OK:
                                                    OCB = out_cookie(A),
                                                    DiB = gen_digest (ChA, OCB)
                          (DiB)
  &lt;----------------------------------------------- send_challenge_ack
recv_challenge_ack                                  DONE
ICA = in_cookie(B),                                - else:
check:                                              CLOSE
DiB == gen_digest(ChA, ICA)?
- if OK:
 DONE
- else:
 CLOSE</pre>
    </section>

    <section>
      <marker id="dflags"/>
      <title>Distribution Flags</title>
      <p>Early in the distribution handshake the two participating nodes
      exchange capability flags. This is done in order to determine how the
      communication between the two nodes should be performed. The intersection
      of the capabilities presented by the two nodes defines the capabilities
      that will be used. The following capability flags are defined:</p>
      <taglist>
        <tag><c>-define(DFLAG_PUBLISHED,16#1).</c></tag>
        <item>
          <p>The node is to be published and part of the global namespace.</p>
        </item>
        <tag><c>-define(DFLAG_ATOM_CACHE,16#2).</c></tag>
        <item>
          <p>The node implements an atom cache (obsolete).</p>
        </item>
        <tag><c>-define(DFLAG_EXTENDED_REFERENCES,16#4).</c></tag>
        <item>
          <p>The node implements extended (3 &times; 32 bits) references. This
            is required today. If not present, the  connection is refused.</p>
        </item>
        <tag><c>-define(DFLAG_DIST_MONITOR,16#8).</c></tag>
        <item>
          <p>The node implements distributed process monitoring.</p>
        </item>
        <tag><c>-define(DFLAG_FUN_TAGS,16#10).</c></tag>
        <item>
          <p>The node uses separate tag for funs (lambdas) in the distribution
            protocol.</p>
        </item>
        <tag><c>-define(DFLAG_DIST_MONITOR_NAME,16#20).</c></tag>
        <item>
          <p>The node implements distributed named process monitoring.</p>
        </item>
        <tag><c>-define(DFLAG_HIDDEN_ATOM_CACHE,16#40).</c></tag>
        <item>
          <p>The (hidden) node implements atom cache (obsolete).</p>
        </item>
        <tag><c>-define(DFLAG_NEW_FUN_TAGS,16#80).</c></tag>
        <item>
	  <p>The node understands the <seeguide marker="erl_ext_dist#NEW_FUN_EXT">
	    <c>NEW_FUN_EXT</c></seeguide> tag.</p>
        </item>
        <tag><c>-define(DFLAG_EXTENDED_PIDS_PORTS,16#100).</c></tag>
        <item>
          <p>The node can handle extended pids and ports. This is required
            today. If not present, the connection is refused.</p>
        </item>
        <tag><c>-define(DFLAG_EXPORT_PTR_TAG,16#200).</c></tag>
        <item>
	  <p>The node understands the <seeguide marker="erl_ext_dist#EXPORT_EXT">
	    <c>EXPORT_EXT</c></seeguide> tag.</p>
        </item>
        <tag><c>-define(DFLAG_BIT_BINARIES,16#400).</c></tag>
        <item>
	  <p>The node understands the <seeguide marker="erl_ext_dist#BIT_BINARY_EXT">
	    <c>BIT_BINARY_EXT</c></seeguide> tag.</p>
        </item>
        <tag><c>-define(DFLAG_NEW_FLOATS,16#800).</c></tag>
        <item>
	  <p>The node understands the <seeguide marker="erl_ext_dist#NEW_FLOAT_EXT">
	    <c>NEW_FLOAT_EXT</c></seeguide> tag.</p>
        </item>
        <tag><c>-define(DFLAG_UNICODE_IO,16#1000).</c></tag>
        <item>
        </item>
        <tag><c>-define(DFLAG_DIST_HDR_ATOM_CACHE,16#2000).</c></tag>
        <item>
          <p>The node implements atom cache in distribution header.</p>
        </item>
        <tag><marker id="DFLAG_SMALL_ATOM_TAGS"/><c>-define(DFLAG_SMALL_ATOM_TAGS, 16#4000).</c></tag>
        <item>
          <p>The node understands the <seeguide marker="erl_ext_dist#SMALL_ATOM_EXT">
	  <c>SMALL_ATOM_EXT</c></seeguide> tag.</p>
        </item>
        <tag><marker id="DFLAG_UTF8_ATOMS"/><c>-define(DFLAG_UTF8_ATOMS, 16#10000).</c></tag>
        <item>
          <p>The node understands UTF-8 atoms encoded with
	    <seeguide marker="erl_ext_dist#ATOM_UTF8_EXT">
	    <c>ATOM_UTF8_EXT</c></seeguide> and
	    <seeguide marker="erl_ext_dist#SMALL_ATOM_UTF8_EXT">
	    <c>SMALL ATOM_UTF8_EXT</c></seeguide>.</p>
        </item>
        <tag><c>-define(DFLAG_MAP_TAG, 16#20000).</c></tag>
        <item>
          <p>The node understands the map tag
	  <seeguide marker="erl_ext_dist#MAP_EXT"><c>MAP_EXT</c></seeguide>.</p>
        </item>
        <tag><marker id="DFLAG_BIG_CREATION"/><c>-define(DFLAG_BIG_CREATION, 16#40000).</c></tag>
        <item>
          <p>The node understands big node creation tags
	  <seeguide marker="erl_ext_dist#NEW_PID_EXT"><c>NEW_PID_EXT</c></seeguide>,
	  <seeguide marker="erl_ext_dist#NEW_PORT_EXT"><c>NEW_PORT_EXT</c></seeguide> and
	  <seeguide marker="erl_ext_dist#NEWER_REFERENCE_EXT"><c>NEWER_REFERENCE_EXT</c></seeguide>.
	  </p>
        </item>
        <tag><c>-define(DFLAG_SEND_SENDER, 16#80000).</c></tag>
        <item>
          <p>
	    Use the <c>SEND_SENDER</c>
	    <seeguide marker="#control_message">control message</seeguide>
	    instead of the <c>SEND</c> control message and use the
	    <c>SEND_SENDER_TT</c> control message instead
	    of the <c>SEND_TT</c> control message.
	  </p>
        </item>
        <tag><c>-define(DFLAG_BIG_SEQTRACE_LABELS, 16#100000).</c></tag>
        <item>
          <p>The node understands any term as the seqtrace label.</p>
        </item>
        <tag><c>-define(DFLAG_EXIT_PAYLOAD, 16#400000).</c></tag>
        <item>
          <p>Use the <c>PAYLOAD_EXIT</c>, <c>PAYLOAD_EXIT_TT</c>,
            <c>PAYLOAD_EXIT2</c>, <c>PAYLOAD_EXIT2_TT</c>
            and <c>PAYLOAD_MONITOR_P_EXIT</c>
            <seeguide marker="#control_message">control message</seeguide>s
            instead of the non-PAYLOAD variants.</p>
        </item>
        <tag><marker id="DFLAG_FRAGMENTS"/><c>-define(DFLAG_FRAGMENTS, 16#800000).</c></tag>
        <item>
          <p>Use <seeguide marker="erl_ext_dist#fragments">fragmented</seeguide>
            distribution messages to send large messages.</p>
        </item>
        <tag><marker id="DFLAG_HANDSHAKE_23"/><c>-define(DFLAG_HANDSHAKE_23, 16#1000000).</c></tag>
        <item>
          <p>The node supports the new connection setup handshake (version 6)
	  introduced in OTP 23.</p>
        </item>
        <tag><marker id="DFLAG_UNLINK_ID"/><c>-define(DFLAG_UNLINK_ID, 16#2000000).</c></tag>
        <item>
	  <p>Use the <seeguide marker="#new_link_protocol">new link protocol</seeguide>.</p>
	  <note><p>This flag will become mandatory in OTP 26.</p></note>
	  <p>Unless both nodes have set the <c>DFLAG_UNLINK_ID</c> flag, the
	  <seeguide marker="#old_link_protocol">old link protocol</seeguide>
	  will be used as a fallback.</p>
	</item>
        <tag><marker id="DFLAG_SPAWN"/><c>-define(DFLAG_SPAWN, (1 bsl 32)).</c></tag>
        <item>
          <p>Set if the <seeguide marker="#SPAWN_REQUEST"><c>SPAWN_REQUEST</c></seeguide>,
	  <seeguide marker="#SPAWN_REQUEST_TT"><c>SPAWN_REQUEST_TT</c></seeguide>,
	  <seeguide marker="#SPAWN_REPLY"><c>SPAWN_REPLY</c></seeguide>,
	  <seeguide marker="#SPAWN_REPLY_TT"><c>SPAWN_REPLY_TT</c></seeguide>
	  control messages are supported.</p>
        </item>
	<tag><marker id="DFLAG_NAME_ME"/><c>-define(DFLAG_NAME_ME, (1 bsl 33)).</c></tag>
        <item><p>
	  Dynamic node name. This is not a capability but rather used as a
	  request from the connecting node to receive its node name from the
	  accepting node as part of the handshake.</p>
	</item>
      </taglist>
      <p>
	There is also function <c>dist_util:strict_order_flags/0</c>
	returning all flags (bitwise or:ed together) corresponding to features
	that require strict ordering of data over distribution channels.
      </p>
    </section>
  </section>

  <section>
    <marker id="connected_nodes"/>
    <title>Protocol between Connected Nodes</title>
    <p>Since ERTS 5.7.2 (OTP R13B) the runtime system passes a distribution flag
      in the handshake stage that enables the use of a
      <seeguide marker="erl_ext_dist#distribution_header">distribution header
      </seeguide> on all messages passed. Messages passed between nodes have in
      this case the following format:</p>

    <table align="left">
      <row>
        <cell align="center">4</cell>
        <cell align="center">d</cell>
        <cell align="center">n</cell>
        <cell align="center">m</cell>
      </row>
      <row>
        <cell align="center"><c>Length</c></cell>
        <cell align="center"><c>DistributionHeader</c></cell>
        <cell align="center"><c>ControlMessage</c></cell>
        <cell align="center"><c>Message</c></cell>
      </row>
      <tcaption>Format of Messages Passed between Nodes (as from ERTS 5.7.2 (OTP R13B))
      </tcaption>
    </table>

    <taglist>
      <tag><c>Length</c></tag>
      <item>
        <p>Equal to d + n + m.</p>
      </item>
      <tag><c>DistributionHeader</c></tag>
      <item>
        <p>
          <seeguide marker="erl_ext_dist#distribution_header">Distribution header
          describing the atom cache and fragmented distribution messages.
          </seeguide>
        </p>
      </item>
      <tag><c>ControlMessage</c></tag>
      <item>
        <p>A tuple passed using the external format of Erlang.</p>
      </item>
      <tag><c>Message</c></tag>
      <item>
        <p>The message sent to another node using the '!'
          or the reason for a EXIT, EXIT2 or DOWN signal using
          the external term format.</p>
      </item>
    </taglist>

    <p>Notice that <seeguide marker="erl_ext_dist#overall_format">the version
      number is omitted from the terms that follow a distribution header
      </seeguide>.</p>

    <p>Nodes with an ERTS version earlier than 5.7.2 (OTP R13B) does not pass the
      distribution flag that enables the distribution header. Messages passed
      between nodes have in this case the following format:</p>

    <table align="left">
      <row>
        <cell align="center">4</cell>
        <cell align="center">1</cell>
        <cell align="center">n</cell>
        <cell align="center">m</cell>
      </row>
      <row>
        <cell align="center"><c>Length</c></cell>
        <cell align="center"><c>Type</c></cell>
        <cell align="center"><c>ControlMessage</c></cell>
        <cell align="center"><c>Message</c></cell>
      </row>
      <tcaption>Format of Messages Passed between Nodes (before ERTS 5.7.2 (OTP R13B))
      </tcaption>
    </table>

    <taglist>
      <tag><c>Length</c></tag>
      <item>
        <p>Equal to 1 + n + m.</p>
      </item>
      <tag><c>Type</c></tag>
      <item>
        <p>Equal to <c>112</c> (pass through).</p>
      </item>
      <tag><c>ControlMessage</c></tag>
      <item>
        <p>A tuple passed using the external format of Erlang.</p>
      </item>
      <tag><c>Message</c></tag>
      <item>
        <p>The message sent to another node using the '!' (in external format).
          Notice that <c>Message</c> is only passed in combination with a
          <c>ControlMessage</c> encoding a send ('!').</p>
      </item>
    </taglist>

    <marker id="control_message"/>
    <p>The <c>ControlMessage</c> is a tuple, where the first element indicates
      which distributed operation it encodes:</p>

    <taglist>
      <tag><marker id="LINK"/><c>LINK</c></tag>
      <item>
        <p><c>{1, FromPid, ToPid}</c></p>
	<p>This signal is sent by <c>FromPid</c> in order
	to create a link between <c>FromPid</c> and
	<c>ToPid</c>.</p>
      </item>
      <tag><c>SEND</c></tag>
      <item>
        <p><c>{2, Unused, ToPid}</c></p>
        <p>Followed by <c>Message</c>.</p>
        <p><c>Unused</c> is kept for backward compatibility.</p>
      </item>
      <tag><c>EXIT</c></tag>
      <item>
        <p><c>{3, FromPid, ToPid, Reason}</c></p>
        <p>This signal is sent when a link has been broken</p>
      </item>
      <tag><marker id="UNLINK"/><c>UNLINK</c> (deprecated)</tag>
      <item>
        <p><c>{4, FromPid, ToPid}</c></p>
	<p>This signal is sent by <c>FromPid</c> in order to remove
	a link between <c>FromPid</c> and <c>ToPid</c>, when using the
	<seeguide marker="#old_link_protocol">old link
	protocol</seeguide>.</p>
	<warning><p>This signal has been deprecated and will not
	be supported in OTP 26. For more information see the
	documentation of the
	<seeguide marker="#new_link_protocol">new link protocol</seeguide>.
	</p></warning>
      </item>
      <tag><c>NODE_LINK</c></tag>
      <item>
        <p><c>{5}</c></p>
      </item>
      <tag><c>REG_SEND</c></tag>
      <item>
        <p><c>{6, FromPid, Unused, ToName}</c></p>
        <p>Followed by <c>Message</c>.</p>
        <p><c>Unused</c> is kept for backward compatibility.</p>
      </item>
      <tag><c>GROUP_LEADER</c></tag>
      <item>
        <p><c>{7, FromPid, ToPid}</c></p>
      </item>	
      <tag><c>EXIT2</c></tag>
      <item>
        <p><c>{8, FromPid, ToPid, Reason}</c></p>
        <p>This signal is sent by a call to the erlang:exit/2 bif</p>
      </item>
      <tag><c>SEND_TT</c></tag>
      <item>
        <p><c>{12, Unused, ToPid, TraceToken}</c></p>
        <p>Followed by <c>Message</c>.</p>
        <p><c>Unused</c> is kept for backward compatibility.</p>
      </item>
      <tag><c>EXIT_TT</c></tag>
      <item>
        <p><c>{13, FromPid, ToPid, TraceToken, Reason}</c></p>
      </item>
      <tag><c>REG_SEND_TT</c></tag>
      <item>
        <p><c>{16, FromPid, Unused, ToName, TraceToken}</c></p>
        <p>Followed by <c>Message</c>.</p>
        <p><c>Unused</c> is kept for backward compatibility.</p>
      </item>
      <tag><c>EXIT2_TT</c></tag>
      <item>
        <p><c>{18, FromPid, ToPid, TraceToken, Reason}</c></p>
      </item>
      <tag><c>MONITOR_P</c></tag>
      <item>
        <p><c>{19, FromPid, ToProc, Ref}</c>, where
          <c>FromPid</c> = monitoring process and
          <c>ToProc</c> = monitored process pid or name (atom)</p>
      </item>
      <tag><c>DEMONITOR_P</c></tag>
      <item>
        <p><c>{20, FromPid, ToProc, Ref}</c>, where
          <c>FromPid</c> = monitoring process and
          <c>ToProc</c> = monitored process pid or name (atom)</p>
        <p>We include <c>FromPid</c> just in case we want to trace this.</p>
      </item>
      <tag><c>MONITOR_P_EXIT</c></tag>
      <item>
        <p><c>{21, FromProc, ToPid, Ref, Reason}</c>, where
          <c>FromProc</c> = monitored process pid or name (atom),
          <c>ToPid</c> = monitoring process, and
          <c>Reason</c> = exit reason for the monitored process</p>
      </item>
    </taglist>

    <section>
    <title>New Ctrlmessages for Erlang/OTP 21</title>
    <taglist>
      <tag><c>SEND_SENDER</c></tag>
      <item>
        <p><c>{22, FromPid, ToPid}</c></p>
        <p>Followed by <c>Message</c>.</p>
	<p>
	  This control message replaces the <c>SEND</c> control
	  message and will be sent when the distribution flag
	  <seeguide marker="erl_dist_protocol#dflags"><c>DFLAG_SEND_SENDER</c></seeguide>
	  has been negotiated in the connection setup handshake.
	</p>
	<note><p>
	  Messages encoded before the connection has
	  been set up may still use the <c>SEND</c> control
	  message. However, once a <c>SEND_SENDER</c> or <c>SEND_SENDER_TT</c>
	  control message has been sent, no more <c>SEND</c>
	  control messages will be sent in the same direction
	  on the connection.
	</p></note>
      </item>
      <tag><c>SEND_SENDER_TT</c></tag>
      <item>
        <p><c>{23, FromPid, ToPid, TraceToken}</c></p>
        <p>Followed by <c>Message</c>.</p>
	<p>
	  This control message replaces the <c>SEND_TT</c> control
	  message and will be sent when the distribution flag
	  <seeguide marker="erl_dist_protocol#dflags"><c>DFLAG_SEND_SENDER</c></seeguide>
	  has been negotiated in the connection setup handshake.
	</p>
	<note><p>
	  Messages encoded before the connection has
	  been set up may still use the <c>SEND_TT</c> control
	  message. However, once a <c>SEND_SENDER</c> or <c>SEND_SENDER_TT</c>
	  control message has been sent, no more <c>SEND_TT</c>
	  control messages will be sent in the same direction
	  on the connection.
	</p></note>
      </item>
    </taglist>
  </section>

  <section>
    <title>New Ctrlmessages for Erlang/OTP 22</title>
    <note><p>
      Messages encoded before the connection has
      been set up may still use the non-PAYLOAD variant.
      However, once a PAYLOAD control message has been sent,
      no more non-PAYLOAD control messages will be sent in
      the same direction on the connection.
    </p></note>
    <taglist>
      <tag><c>PAYLOAD_EXIT</c></tag>
      <item>
        <p><c>{24, FromPid, ToPid}</c></p>
        <p>Followed by <c>Reason</c>.</p>
	<p>
	  This control message replaces the <c>EXIT</c> control
	  message and will be sent when the distribution flag
	  <seeguide marker="erl_dist_protocol#dflags"><c>DFLAG_EXIT_PAYLOAD</c></seeguide>
	  has been negotiated in the connection setup handshake.
	</p>
      </item>
      <tag><c>PAYLOAD_EXIT_TT</c></tag>
      <item>
        <p><c>{25, FromPid, ToPid}</c></p>
        <p>Followed by <c>Reason</c>.</p>
	<p>
	  This control message replaces the <c>EXIT_TT</c> control
	  message and will be sent when the distribution flag
	  <seeguide marker="erl_dist_protocol#dflags"><c>DFLAG_EXIT_PAYLOAD</c></seeguide>
	  has been negotiated in the connection setup handshake.
	</p>
      </item>
      <tag><c>PAYLOAD_EXIT2</c></tag>
      <item>
        <p><c>{26, FromPid, ToPid}</c></p>
        <p>Followed by <c>Reason</c>.</p>
	<p>
	  This control message replaces the <c>EXIT2</c> control
	  message and will be sent when the distribution flag
	  <seeguide marker="erl_dist_protocol#dflags"><c>DFLAG_EXIT_PAYLOAD</c></seeguide>
	  has been negotiated in the connection setup handshake.
	</p>
      </item>
      <tag><c>PAYLOAD_EXIT2_TT</c></tag>
      <item>
        <p><c>{27, FromPid, ToPid}</c></p>
        <p>Followed by <c>Reason</c>.</p>
	<p>
	  This control message replaces the <c>EXIT2_TT</c> control
	  message and will be sent when the distribution flag
	  <seeguide marker="erl_dist_protocol#dflags"><c>DFLAG_EXIT_PAYLOAD</c></seeguide>
	  has been negotiated in the connection setup handshake.
	</p>
      </item>
      <tag><c>PAYLOAD_MONITOR_P_EXIT</c></tag>
      <item>
        <p><c>{28, FromPid, ToPid, Ref}</c></p>
        <p>Followed by <c>Reason</c>.</p>
	<p>
	  This control message replaces the <c>MONITOR_P_EXIT</c> control
	  message and will be sent when the distribution flag
	  <seeguide marker="erl_dist_protocol#dflags"><c>DFLAG_EXIT_PAYLOAD</c></seeguide>
	  has been negotiated in the connection setup handshake.
	</p>
      </item>
      
    </taglist>
  </section>
  <section>
    <title>New Ctrlmessages for Erlang/OTP 23</title>
    <taglist>
      <tag><marker id="SPAWN_REQUEST"/><c>SPAWN_REQUEST</c></tag>
      <item>
        <p><c>{29, ReqId, From, GroupLeader, {Module, Function, Arity}, OptList}</c></p>
        <p>Followed by <c>ArgList</c>.</p>
	<p>This signal is sent by the
	<seemfa marker="erlang#spawn_request/5"><c>spawn_request()</c></seemfa> BIF.</p>
	<taglist>
	  <tag><c>ReqId :: reference()</c></tag>
	  <item><p>Request identifier. Also used as monitor
	  reference in case the <c>monitor</c> option has been
	  passed.</p></item>
	  <tag><c>From :: pid()</c></tag>
	  <item><p>Process identifier of the process making the
	  request. That is, the parent process to be.</p></item>
	  <tag><c>GroupLeader :: pid()</c></tag>
	  <item><p>Process identifier of the group leader of the
	  newly created process.</p></item>
	  <tag><c>{Module :: atom(), Function :: atom(), Arity :: integer() >= 0}</c></tag>
	  <item><p>Entry point for the the new process.</p></item>
	  <tag><c>OptList :: [term()]</c></tag>
	  <item><p>A proper list of spawn options to use when spawning.</p></item>
	  <tag><c>ArgList :: [term()]</c></tag>
	  <item><p>A proper list of arguments to use in the call to the entry point.</p></item>
	</taglist>
	<p>
	  Only supported when the
	  <seeguide marker="erl_dist_protocol#DFLAG_SPAWN"><c>DFLAG_SPAWN</c></seeguide>
	  <seeguide marker="erl_dist_protocol#dflags">distribution flag</seeguide>
	  has been passed.
	</p>
      </item>
      <tag><marker id="SPAWN_REQUEST_TT"/><c>SPAWN_REQUEST_TT</c></tag>
      <item>
        <p><c>{30, ReqId, From, GroupLeader, {Module, Function, Arity}, OptList, Token}</c></p>
        <p>Followed by <c>ArgList</c>.</p>
	<p>Same as <seeguide marker="#SPAWN_REQUEST"><c>SPAWN_REQUEST</c></seeguide>, but also
	with a sequential trace <c>Token</c>.
	</p>
	<p>
	  Only supported when the
	  <seeguide marker="erl_dist_protocol#DFLAG_SPAWN"><c>DFLAG_SPAWN</c></seeguide>
	  <seeguide marker="erl_dist_protocol#dflags">distribution flag</seeguide>
	  has been passed.
	</p>
      </item>
      <tag><marker id="SPAWN_REPLY"/><c>SPAWN_REPLY</c></tag>
      <item>
        <p><c>{31, ReqId, To, Flags, Result}</c></p>
	<p>This signal is sent as a reply to a process previously sending
	a <seeguide marker="#SPAWN_REQUEST"><c>SPAWN_REQUEST</c></seeguide> signal.</p>
	<taglist>
	  <tag><c>ReqId :: reference()</c></tag>
	  <item><p>Request identifier. Also used as monitor
	  reference in case the <c>monitor</c> option has been
	  passed.</p></item>
	  <tag><c>To :: pid()</c></tag>
	  <item><p>Process identifier of the process making the
	  spawn request.</p></item>
	  <tag><c>Flags :: integer() >= 0</c></tag>
	  <item><p>A bit flag field of bit flags bitwise or:ed together. Currently the
	  following flags are defined:</p>
	  <taglist>
	    <tag><c>1</c></tag>
	    <item><p>A link between <c>To</c> and <c>Result</c> was set up on
	    the node where <c>Result</c> resides.</p></item>
	    <tag><c>2</c></tag>
	    <item><p>A monitor from <c>To</c> to <c>Result</c> was set up on
	    the node where <c>Result</c> resides.</p></item>
	  </taglist>
	  </item>
	  <tag><c>Result :: pid() | atom()</c></tag>
	  <item><p>Result of the operation. If <c>Result</c> is a process
	  identifier, the operation succeeded and the process identifier
	  is the identifier of the newly created process. If <c>Result</c>
	  is an atom, the operation failed and the atom identifies failure
	  reason.</p></item>
	</taglist>
	<p>
	  Only supported when the
	  <seeguide marker="erl_dist_protocol#DFLAG_SPAWN"><c>DFLAG_SPAWN</c></seeguide>
	  <seeguide marker="erl_dist_protocol#dflags">distribution flag</seeguide>
	  has been passed.
	</p>
      </item>
      <tag><marker id="SPAWN_REPLY_TT"/><c>SPAWN_REPLY_TT</c></tag>
      <item>
        <p><c>{32, ReqId, To, Flags, Result, Token}</c></p>
	<p>Same as <seeguide marker="#SPAWN_REPLY"><c>SPAWN_REPLY</c></seeguide>, but also
	with a sequential trace <c>Token</c>.</p>
	<p>
	  Only supported when the
	  <seeguide marker="erl_dist_protocol#DFLAG_SPAWN"><c>DFLAG_SPAWN</c></seeguide>
	  <seeguide marker="erl_dist_protocol#dflags">distribution flag</seeguide>
	  has been passed.
	</p>
      </item>
      <tag><marker id="UNLINK_ID"/><c>UNLINK_ID</c></tag>
      <item>
        <p><c>{35, Id, FromPid, ToPid}</c></p>
	<p>This signal is sent by <c>FromPid</c> in order to remove a
	link between <c>FromPid</c> and <c>ToPid</c>. This unlink signal
        replaces the <seeguide marker="#UNLINK"><c>UNLINK</c></seeguide>
	signal. Besides process identifiers of the sender and receiver
	the <c>UNLINK_ID</c> signal also contains an integer identifier
	<c>Id</c>. Valid range of <c>Id</c> is <c>[1, (1 bsl 64) - 1]</c>.
	<c>Id</c> is to be passed back to the sender by the receiver in an
	<seeguide marker="#UNLINK_ID_ACK"><c>UNLINK_ID_ACK</c></seeguide>
	signal. <c>Id</c> must uniquely identify the <c>UNLINK_ID</c> signal
	among all not yet acknowledged <c>UNLINK_ID</c> signals from
	<c>FromPid</c> to <c>ToPid</c>.</p>
	<p>
	  This signal is only passed when the 
	  <seeguide marker="#new_link_protocol">new link protocol</seeguide>
	  has been negotiated using the
	  <seeguide marker="erl_dist_protocol#DFLAG_UNLINK_ID"><c>DFLAG_UNLINK_ID</c></seeguide>
	  <seeguide marker="erl_dist_protocol#dflags">distribution flag</seeguide>.
	</p>
      </item>
      <tag><marker id="UNLINK_ID_ACK"/><c>UNLINK_ID_ACK</c></tag>
      <item>
        <p><c>{36, Id, FromPid, ToPid}</c></p>
        <p>An unlink acknowledgement signal. This signal is sent as an
	acknowledgement of the reception of an 
	<seeguide marker="#UNLINK_ID"><c>UNLINK_ID</c></seeguide>
	signal. The <c>Id</c> element should be the same <c>Id</c>
	as present in the <c>UNLINK_ID</c> signal. <c>FromPid</c>
	identifies the sender of the <c>UNLINK_ID_ACK</c> signal and
	<c>ToPid</c> identifies the sender of the <c>UNLINK_ID</c>
	signal.</p>
	<p>
	  This signal is only passed when the 
	  <seeguide marker="#new_link_protocol">new link protocol</seeguide>
	  has been negotiated using the
	  <seeguide marker="erl_dist_protocol#DFLAG_UNLINK_ID"><c>DFLAG_UNLINK_ID</c></seeguide>
	  <seeguide marker="erl_dist_protocol#dflags">distribution flag</seeguide>.
	</p>
      </item>
    </taglist>
  </section>
  <section>
    <marker id="link_protocol"/>
    <title>Link Protocol</title>

    <section>
      <marker id="new_link_protocol"/>
      <title>New Link Protocol</title>

      <p>
	The new link protocol will be used when both nodes flag that
	they understand it using the
	<seeguide marker="#DFLAG_UNLINK_ID"><c>DFLAG_UNLINK_ID</c></seeguide>
	<seeguide marker="#dflags">distribution flag</seeguide>. If
	one of the nodes does not understand the new link protocol, the
	<seeguide marker="#old_link_protocol">old link protocol</seeguide>
	will be used as a fallback.
      </p>
      
      <p>
	The new link protocol introduces two new signals,
	<seeguide marker="#UNLINK_ID"><c>UNLINK_ID</c></seeguide> and
	<seeguide marker="#UNLINK_ID"><c>UNLINK_ID_ACK</c></seeguide>,
	which replace the old
	<seeguide marker="#UNLINK"><c>UNLINK</c></seeguide>
	signal. The old <seeguide marker="#LINK"><c>LINK</c></seeguide>
	signal is still sent in order to set up a link, but handled
	differently upon reception.
      </p>

      <p>
	In order to set up a link, a <c>LINK</c> signal is sent, from
	the process initiating the operation, to the process that it
	wants to link to. In order to remove a link, an
	<c>UNLINK_ID</c> signal is sent, from the process initiating
	the operation, to the linked process. The receiver of an
	<c>UNLINK_ID</c> signal responds with an <c>UNLINK_ID_ACK</c>
	signal. Upon reception of an <c>UNLINK_ID</c> signal, the
	corresponding <c>UNLINK_ID_ACK</c> signal <em>must</em> be
	sent before any other signals are sent to the sender of the
	<c>UNLINK_ID</c> signal. Together with
	<seeguide marker="erts:communication#passing-of-signals">the
	signal ordering guarantees</seeguide> of Erlang this makes it
	possible for the sender of the <c>UNLINK_ID</c> signal to know
	the order of other signals which is essential for the protocol.
	The <c>UNLINK_ID_ACK</c> signal should contain the same
	<c>Id</c> as the <c>Id</c> contained in the <c>UNLINK_ID</c>
	signal being acknowledged.
      </p>

      <p>
	Processes also need to maintain process local information about
	links. The state of this process local information is changed
	when the signals above are sent and received. This process
	local information also determines if a signal should be sent
	when a process calls
	<seemfa marker="erlang#link/1"><c>link/1</c></seemfa> or
	<seemfa marker="erlang#unlink/1"><c>unlink/1</c></seemfa>.
	A <c>LINK</c> signal is only sent if there does not currently
	exist an active link between the processes according to the
	process local information and an <c>UNLINK_ID</c> signal is
	only sent if there currently exists an active link between the
	processes according to the process local information.
      </p>

      <p>
	The process local information about a link contains:
      </p>
      <taglist>
	<tag>Pid</tag>
	<item>
	  Process identifier of the linked process.
	</item>
	<tag>Active Flag</tag>
	<item>
	  If set, the link is active and the process will react on
	  <seeguide marker="system/reference_manual:processes#receiving_exit_signals">incoming
	  exit signals</seeguide> issued due to the link. If not set,
	  the link is inactive and incoming exit signals, issued due
	  to the link, will be ignored. That is, the processes are
	  considered as <em>not</em> linked.
	</item>
	<tag>Unlink Id</tag>
	<item>
	  Identifier of an outstanding unlink operation. That is,
	  an unlink operation that has not yet been acknowledged.
	  This information is only used when the active flag is not
	  set.
	</item>
      </taglist>

      <p>
	A process is only considered linked to another process
	if it has process local information about the link
	containing the process identifier of the other process and
	with the active flag set.
      </p>

      <p>
	The process local information about a link is updated as
	follows:
      </p>
      <taglist>
	<tag>A <c>LINK</c> signal is sent</tag>
	<item>
	  Link information is created if not already existing. The
	  active flag is set, and unlink id is cleared. That is,
	  if we had an outstanding unlink operation we will ignore
	  the result of that operation and enable the link.
	</item>
	<tag>A <c>LINK</c> signal is received</tag>
	<item>
	  If no link information already exists, it is created, the
	  active flag is set and unlink id is cleared. If the link
	  information already exists, the signal is silently ignored,
	  regardless of whether the active flag is set or not.
	  That is, if we have an outstanding unlink operation we will
	  <em>not</em> activate the link. In this scenario, the sender
	  of the <c>LINK</c> signal has not yet sent an
	  <c>UNLINK_ID_ACK</c> signal corresponding to our
	  <c>UNLINK_ID</c> signal which means that it will receive
	  our <c>UNLINK_ID</c> signal after it sent its
	  <c>LINK</c> signal. This in turn means that both processes
	  in the end will agree that there is no link between them.
	</item>
	<tag>An <c>UNLINK_ID</c> signal is sent</tag>
	<item>
	  Link information already exists and the active flag is set
	  (otherwise the signal would not be sent). The active flag
	  is unset, and the unlink id of the signal is saved in the
	  link information.
	</item>
	<tag>An <c>UNLINK_ID</c> signal is received</tag>
	<item>
	  If the active flag is set, information about the link
	  is removed. If the active flag is not set (that is, we have
	  an outstanding unlink operation), the information about the
	  link is left unchanged.
	</item>
	<tag>An <c>UNLINK_ID_ACK</c> signal is sent</tag>
	<item>
	  This is done when an <c>UNLINK_ID</c> signal is received and
	  causes no further changes of the link information.
	</item>
	<tag>An <c>UNLINK_ID_ACK</c> signal is received</tag>
	<item>
	  If information about the link exists, the active flag is not
	  set, and the unlink id in the link information equals the
	  <c>Id</c> in the signal, the link information is removed;
	  otherwise, the signal is ignored.
	</item>
      </taglist>

      <p>
	When a process receives an exit signal due to a link, the
	process will first react to the exit signal if the link
	is active and then remove the process local information about
	the link.
      </p>
      <p>
	In case the connection is lost between two nodes, exit signals
	with exit reason <c>noconnection</c> are sent to all processes
	with links over the connection. This will cause all process
	local information about links over the connection to be
	removed.
      </p>
      <p>
	Exactly the same link protocol is also used internally on an
	Erlang node. The signals however have different formats since
	they do not have to be sent over the wire.
      </p>
    </section>

    <section>
      <marker id="old_link_protocol"/>
      <title>Old Link Protocol</title>

      <p>
	The old link protocol utilize two signals
	<seeguide marker="#LINK"><c>LINK</c></seeguide>, and
	<seeguide marker="#UNLINK"><c>UNLINK</c></seeguide>. The
	<c>LINK</c> signal informs the other process that a link
	should be set up, and the <c>UNLINK</c> signal informs the
	other process that a link should be removed. This protocol
	is however a bit too naive. If both processes operate on the
	link simultaneously, the link may end up in an inconsistent
	state where one process thinks it is linked while the other
	thinks it is not linked.
      </p>
      <p>
	This protocol is deprecated and support for it will be removed
	in OTP 26. Until then, it will be used as fallback when
	communicating with old nodes that do not understand the
	<seeguide marker="#new_link_protocol">new link
	protocol</seeguide>.
      </p>
    </section>

  </section>
  </section>

</chapter>