anode_protocol.txt 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. *****************************************************************************
  2. Anode Protocol Specification Draft
  3. Version 0.8
  4. (c)2009-2010 Adam Ierymenko
  5. *****************************************************************************
  6. Table of Contents
  7. *****************************************************************************
  8. 1. Introduction
  9. Anode provides three components that work together to provide a global,
  10. secure, and mobile addressing system for computer networks:
  11. 1) An addressing system based on public key cryptography enabling network
  12. devices or applications to assign themselves secure, unique, and globally
  13. reachable network addresses in a flat address space.
  14. 2) A system enabling network participants holding global addresses to locate
  15. one another on local or global networks with "zero configuration."
  16. 3) A communications protocol for communication between addressed network
  17. participants that requires no special operating system support and no
  18. changes to existing network infrastructure.
  19. Using Anode, both fixed and mobile applications and devices can communicate
  20. directly as if they were all connected to the same VPN. Anode restores the
  21. original vision of the Internet as a "flat" network where anything can talk
  22. to anything, and adds the added benefits of address mobility and strong
  23. protection against address spoofing and other protocol level attacks.
  24. 1.1. Design Philosophy
  25. Anode's design philosophy is the classical "KISS" principle: "Keep It Simple
  26. Stupid." Anode's design principles are:
  27. #1: Do not try to solve too many problems at once, and stay in scope.
  28. Anode does not attempt to solve too many problems at once. It attempts to
  29. solve the problems of mobile addressing, address portability, and "flat"
  30. addressing in the presence of NAT or other barriers.
  31. It does not attempt to duplicate the full functionality of SSL, X.509, SSH,
  32. XMPP, an enterprise service bus, a pub/sub architecture, BitTorrent, etc. All
  33. of those protocols and services can be used over Anode if their functionality
  34. is desired.
  35. #2: Avoid state management.
  36. State multiplies the complexity and failure modes of network protocols. State
  37. also tends to get in the way of the achievement of new features implicitly
  38. (see principle #4). Avoid state whenever possible.
  39. #3: Avoid algorithm and dependency bloat.
  40. Anode uses only elliptic curve Diffie-Hellman (EC-DH) and AES-256. No other
  41. cryptographic algorithms or hash functions are presently necessary. This
  42. yields implementations compact enough for embedded devices.
  43. Anode also requires few or no dependencies, depending on whether the two
  44. needed cryptographic algorithms are obtained through a library or included.
  45. No other protocols or libraries are required in an implementation.
  46. #4: Achieve features implicitly.
  47. Use a simple stateless design that allows features to be achieved implicitly
  48. rather than specified explicitly. For example, Anode can do multi-homing and
  49. could be used to build a mesh network, but neither of these features is
  50. explicitly specified.
  51. *****************************************************************************
  52. 2. Core Concepts and Algorithms
  53. This section describes addresses, zones, common algorithms, and other core
  54. concepts.
  55. 2.1. Zones
  56. A zone is a 32-bit integer encoded into every Anode address. Zones serve to
  57. assist in the location of peers by address on global IP networks. They are
  58. not presently significant for local communications, though they could be
  59. used to partition addresses into groups or link them with configuration
  60. options.
  61. Each zone has a corresponding zone file which can be fetched in a number of
  62. ways (see below). A zone file is a flat text format dictionary of the format
  63. "key=value" separated by carriage returns. Line feeds are ignored, and any
  64. character may be escaped with a backslash (\) character. Blank lines are
  65. ignored.
  66. The following entries must appear in a zone file:
  67. n=<zone name>
  68. d=<zone description>
  69. c=<zone contact, e-mail address of zone administrator>
  70. r=<zone revision, monotonically increasing integer with each edit>
  71. ttl=<seconds before zone file should be re-checked for changes>
  72. Additional fields may appear as well, including fields specific to special
  73. applications or protocols supported within the zone. Some of these are
  74. defined in this document.
  75. Zone file fetching mechanisms are described below. Multiple mechanisms are
  76. specified to enable fallback in the event that one mechanism is not available.
  77. 2.1.1. Zone File Retrieval
  78. Zone files are retrieved via HTTP, with the HTTP address being formed in one
  79. of two ways.
  80. The preferred DNS method:
  81. To fetch a zone file via DNS, use the zone ID to generate a host name and URI
  82. of the form:
  83. http://a--XXXXXXXX.net/z
  84. The XXXXXXXX field is the zone ID in hexadecimal.
  85. The fallback IP method:
  86. For fallback in the absence of DNS, the zone ID can be used directly as an
  87. IPv4 or IPv4-mapped-to-IPv6 IP address. A URI is generated of the form:
  88. http://ip_address/z
  89. Support for this method requires that a zone ID be chosen to correspond to a
  90. permanent IPv4 (preferably mappable to IPv6 space as well) IP address.
  91. 2.1.2. Zone ID Reservation
  92. By convention, a zone ID is considered reserved when a domain of the form
  93. "a--XXXXXXXX.net" (where XXXXXXXX is the ID in hex) is registered.
  94. It is recommended that this be done even for zone IDs not used for global
  95. address location in order to globally reserve them.
  96. 2.2. Addresses
  97. Anode addresses are binary strings containing a 32-bit zone ID, a public key,
  98. and possibly other fields. Only one address type is presently defined:
  99. |---------------------------------------------------------------------------|
  100. | Name | Type ID | Elliptic Curve Parameters | Total Length |
  101. |---------------------------------------------------------------------------|
  102. | ANODE-256-40 | 1 | NIST-P-256 | 40 |
  103. |---------------------------------------------------------------------------|
  104. |---------------------------------------------------------------------------|
  105. | Name | Binary Layout |
  106. |---------------------------------------------------------------------------|
  107. | ANODE-256-40 | <type[1]><zone[4]><unused[2]><public key[33]> |
  108. |---------------------------------------------------------------------------|
  109. The public key is a "compressed" form elliptic curve public key as described
  110. in RFC5480.
  111. The unused section of the address must be zero. These bytes are reserved for
  112. future use.
  113. 2.2.1. ASCII Format For Addresses
  114. Addresses are encoded in ASCII using base-32, which provides a quotable and
  115. printable encoding that is of manageable length and is case-insensitive. For
  116. example, an ANODE-256-40 address is 64 characters long in base-32 encoding.
  117. 2.3. Relaying
  118. An Anode peer may optionally relay packets to any other reachable peer.
  119. Relaying is accomplished by sending a packet to a peer with the recipient set
  120. to the final recipient. The receiving peer will, if relaying is allowed and if
  121. it knows of or can reach the recipient, forward the packet.
  122. No error is returned if relaying fails, so relay paths are treated as possible
  123. paths for communication until a return is received in the same way as direct
  124. paths.
  125. Relaying can be used by peers to send messages indirectly, locate one
  126. another, and determine network location information to facilitate the
  127. establishment of direct communications.
  128. Peers may refuse to relay or may limit the transmission rate at which packets
  129. can be relayed.
  130. 2.3.1. Zone Relays
  131. If a zone's addresses are globally reachable on global IP networks, it must
  132. have one or more zone relays. These must have globally reachable public
  133. static IP addresses.
  134. Zone relays are specified in the zone file in the following format:
  135. zr.<address checksum>=<ip>[,<ip>]:<udp port>:<tcp port>:<anode addresses>
  136. The address checksum is the sum of the bytes in the Anode address modulus
  137. the number of "zr" entries, in hexadecimal. For example, if a zone had four
  138. global relays its zone file could contain the lines:
  139. zr.0=1.2.3.4:4343:4344:klj4j3...
  140. zr.1=2.3.4.5:4343:4344:00194j...
  141. zr.2=3.4.5.6:4343:4344:1j42zz...
  142. zr.3=4.5.6.7:4343:4344:z94j1q...
  143. The relay would be chosen by taking the sum of the bytes in the address
  144. modulo 4. For example, if the bytes of an address sum to 5081 then relay
  145. zr.1 would be used to communicate with that address.
  146. If more than one IP address is listed for a given relay, the peer must choose
  147. at random from among the addresses of the desired type (IPv4 or IPv6).
  148. Each relay must have one Anode address for every address type supported within
  149. the zone. (At present there is only one address type defined.)
  150. Peers should prefer UDP and fall back to TCP only if UDP is not available.
  151. To make itself available, a peer must make itself known to its designated zone
  152. relay. This is accomplished by sending a PING message.
  153. 2.4. Key Agreement and Derivation
  154. Key agreement is performed using elliptic curve Diffie-Hellman. This yields
  155. a raw key whose size depends on the elliptic curve parameters in use.
  156. The following algorithm is used to derive a key of any length from a raw
  157. key generated through key agreement:
  158. 1) Zero the derived key buffer.
  159. 2) Determine the largest of the original raw key or the derived key.
  160. 3) Loop from 0 to the largest length determined in step 2, XOR each byte of
  161. the derived key buffer with the corresponding byte of the original key
  162. buffer with each index being modulus the length of the respective buffer.
  163. 2.5. Message Authentication
  164. For message authentication, CMAC-AES (with AES-256) is used. This is also
  165. known in some literature as OMAC1-AES. The key is derived from key agreement
  166. between the key pair of the sending peer and the address of the recipient.
  167. 2.6. AES-DIGEST
  168. To maintain cryptographic algorithm frugality, a cryptographic hash function
  169. is constructed from the AES-256 cipher. This hash function uses the common
  170. Davis-Meyer construction with Merkle-Damgård length padding.
  171. It is described by the following pseudocode:
  172. byte previous_digest[16]
  173. byte digest[16] = { 0,0,... }
  174. byte block[32] = { 0,0,... }
  175. integer block_counter = 0
  176. ; digest message
  177. for each byte b of message
  178. block[block_counter] = b
  179. block_counter = block_counter + 1
  180. if block_counter == 32 then
  181. block_counter = 0
  182. save digest[] in previous_digest[]
  183. encrypt digest[] with aes-256 using block[] as 256-bit aes-256 key
  184. xor digest[] with previous_digest[]
  185. end if
  186. next
  187. ; append end marker, do final block
  188. block[block_counter] = 0x80
  189. block_counter = block_counter + 1
  190. zero rest of block[] from block_counter to 15
  191. save digest[] in previous_digest[]
  192. encrypt digest[] with aes-256 using block[] as 256-bit aes-256 key
  193. xor digest[] with previous_digest[]
  194. ; Merkle-Damgård length padding
  195. zero first 8 bytes of block[]
  196. fill last 8 bytes of block[] w/64-bit length in big-endian order
  197. save digest[] in previous_digest[]
  198. encrypt digest[] with aes-256 using block[] as 256-bit aes-128 key
  199. xor digest[] with previous_digest[]
  200. ; digest[] now contains 128-bit message digest
  201. 2.7. Short Address Identifiers (Address IDs)
  202. A short 8-byte version of the Anode address is used in the protocol to reduce
  203. transmission overhead when both sides are already aware of the other's full
  204. address.
  205. The short address identifier is formed by computing the AES-DIGEST of the
  206. full address and then XORing the first 8 bytes of the digest with the last
  207. 8 bytes to yield an 8-byte shortened digest.
  208. 2.8. DNS Resolution of Anode Addresses
  209. Anode addresses can be saved in DNS TXT records in the following format:
  210. anode:<address in base32 ASCII encoding>
  211. This permits Anode addresses to be resolved from normal DNS host name.
  212. 2.9. Packet Transmission Mechanisms
  213. 2.9.1. UDP Transmission
  214. The recommended method of sending Anode packets is UDP. Each packet is simply
  215. sent as a UDP packet.
  216. 2.9.2. TCP Transmission
  217. To send packets over TCP, each packet is prefixed by its size as a 16-bit
  218. integer.
  219. 2.9.3. HTTP Transmission
  220. Anode packets may be submitted in HTTP POST transactions for transport over
  221. networks where HTTP is the only available protocol.
  222. Anode packets are simply prefixed with a 16-byte packet size and concatenated
  223. together just as they are in a TCP stream. One or more packets may be sent
  224. with each HTTP POST transaction for improved performance.
  225. Since this method is intended for use in "hostile" or highly restricted
  226. circumstances, no additional details such as special headers or MIME types
  227. are specified to allow maximum flexibility. Peers should ignore anything
  228. other than the payload.
  229. 2.10. Endpoints
  230. An endpoint indicates a place where Anode packets may be sent. The following
  231. endpoint types are specified:
  232. |---------------------------------------------------------------------------|
  233. | Endpoint Type | Description | Address Format |
  234. |---------------------------------------------------------------------------|
  235. | 0x00 | Unspecified | (none) |
  236. | 0x01 | Ethernet | <mac[6]> |
  237. | 0x02 | UDP/IPv4 | <ip[4]><port[2]> |
  238. | 0x03 | TCP/IPv4 | <ip[4]><port[2]> |
  239. | 0x04 | UDP/IPv6 | <ip[16]><port[2]> |
  240. | 0x05 | TCP/IPv6 | <ip[16]><port[2]> |
  241. | 0x06 | HTTP | <null-terminated full URI> |
  242. |---------------------------------------------------------------------------|
  243. Endpoints are encoded by beginning with a single byte indicating the endpoint
  244. type followed by the address information required for the given type.
  245. Note that IP ports bear no relationship to Anode protocol ports.
  246. 2.11. Notes
  247. All integers in the protocol are transmitted in network (big endian) byte
  248. order.
  249. *****************************************************************************
  250. 3. Common Packet Format
  251. A common header is used for all Anode packets:
  252. |---------------------------------------------------------------------------|
  253. | Field | Length | Description |
  254. |---------------------------------------------------------------------------|
  255. | Hop Count | 1 | 8-bit hop count (not included in MAC) |
  256. | Flags | 1 | 8-bit flags |
  257. | MAC | 8 | 8 byte shortened CMAC-AES of packet |
  258. | Sender Address | ? | Full address or short ID of sender |
  259. | Recipient Address | ? | Full address or short ID of recipient |
  260. | Peer IDs | 1 | Two 4-bit peer IDs: sender, recipient |
  261. | Message Type | 1 | 8-bit message type |
  262. | Message | ? | Message payload |
  263. |---------------------------------------------------------------------------|
  264. 3.1. Hop Count
  265. The hop count begins at zero and must be incremented by each peer that relays
  266. the packet to another peer. The hop count must not wrap to zero at 255.
  267. Because the hop count is modified in transit, it is not included in MAC
  268. calculation or authentication.
  269. The hop count is used to prioritize endpoints that are direct over endpoints
  270. that involve relaying, or to prioritize closer routes over more distant
  271. ones.
  272. 3.2. Flags and Flag Behavior
  273. |---------------------------------------------------------------------------|
  274. | Flag | Description |
  275. |---------------------------------------------------------------------------|
  276. | 0x01 | Sender address fully specified |
  277. | 0x02 | Recipient address fully specified |
  278. | 0x04 | Authentication error response |
  279. |---------------------------------------------------------------------------|
  280. If flag 0x01 is set, then the sender address will be the full address rather
  281. than a short address identifier. The length of the address can be determined
  282. from the first byte of the address, which always specifies the address type.
  283. Flag 0x02 has the same meaning for the recipient address.
  284. A peer must send fully specified sender addresses until it receives a response
  285. from the recipient. At this point the sender may assume that the recipient
  286. knows its address and use short a short sender address instead. This
  287. assumption should time out, with a recommended timeout of 60 seconds.
  288. There is presently no need to send fully specified recipient addresses, but
  289. the flag is present in case it is needed and must be honored.
  290. Flag 0x04 indicates that this is an error response containing a failed
  291. authentication error. Since authentication failed, this packet may not have
  292. a valid MAC. Packets with this flag must never have any effect other than
  293. to inform of an error. This error, since it is unauthenticated, must never
  294. have any side effects such as terminating a connection.
  295. 3.3. MAC
  296. The MAC is calculated as follows:
  297. 1) Temporarily set the 64-bit/8-byte MAC field in the packet to the packet's
  298. size as a 64-bit big-endian integer.
  299. 2) Calculate the MAC for the entire packet (excluding the first byte) using
  300. the key agreed upon between the sender and the recipient, resulting in a
  301. 16 byte full CMAC-AES MAC.
  302. 3) Derive the 8 byte packet MAC by XORing the first 8 bytes of the full 16
  303. byte CMAC-AES MAC with the last 8 bytes. Place this into the packet's MAC
  304. field.
  305. 3.4. Peer IDs
  306. Peer IDs provide a method for up to 15 different peers to share an address,
  307. each with a unique ID allowing packets to be routed to them individually.
  308. A peer ID of zero indicates "any" or "unspecified." Real peers must have a
  309. nonzero peer ID. In the normal single peer per address case, any peer ID may
  310. be used. If multiple peers are to share an address, some implementation-
  311. dependent method must be used to ensure that each peer has a unique peer ID.
  312. Relaying peers must follow these rules based on the recipient peer ID when
  313. relaying messages:
  314. - IF the peer ID is zero or if the peer ID is not known, the message must
  315. be forwarded to a random endpoint for the given recipient address.
  316. - IF the peer ID is nonzero and matches one or more known endpoints for the
  317. given recipient address and peer ID, the message must only be sent to
  318. a matching endpoint.
  319. A receiving peer should process any message that it receives regardless of
  320. whether its recipient peer ID is correct. The peer ID is primarily for relays.
  321. Peers should typically send messages with a nonzero recipient peer ID when
  322. responding to or involved in a conversation with a specific peer (e.g. a
  323. streaming connection), and send zero recipient peer IDs otherwise.
  324. 3.5. Short Address Conflict Disambiguation
  325. In the unlikely event of two Anode addresses with the same short identifier,
  326. the recipient should use MAC validation to disambiguate. The peer ID must not
  327. be relied upon for this purpose.
  328. *****************************************************************************
  329. 4. Basic Signaling and Transport Protocol
  330. 4.1. Message Types
  331. |---------------------------------------------------------------------------|
  332. | Type | ID | Description |
  333. |---------------------------------------------------------------------------|
  334. | ERROR | 0x00 | Error response |
  335. | PING | 0x01 | Echo request |
  336. | PONG | 0x02 | Echo response |
  337. | EPC_REQ | 0x03 | Endpoint check request |
  338. | EPC | 0x04 | Endpoint check response |
  339. | EPI | 0x05 | Endpoint information |
  340. | NAT_T | 0x06 | NAT traversal message |
  341. | NETID_REQ | 0x07 | Request network address identification and/or test |
  342. | NETID | 0x08 | Response to network address identification request |
  343. | DGRAM | 0x09 | Simple UDP-like datagram |
  344. |---------------------------------------------------------------------------|
  345. 4.2. Message Details
  346. 4.2.1. ERROR
  347. |---------------------------------------------------------------------------|
  348. | Field | Length | Description |
  349. |---------------------------------------------------------------------------|
  350. | Error Code | 2 | 16-bit error code |
  351. | Error Arguments | ? | Error arguments, depending on error type |
  352. |---------------------------------------------------------------------------|
  353. Error arguments are empty unless otherwise stated below.
  354. Error codes:
  355. |---------------------------------------------------------------------------|
  356. | Error Code | Description |
  357. |---------------------------------------------------------------------------|
  358. | 0x01 | Message not valid |
  359. | 0x02 | Message authentication or decryption failed |
  360. | 0x03 | Relaying and related features not authorized |
  361. | 0x04 | Relay recipient not reachable |
  362. |---------------------------------------------------------------------------|
  363. Generation of errors is optional. A peer may choose to ignore invalid
  364. messages or to throttle the sending of errors.
  365. 4.2.2. PING
  366. (Payload unspecified.)
  367. Request echo of payload as PONG message.
  368. 4.2.3. PONG
  369. (Payload unspecified.)
  370. Echoed payload of received PING message.
  371. 4.2.4. EPC_REQ
  372. |---------------------------------------------------------------------------|
  373. | Field | Length | Description |
  374. |---------------------------------------------------------------------------|
  375. | Request ID | 4 | 32-bit request ID |
  376. |---------------------------------------------------------------------------|
  377. Request echo of request ID in EPC message, used to check and learn endpoints.
  378. To learn a network endpoint for a peer, CHECK_REQ is sent. If CHECK is
  379. returned with a valid request ID, the endpoint is considered valid.
  380. 4.2.5. EPC
  381. |---------------------------------------------------------------------------|
  382. | Field | Length | Description |
  383. |---------------------------------------------------------------------------|
  384. | Request ID | 4 | 32-bit request ID echoed back |
  385. |---------------------------------------------------------------------------|
  386. Response to EPC_REQ containing request ID.
  387. 4.2.6. EPI
  388. |---------------------------------------------------------------------------|
  389. | Field | Length | Description |
  390. |---------------------------------------------------------------------------|
  391. | Flags | 1 | 8-bit flags |
  392. | Endpoint | ? | Endpoint type and address |
  393. | NAT-T mode | 1 | 8-bit NAT traversal mode |
  394. | NAT-T options | ? | Options related to specified NAT-T mode |
  395. |---------------------------------------------------------------------------|
  396. EPI stands for EndPoint Identification, and is sent to notify another peer of
  397. a network endpoint where the sending peer is reachable.
  398. If the receiving peer is interested in communicating with the sending peer,
  399. the receiving peer must send EPC_REQ to the sending peer at the specified
  400. endpoint to check the validity of that endpoint. The endpoint is learned if a
  401. valid EPC is returned.
  402. If the endpoint in EPI is unspecified, the actual source of the EPI message
  403. is the endpoint. This allows EPI messages to be broadcast on a local LAN
  404. segment to advertise the presence of an address on a local network. EPI
  405. broadcasts on local IP networks must be made to UDP port 8737.
  406. Usually EPI is sent via relays (usually zone relays) to inform a peer of an
  407. endpoint for direct communication.
  408. There are presently no flags, so flags must be zero.
  409. 4.2.7. NAT_T
  410. |---------------------------------------------------------------------------|
  411. | Field | Length | Description |
  412. |---------------------------------------------------------------------------|
  413. | NAT-T mode | 1 | 8-bit NAT traversal mode |
  414. | NAT-T options | ? | Options related to specified NAT-T mode |
  415. |---------------------------------------------------------------------------|
  416. NAT_T is used to send messages specific to certain NAT traversal modes.
  417. 4.2.8. NETID_REQ
  418. |---------------------------------------------------------------------------|
  419. | Field | Length | Description |
  420. |---------------------------------------------------------------------------|
  421. | Request ID | 4 | 32-bit request ID |
  422. | Endpoint | ? | Endpoint type and address information |
  423. |---------------------------------------------------------------------------|
  424. When a NETID_REQ message is received, the recipient attempts to echo it back
  425. as a NETID message to the specified endpoint address. If the endpoint is
  426. unspecified, the recipient must fill it in with the actual origin of the
  427. NETID_REQ message. This allows a peer to cooperate with another peer (usually
  428. a zone relay) to empirically determine its externally visible network
  429. address information.
  430. A peer may ignore NETID_REQ or respond with an error if it does not allow
  431. relaying.
  432. 4.2.9. NETID
  433. |---------------------------------------------------------------------------|
  434. | Field | Length | Description |
  435. |---------------------------------------------------------------------------|
  436. | Request ID | 4 | 32-bit request ID echoed back |
  437. | Endpoint Type | 1 | 8-bit endpoint type |
  438. | Endpoint Address | ? | Endpoint Address (size depends on type) |
  439. |---------------------------------------------------------------------------|
  440. NETID is sent in response to NETID_REQ to the specified endpoint address. It
  441. always contains the endpoint address to which it was sent.
  442. 4.2.10. DGRAM
  443. |---------------------------------------------------------------------------|
  444. | Field | Length | Description |
  445. |---------------------------------------------------------------------------|
  446. | Source Port | 2 | 16-bit source port |
  447. | Destination Port | 2 | 16-bit destination port |
  448. | Payload | ? | Datagram packet payload |
  449. |---------------------------------------------------------------------------|
  450. A datagram is a UDP-like message without flow control or delivery assurance.
  451. *****************************************************************************
  452. 5. Stream Protocol
  453. The stream protocol is very similar to TCP, though it omits some features
  454. that are not required since they are taken care of by the encapsulating
  455. protocol. SCTP was also an inspiration in the design.
  456. 5.1. Message Types
  457. |---------------------------------------------------------------------------|
  458. | Type | ID | Description |
  459. |---------------------------------------------------------------------------|
  460. | S_OPEN | 20 | Initiate a streaming connection (like TCP SYN) |
  461. | S_CLOSE | 21 | Terminate a streaming connection (like TCP RST/FIN) |
  462. | S_DATA | 22 | Data packet |
  463. | S_ACK | 23 | Acknowedge receipt of one or more data packets |
  464. | S_DACK | 24 | Combination of DATA and ACK |
  465. |---------------------------------------------------------------------------|
  466. 5.2. Message Details
  467. 5.2.1. S_OPEN
  468. |---------------------------------------------------------------------------|
  469. | Field | Length | Description |
  470. |---------------------------------------------------------------------------|
  471. | Sender Link ID | 2 | 16-bit sender link ID |
  472. | Destination Port | 2 | 16-bit destination port |
  473. | Window Size | 2 | 16-bit window size in 1024-byte increments |
  474. | Init. Seq. Number | 4 | 32-bit initial sequence number |
  475. | Flags | 1 | 8-bit flags |
  476. |---------------------------------------------------------------------------|
  477. The OPEN message corresponds to TCP SYN, and initiates a connection. It
  478. specifies the initial window size for the sender and the sender's initial
  479. sequence number, which should be randomly chosen to prevent replay attacks.
  480. If OPEN is successful, the recipient sends its own OPEN to establish the
  481. connetion. If OPEN is unsuccessful, CLOSE is sent with its initial and current
  482. sequence numbers equal and an appropriate reason such as "connection refused."
  483. The sender link ID must be unique for a given recipient.
  484. If flag 01 is set, the sender link ID is actually a source port where the
  485. sender might be listening for connections as well. This exactly duplicates
  486. the behavior of standard TCP. Otherwise, the sender link ID is simply an
  487. arbitrary number that the sender uses to identify the connection with this
  488. recipient and there is no port of origin. Ports of origin are optional for
  489. Anode streaming connections to permit greater scalability.
  490. 5.2.2. S_CLOSE
  491. |---------------------------------------------------------------------------|
  492. | Field | Length | Description |
  493. |---------------------------------------------------------------------------|
  494. | Sender Link ID | 2 | 16-bit sender link ID |
  495. | Destination Port | 2 | 16-bit destination port |
  496. | Flags | 1 | 8-bit flags |
  497. | Reason | 1 | 8-bit close reason |
  498. | Init. Seq. Number | 4 | 32-bit initial sequence number |
  499. | Sequence Number | 4 | 32-bit current sequence number |
  500. |---------------------------------------------------------------------------|
  501. The CLOSE message serves a function similar to TCP FIN. The initial sequence
  502. number is the original starting sequence number sent with S_OPEN, while the
  503. current sequence number is the sequence number corresponding to the close
  504. and must be ACKed to complete the close operation. The use of the initial
  505. sequence number helps to serve as a key to prevent replay attacks.
  506. CLOSE is also used to indicate a failed OPEN attempt. In this case the current
  507. sequence number will be equal to the initial sequence number and no ACK will
  508. be expected.
  509. There are currently no flags, so flags must be zero.
  510. The reason field describes the reason for the close:
  511. |---------------------------------------------------------------------------|
  512. | Reason Code | Description |
  513. |---------------------------------------------------------------------------|
  514. | 00 | Application closed connection |
  515. | 01 | Connection refused |
  516. | 02 | Protocol error |
  517. | 03 | Timed out |
  518. |---------------------------------------------------------------------------|
  519. Established connections will usually be closed with reason 00, while reason
  520. 01 is usually provided if an OPEN is received but the port is not bound.
  521. 5.2.3. S_DATA
  522. |---------------------------------------------------------------------------|
  523. | Field | Length | Description |
  524. |---------------------------------------------------------------------------|
  525. | Sender Link ID | 2 | 16-bit sender link ID |
  526. | Destination Port | 2 | 16-bit destination port |
  527. | Sequence Number | 4 | 32-bit sequence number |
  528. | Payload | ? | Data payload |
  529. |---------------------------------------------------------------------------|
  530. The DATA message carries a packet of data, with the sequence number
  531. determining order. The sequence number is monotonically incremented with
  532. each data packet, and wraps at the maximum value of an unsigned 32-bit
  533. integer.
  534. 5.2.4. S_ACK
  535. |---------------------------------------------------------------------------|
  536. | Field | Length | Description |
  537. |---------------------------------------------------------------------------|
  538. | Sender Link ID | 2 | 16-bit sender link ID |
  539. | Destination Port | 2 | 16-bit destination port |
  540. | Window Size | 2 | 16-bit window size in 1024-byte increments |
  541. | Acknowledgements | ? | One or more acknowledgements (see below) |
  542. |---------------------------------------------------------------------------|
  543. Each acknowledgement is a 32-bit integer followed by an 8-bit integer (5 bytes
  544. total). The 32-bit integer is the first sequence number to acknowledge, and
  545. the 8-bit integer is the number of sequential following sequence numbers to
  546. acknowledge. For example "1, 4" would acknowledge sequence numbers 1, 2, 3,
  547. and 4.
  548. 5.2.5. S_DACK
  549. |---------------------------------------------------------------------------|
  550. | Field | Length | Description |
  551. |---------------------------------------------------------------------------|
  552. | Sender Link ID | 2 | 16-bit sender link ID |
  553. | Destination Port | 2 | 16-bit destination port |
  554. | Window Size | 2 | 16-bit window size in 1024-byte increments |
  555. | Num. Acks | 1 | 8-bit number of acknowledgements |
  556. | Acknowledgements | ? | One or more acknowledgements |
  557. | Payload | ? | Data payload |
  558. |---------------------------------------------------------------------------|
  559. The DACK message combines ACK and DATA, allowing two peers that are both
  560. transmitting data to efficiently ACK without a separate packet.