📄 erl_ext_dist.txt
字号:
<---------------- PORT2_RESP NAMES_REQ ----------------> <---------------- NAMES_RESP DUMP_REQ ----------------> <---------------- DUMP_RESP KILL_REQ ----------------> <---------------- KILL_RESP STOP_REQ ----------------> <---------------- STOP_OK_RESP <---------------- STOP_NOTOK_RESP3.1 RequestsEach request *_REQ is presided by a two byte length field. Thus, theoverall request format is: 2 n+--------+---------+| Length | Request |+--------+---------+3.1.1 ALIVE_REQ (97) 1 2 n+----+--------+----------+| 97 | PortNo | NodeName |+----+--------+----------+where n = Length - 3The connection created to the EPMD must be kept until the node isnot a distributed node any longer.3.1.1.1 ALIVE2_REQ (120)[120, PortNo, NodeType, Protocol, DistrvsnRange, Nlen, NodeName, Elen, Extra]PortNo = 2 bytesNodeType = 1 byte (77 = normal erlang node, 72 hidden node (c-node) ...)Protocol = 1 byte [0 = tcp/ip-v4, ... ]DistrvsnRange = [Highestvsn, Lowestvsn] where Highestvsn = Lowestvsn = 2 byte for erts-4.6.x (OTP-R3)the vsn = 0 for erts-4.7.x (OTP-R4)Nlen = 2 bytesNodeName = string ,length = NlenElen = 2 bytesExtra = string ,length = ElenThe connection created to the EPMD must be kept until the node isnot a distributed node any longer.3.1.2 ALIVE_CLOSE_REQ ()The connection is simply closed by the client.3.1.3 PORT_PLEASE_REQ (112) 1 n+-----+----------+| 112 | NodeName |+-----+----------+where n = Length - 13.1.3.1 PORT_PLEASE2_REQ (122) 1 n+-----+----------+| 122 | NodeName |+-----+----------+where n = Length - 13.1.4 NAMES_REQ (110) 1 +-----+| 110 |+-----+3.1.5 DUMP_REQ (100) 1 +-----+| 100 |+-----+3.1.6 KILL_REQ (107) 1 +-----+| 107 |+-----+3.1.7 STOP_REQ (115) (Not Used) 1 n+-----+----------+| 115 | NodeName |+-----+----------+where n = Length - 1The current implementation of Erlang does not care if the connectionto the EPMD is broken.3.2 Responses3.2.1 ALIVE_OK_RESP (89) 1 2+----+----------+| 89 | Creation |+----+----------+3.2.1.1 ALIVE2_RESP (121) 1 1 2+----+--------+-----------+|121 | Result | Creation |+----+--------+-----------+Result = 0 -> ok, Result > 0 -> error3.2.2 ALIVE_NOTOK_RESP ()EPMD closed the connection.3.2.3 PORT_OK_RESP () 2+--------+| PortNo |+--------+3.2.4 PORT_NOTOK_RESP ()EPMD closed the connection.3.2.4.1 PORT2_RESP (119)[119, Result] or[119, Result, PortNo, NodeType, Protocol, DistrvsnRange, Nlen, NodeName, Elen, Extra]Result = 1 byte (0 = ok, >0 error)NodeType = 1 byte ( 77 - normal Erlang node , 72 - hidden node ...)PortNo = 2 byteProtocol = 1 byteDistrvsnRange = [Highestvsn, Lowestvsn] Highestvsn = Lowestvsn = 2 bytesNlen = 2 bytesNodeName = string, length = NlenElen = 2 bytesExtra = string, length = ElenIf Result > 0, the packet only consists of [119, Result].3.2.4 PORT_NOTOK_RESP ()EPMD closed the connection.3.2.5 NAMES_RESP () 4+------------+-----------+| EPMDPortNo | NodeInfo* |+------------+-----------+NodeInfo is a string written for each active node.When all NodeInfo has been written the connection isclosed by EPMD.NodeInfo is, as expressed in Erlang: io:format("name ~s at port ~p~n", [NodeName, Port]).3.2.6 DUMP_RESP () 4+------------+-----------+| EPMDPortNo | NodeInfo* |+------------+-----------+NodeInfo is a string written for each node kept in EPMD.When all NodeInfo has been written the connection isclosed by EPMD.NodeInfo is, as expressed in Erlang: io:format("active name ~s at port ~p, fd = ~p ~n", [NodeName, Port, Fd]).or io:format("old/unused name ~s at port ~p, fd = ~p~n", [NodeName, Port, Fd]).3.2.7 KILL_RESP () 2+----------+| OKString |+----------+where OKString is "OK".3.2.8 STOP_OK_RESP () 7+----------+| OKString |+----------+where OKString is "STOPPED".3.2.9 STOP_NOTOK_RESP () 7+-----------+| NOKString |+-----------+where NOKString is "NOEXIST".4 The Erlang <-> Erlang distribution protocolThe distribution protocol can be divided into four (4) parts: 1. Low level socket connection. 2. Handshake, interchange node name and authenticate. 3. Authentication (done by net_kernel). 4. Connected. A node fetches the Port number of another node through the EPMD (at theother host) in order to initiate a connection request.3 and 4 are performed at the same level but the net_kernel disconnects theother node if it communicates using an invalid cookie (after one (1) second).4.1 HandshakeThe handshake is discussed in detail in the internal documentation for the kernel (erlang) application.4.2 Protocol between connected nodes 4 1 n m+--------+------+------------+----------+| Length | Type | ControlMsg | Message |+--------+------+------------+----------+where: Length is equal to 1 + n + m Type is: 112 - pass through ControlMsg is a tuple passed using the external format of Erlang. Message is the message sent to another node using the '!' (in external format). But, Message is only passed in combination with a ControlMsg encoding a send ('!').4.2.1 Pass throughThe control message is a tuple, where the first element indicateswhich distributed operation it encodes.4.2.1.1 LINK {1, FromPid, ToPid}4.2.1.2 SEND {2, Cookie, ToPid} Note: Message is sent as well.4.2.1.3 EXIT {3, FromPid, ToPid, Reason}4.2.1.4 UNLINK {4, FromPid, ToPid}4.2.1.5 NODE_LINK {5}4.2.1.6 REG_SEND {6, FromPid, Cookie, ToName} Note: Message is sent as well.4.2.1.7 GROUP_LEADER {7, FromPid, ToPid}4.2.1.8 EXIT2 {8, FromPid, ToPid, Reason}-----------------------------------------------New Ctrlmessages for distrvsn = 1 (OTP R4)-----------------------------------------------4.3.1 SEND_TT {12, Cookie, ToPid, TraceToken} Note: Message is sent as well.4.3.2 EXIT_TT {13, FromPid, ToPid, TraceToken, Reason}4.3.3 REG_SEND_TT {16, FromPid, Cookie, ToName, TraceToken} Note: Message is sent as well.4.3.4 EXIT2_TT {18, FromPid, ToPid, TraceToken, Reason}-----------------------------------------------New Ctrlmessages for distrvsn = 2-----------------------------------------------distrvsn 2 was never used.-----------------------------------------------New Ctrlmessages for distrvsn = 3 (OTP R5C)-----------------------------------------------None, but the version number was increased anyway.-----------------------------------------------New Ctrlmessages for distrvsn = 4 (OTP R6)These are only recognized by Erlang nodes, not by hidden nodes.-----------------------------------------------4.4.1 MONITOR_P {19, FromPid, ToProc, Ref} FromPid = monitoring process ToProc = monitored process pid or name (atom)4.4.2 DEMONITOR_P {20, FromPid, ToProc, Ref} We include the FromPid just in case we want to trace this. FromPid = monitoring process ToProc = monitored process pid or name (atom)4.4.3 MONITOR_P_EXIT {21, FromProc, ToPid, Ref, Reason} FromProc = monitored process pid or name (atom) ToPid = monitoring process Reason = exit reason for the monitored process
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -