Article View: news.software.nntp
Article #63626xBin Message-ID convention
From: Kjetil Torgrim Homme
Date: Sat, 25 Jan 2003 01:28
Date: Sat, 25 Jan 2003 01:28
296 lines
12641 bytes
12641 bytes
alright. here's my write-up of xBin. it's not perfect, I'm sure
there are lots of details missing, and I'm pretty tired so the
explanations are probably not perfectly enlightening. anyhow:
xBin is a method for distributing large files over Usenet. here,
"large" means more than approx. 200 kB. large files need to be split
across several news articles, and reassembled into one file by the
reader of the newsgroup. the integrity of an individual part can be
proven by including a header called Content-SHA1-Tree[TBD], which is
described elsewhere. the algorithm in Content-SHA1-Tree produces a
160-bit hash of the data in the file which uniquely identifies its
contents. the chance of two files having the same hash but different
content is infinitesimal: if every person on Earth each owns 150
million million files which are different from everyone else's files,
there is a 50% chance of two files, worldwide, having the same hash.
this 160-bit identifying hash is called the root hash.
in order to recognise which articles constitute parts of the file,
news reading software (from now on "reader" for short) has
traditionally looked at the Subject for substrings like "(3/9)", which
means part 3 in a sequence of 9. this is however prone to mistakes,
and the reader must filter out dataless replies or bogus data posted
to sabotage. furthermore, if someone posts the same file, but using a
different descriptive text in the Subject, the reader will not know
that it is the same file. if it knew, it could ignore it if the file
was completely downloaded, or take advantage of the data if it was
only partially downloaded.
xBin uses the root hash as an identifier which is put in the
Message-ID, a header which is efficiently available for the reader
from any news server. the root hash is a global identifier which is
constant regardless of who posts the file, and so the problems with
parsing Subject noted above go away.
in addition to the root hash, information on total size, offset into
the file and more is put into the Message-ID for easy filtering by the
reader or news server.
an xBin msgid is identified by a LHS (Left Hand Side of the @-sign)
containing the magic string "~XB~". the magic string is followed by
the first 72 bits[TBD] of the root hash, a number of other parameters,
and terminated by the string "~~". there can only be one such xBin
string in a msgid, but arbitrary text either before or after the
string is allowed. it is highly recommended that the news posting
software ("poster") includes random text outside the xBin string to
make the msgid unguessable. 18 bits or more of randomness, ie. at
least three BASE64 digits, would be suitable. each msgid should have
a different random component.
each parameter is specified on the form "~C" followed by an integer
value, where C is some character identifying the parameter. the
parameters are:
S total size. the complete size of the file in octets. mandatory.
o offset. the first octet of this fragment is the octet at OFFSET
of the complete file. defaults to 0.
s part size. the size of this fragment in octets. defaults to
total size minus offset.
H hashing method. defaults to 0, which is 72-bits
Content-SHA1-Tree.
the H parameter is reserved for the future in the unlikely event that
SHA1 must be replaced. a xBin decoder MUST NOT try to calculate
the hash excerpt is regarded as 9 octets of data, and coded using
BASE64.
the integer values are coded as big-endians in BASE64. examples:
0 is encoded as "A"
4711 is encoded as "BJn"
("B" == 1, "J" == 9, "n" == 39, and 1*64*64 + 9*64 + 39 == 4711)
an xBin implementation MUST be able to encode or decode 63 bit integer
values.
file sets
=========
file sets introduce two new parameters:
M multi-file. the number of files included in this set. defaults
to 1.
F file number. which file this article is a part of. if there is
more than one file represented in the article, choose the highest
number. defaults to 1.
the presence of an M parameter changes the meaning of the other
parameters, and the root hash is calculated slightly differently.
the news posting software ("poster") takes all the files in the set
and calculates the root hash for each. it then takes these 160 bit
root hashes, concatenates them in order, and calculates the SHA1 hash
of that data. the resulting hash is the root hash for the set.
the values S, o and s parameters are specified as if one hypothetical
file consisting of all the files in the set were being transmitted.
other headers
=============
xBin posters should put all meta-data about the files in suitable
headers.
filename (mandatory):
Content-Disposition: attachment; filename="somefile.mp3"
filetype (optional for single files):
Content-Type: audio/mpeg
fragment information (mandatory for file sets):
Content-Type: message/fragment; offset=OCTETS; total-size=OCTETS
these are MIME headers, but the article should not declare
"MIME-Version: 1.0" unless it is a well formed MIME document.
size of parts
=============
to ensure smooth propagation of all the parts of a file, the parts
should be as similar as possible in size.
many servers will transmit small articles faster than large articles,
and this can cause the last article to arrive much earlier (perhaps an
hour) than the first article. on a server with limited retention,
this may cause the last part to expire an hour or two before the
second-to-last part of the file, which is confusing to users.
even worse, some servers will drop articles larger than some size. if
the last article is much smaller than the others, it may be let
through, while all the large articles are ignored. the user will see
a newsgroup with only one part from each file: the last one. again
very confusing to users who may ask the other users of the newsgroup
for reposts to no avail.
how should the part size be calculated? the user should be allowed to
set an upper bound for the part size. this upper bound is measured
against the encoded size of the part. subtract a couple of KB for
miscellaneous headers, and use an appropriate estimate of encoding
overhead (40% for uuencode, 25% for BASE64, 3% for yEnc).
Content-SHA1-Tree requires the size of each fragment to be a complete
number of blocks (22500 octets[TBD]). only the last fragment can
contain an incomplete block.
here's some simple pseudo code to find a suitable size for each part:
file_size = <size of file>
block_size = 22500
max_part_size = 500000
raw_max_part_size = (max_part_size - 2000) * 0.75
part_size = trunc(raw_max_part_size / block_size) * block_size
# set it up so the loop condition is always true
too_much = 1
number_of_parts = 0
part_size = part_size + block_size
while (too_much > number_of_parts * block_size)
{
part_size = part_size - block_size
number_of_parts = trunc((file_size - 1) / part_size) + 1;
too_much = number_of_parts*part_size - $file_size;
}
# we now know how large the largest part will be. the last part
# will have the same number of blocks, but the last block is
# incomplete. the remainder surplus will be distributed among the
# next to last parts.
surplus_blocks = trunc((too_much-1) / block_size)
last_block = too_much - surplus_blocks*block_size
for i = 1 to (number_of_parts - surplus_blocks - 1)
print "part", i, "contains", part_size, "bytes"
for i = (number_of_parts - surplus_blocks) to (number_of_parts - 1)
print "part", i, "contains", part_size - block_size, "bytes"
print "part", number_of_parts, "contains", last_block, "bytes"
interaction with uuencode
=========================
existing decoders will depend on meta-information in Subject, and
therefore an xBin aware poster SHOULD follow existing conventions for
tagging multipart files in Subject. an xBin aware reader MUST NOT
rely on data in Subject.
the filename MUST be specified using Content-Disposition in the first
part. Content-Disposition MAY be included in other parts as well.
the filename SHOULD be the same as the filename specified in the
uuencode "begin" line.
single file
-----------
xBin requires the size of each part to be a multiple of 22500 bytes.
following the above algorithm will satisfy this requirement.
multiple files
--------------
each part MUST only contain blocks from a single file. the part size
algorithm should thus be run on each file individually. each part
must contain Content-SHA1-Tree corresponding to the fragment of the
file, and fragment information in Content-Type.
interaction with yEnc
=====================
same issues as uuencode. an xBin reader MUST NOT rely on information
from the =ybegin line. an xBin poster MUST include valid information
in =ybegin.
interaction with MIME
=====================
there are two methods for posting files too large for a single
article, message/partial (old method) and message/fragment (new
method, not an official part of MIME yet).
message/partial
---------------
the messages are constructed as usual, except for the part size
limitation. all the usual MIME headers are in use, and in addition
Content-SHA1-Tree must be included with each fragment.
single file
the Content-SHA1-Tree is included in the article headers of each
fragment.
multiple files
the first fragment of each file includes the Content-SHA1-Tree in its
entity headers. the following fragments put the Content-SHA1-Tree in
the article headers.
message/fragment
----------------
with message/fragment, each part is a well formed MIME document
standing alone. a message/fragment contains an inner set of entity
headers and an encoded body. Content-Type and
Content-Transfer-Encoding will usually have to be set in the inner
entity headers. there is no backwards compatibility to consider in
this mode, but all except the first part SHOULD have a References
referring to the first part in the set so that existing clients will
consider it one thread which can be collapsed.
single file
Content-Disposition and Content-SHA1-Tree SHOULD be put on the outer
level (== in the article headers).
From: someone@example.com
Subject: my wedding march
Newsgroups: alt.binaries.misc
Message-ID: <~XB~53F8b3f9C0/1~SVLIw~sBX5A~oBX5A~~pI+@example.com>
References: <~XB~53F8b3f9C0/1~SVLIw~sBX5A~~hQa@example.com>
Content-SHA1-Tree: ....
MIME-Version: 1.0
Content-Type: message/fragment; offset=360000; total-size=5550640
Date: Sat, 25 Jan 2003 02:06:03 +0100
Content-Type: audio/mpeg
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="wedding.mp3"
data...
multiple files are encoded in a similar manner, but the
message/fragments are put inside multipart/mixed. this means
Content-Disposition and Content-SHA1-Tree SHOULD be part of the
internal entity headers of each message/fragment. it is however
possible to avoid fragments from two files in the same article
(similar to the method used with uuencode and yEnc), and then the
method for single parts is to be used. Subject can be descriptive for
the complete set, or for each file, at the user's discretion.
--
Kjetil T. | read and make up your own mind
| http://www.cactus48.com/truth.html
Technical Details
Message-ID:
<1rvg0ehvar.fsf@vingodur.ifi.uio.no>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!syros.belnet.be!news.belnet.be!feed.news.nacamar.de!uio.no!nntp.uio.no!ifi.uio.no!not-for-mailShow Full Headers
Complete Article Headers
Message-ID: <1rvg0ehvar.fsf@vingodur.ifi.uio.no> Subject: xBin Message-ID convention Date: Sat, 25 Jan 2003 01:28:44 +0000 From: Kjetil Torgrim Homme <kjetilho@haey.ifi.uio.no> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!syros.belnet.be!news.belnet.be!feed.news.nacamar.de!uio.no!nntp.uio.no!ifi.uio.no!not-for-mail Newsgroups: news.software.nntp Organization: Dept. of Informatics, Univ. of Oslo, Norway Lines: 295 NNTP-Posting-Host: vingodur.ifi.uio.no Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: maud.ifi.uio.no 1043458124 19755 129.240.68.200 (25 Jan 2003 01:28:44 GMT) X-Complaints-To: abuse@ifi.uio.no NNTP-Posting-Date: 25 Jan 2003 01:28:44 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7