File: reference-Create_Torrents.html

package info (click to toggle)
libtorrent-rasterbar 1.1.13-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 17,248 kB
  • sloc: cpp: 134,519; sh: 4,666; python: 2,591; ansic: 1,754; makefile: 914
file content (477 lines) | stat: -rw-r--r-- 26,538 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.14: http://docutils.sourceforge.net/" />
<title>reference-Create_Torrents.rst</title>
<meta name="author" content="Arvid Norberg, arvid&#64;libtorrent.org" />
<meta name=viewport content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="rst.css" />
<style type="text/css">
/* Hides from IE-mac \*/
* html pre { height: 1%; }
/* End hide from IE-mac */
</style>
</head>
<body>
<div class="document">
    <div id="container">
    <a href="index.html"><table id="header">
    <tr><td id="orange"></td>
    <td id="logo">libtorrent</td></tr>
    </table></a>
    <div id="main">

<table class="docinfo" frame="void" rules="none">
<col class="docinfo-name" />
<col class="docinfo-content" />
<tbody valign="top">
<tr><th class="docinfo-name">Author:</th>
<td>Arvid Norberg, <a class="last reference external" href="mailto:arvid&#64;libtorrent.org">arvid&#64;libtorrent.org</a></td></tr>
<tr><th class="docinfo-name">Version:</th>
<td>1.1.13</td></tr>
</tbody>
</table>
<p><a class="reference external" href="reference.html">home</a></p>
<div class="section" id="create-torrents">
<h1>Create Torrents</h1>
<div class="contents topic" id="table-of-contents">
<p class="topic-title first">Table of contents</p>
<ul class="simple">
<li><a class="reference internal" href="#create-torrents" id="id22">Create Torrents</a><ul>
<li><a class="reference internal" href="#create-torrent" id="id23">create_torrent</a></li>
<li><a class="reference internal" href="#add-files" id="id24">add_files()</a></li>
<li><a class="reference internal" href="#set-piece-hashes" id="id25">set_piece_hashes()</a></li>
</ul>
</li>
</ul>
</div>
<p>This section describes the functions and classes that are used
to create torrent files. It is a layered API with low level classes
and higher level convenience functions. A torrent is created in 4
steps:</p>
<ol class="arabic simple">
<li>first the files that will be part of the torrent are determined.</li>
<li>the torrent properties are set, such as tracker url, web seeds,
DHT nodes etc.</li>
<li>Read through all the files in the torrent, SHA-1 all the data
and set the piece hashes.</li>
<li>The torrent is bencoded into a file or buffer.</li>
</ol>
<p>If there are a lot of files and or deep directory hierarchies to
traverse, step one can be time consuming.</p>
<p>Typically step 3 is by far the most time consuming step, since it
requires to read all the bytes from all the files in the torrent.</p>
<p>All of these classes and functions are declared by including
<tt class="docutils literal">libtorrent/create_torrent.hpp</tt>.</p>
<p>example:</p>
<pre class="code c++ literal-block">
<span class="name">file_storage</span> <span class="name">fs</span><span class="punctuation">;</span>

<span class="comment single">// recursively adds files in directories
</span><span class="name">add_files</span><span class="punctuation">(</span><span class="name">fs</span><span class="punctuation">,</span> <span class="literal string">&quot;./my_torrent&quot;</span><span class="punctuation">);</span>

