Skip to content

Commit 1ee8834

Browse files
committed
1.10: astyle --style=allman
1 parent 586edf7 commit 1ee8834

File tree

3 files changed

+1377
-1177
lines changed

3 files changed

+1377
-1177
lines changed

README.md

Lines changed: 152 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,152 @@
1-
# torrentcheck
2-
3-
torrentcheck - catalog a `.torrent` file and optionally verify content hashes.
4-
5-
Usage: `torrentcheck torrent-file [-p content-path] [-n] [-h] [-c] [-d]`
6-
7-
Options:
8-
`-n` suppresses progress count,
9-
`-h` shows all hash values,
10-
`-c` or `-d` uses comma or dot formatted byte counts.
11-
12-
Returns 0 if successful, nonzero return code if errors found.
13-
14-
Option: `-sha1` [optional hash] acts as a simple SHA1 filter.
15-
16-
If `-sha1` is followed by a hex hash, the return code will be zero
17-
on match and nonzero otherwise.
18-
19-
### Summary
20-
21-
This program is a command-line utility to catalog and verify torrent files.
22-
Run with only the -t option, it displays the metadata, name, and size of
23-
each file in the torrent. Run with the -t and -p options, it computes the
24-
hashes of all files in the torrent, compares them against the hashes stored
25-
in the metadata, and warns of any errors.
26-
27-
If torrentcheck returns "torrent is good" at the end of its output, every
28-
byte of every file in the torrent is present and correct, to a high degree of
29-
certainty as explained below.
30-
31-
For example, if you run torrents on a fast external server and then download
32-
the files, this utility will verify that the files you received are complete
33-
and uncorrupted. It can also be used to verify backups or to automatically
34-
check a series of torrents using scripting.
35-
36-
The -t parameter should be the path to the .torrent metadata file. The -p path
37-
should point to the file or files. It can include or leave out the torrent name.
38-
The -n option suppresses the running count, which is useful if you are writing
39-
the output to a file. The -h option shows all piece hash values. The -c or -d
40-
options produce comma or dot formatted byte counts for readability.
41-
42-
The -sha1 option disables torrent checking, and instead acts as a SHA1 filter.
43-
Most Windows machines do not have a SHA1 utility, so I included this mode as a
44-
convenience feature. It reads in binary data from standard input until end of
45-
file, and prints the SHA1 hash. If a SHA1 hash is provided on the command line,
46-
it will return 0 if the hashes match or nonzero if they do not. This mode
47-
should agree with the output of "openssl dgst -sha1" or "digest -a sha1"
48-
49-
### Examples
50-
51-
```shell
52-
torrentcheck \torrents\ubuntu-10.10-desktop-i386.iso.torrent
53-
torrentcheck \torrents\ubuntu-10.10-desktop-i386.iso.torrent -p \download
54-
torrentcheck \torrents\ubuntu-10.10-desktop-i386.iso.torrent -p \download && echo good
55-
torrentcheck \torrents\ubuntu-10.10-desktop-i386.iso.torrent -p \download || echo bad
56-
torrentcheck \torrents\ubuntu-10.10-desktop-i386.iso.torrent -p \download\ubuntu-10.10-desktop-i386.iso
57-
torrentcheck -sha1 < \download\ubuntu-10.10-desktop-i386.iso
58-
torrentcheck -sha1 b28bbd742aff85d21b9ad96bb45b67c2d133be99 < \download\ubuntu-10.10-desktop-i386.iso && echo good
59-
```
60-
(These are for Windows; use forward slashes in Unix/Linux)
61-
62-
### Automation and scripting
63-
64-
Torrentcheck returns 0 in the Unix $? return code or Windows errorlevel
65-
if it successfully verifies a torrent, or nonzero return codes if it fails.
66-
67-
If you have your torrents in `\torrents` and the downloaded files in `\share`,
68-
make a "bad" directory under `\torrents`, cd to `\torrents`, and run:
69-
70-
(Windows)
71-
```shell
72-
for %i in (*.torrent) do torrentcheck "%i" -p \share || move "%i" bad
73-
```
74-
75-
(Linux)
76-
```shell
77-
for i in *.torrent; do torrentcheck "$i" -p /share || mv "$i" bad ; done
78-
```
79-
80-
This will check all the torrents, and move any that are not fully
81-
downloaded and correct into `\torrents\bad`.
82-
83-
Run this command to generate a master list file with the contents of all your
84-
torrents. This file can be searched to find a particular file and which torrent
85-
it comes from.
86-
87-
(Windows)
88-
```shell
89-
for %i in (*.torrent) do torrentcheck "%i" >> masterlist.txt & echo. >> masterlist.txt
90-
```
91-
92-
(Linux)
93-
```shell
94-
for i in *.torrent; do torrentcheck "$i" >> masterlist.txt ; echo >> masterlist.txt ; done
95-
```
96-
97-
### Detailed description
98-
99-
BitTorrent is a file sharing system which uses a metadata file, usually with
100-
the .torrent extension, to identify a data file or group of files. Given the
101-
metadata file, a BitTorrent client can download and share the data files.
102-
It can also verify the integrity of the files.
103-
104-
The metadata file uses an encoding scheme called "bencode" which can store
105-
integers, strings, lists, and key-value pairs. It can represent binary values
106-
without any escaping, so a bencoded string can be loaded into memory and parsed
107-
in place, without any decoding. Torrent metadata contains the names and sizes
108-
of all the files in the torrent, and also contains a series of SHA1 hashes on
109-
each piece of the data file or files. The piece size is specified in the
110-
metadata, ranging from 32KiB (32768) to 4MiB (4194304) in a sample of torrents.
111-
112-
SHA1 is a complex error-checking code designed by the National Security Agency
113-
for the military Defense Messaging System. It inputs an arbitrarily long byte
114-
string and outputs a 20-byte check code. If any bit in the input changes, the
115-
check code will change. SHA1 is complex enough so that even by deliberate
116-
effort it is very difficult to find two strings with the same check code. The
117-
chance of this happening by accident is small enough to ignore.
118-
119-
To check a single-file torrent, allocate a buffer equal to the "piece size"
120-
string in the metadata, open the input file identified by the "name" string
121-
or specified on the command line, and read in pieces one at a time. The last
122-
piece will likely be short; keep track of the number of bytes actually read.
123-
Hash each piece, and compare the hash code against the corresponding hash code
124-
in the metadata. Any mismatch is an error.
125-
126-
To check a multiple-file torrent, allocate a buffer as above. Read files in
127-
order from the "files" list in the metadata and reconstruct the paths, where
128-
the "name" string may be the base directory. Read from each file in sequence
129-
into the buffer until the buffer is full or the last file has been read, then
130-
hash it and check against the list in the metadata. Any mismatch is an error.
131-
132-
Hash pieces span multiple files, so a missing or corrupt file can cause the
133-
previous or next file to fail as well. In particular, a missing file usually
134-
causes the previous and next files to fail verification. This is an artifact of
135-
the torrent format, and there is no way to avoid it. Torrents often contain a
136-
large media file and a small descriptive text file. If the text file is
137-
missing, the media file usually cannot be verified.
138-
139-
Torrentcheck also verifies the length of each file, and flags an error if the
140-
length is wrong even if the hash codes match. It is designed to handle files
141-
over 4GB on a 32-bit machine.
142-
143-
The SHA1 implementation used by torrentcheck was written by David Ireland,
144-
AM Kuchling, and Peter Gutmann. The source code does not contain a copyright
145-
notice, and this file is widely used on the Internet.
146-
147-
### Compiling
148-
149-
There is no makefile. The required `gcc` lines are at the top of the
150-
`torrentcheck.c` source file. The major catch in compiling is making 64-bit file
151-
I/O work. It is tested on Windows, Linux, and Solaris, but you may have to
152-
experiment with compiler options to get 64-bit ftell and fseek working.
1+
# torrentcheck
2+
3+
torrentcheck - catalog a `.torrent` file and optionally verify content hashes.
4+
5+
Usage: `torrentcheck torrent-file [-p content-path] [-n] [-h] [-c] [-d]`
6+
7+
Options:
8+
`-n` suppresses progress count,
9+
`-h` shows all hash values,
10+
`-c` or `-d` uses comma or dot formatted byte counts.
11+
12+
Returns 0 if successful, nonzero return code if errors found.
13+
14+
Option: `-sha1` [optional hash] acts as a simple SHA1 filter.
15+
16+
If `-sha1` is followed by a hex hash, the return code will be zero
17+
on match and nonzero otherwise.
18+
19+
### Summary
20+
21+
This program is a command-line utility to catalog and verify torrent files.
22+
Run with only the -t option, it displays the metadata, name, and size of
23+
each file in the torrent. Run with the -t and -p options, it computes the
24+
hashes of all files in the torrent, compares them against the hashes stored
25+
in the metadata, and warns of any errors.
26+
27+
If torrentcheck returns "torrent is good" at the end of its output, every
28+
byte of every file in the torrent is present and correct, to a high degree of
29+
certainty as explained below.
30+
31+
For example, if you run torrents on a fast external server and then download
32+
the files, this utility will verify that the files you received are complete
33+
and uncorrupted. It can also be used to verify backups or to automatically
34+
check a series of torrents using scripting.
35+
36+
The -t parameter should be the path to the .torrent metadata file. The -p path
37+
should point to the file or files. It can include or leave out the torrent name.
38+
The -n option suppresses the running count, which is useful if you are writing
39+
the output to a file. The -h option shows all piece hash values. The -c or -d
40+
options produce comma or dot formatted byte counts for readability.
41+
42+
The -sha1 option disables torrent checking, and instead acts as a SHA1 filter.
43+
Most Windows machines do not have a SHA1 utility, so I included this mode as a
44+
convenience feature. It reads in binary data from standard input until end of
45+
file, and prints the SHA1 hash. If a SHA1 hash is provided on the command line,
46+
it will return 0 if the hashes match or nonzero if they do not. This mode
47+
should agree with the output of "openssl dgst -sha1" or "digest -a sha1"
48+
49+
### Examples
50+
51+
```shell
52+
torrentcheck \torrents\ubuntu-10.10-desktop-i386.iso.torrent
53+
torrentcheck \torrents\ubuntu-10.10-desktop-i386.iso.torrent -p \download
54+
torrentcheck \torrents\ubuntu-10.10-desktop-i386.iso.torrent -p \download && echo good
55+
torrentcheck \torrents\ubuntu-10.10-desktop-i386.iso.torrent -p \download || echo bad
56+
torrentcheck \torrents\ubuntu-10.10-desktop-i386.iso.torrent -p \download\ubuntu-10.10-desktop-i386.iso
57+
torrentcheck -sha1 < \download\ubuntu-10.10-desktop-i386.iso
58+
torrentcheck -sha1 b28bbd742aff85d21b9ad96bb45b67c2d133be99 < \download\ubuntu-10.10-desktop-i386.iso && echo good
59+
```
60+
(These are for Windows; use forward slashes in Unix/Linux)
61+
62+
### Automation and scripting
63+
64+
Torrentcheck returns 0 in the Unix $? return code or Windows errorlevel
65+
if it successfully verifies a torrent, or nonzero return codes if it fails.
66+
67+
If you have your torrents in `\torrents` and the downloaded files in `\share`,
68+
make a "bad" directory under `\torrents`, cd to `\torrents`, and run:
69+
70+
(Windows)
71+
```shell
72+
for %i in (*.torrent) do torrentcheck "%i" -p \share || move "%i" bad
73+
```
74+
75+
(Linux)
76+
```shell
77+
for i in *.torrent; do torrentcheck "$i" -p /share || mv "$i" bad ; done
78+
```
79+
80+
This will check all the torrents, and move any that are not fully
81+
downloaded and correct into `\torrents\bad`.
82+
83+
Run this command to generate a master list file with the contents of all your
84+
torrents. This file can be searched to find a particular file and which torrent
85+
it comes from.
86+
87+
(Windows)
88+
```shell
89+
for %i in (*.torrent) do torrentcheck "%i" >> masterlist.txt & echo. >> masterlist.txt
90+
```
91+
92+
(Linux)
93+
```shell
94+
for i in *.torrent; do torrentcheck "$i" >> masterlist.txt ; echo >> masterlist.txt ; done
95+
```
96+
97+
### Detailed description
98+
99+
BitTorrent is a file sharing system which uses a metadata file, usually with
100+
the .torrent extension, to identify a data file or group of files. Given the
101+
metadata file, a BitTorrent client can download and share the data files.
102+
It can also verify the integrity of the files.
103+
104+
The metadata file uses an encoding scheme called "bencode" which can store
105+
integers, strings, lists, and key-value pairs. It can represent binary values
106+
without any escaping, so a bencoded string can be loaded into memory and parsed
107+
in place, without any decoding. Torrent metadata contains the names and sizes
108+
of all the files in the torrent, and also contains a series of SHA1 hashes on
109+
each piece of the data file or files. The piece size is specified in the
110+
metadata, ranging from 32KiB (32768) to 4MiB (4194304) in a sample of torrents.
111+
112+
SHA1 is a complex error-checking code designed by the National Security Agency
113+
for the military Defense Messaging System. It inputs an arbitrarily long byte
114+
string and outputs a 20-byte check code. If any bit in the input changes, the
115+
check code will change. SHA1 is complex enough so that even by deliberate
116+
effort it is very difficult to find two strings with the same check code. The
117+
chance of this happening by accident is small enough to ignore.
118+
119+
To check a single-file torrent, allocate a buffer equal to the "piece size"
120+
string in the metadata, open the input file identified by the "name" string
121+
or specified on the command line, and read in pieces one at a time. The last
122+
piece will likely be short; keep track of the number of bytes actually read.
123+
Hash each piece, and compare the hash code against the corresponding hash code
124+
in the metadata. Any mismatch is an error.
125+
126+
To check a multiple-file torrent, allocate a buffer as above. Read files in
127+
order from the "files" list in the metadata and reconstruct the paths, where
128+
the "name" string may be the base directory. Read from each file in sequence
129+
into the buffer until the buffer is full or the last file has been read, then
130+
hash it and check against the list in the metadata. Any mismatch is an error.
131+
132+
Hash pieces span multiple files, so a missing or corrupt file can cause the
133+
previous or next file to fail as well. In particular, a missing file usually
134+
causes the previous and next files to fail verification. This is an artifact of
135+
the torrent format, and there is no way to avoid it. Torrents often contain a
136+
large media file and a small descriptive text file. If the text file is
137+
missing, the media file usually cannot be verified.
138+
139+
Torrentcheck also verifies the length of each file, and flags an error if the
140+
length is wrong even if the hash codes match. It is designed to handle files
141+
over 4GB on a 32-bit machine.
142+
143+
The SHA1 implementation used by torrentcheck was written by David Ireland,
144+
AM Kuchling, and Peter Gutmann. The source code does not contain a copyright
145+
notice, and this file is widely used on the Internet.
146+
147+
### Compiling
148+
149+
There is no makefile. The required `gcc` lines are at the top of the
150+
`torrentcheck.c` source file. The major catch in compiling is making 64-bit file
151+
I/O work. It is tested on Windows, Linux, and Solaris, but you may have to
152+
experiment with compiler options to get 64-bit ftell and fseek working.

0 commit comments

Comments
 (0)