technical-notes.rst 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. Technical Notes
  2. ===============
  3. This document describes additional technical information of aria2. The
  4. expected audience is developers.
  5. Control File (\*.aria2) Format
  6. ------------------------------
  7. The control file uses a binary format to store progress information of
  8. a download. Here is the diagram for each field:
  9. .. code-block:: text
  10. 0 1 2 3
  11. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  12. +---+-------+-------+-------------------------------------------+
  13. |VER| EXT |INFO |INFO HASH ... |
  14. |(2)| (4) |HASH | (INFO HASH LENGTH) |
  15. | | |LENGTH | |
  16. | | | (4) | |
  17. +---+---+---+-------+---+---------------+-------+---------------+
  18. |PIECE |TOTAL LENGTH |UPLOAD LENGTH |BIT- |BITFIELD ... |
  19. |LENGTH | (8) | (8) |FIELD | (BITFIELD |
  20. | (4) | | |LENGTH | LENGTH) |
  21. | | | | (4) | |
  22. +-------+-------+-------+-------+-------+-------+---------------+
  23. |NUM |INDEX |LENGTH |PIECE |PIECE BITFIELD ... |
  24. |IN- | (4) | (4) |BIT- | (PIECE BITFIELD LENGTH) |
  25. |FLIGHT | | |FIELD | |
  26. |PIECE | | |LENGTH | |
  27. | (4) | | | (4) | |
  28. +-------+-------+-------+-------+-------------------------------+
  29. ^ ^
  30. | |
  31. +-------------------------------------------------------+
  32. Repeated in (NUM IN-FLIGHT) PIECE times
  33. ``VER`` (VERSION): 2 bytes
  34. Should be either version 0(0x0000) or version 1(0x0001). In
  35. version 1, all multi-byte integers are saved in network byte
  36. order(big endian). In version 0, all multi-byte integers are saved
  37. in host byte order. aria2 1.4.1 can read both versions and only
  38. writes a control file in version 1 format. version 0 support will
  39. be disappear in the future version.
  40. ``EXT`` (EXTENSION): 4 bytes
  41. If LSB is 1(i.e. ``EXT[3]&1 == 1``), aria2 checks whether the saved
  42. InfoHash and current downloading one are the same. If they are not
  43. the same, an exception is thrown. This is called "infoHashCheck"
  44. extension.
  45. ``INFO HASH LENGTH``: 4 bytes
  46. The length of InfoHash that is located after this field. If
  47. "infoHashCheck" extension is enabled, if this value is 0, then an
  48. exception is thrown. For http/ftp downloads, this value should be
  49. 0.
  50. ``INFO HASH``: ``(INFO HASH LENGTH)`` bytes
  51. BitTorrent InfoHash.
  52. ``PIECE LENGTH``: 4 bytes
  53. The length of the piece.
  54. ``TOTAL LENGTH``: 8 bytes
  55. The total length of the download.
  56. ``UPLOAD LENGTH``: 8 bytes
  57. The uploaded length in this download.
  58. ``BITFIELD LENGTH``: 4 bytes
  59. The length of bitfield.
  60. ``BITFIELD``: ``(BITFIELD LENGTH)`` bytes
  61. This is the bitfield which represents current download progress.
  62. ``NUM IN-FLIGHT PIECE``: 4 bytes
  63. The number of in-flight pieces. These piece is not marked
  64. 'downloaded' in the bitfield, but it has at least one downloaded
  65. chunk.
  66. The following 4 fields are repeated in ``(NUM IN-FLIGHT PIECE)``
  67. times.
  68. ``INDEX``: 4 bytes
  69. The index of the piece.
  70. ``LENGTH``: 4 bytes
  71. The length of the piece.
  72. ``PIECE BITFIELD LENGTH``: 4 bytes
  73. The length of bitfield of this piece.
  74. ``PIECE BITFIELD``: ``(PIECE BITFIELD LENGTH)`` bytes
  75. The bitfield of this piece. The each bit represents 16KiB chunk.
  76. DHT routing table file format
  77. -----------------------------
  78. aria2 saves IPv4 DHT routing table in
  79. ``${XDG_CACHE_HOME}/aria2/dht.dat`` and IPv6 DHT routing table in
  80. ``${XDG_CACHE_HOME}/aria2/dht6.dat`` by default unless
  81. ``${HOME}/.aria2/dht.dat`` and ``${HOME}/.aria2/dht.dat`` are present.
  82. ``dht.dat`` and ``dht6.dat`` files use same binary encoding and have
  83. following fields. All multi byte integers are in network byte
  84. order. ``RSV`` (RESERVED) fields are reserved for future use. For now
  85. they should be all zeros:
  86. .. code-block:: text
  87. 0 1 2 3
  88. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  89. +---+-+---+-----+---------------+---------------+---------------+
  90. |MGC|F|VER| RSV | MTIME | RSV |LOCAL NODE ID :
  91. |(2)|M|(2)| (3) | (8) | (8) | (20) :
  92. | |T| | | | | :
  93. +---+-+---+-----+-------+-------+-------+-------+---------------+
  94. :LOCAL NODE ID | RSV | NUM | RSV |
  95. : (continued) | (4) | NODE | (4) |
  96. : | | (4) | |
  97. +-+-------------+-------+-------+-+-----+-------+---------------+
  98. |P| RSV |COMPACT PEER INFO| RSV | <-+
  99. |L| (7) | (PLEN) | (24 - PLEN) | |
  100. |E| | | | |
  101. |N| | | | |
  102. +-+-------------+-----------------+-----+-------+---------------+ |
  103. | NODE ID | RSV | |
  104. | (20) | (4) | <-----------------+
  105. +---------------------------------------+-------+ Repeated in
  106. (NUM NODE) times.
  107. ``MGC`` (MAGIC): 2 bytes
  108. It must be ``0xa1 0xa2``.
  109. ``FMT`` (FORMAT ID): 1 byte
  110. The format ID should be ``0x02``.
  111. ``VER`` (VERSION): 2 bytes
  112. The version number should be ``0x00 0x03``.
  113. ``MTIME``: 8 bytes
  114. This is the time when aria2 saved the file. The value is the time
  115. since the Epoch(1970/1/1 00:00:00) in 64 bits integer.
  116. ``LOCALNODE ID``: 20 bytes
  117. Node ID of the client.
  118. ``NUM NODE``: 4 bytes
  119. The number of nodes the routing table has. ``NUM NODE`` node
  120. information follows.
  121. The data of ``NUM NODE`` node will follow. The node information are
  122. stored in the following fields. They are repeated in ``NUM NODE``
  123. times.
  124. ``PLEN`` (COMPACT PEER INFO LENGTH): 1 byte
  125. The length of compact peer info. For IPv4 DHT, it must be 6. For
  126. IPv6 DHT, it must be 18.
  127. ``COMPACT PEER INFO``: ``(PLEN)`` bytes
  128. The address and port of peer in compact peer format.
  129. ``NODE ID``: 20 bytes
  130. The node ID of this node.