<span class="name">create_torrent</span> <span class="name function">t</span><span class="punctuation">(</span><span class="name">fs</span><span class="punctuation">);</span>
<span class="name">t</span><span class="punctuation">.</span><span class="name">add_tracker</span><span class="punctuation">(</span><span class="literal string">&quot;http://my.tracker.com/announce&quot;</span><span class="punctuation">);</span>
<span class="name">t</span><span class="punctuation">.</span><span class="name">set_creator</span><span class="punctuation">(</span><span class="literal string">&quot;libtorrent example&quot;</span><span class="punctuation">);</span>

<span class="comment single">// reads the files and calculates the hashes
</span><span class="name">set_piece_hashes</span><span class="punctuation">(</span><span class="name">t</span><span class="punctuation">,</span> <span class="literal string">&quot;.&quot;</span><span class="punctuation">);</span>

<span class="name">ofstream</span> <span class="name function">out</span><span class="punctuation">(</span><span class="literal string">&quot;my_torrent.torrent&quot;</span><span class="punctuation">,</span> <span class="name">std</span><span class="operator">::</span><span class="name">ios_base</span><span class="operator">::</span><span class="name">binary</span><span class="punctuation">);</span>
<span class="name">bencode</span><span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">ostream_iterator</span><span class="operator">&lt;</span><span class="keyword type">char</span><span class="operator">&gt;</span><span class="punctuation">(</span><span class="name">out</span><span class="punctuation">),</span> <span class="name">t</span><span class="punctuation">.</span><span class="name">generate</span><span class="punctuation">());</span>
</pre>
<a name="create_torrent"></a><div class="section" id="create-torrent">
<h2>create_torrent</h2>
<p>Declared in &quot;<a class="reference external" href="../include/libtorrent/create_torrent.hpp">libtorrent/create_torrent.hpp</a>&quot;</p>
<p>This class holds state for creating a torrent. After having added
all information to it, call <a class="reference external" href="reference-Create_Torrents.html#generate()">create_torrent::generate()</a> to generate
the torrent. The <a class="reference external" href="reference-Bencoding.html#entry">entry</a> that's returned can then be bencoded into a
.torrent file using <a class="reference external" href="reference-Bencoding.html#bencode()">bencode()</a>.</p>
<pre class="literal-block">
struct create_torrent
{
   <strong>create_torrent</strong> (torrent_info const&amp; ti);
   <strong>create_torrent</strong> (torrent_info const&amp; ti, bool use_preformatted);
   <strong>create_torrent</strong> (file_storage&amp; fs, int piece_size = 0
      , int pad_file_limit = -1, int flags = optimize_alignment
      , int alignment = -1);
   entry <strong>generate</strong> () const;
   file_storage const&amp; <strong>files</strong> () const;
   void <strong>set_comment</strong> (char const* str);
   void <strong>set_creator</strong> (char const* str);
   void <strong>set_hash</strong> (int index, sha1_hash const&amp; h);
   void <strong>set_file_hash</strong> (int index, sha1_hash const&amp; h);
   void <strong>add_url_seed</strong> (std::string const&amp; url);
   void <strong>add_http_seed</strong> (std::string const&amp; url);
   void <strong>add_node</strong> (std::pair&lt;std::string, int&gt; const&amp; node);
   void <strong>add_tracker</strong> (std::string const&amp; url, int tier = 0);
   void <strong>set_root_cert</strong> (std::string const&amp; pem);
   bool <strong>priv</strong> () const;
   void <strong>set_priv</strong> (bool p);
   int <strong>num_pieces</strong> () const;
   int <strong>piece_length</strong> () const;
   int <strong>piece_size</strong> (int i) const;
   std::vector&lt;sha1_hash&gt; const&amp; <strong>merkle_tree</strong> () const;
   void <strong>add_similar_torrent</strong> (sha1_hash ih);
   void <strong>add_collection</strong> (std::string c);

   enum flags_t
   {
      optimize_alignment,
      merkle,
      modification_time,
      symlinks,
      mutable_torrent_support,
   };
};
</pre>
<a name="create_torrent()"></a><div class="section" id="id6">
<h3>create_torrent()</h3>
<pre class="literal-block">
<strong>create_torrent</strong> (torrent_info const&amp; ti);
<strong>create_torrent</strong> (torrent_info const&amp; ti, bool use_preformatted);
<strong>create_torrent</strong> (file_storage&amp; fs, int piece_size = 0
      , int pad_file_limit = -1, int flags = optimize_alignment
      , int alignment = -1);
</pre>
<p>The <tt class="docutils literal">piece_size</tt> is the size of each piece in bytes. It must
be a multiple of 16 kiB. If a piece size of 0 is specified, a
piece_size will be calculated such that the torrent file is roughly 40 kB.</p>
<p>If a <tt class="docutils literal">pad_file_limit</tt> is specified (other than -1), any file larger than
the specified number of bytes will be preceded by a pad file to align it
with the start of a piece. The pad_file_limit is ignored unless the
<tt class="docutils literal">optimize_alignment</tt> flag is passed. Typically it doesn't make sense
to set this any lower than 4 kiB.</p>
<p>The overload that takes a <tt class="docutils literal">torrent_info</tt> object will make a verbatim
copy of its info dictionary (to preserve the info-hash). The copy of
the info dictionary will be used by <a class="reference external" href="reference-Create_Torrents.html#generate()">create_torrent::generate()</a>. This means
that none of the member functions of <a class="reference external" href="reference-Create_Torrents.html#create_torrent">create_torrent</a> that affects
the content of the info dictionary (such as <tt class="docutils literal">set_hash()</tt>), will
have any affect.</p>
<p>The <tt class="docutils literal">flags</tt> arguments specifies options for the torrent creation. It can
be any combination of the flags defined by <a class="reference external" href="reference-Create_Torrents.html#flags_t">create_torrent::flags_t</a>.</p>
<p><tt class="docutils literal">alignment</tt> is used when pad files are enabled. This is the size
eligible files are aligned to. The default is -1, which means the
piece size of the torrent.
The <tt class="docutils literal">use_preformatted</tt> parameter can be set to true to preserve
invalid encoding of the .torrent file.</p>
<a name="generate()"></a></div>
<div class="section" id="generate">
<h3>generate()</h3>
<pre class="literal-block">
entry <strong>generate</strong> () const;
</pre>
<p>This function will generate the .torrent file as a bencode tree. In order to
generate the flat file, use the <a class="reference external" href="reference-Bencoding.html#bencode()">bencode()</a> function.</p>
<p>It may be useful to add custom entries to the torrent file before bencoding it
and saving it to disk.</p>
<p>If anything goes wrong during torrent generation, this function will return
an empty <tt class="docutils literal">entry</tt> structure. You can test for this condition by querying the
type of the entry:</p>
<pre class="code c++ literal-block">
<span class="name">file_storage</span> <span class="name">fs</span><span class="punctuation">;</span>
<span class="comment single">// add file ...
</span><span class="name">create_torrent</span> <span class="name function">t</span><span class="punctuation">(</span><span class="name">fs</span><span class="punctuation">);</span>
<span class="comment single">// add trackers and piece hashes ...
</span><span class="name">e</span> <span class="operator">=</span> <span class="name">t</span><span class="punctuation">.</span><span class="name">generate</span><span class="punctuation">();</span>

<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">e</span><span class="punctuation">.</span><span class="name">type</span><span class="punctuation">()</span> <span class="operator">==</span> <span class="name">entry</span><span class="operator">::</span><span class="name">undefined_t</span><span class="punctuation">)</span>
<span class="punctuation">{</span>
        <span class="comment single">// something went wrong
</span><span class="punctuation">}</span>
</pre>
<p>For instance, you cannot generate a torrent with 0 files in it. If you don't add
any files to the <tt class="docutils literal">file_storage</tt>, torrent generation will fail.</p>
<a name="files()"></a></div>
<div class="section" id="files">
<h3>files()</h3>
<pre class="literal-block">
file_storage const&amp; <strong>files</strong> () const;
</pre>
<p>returns an immutable reference to the <a class="reference external" href="reference-Storage.html#file_storage">file_storage</a> used to create
the torrent from.</p>
<a name="set_comment()"></a></div>
<div class="section" id="set-comment">
<h3>set_comment()</h3>
<pre class="literal-block">
void <strong>set_comment</strong> (char const* str);
</pre>
<p>Sets the comment for the torrent. The string <tt class="docutils literal">str</tt> should be utf-8 encoded.
The comment in a torrent file is optional.</p>
<a name="set_creator()"></a></div>
<div class="section" id="set-creator">
<h3>set_creator()</h3>
<pre class="literal-block">
void <strong>set_creator</strong> (char const* str);
</pre>
<p>Sets the creator of the torrent. The string <tt class="docutils literal">str</tt> should be utf-8 encoded.
This is optional.</p>
<a name="set_hash()"></a></div>
<div class="section" id="set-hash">
<h3>set_hash()</h3>
<pre class="literal-block">
void <strong>set_hash</strong> (int index, sha1_hash const&amp; h);
</pre>
<p>This sets the SHA-1 hash for the specified piece (<tt class="docutils literal">index</tt>). You are required
to set the hash for every piece in the torrent before generating it. If you have
the files on disk, you can use the high level convenience function to do this.
See <a class="reference external" href="reference-Create_Torrents.html#set_piece_hashes()">set_piece_hashes()</a>.</p>
<a name="set_file_hash()"></a></div>
<div class="section" id="set-file-hash">
<h3>set_file_hash()</h3>
<pre class="literal-block">
void <strong>set_file_hash</strong> (int index, sha1_hash const&amp; h);
</pre>
<p>This sets the sha1 hash for this file. This hash will end up under the key <tt class="docutils literal">sha1</tt>
associated with this file (for multi-file torrents) or in the root info dictionary
for single-file torrents.</p>
<a name="add_url_seed()"></a>
<a name="add_http_seed()"></a></div>
<div class="section" id="add-url-seed-add-http-seed">
<h3>add_url_seed() add_http_seed()</h3>
<pre class="literal-block">
void <strong>add_url_seed</strong> (std::string const&amp; url);
void <strong>add_http_seed</strong> (std::string const&amp; url);
</pre>
<p>This adds a url seed to the torrent. You can have any number of url seeds. For a
single file torrent, this should be an HTTP url, pointing to a file with identical
content as the file of the torrent. For a multi-file torrent, it should point to
a directory containing a directory with the same name as this torrent, and all the
files of the torrent in it.</p>
<p>The second function, <tt class="docutils literal">add_http_seed()</tt> adds an HTTP seed instead.</p>
<a name="add_node()"></a></div>
<div class="section" id="add-node">
<h3>add_node()</h3>
<pre class="literal-block">
void <strong>add_node</strong> (std::pair&lt;std::string, int&gt; const&amp; node);
</pre>
<p>This adds a DHT node to the torrent. This especially useful if you're creating a
tracker less torrent. It can be used by clients to bootstrap their DHT node from.
The node is a hostname and a port number where there is a DHT node running.
You can have any number of DHT nodes in a torrent.</p>
<a name="add_tracker()"></a></div>
<div class="section" id="add-tracker">
<h3>add_tracker()</h3>
<pre class="literal-block">
void <strong>add_tracker</strong> (std::string const&amp; url, int tier = 0);
</pre>
<p>Adds a tracker to the torrent. This is not strictly required, but most torrents
use a tracker as their main source of peers. The url should be an <a class="reference external" href="http://">http://</a> or udp://
url to a machine running a bittorrent tracker that accepts announces for this torrent's
info-hash. The tier is the fallback priority of the tracker. All trackers with tier 0 are
tried first (in any order). If all fail, trackers with tier 1 are tried. If all of those
fail, trackers with tier 2 are tried, and so on.</p>
<a name="set_root_cert()"></a></div>
<div class="section" id="set-root-cert">
<h3>set_root_cert()</h3>
<pre class="literal-block">
void <strong>set_root_cert</strong> (std::string const&amp; pem);
</pre>
<p>This function sets an X.509 certificate in PEM format to the torrent. This makes the
torrent an <em>SSL torrent</em>. An SSL torrent requires that each peer has a valid certificate
signed by this root certificate. For SSL torrents, all peers are connecting over SSL
connections. For more information, see the section on <a class="reference external" href="manual-ref.html#ssl-torrents">ssl torrents</a>.</p>
<p>The string is not the path to the cert, it's the actual content of the certificate,
loaded into a std::string.</p>
<a name="priv()"></a>
<a name="set_priv()"></a></div>
<div class="section" id="priv-set-priv">
<h3>priv() set_priv()</h3>
<pre class="literal-block">
bool <strong>priv</strong> () const;
void <strong>set_priv</strong> (bool p);
</pre>
<p>Sets and queries the private flag of the torrent.
Torrents with the private flag set ask clients to not use any other
sources than the tracker for peers, and to not advertise itself publicly,
apart from the tracker.</p>
<a name="num_pieces()"></a></div>
<div class="section" id="num-pieces">
<h3>num_pieces()</h3>
<pre class="literal-block">
int <strong>num_pieces</strong> () const;
</pre>
<p>returns the number of pieces in the associated <a class="reference external" href="reference-Storage.html#file_storage">file_storage</a> object.</p>
<a name="piece_length()"></a>
<a name="piece_size()"></a></div>
<div class="section" id="piece-length-piece-size">
<h3>piece_length() piece_size()</h3>
<pre class="literal-block">
int <strong>piece_length</strong> () const;
int <strong>piece_size</strong> (int i) const;
</pre>
<p><tt class="docutils literal">piece_length()</tt> returns the piece size of all pieces but the
last one. <tt class="docutils literal">piece_size()</tt> returns the size of the specified piece.
these functions are just forwarding to the associated <a class="reference external" href="reference-Storage.html#file_storage">file_storage</a>.</p>
<a name="merkle_tree()"></a></div>
<div class="section" id="merkle-tree">
<h3>merkle_tree()</h3>
<pre class="literal-block">
std::vector&lt;sha1_hash&gt; const&amp; <strong>merkle_tree</strong> () const;
</pre>
<p>This function returns the merkle hash tree, if the torrent was created as a merkle
torrent. The tree is created by <tt class="docutils literal">generate()</tt> and won't be valid until that function
has been called. When creating a merkle tree torrent, the actual tree itself has to
be saved off separately and fed into libtorrent the first time you start seeding it,
through the <tt class="docutils literal"><span class="pre">torrent_info::set_merkle_tree()</span></tt> function. From that point onwards, the
tree will be saved in the resume data.</p>
<a name="add_collection()"></a>
<a name="add_similar_torrent()"></a></div>
<div class="section" id="add-collection-add-similar-torrent">
<h3>add_collection() add_similar_torrent()</h3>
<pre class="literal-block">
void <strong>add_similar_torrent</strong> (sha1_hash ih);
void <strong>add_collection</strong> (std::string c);
</pre>
<p>Add similar torrents (by info-hash) or collections of similar torrents.
Similar torrents are expected to share some files with this torrent.
Torrents sharing a collection name with this torrent are also expected
to share files with this torrent. A torrent may have more than one
collection and more than one similar torrents. For more information,
see <a class="reference external" href="http://www.bittorrent.org/beps/bep_0038.html">BEP 38</a>.</p>
<a name="flags_t"></a></div>
<div class="section" id="enum-flags-t">
<h3>enum flags_t</h3>
<p>Declared in &quot;<a class="reference external" href="../include/libtorrent/create_torrent.hpp">libtorrent/create_torrent.hpp</a>&quot;</p>
<table border="1" class="docutils">
<colgroup>
<col width="23%" />
<col width="7%" />
<col width="70%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">name</th>
<th class="head">value</th>
<th class="head">description</th>
</tr>
</thead>
<tbody valign="top">
<tr><td>optimize_alignment</td>
<td>1</td>
<td>This will insert pad files to align the files to piece boundaries, for
optimized disk-I/O. This will minimize the number of bytes of pad-
files, to keep the impact down for clients that don't support
them.</td>
</tr>
<tr><td>merkle</td>
<td>2</td>
<td>This will create a merkle hash tree torrent. A merkle torrent cannot
be opened in clients that don't specifically support merkle torrents.
The benefit is that the resulting torrent file will be much smaller and
not grow with more pieces. When this option is specified, it is
recommended to have a fairly small piece size, say 64 kiB.
When creating merkle torrents, the full hash tree is also generated
and should be saved off separately. It is accessed through the
<a class="reference external" href="reference-Create_Torrents.html#merkle_tree()">create_torrent::merkle_tree()</a> function.</td>
</tr>
<tr><td>modification_time</td>
<td>4</td>
<td>This will include the file modification time as part of the torrent.
This is not enabled by default, as it might cause problems when you
create a torrent from separate files with the same content, hoping to
yield the same info-hash. If the files have different modification times,
with this option enabled, you would get different info-hashes for the
files.</td>
</tr>
<tr><td>symlinks</td>
<td>8</td>
<td>If this flag is set, files that are symlinks get a symlink attribute
set on them and their data will not be included in the torrent. This
is useful if you need to reconstruct a file hierarchy which contains
symlinks.</td>
</tr>
<tr><td>mutable_torrent_support</td>
<td>16</td>
<td>to create a torrent that can be updated via a <em>mutable torrent</em>
(see <a class="reference external" href="http://www.bittorrent.org/beps/bep_0038.html">BEP 38</a>). This also needs to be enabled for torrents that update
another torrent.</td>
</tr>
</tbody>
</table>
<a name="add_files()"></a></div>
</div>
<div class="section" id="add-files">
<h2>add_files()</h2>
<p>Declared in &quot;<a class="reference external" href="../include/libtorrent/create_torrent.hpp">libtorrent/create_torrent.hpp</a>&quot;</p>
<pre class="literal-block">
void <strong>add_files</strong> (file_storage&amp; fs, std::string const&amp; file
   , boost::function&lt;bool(std::string)&gt; p, boost::uint32_t flags = 0);
void <strong>add_files</strong> (file_storage&amp; fs, std::string const&amp; file
   , boost::uint32_t flags = 0);
</pre>
<p>Adds the file specified by <tt class="docutils literal">path</tt> to the <a class="reference external" href="reference-Storage.html#file_storage">file_storage</a> object. In case <tt class="docutils literal">path</tt>
refers to a directory, files will be added recursively from the directory.</p>
<p>If specified, the predicate <tt class="docutils literal">p</tt> is called once for every file and directory that
is encountered. Files for which <tt class="docutils literal">p</tt> returns true are added, and directories for
which <tt class="docutils literal">p</tt> returns true are traversed. <tt class="docutils literal">p</tt> must have the following signature:</p>
<pre class="literal-block">
bool Pred(std::string const&amp; p);
</pre>
<p>The path that is passed in to the predicate is the full path of the file or
directory. If no predicate is specified, all files are added, and all directories
are traversed.</p>
<p>The &quot;..&quot; directory is never traversed.</p>
<p>The <tt class="docutils literal">flags</tt> argument should be the same as the flags passed to the <a class="reference internal" href="#create-torrent">create_torrent</a>
constructor.</p>
<a name="set_piece_hashes()"></a></div>
<div class="section" id="set-piece-hashes">
<h2>set_piece_hashes()</h2>
<p>Declared in &quot;<a class="reference external" href="../include/libtorrent/create_torrent.hpp">libtorrent/create_torrent.hpp</a>&quot;</p>
<pre class="literal-block">
void <strong>set_piece_hashes</strong> (create_torrent&amp; t, std::string const&amp; p
   , boost::function&lt;void(int)&gt; const&amp; f, error_code&amp; ec);
inline void <strong>set_piece_hashes</strong> (create_torrent&amp; t, std::string const&amp; p);
inline void <strong>set_piece_hashes</strong> (create_torrent&amp; t, std::string const&amp; p, error_code&amp; ec);
</pre>
<p>This function will assume that the files added to the torrent file exists at path
<tt class="docutils literal">p</tt>, read those files and hash the content and set the hashes in the <tt class="docutils literal">create_torrent</tt>
object. The optional function <tt class="docutils literal">f</tt> is called in between every hash that is set. <tt class="docutils literal">f</tt>
must have the following signature:</p>
<pre class="literal-block">
void Fun(int);
</pre>
<p>The overloads that don't take an <tt class="docutils literal">error_code&amp;</tt> may throw an exception in case of a
file error, the other overloads sets the error code to reflect the error, if any.</p>
</div>
</div>

    </div>
    </div>
    <div id="gradient"></div>
    <div id="footer">
    <table>
    <tr>
      <td><a href="index.html">home</a></td>
      <td><a href="https://blog.libtorrent.org">blog</a></td>
      <td><a href="utp.html">uTP</a></td>
    </tr>
    <tr>
      <td><a href="https://sourceforge.net/projects/libtorrent/files/libtorrent/">download</a></td>
      <td><a href="reference.html">documentation</a></td>
      <td><a href="dht_store.html">DHT put extension</a></td>
    </tr>
    <tr>
      <td><a href="https://sourceforge.net/projects/libtorrent/files/py-libtorrent/">python bindings</a></td>
      <td><a href="features.html">features</a></td>
      <td><a href="dht_sec.html">DHT security extension</a></td>
    </tr>
    <tr>
      <td><a href="https://sourceforge.net/p/libtorrent/mailman/libtorrent-discuss/">mailing list archive</a></td>
      <td><a href="contributing.html">contributing</a></td>
      <td><a href="streaming.html">streaming</a></td>
    </tr>
    <tr>
      <td><a href="https://github.com/arvidn/libtorrent/issues">report a bug</a></td>
      <td><a href="building.html">building</a></td>
      <td><a href="bittorrent.pdf">bittorrent slides</a></td>
    </tr>
    </table>
    </div>
    <div id="filler"></div>

</div>
</body>
</html>