forked from premiere/premiere-libtorrent
added ip filters and fixed torrent_info::create_torrent()
This commit is contained in:
parent
8f975b13b1
commit
e003bb8ad5
7
Jamfile
7
Jamfile
|
@ -52,6 +52,7 @@ SOURCES =
|
|||
escape_string.cpp
|
||||
file.cpp
|
||||
identify_client.cpp
|
||||
ip_filter.cpp
|
||||
peer_connection.cpp
|
||||
piece_picker.cpp
|
||||
policy.cpp
|
||||
|
@ -93,8 +94,10 @@ LIBS = ;
|
|||
LIBS += wsock32 ;
|
||||
}
|
||||
|
||||
variant release_log : release : <define>TORRENT_VERBOSE_LOGGING ;
|
||||
variant debug_log : debug : <define>TORRENT_VERBOSE_LOGGING ;
|
||||
variant release_vlog : release : <define>TORRENT_VERBOSE_LOGGING ;
|
||||
variant release_log : release : <define>TORRENT_LOGGING ;
|
||||
variant debug_vlog : debug : <define>TORRENT_VERBOSE_LOGGING ;
|
||||
variant debug_log : debug : <define>TORRENT_LOGGING ;
|
||||
|
||||
|
||||
lib torrent
|
||||
|
|
586
docs/manual.html
586
docs/manual.html
|
@ -22,115 +22,126 @@
|
|||
<div class="contents topic" id="contents">
|
||||
<p class="topic-title first"><a name="contents">Contents</a></p>
|
||||
<ul class="simple">
|
||||
<li><a class="reference" href="#introduction" id="id17" name="id17">introduction</a></li>
|
||||
<li><a class="reference" href="#downloading-and-building" id="id18" name="id18">downloading and building</a><ul>
|
||||
<li><a class="reference" href="#cygwin-and-msvc" id="id19" name="id19">cygwin and msvc</a></li>
|
||||
<li><a class="reference" href="#release-and-debug-builds" id="id20" name="id20">release and debug builds</a></li>
|
||||
<li><a class="reference" href="#introduction" id="id19" name="id19">introduction</a></li>
|
||||
<li><a class="reference" href="#downloading-and-building" id="id20" name="id20">downloading and building</a><ul>
|
||||
<li><a class="reference" href="#cygwin-and-msvc" id="id21" name="id21">cygwin and msvc</a></li>
|
||||
<li><a class="reference" href="#release-and-debug-builds" id="id22" name="id22">release and debug builds</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#using" id="id21" name="id21">using</a></li>
|
||||
<li><a class="reference" href="#session" id="id22" name="id22">session</a><ul>
|
||||
<li><a class="reference" href="#id7" id="id23" name="id23">session()</a></li>
|
||||
<li><a class="reference" href="#id8" id="id24" name="id24">~session()</a></li>
|
||||
<li><a class="reference" href="#add-torrent" id="id25" name="id25">add_torrent()</a></li>
|
||||
<li><a class="reference" href="#remove-torrent" id="id26" name="id26">remove_torrent()</a></li>
|
||||
<li><a class="reference" href="#disable-extensions-enable-extension" id="id27" name="id27">disable_extensions() enable_extension()</a></li>
|
||||
<li><a class="reference" href="#set-upload-rate-limit-set-download-rate-limit" id="id28" name="id28">set_upload_rate_limit() set_download_rate_limit()</a></li>
|
||||
<li><a class="reference" href="#set-max-uploads-set-max-connections" id="id29" name="id29">set_max_uploads() set_max_connections()</a></li>
|
||||
<li><a class="reference" href="#status" id="id30" name="id30">status()</a></li>
|
||||
<li><a class="reference" href="#is-listening-listen-port-listen-on" id="id31" name="id31">is_listening() listen_port() listen_on()</a></li>
|
||||
<li><a class="reference" href="#pop-alert-set-severity-level" id="id32" name="id32">pop_alert() set_severity_level()</a></li>
|
||||
<li><a class="reference" href="#using" id="id23" name="id23">using</a></li>
|
||||
<li><a class="reference" href="#session" id="id24" name="id24">session</a><ul>
|
||||
<li><a class="reference" href="#id7" id="id25" name="id25">session()</a></li>
|
||||
<li><a class="reference" href="#id8" id="id26" name="id26">~session()</a></li>
|
||||
<li><a class="reference" href="#add-torrent" id="id27" name="id27">add_torrent()</a></li>
|
||||
<li><a class="reference" href="#remove-torrent" id="id28" name="id28">remove_torrent()</a></li>
|
||||
<li><a class="reference" href="#disable-extensions-enable-extension" id="id29" name="id29">disable_extensions() enable_extension()</a></li>
|
||||
<li><a class="reference" href="#set-upload-rate-limit-set-download-rate-limit" id="id30" name="id30">set_upload_rate_limit() set_download_rate_limit()</a></li>
|
||||
<li><a class="reference" href="#set-max-uploads-set-max-connections" id="id31" name="id31">set_max_uploads() set_max_connections()</a></li>
|
||||
<li><a class="reference" href="#set-ip-filter" id="id32" name="id32">set_ip_filter()</a></li>
|
||||
<li><a class="reference" href="#status" id="id33" name="id33">status()</a></li>
|
||||
<li><a class="reference" href="#is-listening-listen-port-listen-on" id="id34" name="id34">is_listening() listen_port() listen_on()</a></li>
|
||||
<li><a class="reference" href="#pop-alert-set-severity-level" id="id35" name="id35">pop_alert() set_severity_level()</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#entry" id="id33" name="id33">entry</a><ul>
|
||||
<li><a class="reference" href="#integer-string-list-dict-type" id="id34" name="id34">integer() string() list() dict() type()</a></li>
|
||||
<li><a class="reference" href="#entry" id="id36" name="id36">entry</a><ul>
|
||||
<li><a class="reference" href="#integer-string-list-dict-type" id="id37" name="id37">integer() string() list() dict() type()</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#torrent-info" id="id35" name="id35">torrent_info</a><ul>
|
||||
<li><a class="reference" href="#begin-files-end-files-rbegin-files-rend-files" id="id36" name="id36">begin_files() end_files() rbegin_files() rend_files()</a></li>
|
||||
<li><a class="reference" href="#num-files-file-at" id="id37" name="id37">num_files() file_at()</a></li>
|
||||
<li><a class="reference" href="#print" id="id38" name="id38">print()</a></li>
|
||||
<li><a class="reference" href="#trackers" id="id39" name="id39">trackers()</a></li>
|
||||
<li><a class="reference" href="#total-size-piece-length-piece-size-num-pieces" id="id40" name="id40">total_size() piece_length() piece_size() num_pieces()</a></li>
|
||||
<li><a class="reference" href="#hash-for-piece-info-hash" id="id41" name="id41">hash_for_piece() info_hash()</a></li>
|
||||
<li><a class="reference" href="#name-comment-creation-date" id="id42" name="id42">name() comment() creation_date()</a></li>
|
||||
<li><a class="reference" href="#torrent-info" id="id38" name="id38">torrent_info</a><ul>
|
||||
<li><a class="reference" href="#id9" id="id39" name="id39">torrent_info()</a></li>
|
||||
<li><a class="reference" href="#set-comment-set-piece-size-set-creator-set-hash-add-tracker-add-file" id="id40" name="id40">set_comment() set_piece_size() set_creator() set_hash() add_tracker() add_file()</a></li>
|
||||
<li><a class="reference" href="#create-torrent" id="id41" name="id41">create_torrent()</a></li>
|
||||
<li><a class="reference" href="#begin-files-end-files-rbegin-files-rend-files" id="id42" name="id42">begin_files() end_files() rbegin_files() rend_files()</a></li>
|
||||
<li><a class="reference" href="#num-files-file-at" id="id43" name="id43">num_files() file_at()</a></li>
|
||||
<li><a class="reference" href="#print" id="id44" name="id44">print()</a></li>
|
||||
<li><a class="reference" href="#trackers" id="id45" name="id45">trackers()</a></li>
|
||||
<li><a class="reference" href="#total-size-piece-length-piece-size-num-pieces" id="id46" name="id46">total_size() piece_length() piece_size() num_pieces()</a></li>
|
||||
<li><a class="reference" href="#hash-for-piece-info-hash" id="id47" name="id47">hash_for_piece() info_hash()</a></li>
|
||||
<li><a class="reference" href="#name-comment-creation-date" id="id48" name="id48">name() comment() creation_date()</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#torrent-handle" id="id43" name="id43">torrent_handle</a><ul>
|
||||
<li><a class="reference" href="#save-path" id="id44" name="id44">save_path()</a></li>
|
||||
<li><a class="reference" href="#move-storage" id="id45" name="id45">move_storage()</a></li>
|
||||
<li><a class="reference" href="#force-reannounce" id="id46" name="id46">force_reannounce()</a></li>
|
||||
<li><a class="reference" href="#connect-peer" id="id47" name="id47">connect_peer()</a></li>
|
||||
<li><a class="reference" href="#set-ratio" id="id48" name="id48">set_ratio()</a></li>
|
||||
<li><a class="reference" href="#set-upload-limit-set-download-limit" id="id49" name="id49">set_upload_limit() set_download_limit()</a></li>
|
||||
<li><a class="reference" href="#pause-resume-is-paused" id="id50" name="id50">pause() resume() is_paused()</a></li>
|
||||
<li><a class="reference" href="#is-seed" id="id51" name="id51">is_seed()</a></li>
|
||||
<li><a class="reference" href="#has-metadata" id="id52" name="id52">has_metadata()</a></li>
|
||||
<li><a class="reference" href="#set-tracker-login" id="id53" name="id53">set_tracker_login()</a></li>
|
||||
<li><a class="reference" href="#use-interface" id="id54" name="id54">use_interface()</a></li>
|
||||
<li><a class="reference" href="#info-hash" id="id55" name="id55">info_hash()</a></li>
|
||||
<li><a class="reference" href="#id10" id="id56" name="id56">set_max_uploads() set_max_connections()</a></li>
|
||||
<li><a class="reference" href="#write-resume-data" id="id57" name="id57">write_resume_data()</a></li>
|
||||
<li><a class="reference" href="#metadata" id="id58" name="id58">metadata()</a></li>
|
||||
<li><a class="reference" href="#id11" id="id59" name="id59">status()</a></li>
|
||||
<li><a class="reference" href="#get-download-queue" id="id60" name="id60">get_download_queue()</a></li>
|
||||
<li><a class="reference" href="#get-peer-info" id="id61" name="id61">get_peer_info()</a></li>
|
||||
<li><a class="reference" href="#get-torrent-info" id="id62" name="id62">get_torrent_info()</a></li>
|
||||
<li><a class="reference" href="#is-valid" id="id63" name="id63">is_valid()</a></li>
|
||||
<li><a class="reference" href="#torrent-handle" id="id49" name="id49">torrent_handle</a><ul>
|
||||
<li><a class="reference" href="#save-path" id="id50" name="id50">save_path()</a></li>
|
||||
<li><a class="reference" href="#move-storage" id="id51" name="id51">move_storage()</a></li>
|
||||
<li><a class="reference" href="#force-reannounce" id="id52" name="id52">force_reannounce()</a></li>
|
||||
<li><a class="reference" href="#connect-peer" id="id53" name="id53">connect_peer()</a></li>
|
||||
<li><a class="reference" href="#set-ratio" id="id54" name="id54">set_ratio()</a></li>
|
||||
<li><a class="reference" href="#set-upload-limit-set-download-limit" id="id55" name="id55">set_upload_limit() set_download_limit()</a></li>
|
||||
<li><a class="reference" href="#pause-resume-is-paused" id="id56" name="id56">pause() resume() is_paused()</a></li>
|
||||
<li><a class="reference" href="#is-seed" id="id57" name="id57">is_seed()</a></li>
|
||||
<li><a class="reference" href="#has-metadata" id="id58" name="id58">has_metadata()</a></li>
|
||||
<li><a class="reference" href="#set-tracker-login" id="id59" name="id59">set_tracker_login()</a></li>
|
||||
<li><a class="reference" href="#use-interface" id="id60" name="id60">use_interface()</a></li>
|
||||
<li><a class="reference" href="#info-hash" id="id61" name="id61">info_hash()</a></li>
|
||||
<li><a class="reference" href="#id11" id="id62" name="id62">set_max_uploads() set_max_connections()</a></li>
|
||||
<li><a class="reference" href="#write-resume-data" id="id63" name="id63">write_resume_data()</a></li>
|
||||
<li><a class="reference" href="#metadata" id="id64" name="id64">metadata()</a></li>
|
||||
<li><a class="reference" href="#id12" id="id65" name="id65">status()</a></li>
|
||||
<li><a class="reference" href="#get-download-queue" id="id66" name="id66">get_download_queue()</a></li>
|
||||
<li><a class="reference" href="#get-peer-info" id="id67" name="id67">get_peer_info()</a></li>
|
||||
<li><a class="reference" href="#get-torrent-info" id="id68" name="id68">get_torrent_info()</a></li>
|
||||
<li><a class="reference" href="#is-valid" id="id69" name="id69">is_valid()</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#torrent-status" id="id64" name="id64">torrent_status</a></li>
|
||||
<li><a class="reference" href="#peer-info" id="id65" name="id65">peer_info</a></li>
|
||||
<li><a class="reference" href="#address" id="id66" name="id66">address</a></li>
|
||||
<li><a class="reference" href="#http-settings" id="id67" name="id67">http_settings</a></li>
|
||||
<li><a class="reference" href="#big-number" id="id68" name="id68">big_number</a></li>
|
||||
<li><a class="reference" href="#hasher" id="id69" name="id69">hasher</a></li>
|
||||
<li><a class="reference" href="#fingerprint" id="id70" name="id70">fingerprint</a></li>
|
||||
<li><a class="reference" href="#free-functions" id="id71" name="id71">free functions</a><ul>
|
||||
<li><a class="reference" href="#identify-client" id="id72" name="id72">identify_client()</a></li>
|
||||
<li><a class="reference" href="#bdecode-bencode" id="id73" name="id73">bdecode() bencode()</a></li>
|
||||
<li><a class="reference" href="#torrent-status" id="id70" name="id70">torrent_status</a></li>
|
||||
<li><a class="reference" href="#peer-info" id="id71" name="id71">peer_info</a></li>
|
||||
<li><a class="reference" href="#address" id="id72" name="id72">address</a></li>
|
||||
<li><a class="reference" href="#http-settings" id="id73" name="id73">http_settings</a></li>
|
||||
<li><a class="reference" href="#ip-filter" id="id74" name="id74">ip_filter</a><ul>
|
||||
<li><a class="reference" href="#id14" id="id75" name="id75">ip_filter()</a></li>
|
||||
<li><a class="reference" href="#add-rule" id="id76" name="id76">add_rule()</a></li>
|
||||
<li><a class="reference" href="#access" id="id77" name="id77">access()</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#alerts" id="id74" name="id74">alerts</a><ul>
|
||||
<li><a class="reference" href="#listen-failed-alert" id="id75" name="id75">listen_failed_alert</a></li>
|
||||
<li><a class="reference" href="#file-error-alert" id="id76" name="id76">file_error_alert</a></li>
|
||||
<li><a class="reference" href="#tracker-announce-alert" id="id77" name="id77">tracker_announce_alert</a></li>
|
||||
<li><a class="reference" href="#tracker-alert" id="id78" name="id78">tracker_alert</a></li>
|
||||
<li><a class="reference" href="#tracker-reply-alert" id="id79" name="id79">tracker_reply_alert</a></li>
|
||||
<li><a class="reference" href="#hash-failed-alert" id="id80" name="id80">hash_failed_alert</a></li>
|
||||
<li><a class="reference" href="#peer-ban-alert" id="id81" name="id81">peer_ban_alert</a></li>
|
||||
<li><a class="reference" href="#peer-error-alert" id="id82" name="id82">peer_error_alert</a></li>
|
||||
<li><a class="reference" href="#invalid-request-alert" id="id83" name="id83">invalid_request_alert</a></li>
|
||||
<li><a class="reference" href="#torrent-finished-alert" id="id84" name="id84">torrent_finished_alert</a></li>
|
||||
<li><a class="reference" href="#metadata-received-alert" id="id85" name="id85">metadata_received_alert</a></li>
|
||||
<li><a class="reference" href="#fastresume-rejected-alert" id="id86" name="id86">fastresume_rejected_alert</a></li>
|
||||
<li><a class="reference" href="#dispatcher" id="id87" name="id87">dispatcher</a></li>
|
||||
<li><a class="reference" href="#big-number" id="id78" name="id78">big_number</a></li>
|
||||
<li><a class="reference" href="#hasher" id="id79" name="id79">hasher</a></li>
|
||||
<li><a class="reference" href="#fingerprint" id="id80" name="id80">fingerprint</a></li>
|
||||
<li><a class="reference" href="#free-functions" id="id81" name="id81">free functions</a><ul>
|
||||
<li><a class="reference" href="#identify-client" id="id82" name="id82">identify_client()</a></li>
|
||||
<li><a class="reference" href="#bdecode-bencode" id="id83" name="id83">bdecode() bencode()</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#exceptions" id="id88" name="id88">exceptions</a><ul>
|
||||
<li><a class="reference" href="#invalid-handle" id="id89" name="id89">invalid_handle</a></li>
|
||||
<li><a class="reference" href="#duplicate-torrent" id="id90" name="id90">duplicate_torrent</a></li>
|
||||
<li><a class="reference" href="#invalid-encoding" id="id91" name="id91">invalid_encoding</a></li>
|
||||
<li><a class="reference" href="#type-error" id="id92" name="id92">type_error</a></li>
|
||||
<li><a class="reference" href="#invalid-torrent-file" id="id93" name="id93">invalid_torrent_file</a></li>
|
||||
<li><a class="reference" href="#alerts" id="id84" name="id84">alerts</a><ul>
|
||||
<li><a class="reference" href="#listen-failed-alert" id="id85" name="id85">listen_failed_alert</a></li>
|
||||
<li><a class="reference" href="#file-error-alert" id="id86" name="id86">file_error_alert</a></li>
|
||||
<li><a class="reference" href="#tracker-announce-alert" id="id87" name="id87">tracker_announce_alert</a></li>
|
||||
<li><a class="reference" href="#tracker-alert" id="id88" name="id88">tracker_alert</a></li>
|
||||
<li><a class="reference" href="#tracker-reply-alert" id="id89" name="id89">tracker_reply_alert</a></li>
|
||||
<li><a class="reference" href="#hash-failed-alert" id="id90" name="id90">hash_failed_alert</a></li>
|
||||
<li><a class="reference" href="#peer-ban-alert" id="id91" name="id91">peer_ban_alert</a></li>
|
||||
<li><a class="reference" href="#peer-error-alert" id="id92" name="id92">peer_error_alert</a></li>
|
||||
<li><a class="reference" href="#invalid-request-alert" id="id93" name="id93">invalid_request_alert</a></li>
|
||||
<li><a class="reference" href="#torrent-finished-alert" id="id94" name="id94">torrent_finished_alert</a></li>
|
||||
<li><a class="reference" href="#metadata-received-alert" id="id95" name="id95">metadata_received_alert</a></li>
|
||||
<li><a class="reference" href="#fastresume-rejected-alert" id="id96" name="id96">fastresume_rejected_alert</a></li>
|
||||
<li><a class="reference" href="#dispatcher" id="id97" name="id97">dispatcher</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#examples" id="id94" name="id94">examples</a><ul>
|
||||
<li><a class="reference" href="#dump-torrent" id="id95" name="id95">dump_torrent</a></li>
|
||||
<li><a class="reference" href="#simple-client" id="id96" name="id96">simple client</a></li>
|
||||
<li><a class="reference" href="#exceptions" id="id98" name="id98">exceptions</a><ul>
|
||||
<li><a class="reference" href="#invalid-handle" id="id99" name="id99">invalid_handle</a></li>
|
||||
<li><a class="reference" href="#duplicate-torrent" id="id100" name="id100">duplicate_torrent</a></li>
|
||||
<li><a class="reference" href="#invalid-encoding" id="id101" name="id101">invalid_encoding</a></li>
|
||||
<li><a class="reference" href="#type-error" id="id102" name="id102">type_error</a></li>
|
||||
<li><a class="reference" href="#invalid-torrent-file" id="id103" name="id103">invalid_torrent_file</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#fast-resume" id="id97" name="id97">fast resume</a><ul>
|
||||
<li><a class="reference" href="#file-format" id="id98" name="id98">file format</a></li>
|
||||
<li><a class="reference" href="#examples" id="id104" name="id104">examples</a><ul>
|
||||
<li><a class="reference" href="#dump-torrent" id="id105" name="id105">dump_torrent</a></li>
|
||||
<li><a class="reference" href="#simple-client" id="id106" name="id106">simple client</a></li>
|
||||
<li><a class="reference" href="#make-torrent" id="id107" name="id107">make_torrent</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#extensions" id="id99" name="id99">extensions</a><ul>
|
||||
<li><a class="reference" href="#chat-messages" id="id100" name="id100">chat messages</a></li>
|
||||
<li><a class="reference" href="#metadata-from-peers" id="id101" name="id101">metadata from peers</a></li>
|
||||
<li><a class="reference" href="#fast-resume" id="id108" name="id108">fast resume</a><ul>
|
||||
<li><a class="reference" href="#file-format" id="id109" name="id109">file format</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#filename-checks" id="id102" name="id102">filename checks</a></li>
|
||||
<li><a class="reference" href="#acknowledgements" id="id103" name="id103">acknowledgements</a></li>
|
||||
<li><a class="reference" href="#extensions" id="id110" name="id110">extensions</a><ul>
|
||||
<li><a class="reference" href="#chat-messages" id="id111" name="id111">chat messages</a></li>
|
||||
<li><a class="reference" href="#metadata-from-peers" id="id112" name="id112">metadata from peers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#filename-checks" id="id113" name="id113">filename checks</a></li>
|
||||
<li><a class="reference" href="#acknowledgements" id="id114" name="id114">acknowledgements</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="introduction">
|
||||
|
@ -268,9 +279,15 @@ invariant checks and general debug code will be
|
|||
removed. This option takes precedence over
|
||||
other debug settings.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_LOGGING</span></tt></td>
|
||||
<td>This macro will enable logging of the session
|
||||
events, such as tracker announces and incoming
|
||||
connections (as well as blocked connections).</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_VERBOSE_LOGGING</span></tt></td>
|
||||
<td>If you define this macro, every peer connection
|
||||
will log its traffic to a log file.</td>
|
||||
will log its traffic to a log file as well as
|
||||
the session log.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_STORAGE_DEBUG</span></tt></td>
|
||||
<td>This will enable extra expensive invariant
|
||||
|
@ -281,6 +298,17 @@ piece sorting.</td>
|
|||
</table>
|
||||
<p>If you experience that libtorrent uses unreasonable amounts of cpu, it will definately help to
|
||||
define <tt class="docutils literal"><span class="pre">NDEBUG</span></tt>, since it will remove the invariant checks within the library.</p>
|
||||
<p>The <tt class="docutils literal"><span class="pre">Jamfile</span></tt> has the following build variants:</p>
|
||||
<blockquote>
|
||||
<ul class="simple">
|
||||
<li><tt class="docutils literal"><span class="pre">release</span></tt> - release version without any logging</li>
|
||||
<li><tt class="docutils literal"><span class="pre">release_log</span></tt> - release version with standard logging</li>
|
||||
<li><tt class="docutils literal"><span class="pre">release_vlog</span></tt> - release version with verbose logging (all peer connections are logged)</li>
|
||||
<li><tt class="docutils literal"><span class="pre">debug</span></tt> - debug version without any logging</li>
|
||||
<li><tt class="docutils literal"><span class="pre">debug_log</span></tt> - debug version with standard logging</li>
|
||||
<li><tt class="docutils literal"><span class="pre">debug_vlog</span></tt> - debug version with verbose logging</li>
|
||||
</ul>
|
||||
</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="using">
|
||||
|
@ -314,53 +342,55 @@ the <tt class="docutils literal"><span class="pre">session</span></tt>, it conta
|
|||
<h1><a name="session">session</a></h1>
|
||||
<p>The <tt class="docutils literal"><span class="pre">session</span></tt> class has the following synopsis:</p>
|
||||
<pre class="literal-block">
|
||||
class session: public boost::noncopyable
|
||||
{
|
||||
class session: public boost::noncopyable
|
||||
{
|
||||
|
||||
session(const fingerprint& print = libtorrent::fingerprint("LT", 0, 1, 0, 0));
|
||||
session(const fingerprint& print = libtorrent::fingerprint("LT", 0, 1, 0, 0));
|
||||
|
||||
session(
|
||||
const fingerprint& print
|
||||
, std::pair<int, int> listen_port_range
|
||||
, const char* listen_interface = 0);
|
||||
session(
|
||||
const fingerprint& print
|
||||
, std::pair<int, int> listen_port_range
|
||||
, const char* listen_interface = 0);
|
||||
|
||||
torrent_handle add_torrent(
|
||||
entry const& e
|
||||
, boost::filesystem::path const& save_path
|
||||
, entry const& resume_data = entry()
|
||||
, bool compact_mode = true);
|
||||
torrent_handle add_torrent(
|
||||
entry const& e
|
||||
, boost::filesystem::path const& save_path
|
||||
, entry const& resume_data = entry()
|
||||
, bool compact_mode = true);
|
||||
|
||||
torrent_handle add_torrent(
|
||||
char const* tracker_url
|
||||
, sha1_hash const& info_hash
|
||||
, boost::filesystem::path const& save_path
|
||||
, entry const& resume_data = entry()
|
||||
, bool compact_mode = true);
|
||||
torrent_handle add_torrent(
|
||||
char const* tracker_url
|
||||
, sha1_hash const& info_hash
|
||||
, boost::filesystem::path const& save_path
|
||||
, entry const& resume_data = entry()
|
||||
, bool compact_mode = true);
|
||||
|
||||
void remove_torrent(torrent_handle const& h);
|
||||
void remove_torrent(torrent_handle const& h);
|
||||
|
||||
void disable_extensions();
|
||||
void enable_extension(peer_connection::extension_index);
|
||||
void disable_extensions();
|
||||
void enable_extension(peer_connection::extension_index);
|
||||
|
||||
void set_http_settings(const http_settings& settings);
|
||||
void set_http_settings(const http_settings& settings);
|
||||
|
||||
void set_upload_rate_limit(int bytes_per_second);
|
||||
void set_download_rate_limit(int bytes_per_second);
|
||||
void set_max_uploads(int limit);
|
||||
void set_max_connections(int limit);
|
||||
void set_upload_rate_limit(int bytes_per_second);
|
||||
void set_download_rate_limit(int bytes_per_second);
|
||||
void set_max_uploads(int limit);
|
||||
void set_max_connections(int limit);
|
||||
|
||||
session_status status() const;
|
||||
void set_ip_filter(ip_filter const& f);
|
||||
|
||||
bool is_listening() const;
|
||||
unsigned short listen_port() const;
|
||||
bool listen_on(
|
||||
std::pair<int, int> const& port_range
|
||||
, char const* interface = 0);
|
||||
session_status status() const;
|
||||
|
||||
bool is_listening() const;
|
||||
unsigned short listen_port() const;
|
||||
bool listen_on(
|
||||
std::pair<int, int> const& port_range
|
||||
, char const* interface = 0);
|
||||
|
||||
|
||||
std::auto_ptr<alert> pop_alert();
|
||||
void set_severity_level(alert::severity_t s);
|
||||
};
|
||||
std::auto_ptr<alert> pop_alert();
|
||||
void set_severity_level(alert::severity_t s);
|
||||
};
|
||||
</pre>
|
||||
<p>Once it's created, the session object will spawn the main thread that will do all the work.
|
||||
The main thread will be idle as long it doesn't have any torrents to participate in.</p>
|
||||
|
@ -368,11 +398,10 @@ The main thread will be idle as long it doesn't have any torrents to participate
|
|||
<h2><a name="id7">session()</a></h2>
|
||||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
session(const fingerprint& print = libtorrent::fingerprint("LT", 0, 1, 0, 0));
|
||||
session(
|
||||
const fingerprint& print
|
||||
session(fingerprint const& print = libtorrent::fingerprint("LT", 0, 1, 0, 0));
|
||||
session(fingerprint const& print
|
||||
, std::pair<int, int> listen_port_range
|
||||
, const char* listen_interface = 0);
|
||||
, char const* listen_interface = 0);
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>If the fingerprint in the first overload is ommited, the client will get a default
|
||||
|
@ -495,6 +524,18 @@ minimum of at least two connections per torrent, so if you set a too low
|
|||
connections limit, and open too many torrents, the limit will not be met. The
|
||||
number of uploads is at least one per torrent.</p>
|
||||
</div>
|
||||
<div class="section" id="set-ip-filter">
|
||||
<h2><a name="set-ip-filter">set_ip_filter()</a></h2>
|
||||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
void set_ip_filter(ip_filter const& filter);
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>Sets a filter that will be used to reject and accept incoming as well as outgoing
|
||||
connections based on their originating ip address. The default filter will allow
|
||||
connections to any ip address. To build a set of rules for which addresses are
|
||||
accepted and not, see <a class="reference" href="#ip-filter">ip_filter</a>.</p>
|
||||
</div>
|
||||
<div class="section" id="status">
|
||||
<h2><a name="status">status()</a></h2>
|
||||
<blockquote>
|
||||
|
@ -603,21 +644,21 @@ public:
|
|||
|
||||
data_type type() const;
|
||||
|
||||
entry(const dictionary_type&);
|
||||
entry(const string_type&);
|
||||
entry(const list_type&);
|
||||
entry(const integer_type&);
|
||||
entry(dictionary_type const&);
|
||||
entry(string_type const&);
|
||||
entry(list_type const&);
|
||||
entry(integer_type const&);
|
||||
|
||||
entry();
|
||||
entry(data_type t);
|
||||
entry(const entry& e);
|
||||
entry(entry const& e);
|
||||
~entry();
|
||||
|
||||
void operator=(const entry& e);
|
||||
void operator=(const dictionary_type&);
|
||||
void operator=(const string_type&);
|
||||
void operator=(const list_type&);
|
||||
void operator=(const integer_type&);
|
||||
void operator=(entry const& e);
|
||||
void operator=(dictionary_type const&);
|
||||
void operator=(string_type const&);
|
||||
void operator=(list_type const&);
|
||||
void operator=(integer_type const&);
|
||||
|
||||
integer_type& integer();
|
||||
integer_type const& integer() const;
|
||||
|
@ -632,8 +673,8 @@ public:
|
|||
// is a dictionary, otherwise they will throw
|
||||
entry& operator[](char const* key);
|
||||
entry& operator[](std::string const& key);
|
||||
const entry& operator[](char const* key) const;
|
||||
const entry& operator[](std::string const& key) const;
|
||||
entry const& operator[](char const* key) const;
|
||||
entry const& operator[](std::string const& key) const;
|
||||
entry* find_key(char const* key);
|
||||
entry const* find_key(char const* key) const;
|
||||
|
||||
|
@ -669,7 +710,7 @@ can assign the value you want it to have.</p>
|
|||
entry torrent_file;
|
||||
// ...
|
||||
|
||||
const entry::dictionary_type& dict = torrent_file.dict();
|
||||
entry::dictionary_type const& dict = torrent_file.dict();
|
||||
entry::dictionary_type::const_iterator i;
|
||||
i = dict.find("announce");
|
||||
if (i != dict.end())
|
||||
|
@ -698,7 +739,7 @@ public:
|
|||
void set_comment(char const* str);
|
||||
void set_piece_size(int size);
|
||||
void set_creator(char const* str);
|
||||
void set_hash(int index, const sha1_hash& h);
|
||||
void set_hash(int index, sha1_hash const& h);
|
||||
void add_tracker(std::string const& url, int tier = 0);
|
||||
void add_file(boost::filesystem::path file, size_type size);
|
||||
|
||||
|
@ -718,9 +759,9 @@ public:
|
|||
size_type total_size() const;
|
||||
size_type piece_length() const;
|
||||
int num_pieces() const;
|
||||
const sha1_hash& info_hash() const;
|
||||
const std::stirng& name() const;
|
||||
const std::string& comment() const;
|
||||
sha1_hash const& info_hash() const;
|
||||
std::stirng const& name() const;
|
||||
std::string const& comment() const;
|
||||
|
||||
boost::optional<boost::posix_time::ptime>
|
||||
creation_date() const;
|
||||
|
@ -729,9 +770,79 @@ public:
|
|||
void print(std::ostream& os) const;
|
||||
|
||||
size_type piece_size(unsigned int index) const;
|
||||
const sha1_hash& hash_for_piece(unsigned int index) const;
|
||||
sha1_hash const& hash_for_piece(unsigned int index) const;
|
||||
};
|
||||
</pre>
|
||||
<div class="section" id="id9">
|
||||
<h2><a name="id9">torrent_info()</a></h2>
|
||||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
torrent_info();
|
||||
torrent_info(sha1_hash const& info_hash);
|
||||
torrent_info(entry const& torrent_file);
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>The default constructor of <tt class="docutils literal"><span class="pre">torrent_info</span></tt> is used when creating torrent files. It will
|
||||
initialize the object to an empty torrent, containing no files. The info hash will be set
|
||||
to 0 when this constructor is used. To use the empty <tt class="docutils literal"><span class="pre">torrent_info</span></tt> object, add files
|
||||
and piece hashes, announce URLs and optionally a creator tag and comment. To do this you
|
||||
use the members <tt class="docutils literal"><span class="pre">set_comment()</span></tt>, <tt class="docutils literal"><span class="pre">set_piece_size()</span></tt>, <tt class="docutils literal"><span class="pre">set_creator()</span></tt>, <tt class="docutils literal"><span class="pre">set_hash()</span></tt>
|
||||
etc.</p>
|
||||
<p>The contructor that takes an info-hash is identical to the default constructor with the
|
||||
exception that it will initialize the info-hash to the given value. This is used internally
|
||||
when downloading torrents without the metadata. The metadata will be created by libtorrent
|
||||
as soon as it has been downloaded from the swarm.</p>
|
||||
<p>The last constructor is the one that is used in most cases. It will create a <tt class="docutils literal"><span class="pre">torrent_info</span></tt>
|
||||
object from the information found in the given torrent_file. The <tt class="docutils literal"><span class="pre">entry</span></tt> represents a tree
|
||||
node in an bencoded file. To load an ordinary .torrent file into an <tt class="docutils literal"><span class="pre">entry</span></tt>, use bdecode(),
|
||||
see <a class="reference" href="#bdecode-bencode">bdecode() bencode()</a>.</p>
|
||||
</div>
|
||||
<div class="section" id="set-comment-set-piece-size-set-creator-set-hash-add-tracker-add-file">
|
||||
<h2><a name="set-comment-set-piece-size-set-creator-set-hash-add-tracker-add-file">set_comment() set_piece_size() set_creator() set_hash() add_tracker() add_file()</a></h2>
|
||||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
void set_comment(char const* str);
|
||||
void set_piece_size(int size);
|
||||
void set_creator(char const* str);
|
||||
void set_hash(int index, sha1_hash const& h);
|
||||
void add_tracker(std::string const& url, int tier = 0);
|
||||
void add_file(boost::filesystem::path file, size_type size);
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>These files are used when creating a torrent file. <tt class="docutils literal"><span class="pre">set_comment()</span></tt> will simply set
|
||||
the comment that belongs to this torrent. The comment can be retrieved with the
|
||||
<tt class="docutils literal"><span class="pre">comment()</span></tt> member.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">set_piece_size()</span></tt> will set the size of each piece in this torrent. The piece size must
|
||||
be an even multiple of 2. i.e. usually something like 256 kB, 512 kB, 1024 kB etc. The
|
||||
size is given in number of bytes.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">set_creator()</span></tt> is an optional attribute that can be used to identify your application
|
||||
that was used to create the torrent file.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">set_hash()</span></tt> writes the hash for the piece with the given piece-index. You have to call
|
||||
this function for every piece in the torrent. Usually the <a class="reference" href="#hasher">hasher</a> is used to calculate
|
||||
the sha1-hash for a piece.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">add_tracker()</span></tt> adds a tracker to the announce-list. The <tt class="docutils literal"><span class="pre">tier</span></tt> determines the order in
|
||||
which the trackers are to be tried. For more iformation see <a class="reference" href="#trackers">trackers()</a>.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">add_file()</span></tt> adds a file to the torrent. The order in which you add files will determine
|
||||
the order in which they are placed in the torrent file. You have to add at least one file
|
||||
to the torrent. The <tt class="docutils literal"><span class="pre">path</span></tt> you give has to be a relative path from the root directory
|
||||
of the torrent. The <tt class="docutils literal"><span class="pre">size</span></tt> is given in bytes.</p>
|
||||
<p>When you have added all the files and hashes to your torrent, you can generate an <tt class="docutils literal"><span class="pre">entry</span></tt>
|
||||
which then can be encoded as a .torrent file. You do this by calling <a class="reference" href="#create-torrent">create_torrent()</a>.</p>
|
||||
<p>For a complete example of how to create a torrent from a file structure, see <a class="reference" href="#make-torrent">make_torrent</a>.</p>
|
||||
</div>
|
||||
<div class="section" id="create-torrent">
|
||||
<h2><a name="create-torrent">create_torrent()</a></h2>
|
||||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
entry create_torrent();
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>Returns an <tt class="docutils literal"><span class="pre">entry</span></tt> representing the bencoded tree of data that makes up a .torrent file.
|
||||
You can save this data as a torrent file with bencode() (see <a class="reference" href="#bdecode-bencode">bdecode() bencode()</a>), for a
|
||||
complete example, see <a class="reference" href="#make-torrent">make_torrent</a>.</p>
|
||||
<p>This function is not const because it will also set the info-hash of the <tt class="docutils literal"><span class="pre">torrent_info</span></tt>
|
||||
object.</p>
|
||||
</div>
|
||||
<div class="section" id="begin-files-end-files-rbegin-files-rend-files">
|
||||
<h2><a name="begin-files-end-files-rbegin-files-rend-files">begin_files() end_files() rbegin_files() rend_files()</a></h2>
|
||||
<blockquote>
|
||||
|
@ -761,7 +872,7 @@ struct file_entry
|
|||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
int num_files() const;
|
||||
const file_entry& file_at(int index) const;
|
||||
file_entry const& file_at(int index) const;
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>If you need index-access to files you can use the <tt class="docutils literal"><span class="pre">num_files()</span></tt> and <tt class="docutils literal"><span class="pre">file_at()</span></tt>
|
||||
|
@ -781,7 +892,7 @@ the torrent file to the given outstream.</p>
|
|||
<h2><a name="trackers">trackers()</a></h2>
|
||||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
const std::vector<announce_entry>& trackers() const;
|
||||
std::vector<announce_entry> const& trackers() const;
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>The <tt class="docutils literal"><span class="pre">trackers()</span></tt> function will return a sorted vector of <tt class="docutils literal"><span class="pre">announce_entry</span></tt>.
|
||||
|
@ -820,7 +931,7 @@ be smaller.</p>
|
|||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
size_type piece_size(unsigned int index) const;
|
||||
const sha1_hash& hash_for_piece(unsigned int index) const;
|
||||
sha1_hash const& hash_for_piece(unsigned int index) const;
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p><tt class="docutils literal"><span class="pre">hash_for_piece()</span></tt> takes a piece-index and returns the 20-bytes sha1-hash for that
|
||||
|
@ -831,8 +942,8 @@ torrent file. For more information on the <tt class="docutils literal"><span cla
|
|||
<h2><a name="name-comment-creation-date">name() comment() creation_date()</a></h2>
|
||||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
const std::stirng& name() const;
|
||||
const std::string& comment() const;
|
||||
std::string const& name() const;
|
||||
std::string const& comment() const;
|
||||
boost::optional<boost::posix_time::ptime> creation_date() const;
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
@ -886,6 +997,8 @@ struct torrent_handle
|
|||
bool is_piece_filtered(int index) const;
|
||||
std::vector<bool> filtered_pieces() const;
|
||||
|
||||
void filter_files(std::vector<bool> const& files);
|
||||
|
||||
bool has_metadata() const;
|
||||
|
||||
boost::filsystem::path save_path() const;
|
||||
|
@ -893,17 +1006,16 @@ struct torrent_handle
|
|||
|
||||
sha1_hash info_hash() const;
|
||||
|
||||
bool operator==(const torrent_handle&) const;
|
||||
bool operator!=(const torrent_handle&) const;
|
||||
bool operator<(const torrent_handle&) const;
|
||||
bool operator==(torrent_handle const&) const;
|
||||
bool operator!=(torrent_handle const&) const;
|
||||
bool operator<(torrent_handle const&) const;
|
||||
};
|
||||
</pre>
|
||||
<p>The default constructor will initialize the handle to an invalid state. Which means you cannot
|
||||
perform any operation on it, unless you first assign it a valid handle. If you try to perform
|
||||
any operation on an uninitialized handle, it will throw <tt class="docutils literal"><span class="pre">invalid_handle</span></tt>.</p>
|
||||
<p><strong>TODO: document trackers() and replace_trackers()</strong></p>
|
||||
<p><strong>TODO: document how to create a .torrent</strong></p>
|
||||
<p><strong>TODO: document filter_piece(), filter_pieces(), is_piece_filtered() and filtered_pieces()</strong></p>
|
||||
<p><strong>TODO: document filter_piece(), filter_pieces(), is_piece_filtered(), filtered_pieces() and filter_files()</strong></p>
|
||||
<div class="section" id="save-path">
|
||||
<h2><a name="save-path">save_path()</a></h2>
|
||||
<blockquote>
|
||||
|
@ -1047,8 +1159,8 @@ sha1_hash info_hash() const;
|
|||
</blockquote>
|
||||
<p><tt class="docutils literal"><span class="pre">info_hash()</span></tt> returns the info-hash for the torrent.</p>
|
||||
</div>
|
||||
<div class="section" id="id10">
|
||||
<h2><a name="id10">set_max_uploads() set_max_connections()</a></h2>
|
||||
<div class="section" id="id11">
|
||||
<h2><a name="id11">set_max_uploads() set_max_connections()</a></h2>
|
||||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
void set_max_uploads(int max_uploads);
|
||||
|
@ -1096,8 +1208,8 @@ std::vector<char> const& metadata() const;
|
|||
.torrent file. This buffer will be valid as long as the torrent is still running. When hashed,
|
||||
it will produce the same hash as the info-hash.</p>
|
||||
</div>
|
||||
<div class="section" id="id11">
|
||||
<h2><a name="id11">status()</a></h2>
|
||||
<div class="section" id="id12">
|
||||
<h2><a name="id12">status()</a></h2>
|
||||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
torrent_status status();
|
||||
|
@ -1518,6 +1630,64 @@ expand to 2 megs, it will be interrupted before the entire response has been
|
|||
uncompressed (given your limit is lower than 2 megs). Default limit is
|
||||
1 megabyte.</p>
|
||||
</div>
|
||||
<div class="section" id="ip-filter">
|
||||
<h1><a name="ip-filter">ip_filter</a></h1>
|
||||
<p>The <tt class="docutils literal"><span class="pre">ip_filter</span></tt> class is a set of rules that uniquely categorizes all
|
||||
ip addresses as allowed or disallowed. The default constructor creates
|
||||
a single rule that allowes all addresses (0.0.0.0 - 255.255.255.255).</p>
|
||||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
class ip_filter
|
||||
{
|
||||
public:
|
||||
enum access_flags { blocked = 1 };
|
||||
|
||||
ip_filter();
|
||||
void add_rule(address first, address last, int flags);
|
||||
int access(address const& addr) const;
|
||||
};
|
||||
</pre>
|
||||
</blockquote>
|
||||
<div class="section" id="id14">
|
||||
<h2><a name="id14">ip_filter()</a></h2>
|
||||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
ip_filter()
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>Creates a default filter that doesn't filter any address.</p>
|
||||
<p>postcondition:
|
||||
<tt class="docutils literal"><span class="pre">access(x)</span> <span class="pre">==</span> <span class="pre">0</span></tt> for every <tt class="docutils literal"><span class="pre">x</span></tt></p>
|
||||
</div>
|
||||
<div class="section" id="add-rule">
|
||||
<h2><a name="add-rule">add_rule()</a></h2>
|
||||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
void add_rule(address first, address last, int flags);
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>Adds a rule to the filter. <tt class="docutils literal"><span class="pre">first</span></tt> and <tt class="docutils literal"><span class="pre">last</span></tt> defines a range of
|
||||
ip addresses that will be marked with the given flags. The <tt class="docutils literal"><span class="pre">flags</span></tt>
|
||||
can currenly be 0, which means allowed, or <tt class="docutils literal"><span class="pre">ip_filter::blocked</span></tt>, which
|
||||
means disallowed.</p>
|
||||
<p>postcondition:
|
||||
<tt class="docutils literal"><span class="pre">access(x)</span> <span class="pre">==</span> <span class="pre">flags</span></tt> for every <tt class="docutils literal"><span class="pre">x</span></tt> in the range [<tt class="docutils literal"><span class="pre">first</span></tt>, <tt class="docutils literal"><span class="pre">last</span></tt>]</p>
|
||||
<p>This means that in a case of overlapping ranges, the last one applied takes
|
||||
precedence.</p>
|
||||
</div>
|
||||
<div class="section" id="access">
|
||||
<h2><a name="access">access()</a></h2>
|
||||
<blockquote>
|
||||
<pre class="literal-block">
|
||||
int access(address const& addr) const;
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>Returns the access permissions for the given address (<tt class="docutils literal"><span class="pre">addr</span></tt>). The permission
|
||||
can currently be 0 or <tt class="docutils literal"><span class="pre">ip_filter::blocked</span></tt>. The complexity of this operation
|
||||
is O(<tt class="docutils literal"><span class="pre">log</span></tt> n), where n is the minimum number of non-overlapping ranges to describe
|
||||
the current filter.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="big-number">
|
||||
<h1><a name="big-number">big_number</a></h1>
|
||||
<p>Both the <tt class="docutils literal"><span class="pre">peer_id</span></tt> and <tt class="docutils literal"><span class="pre">sha1_hash</span></tt> types are typedefs of the class
|
||||
|
@ -2199,6 +2369,104 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section" id="make-torrent">
|
||||
<h2><a name="make-torrent">make_torrent</a></h2>
|
||||
<p>Shows how to create a torrent from a directory tree:</p>
|
||||
<pre class="literal-block">
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <iomanip>
|
||||
|
||||
#include "libtorrent/entry.hpp"
|
||||
#include "libtorrent/bencode.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/storage.hpp"
|
||||
#include "libtorrent/hasher.hpp"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
using namespace boost::filesystem;
|
||||
using namespace libtorrent;
|
||||
|
||||
void add_files(
|
||||
torrent_info& t
|
||||
, path const& p
|
||||
, path const& l)
|
||||
{
|
||||
path f(p / l);
|
||||
if (is_directory(f))
|
||||
{
|
||||
for (directory_iterator i(f), end; i != end; ++i)
|
||||
add_files(t, p, l / i->leaf());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "adding \"" << l.string() << "\"\n";
|
||||
file fi(f, file::in);
|
||||
fi.seek(0, file::end);
|
||||
libtorrent::size_type size = fi.tell();
|
||||
t.add_file(l, size);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
if (argc != 4)
|
||||
{
|
||||
std::cerr << "usage: make_torrent <output torrent-file> <announce url> <file or directory to create torrent from>\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::filesystem::path::default_name_check(native);
|
||||
|
||||
try
|
||||
{
|
||||
torrent_info t;
|
||||
path full_path = initial_path() / path(argv[3]);
|
||||
ofstream out(initial_path() / path(argv[1]), std::ios_base::binary);
|
||||
|
||||
int piece_size = 256 * 1024;
|
||||
char const* creator_str = "libtorrent";
|
||||
|
||||
add_files(t, full_path.branch_path(), full_path.leaf());
|
||||
t.set_piece_size(piece_size);
|
||||
|
||||
storage st(t, full_path.branch_path());
|
||||
t.add_tracker(argv[2]);
|
||||
|
||||
// calculate the hash for all pieces
|
||||
int num = t.num_pieces();
|
||||
std::vector<char> buf(piece_size);
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
st.read(&buf[0], i, 0, t.piece_size(i));
|
||||
hasher h(&buf[0], t.piece_size(i));
|
||||
t.set_hash(i, h.final());
|
||||
std::cerr << (i+1) << "/" << num << "\r";
|
||||
}
|
||||
|
||||
t.set_creator(creator_str);
|
||||
|
||||
// create the torrent and print it to out
|
||||
entry e = t.create_torrent();
|
||||
libtorrent::bencode(std::ostream_iterator<char>(out), e);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << "\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="fast-resume">
|
||||
<h1><a name="fast-resume">fast resume</a></h1>
|
||||
|
|
342
docs/manual.rst
342
docs/manual.rst
|
@ -159,8 +159,13 @@ debug and release variants respectively, but adds extra logging (``TORRENT_VERBO
|
|||
| | removed. This option takes precedence over |
|
||||
| | other debug settings. |
|
||||
+--------------------------------+-------------------------------------------------+
|
||||
| ``TORRENT_LOGGING`` | This macro will enable logging of the session |
|
||||
| | events, such as tracker announces and incoming |
|
||||
| | connections (as well as blocked connections). |
|
||||
+--------------------------------+-------------------------------------------------+
|
||||
| ``TORRENT_VERBOSE_LOGGING`` | If you define this macro, every peer connection |
|
||||
| | will log its traffic to a log file. |
|
||||
| | will log its traffic to a log file as well as |
|
||||
| | the session log. |
|
||||
+--------------------------------+-------------------------------------------------+
|
||||
| ``TORRENT_STORAGE_DEBUG`` | This will enable extra expensive invariant |
|
||||
| | checks in the storage, including logging of |
|
||||
|
@ -171,6 +176,14 @@ debug and release variants respectively, but adds extra logging (``TORRENT_VERBO
|
|||
If you experience that libtorrent uses unreasonable amounts of cpu, it will definately help to
|
||||
define ``NDEBUG``, since it will remove the invariant checks within the library.
|
||||
|
||||
The ``Jamfile`` has the following build variants:
|
||||
|
||||
* ``release`` - release version without any logging
|
||||
* ``release_log`` - release version with standard logging
|
||||
* ``release_vlog`` - release version with verbose logging (all peer connections are logged)
|
||||
* ``debug`` - debug version without any logging
|
||||
* ``debug_log`` - debug version with standard logging
|
||||
* ``debug_vlog`` - debug version with verbose logging
|
||||
|
||||
using
|
||||
=====
|
||||
|
@ -212,14 +225,14 @@ The ``session`` class has the following synopsis::
|
|||
entry const& e
|
||||
, boost::filesystem::path const& save_path
|
||||
, entry const& resume_data = entry()
|
||||
, bool compact_mode = true);
|
||||
, bool compact_mode = true);
|
||||
|
||||
torrent_handle add_torrent(
|
||||
char const* tracker_url
|
||||
, sha1_hash const& info_hash
|
||||
, boost::filesystem::path const& save_path
|
||||
, entry const& resume_data = entry()
|
||||
, bool compact_mode = true);
|
||||
, bool compact_mode = true);
|
||||
|
||||
void remove_torrent(torrent_handle const& h);
|
||||
|
||||
|
@ -233,6 +246,8 @@ The ``session`` class has the following synopsis::
|
|||
void set_max_uploads(int limit);
|
||||
void set_max_connections(int limit);
|
||||
|
||||
void set_ip_filter(ip_filter const& f);
|
||||
|
||||
session_status status() const;
|
||||
|
||||
bool is_listening() const;
|
||||
|
@ -254,11 +269,10 @@ session()
|
|||
|
||||
::
|
||||
|
||||
session(const fingerprint& print = libtorrent::fingerprint("LT", 0, 1, 0, 0));
|
||||
session(
|
||||
const fingerprint& print
|
||||
session(fingerprint const& print = libtorrent::fingerprint("LT", 0, 1, 0, 0));
|
||||
session(fingerprint const& print
|
||||
, std::pair<int, int> listen_port_range
|
||||
, const char* listen_interface = 0);
|
||||
, char const* listen_interface = 0);
|
||||
|
||||
If the fingerprint in the first overload is ommited, the client will get a default
|
||||
fingerprint stating the version of libtorrent. The fingerprint is a short string that will be
|
||||
|
@ -391,6 +405,19 @@ connections limit, and open too many torrents, the limit will not be met. The
|
|||
number of uploads is at least one per torrent.
|
||||
|
||||
|
||||
set_ip_filter()
|
||||
---------------
|
||||
|
||||
::
|
||||
|
||||
void set_ip_filter(ip_filter const& filter);
|
||||
|
||||
Sets a filter that will be used to reject and accept incoming as well as outgoing
|
||||
connections based on their originating ip address. The default filter will allow
|
||||
connections to any ip address. To build a set of rules for which addresses are
|
||||
accepted and not, see ip_filter_.
|
||||
|
||||
|
||||
status()
|
||||
--------
|
||||
|
||||
|
@ -509,21 +536,21 @@ or a string. This is its synopsis::
|
|||
|
||||
data_type type() const;
|
||||
|
||||
entry(const dictionary_type&);
|
||||
entry(const string_type&);
|
||||
entry(const list_type&);
|
||||
entry(const integer_type&);
|
||||
entry(dictionary_type const&);
|
||||
entry(string_type const&);
|
||||
entry(list_type const&);
|
||||
entry(integer_type const&);
|
||||
|
||||
entry();
|
||||
entry(data_type t);
|
||||
entry(const entry& e);
|
||||
entry(entry const& e);
|
||||
~entry();
|
||||
|
||||
void operator=(const entry& e);
|
||||
void operator=(const dictionary_type&);
|
||||
void operator=(const string_type&);
|
||||
void operator=(const list_type&);
|
||||
void operator=(const integer_type&);
|
||||
void operator=(entry const& e);
|
||||
void operator=(dictionary_type const&);
|
||||
void operator=(string_type const&);
|
||||
void operator=(list_type const&);
|
||||
void operator=(integer_type const&);
|
||||
|
||||
integer_type& integer();
|
||||
integer_type const& integer() const;
|
||||
|
@ -538,8 +565,8 @@ or a string. This is its synopsis::
|
|||
// is a dictionary, otherwise they will throw
|
||||
entry& operator[](char const* key);
|
||||
entry& operator[](std::string const& key);
|
||||
const entry& operator[](char const* key) const;
|
||||
const entry& operator[](std::string const& key) const;
|
||||
entry const& operator[](char const* key) const;
|
||||
entry const& operator[](std::string const& key) const;
|
||||
entry* find_key(char const* key);
|
||||
entry const* find_key(char const* key) const;
|
||||
|
||||
|
@ -579,7 +606,7 @@ The typical code to get info from a torrent file will then look like this::
|
|||
entry torrent_file;
|
||||
// ...
|
||||
|
||||
const entry::dictionary_type& dict = torrent_file.dict();
|
||||
entry::dictionary_type const& dict = torrent_file.dict();
|
||||
entry::dictionary_type::const_iterator i;
|
||||
i = dict.find("announce");
|
||||
if (i != dict.end())
|
||||
|
@ -610,7 +637,7 @@ The ``torrent_info`` has the following synopsis::
|
|||
void set_comment(char const* str);
|
||||
void set_piece_size(int size);
|
||||
void set_creator(char const* str);
|
||||
void set_hash(int index, const sha1_hash& h);
|
||||
void set_hash(int index, sha1_hash const& h);
|
||||
void add_tracker(std::string const& url, int tier = 0);
|
||||
void add_file(boost::filesystem::path file, size_type size);
|
||||
|
||||
|
@ -630,9 +657,9 @@ The ``torrent_info`` has the following synopsis::
|
|||
size_type total_size() const;
|
||||
size_type piece_length() const;
|
||||
int num_pieces() const;
|
||||
const sha1_hash& info_hash() const;
|
||||
const std::stirng& name() const;
|
||||
const std::string& comment() const;
|
||||
sha1_hash const& info_hash() const;
|
||||
std::stirng const& name() const;
|
||||
std::string const& comment() const;
|
||||
|
||||
boost::optional<boost::posix_time::ptime>
|
||||
creation_date() const;
|
||||
|
@ -641,9 +668,90 @@ The ``torrent_info`` has the following synopsis::
|
|||
void print(std::ostream& os) const;
|
||||
|
||||
size_type piece_size(unsigned int index) const;
|
||||
const sha1_hash& hash_for_piece(unsigned int index) const;
|
||||
sha1_hash const& hash_for_piece(unsigned int index) const;
|
||||
};
|
||||
|
||||
torrent_info()
|
||||
--------------
|
||||
|
||||
::
|
||||
|
||||
torrent_info();
|
||||
torrent_info(sha1_hash const& info_hash);
|
||||
torrent_info(entry const& torrent_file);
|
||||
|
||||
The default constructor of ``torrent_info`` is used when creating torrent files. It will
|
||||
initialize the object to an empty torrent, containing no files. The info hash will be set
|
||||
to 0 when this constructor is used. To use the empty ``torrent_info`` object, add files
|
||||
and piece hashes, announce URLs and optionally a creator tag and comment. To do this you
|
||||
use the members ``set_comment()``, ``set_piece_size()``, ``set_creator()``, ``set_hash()``
|
||||
etc.
|
||||
|
||||
The contructor that takes an info-hash is identical to the default constructor with the
|
||||
exception that it will initialize the info-hash to the given value. This is used internally
|
||||
when downloading torrents without the metadata. The metadata will be created by libtorrent
|
||||
as soon as it has been downloaded from the swarm.
|
||||
|
||||
The last constructor is the one that is used in most cases. It will create a ``torrent_info``
|
||||
object from the information found in the given torrent_file. The ``entry`` represents a tree
|
||||
node in an bencoded file. To load an ordinary .torrent file into an ``entry``, use bdecode(),
|
||||
see `bdecode() bencode()`_.
|
||||
|
||||
set_comment() set_piece_size() set_creator() set_hash() add_tracker() add_file()
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
::
|
||||
|
||||
void set_comment(char const* str);
|
||||
void set_piece_size(int size);
|
||||
void set_creator(char const* str);
|
||||
void set_hash(int index, sha1_hash const& h);
|
||||
void add_tracker(std::string const& url, int tier = 0);
|
||||
void add_file(boost::filesystem::path file, size_type size);
|
||||
|
||||
These files are used when creating a torrent file. ``set_comment()`` will simply set
|
||||
the comment that belongs to this torrent. The comment can be retrieved with the
|
||||
``comment()`` member.
|
||||
|
||||
``set_piece_size()`` will set the size of each piece in this torrent. The piece size must
|
||||
be an even multiple of 2. i.e. usually something like 256 kB, 512 kB, 1024 kB etc. The
|
||||
size is given in number of bytes.
|
||||
|
||||
``set_creator()`` is an optional attribute that can be used to identify your application
|
||||
that was used to create the torrent file.
|
||||
|
||||
``set_hash()`` writes the hash for the piece with the given piece-index. You have to call
|
||||
this function for every piece in the torrent. Usually the hasher_ is used to calculate
|
||||
the sha1-hash for a piece.
|
||||
|
||||
``add_tracker()`` adds a tracker to the announce-list. The ``tier`` determines the order in
|
||||
which the trackers are to be tried. For more iformation see `trackers()`_.
|
||||
|
||||
``add_file()`` adds a file to the torrent. The order in which you add files will determine
|
||||
the order in which they are placed in the torrent file. You have to add at least one file
|
||||
to the torrent. The ``path`` you give has to be a relative path from the root directory
|
||||
of the torrent. The ``size`` is given in bytes.
|
||||
|
||||
When you have added all the files and hashes to your torrent, you can generate an ``entry``
|
||||
which then can be encoded as a .torrent file. You do this by calling `create_torrent()`_.
|
||||
|
||||
For a complete example of how to create a torrent from a file structure, see make_torrent_.
|
||||
|
||||
|
||||
create_torrent()
|
||||
----------------
|
||||
|
||||
::
|
||||
|
||||
entry create_torrent();
|
||||
|
||||
Returns an ``entry`` representing the bencoded tree of data that makes up a .torrent file.
|
||||
You can save this data as a torrent file with bencode() (see `bdecode() bencode()`_), for a
|
||||
complete example, see make_torrent_.
|
||||
|
||||
This function is not const because it will also set the info-hash of the ``torrent_info``
|
||||
object.
|
||||
|
||||
|
||||
begin_files() end_files() rbegin_files() rend_files()
|
||||
-----------------------------------------------------
|
||||
|
@ -678,7 +786,7 @@ num_files() file_at()
|
|||
::
|
||||
|
||||
int num_files() const;
|
||||
const file_entry& file_at(int index) const;
|
||||
file_entry const& file_at(int index) const;
|
||||
|
||||
If you need index-access to files you can use the ``num_files()`` and ``file_at()``
|
||||
to access files using indices.
|
||||
|
@ -700,7 +808,7 @@ trackers()
|
|||
|
||||
::
|
||||
|
||||
const std::vector<announce_entry>& trackers() const;
|
||||
std::vector<announce_entry> const& trackers() const;
|
||||
|
||||
The ``trackers()`` function will return a sorted vector of ``announce_entry``.
|
||||
Each announce entry contains a string, which is the tracker url, and a tier index. The
|
||||
|
@ -743,7 +851,7 @@ hash_for_piece() info_hash()
|
|||
::
|
||||
|
||||
size_type piece_size(unsigned int index) const;
|
||||
const sha1_hash& hash_for_piece(unsigned int index) const;
|
||||
sha1_hash const& hash_for_piece(unsigned int index) const;
|
||||
|
||||
``hash_for_piece()`` takes a piece-index and returns the 20-bytes sha1-hash for that
|
||||
piece and ``info_hash()`` returns the 20-bytes sha1-hash for the info-section of the
|
||||
|
@ -755,8 +863,8 @@ name() comment() creation_date()
|
|||
|
||||
::
|
||||
|
||||
const std::stirng& name() const;
|
||||
const std::string& comment() const;
|
||||
std::string const& name() const;
|
||||
std::string const& comment() const;
|
||||
boost::optional<boost::posix_time::ptime> creation_date() const;
|
||||
|
||||
``name()`` returns the name of the torrent.
|
||||
|
@ -815,6 +923,8 @@ Its declaration looks like this::
|
|||
bool is_piece_filtered(int index) const;
|
||||
std::vector<bool> filtered_pieces() const;
|
||||
|
||||
void filter_files(std::vector<bool> const& files);
|
||||
|
||||
bool has_metadata() const;
|
||||
|
||||
boost::filsystem::path save_path() const;
|
||||
|
@ -822,9 +932,9 @@ Its declaration looks like this::
|
|||
|
||||
sha1_hash info_hash() const;
|
||||
|
||||
bool operator==(const torrent_handle&) const;
|
||||
bool operator!=(const torrent_handle&) const;
|
||||
bool operator<(const torrent_handle&) const;
|
||||
bool operator==(torrent_handle const&) const;
|
||||
bool operator!=(torrent_handle const&) const;
|
||||
bool operator<(torrent_handle const&) const;
|
||||
};
|
||||
|
||||
The default constructor will initialize the handle to an invalid state. Which means you cannot
|
||||
|
@ -833,9 +943,7 @@ any operation on an uninitialized handle, it will throw ``invalid_handle``.
|
|||
|
||||
**TODO: document trackers() and replace_trackers()**
|
||||
|
||||
**TODO: document how to create a .torrent**
|
||||
|
||||
**TODO: document filter_piece(), filter_pieces(), is_piece_filtered() and filtered_pieces()**
|
||||
**TODO: document filter_piece(), filter_pieces(), is_piece_filtered(), filtered_pieces() and filter_files()**
|
||||
|
||||
save_path()
|
||||
-----------
|
||||
|
@ -1500,6 +1608,70 @@ uncompressed (given your limit is lower than 2 megs). Default limit is
|
|||
1 megabyte.
|
||||
|
||||
|
||||
ip_filter
|
||||
=========
|
||||
|
||||
The ``ip_filter`` class is a set of rules that uniquely categorizes all
|
||||
ip addresses as allowed or disallowed. The default constructor creates
|
||||
a single rule that allowes all addresses (0.0.0.0 - 255.255.255.255).
|
||||
|
||||
::
|
||||
|
||||
class ip_filter
|
||||
{
|
||||
public:
|
||||
enum access_flags { blocked = 1 };
|
||||
|
||||
ip_filter();
|
||||
void add_rule(address first, address last, int flags);
|
||||
int access(address const& addr) const;
|
||||
};
|
||||
|
||||
|
||||
ip_filter()
|
||||
-----------
|
||||
|
||||
::
|
||||
|
||||
ip_filter()
|
||||
|
||||
Creates a default filter that doesn't filter any address.
|
||||
|
||||
postcondition:
|
||||
``access(x) == 0`` for every ``x``
|
||||
|
||||
|
||||
add_rule()
|
||||
----------
|
||||
|
||||
::
|
||||
|
||||
void add_rule(address first, address last, int flags);
|
||||
|
||||
Adds a rule to the filter. ``first`` and ``last`` defines a range of
|
||||
ip addresses that will be marked with the given flags. The ``flags``
|
||||
can currenly be 0, which means allowed, or ``ip_filter::blocked``, which
|
||||
means disallowed.
|
||||
|
||||
postcondition:
|
||||
``access(x) == flags`` for every ``x`` in the range [``first``, ``last``]
|
||||
|
||||
This means that in a case of overlapping ranges, the last one applied takes
|
||||
precedence.
|
||||
|
||||
|
||||
access()
|
||||
--------
|
||||
|
||||
::
|
||||
|
||||
int access(address const& addr) const;
|
||||
|
||||
Returns the access permissions for the given address (``addr``). The permission
|
||||
can currently be 0 or ``ip_filter::blocked``. The complexity of this operation
|
||||
is O(``log`` n), where n is the minimum number of non-overlapping ranges to describe
|
||||
the current filter.
|
||||
|
||||
|
||||
big_number
|
||||
==========
|
||||
|
@ -2258,6 +2430,104 @@ This is a simple client. It doesn't have much output to keep it simple::
|
|||
return 0;
|
||||
}
|
||||
|
||||
make_torrent
|
||||
------------
|
||||
|
||||
Shows how to create a torrent from a directory tree::
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <iomanip>
|
||||
|
||||
#include "libtorrent/entry.hpp"
|
||||
#include "libtorrent/bencode.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/storage.hpp"
|
||||
#include "libtorrent/hasher.hpp"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
using namespace boost::filesystem;
|
||||
using namespace libtorrent;
|
||||
|
||||
void add_files(
|
||||
torrent_info& t
|
||||
, path const& p
|
||||
, path const& l)
|
||||
{
|
||||
path f(p / l);
|
||||
if (is_directory(f))
|
||||
{
|
||||
for (directory_iterator i(f), end; i != end; ++i)
|
||||
add_files(t, p, l / i->leaf());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "adding \"" << l.string() << "\"\n";
|
||||
file fi(f, file::in);
|
||||
fi.seek(0, file::end);
|
||||
libtorrent::size_type size = fi.tell();
|
||||
t.add_file(l, size);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
if (argc != 4)
|
||||
{
|
||||
std::cerr << "usage: make_torrent <output torrent-file> <announce url> <file or directory to create torrent from>\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::filesystem::path::default_name_check(native);
|
||||
|
||||
try
|
||||
{
|
||||
torrent_info t;
|
||||
path full_path = initial_path() / path(argv[3]);
|
||||
ofstream out(initial_path() / path(argv[1]), std::ios_base::binary);
|
||||
|
||||
int piece_size = 256 * 1024;
|
||||
char const* creator_str = "libtorrent";
|
||||
|
||||
add_files(t, full_path.branch_path(), full_path.leaf());
|
||||
t.set_piece_size(piece_size);
|
||||
|
||||
storage st(t, full_path.branch_path());
|
||||
t.add_tracker(argv[2]);
|
||||
|
||||
// calculate the hash for all pieces
|
||||
int num = t.num_pieces();
|
||||
std::vector<char> buf(piece_size);
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
st.read(&buf[0], i, 0, t.piece_size(i));
|
||||
hasher h(&buf[0], t.piece_size(i));
|
||||
t.set_hash(i, h.final());
|
||||
std::cerr << (i+1) << "/" << num << "\r";
|
||||
}
|
||||
|
||||
t.set_creator(creator_str);
|
||||
|
||||
// create the torrent and print it to out
|
||||
entry e = t.create_torrent();
|
||||
libtorrent::bencode(std::ostream_iterator<char>(out), e);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << "\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
fast resume
|
||||
===========
|
||||
|
|
|
@ -290,6 +290,50 @@ int main(int argc, char* argv[])
|
|||
ses.set_severity_level(alert::debug);
|
||||
// ses.set_severity_level(alert::info);
|
||||
|
||||
// look for ipfilter.dat
|
||||
// poor man's parser
|
||||
// reads emule ipfilter files.
|
||||
// with the following format:
|
||||
//
|
||||
// <first-ip> - <last-ip> , <access> , <comment>
|
||||
//
|
||||
// first-ip is an ip address that defines the first
|
||||
// address of the range
|
||||
// last-ip is the last ip address in the range
|
||||
// access is a number specifying the access control
|
||||
// for this ip-range. Right now values > 127 = allowed
|
||||
// and numbers <= 127 = blocked
|
||||
// the rest of the line is ignored
|
||||
//
|
||||
// In the original spec ranges may not overlap, but
|
||||
// here ranges may overlap, and it is the last added
|
||||
// rule that has precedence for addresses that may fall
|
||||
// into more than one range.
|
||||
std::ifstream in("ipfilter.dat");
|
||||
ip_filter filter;
|
||||
while (in.good())
|
||||
{
|
||||
char line[300];
|
||||
in.getline(line, 300);
|
||||
int len = in.gcount();
|
||||
if (len <= 0) continue;
|
||||
if (line[0] == '#') continue;
|
||||
int a, b, c, d;
|
||||
char dummy;
|
||||
in >> a >> dummy >> b >> dummy >> c >> dummy >> d >> dummy;
|
||||
address start(a, b, c, d, 0);
|
||||
in >> a >> dummy >> b >> dummy >> c >> dummy >> d >> dummy;
|
||||
address last(a, b, c, d, 0);
|
||||
int flags;
|
||||
in >> flags;
|
||||
if (flags <= 127) flags = ip_filter::blocked;
|
||||
else flags = 0;
|
||||
if (in.fail()) break;
|
||||
filter.add_rule(start, last, flags);
|
||||
}
|
||||
|
||||
ses.set_ip_filter(filter);
|
||||
|
||||
for (int i = 0; i < argc-1; ++i)
|
||||
{
|
||||
try
|
||||
|
@ -367,6 +411,7 @@ int main(int argc, char* argv[])
|
|||
torrent_handle h = *i;
|
||||
if (!h.get_torrent_info().is_valid()) continue;
|
||||
|
||||
h.pause();
|
||||
entry data = h.write_resume_data();
|
||||
std::stringstream s;
|
||||
s << h.get_torrent_info().name() << ".fastresume";
|
||||
|
@ -420,12 +465,12 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
// limit the bandwidth for all seeding torrents
|
||||
p->handle.set_max_connections(10);
|
||||
p->handle.set_max_uploads(5);
|
||||
p->handle.set_upload_limit(10000);
|
||||
//p->handle.set_max_uploads(5);
|
||||
//p->handle.set_upload_limit(10000);
|
||||
|
||||
// all finished downloades are
|
||||
// moved into this directory
|
||||
p->handle.move_storage("finished");
|
||||
//p->handle.move_storage("finished");
|
||||
events.push_back(
|
||||
p->handle.get_torrent_info().name() + ": " + a->msg());
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << "\n";
|
||||
std::cerr << e.what() << "\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
|
||||
Copyright (c) 2003, Arvid Norberg
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the author nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef IP_FILTER_HPP
|
||||
#define IP_FILTER_HPP
|
||||
|
||||
#include "libtorrent/socket.hpp"
|
||||
#include <set>
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
||||
class ip_filter
|
||||
{
|
||||
public:
|
||||
|
||||
enum access_flags
|
||||
{
|
||||
blocked = 1
|
||||
};
|
||||
|
||||
ip_filter();
|
||||
void add_rule(address first, address last, int flags);
|
||||
int access(address const& addr) const;
|
||||
//void print() const;
|
||||
|
||||
private:
|
||||
struct range
|
||||
{
|
||||
range(address addr, int access = 0): start(addr), access(access) {}
|
||||
bool operator<(range const& r) const
|
||||
{ return start < r.start; }
|
||||
bool operator<(address const& a) const
|
||||
{ return start < a; }
|
||||
address start;
|
||||
// the end of the range is implicit
|
||||
// and given by the next entry in the set
|
||||
int access;
|
||||
};
|
||||
|
||||
typedef std::set<range> range_t;
|
||||
range_t m_access_list;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -68,6 +68,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/debug.hpp"
|
||||
#include "libtorrent/peer_request.hpp"
|
||||
#include "libtorrent/piece_block_progress.hpp"
|
||||
#include "libtorrent/ip_filter.hpp"
|
||||
|
||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
||||
# include <float.h>
|
||||
|
@ -200,6 +201,9 @@ namespace libtorrent
|
|||
// in loops that iterate over them.
|
||||
std::vector<connection_map::iterator> m_disconnect_peer;
|
||||
|
||||
// filters incomming connections
|
||||
ip_filter m_ip_filter;
|
||||
|
||||
// the peer id that is generated at the start of the session
|
||||
peer_id m_peer_id;
|
||||
|
||||
|
@ -266,7 +270,7 @@ namespace libtorrent
|
|||
#ifndef NDEBUG
|
||||
void check_invariant(const char *place = 0);
|
||||
#endif
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||
boost::shared_ptr<logger> create_log(std::string const& name);
|
||||
boost::shared_ptr<logger> m_logger;
|
||||
#endif
|
||||
|
@ -327,6 +331,7 @@ namespace libtorrent
|
|||
void enable_extension(peer_connection::extension_index i);
|
||||
void disable_extensions();
|
||||
|
||||
void set_ip_filter(ip_filter const& f);
|
||||
void set_peer_id(peer_id const& id);
|
||||
void set_key(int key);
|
||||
|
||||
|
|
|
@ -90,6 +90,8 @@ namespace libtorrent
|
|||
std::string as_string() const;
|
||||
unsigned int ip() const { return m_ip; }
|
||||
|
||||
bool operator<=(const address& a) const
|
||||
{ if (ip() == a.ip()) return port <= a.port; else return ip() <= a.ip(); }
|
||||
bool operator<(const address& a) const
|
||||
{ if (ip() == a.ip()) return port < a.port; else return ip() < a.ip(); }
|
||||
bool operator!=(const address& a) const
|
||||
|
|
|
@ -91,12 +91,12 @@ namespace libtorrent
|
|||
torrent_info(entry const& torrent_file);
|
||||
~torrent_info();
|
||||
|
||||
entry create_torrent() const;
|
||||
entry create_torrent();
|
||||
entry create_info_metadata() const;
|
||||
void set_comment(char const* str);
|
||||
void set_creator(char const* str);
|
||||
void set_piece_size(int size);
|
||||
void set_hash(int index, const sha1_hash& h);
|
||||
void set_hash(int index, sha1_hash const& h);
|
||||
void add_tracker(std::string const& url, int tier = 0);
|
||||
void add_file(boost::filesystem::path file, size_type size);
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/allocate_resources.hpp"
|
||||
#include "libtorrent/peer_connection.hpp"
|
||||
#include "libtorrent/ip_filter.hpp"
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1300
|
||||
namespace std
|
||||
|
@ -232,7 +233,7 @@ namespace libtorrent { namespace detail
|
|||
, m_max_connections(-1)
|
||||
, m_incoming_connection(false)
|
||||
{
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||
m_logger = create_log("main_session");
|
||||
#endif
|
||||
std::fill(m_extension_enabled, m_extension_enabled
|
||||
|
@ -303,7 +304,7 @@ namespace libtorrent { namespace detail
|
|||
std::string msg = "cannot listen on the given interface '" + m_listen_interface.as_string() + "'";
|
||||
m_alerts.post_alert(listen_failed_alert(msg));
|
||||
}
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||
std::string msg = "cannot listen on the given interface '" + m_listen_interface.as_string() + "'";
|
||||
(*m_logger) << msg << "\n";
|
||||
#endif
|
||||
|
@ -320,7 +321,7 @@ namespace libtorrent { namespace detail
|
|||
<< ", " << m_listen_port_range.second
|
||||
<< "] could be opened for listening";
|
||||
m_alerts.post_alert(listen_failed_alert(msg.str()));
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||
(*m_logger) << msg.str() << "\n";
|
||||
#endif
|
||||
m_listen_socket.reset();
|
||||
|
@ -334,7 +335,7 @@ namespace libtorrent { namespace detail
|
|||
m_alerts.post_alert(listen_failed_alert(e.what()));
|
||||
}
|
||||
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||
if (m_listen_socket)
|
||||
{
|
||||
(*m_logger) << "listening on port: " << m_listen_interface.port << "\n";
|
||||
|
@ -513,7 +514,7 @@ namespace libtorrent { namespace detail
|
|||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||
(*m_logger) << "accept failed: " << e.what() << "\n";
|
||||
#endif
|
||||
}
|
||||
|
@ -522,10 +523,17 @@ namespace libtorrent { namespace detail
|
|||
s->set_blocking(false);
|
||||
// we got a connection request!
|
||||
m_incoming_connection = true;
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||
(*m_logger) << s->sender().as_string() << " <== INCOMING CONNECTION\n";
|
||||
#endif
|
||||
// TODO: filter ip:s
|
||||
if (m_ip_filter.access(s->sender()) & ip_filter::blocked)
|
||||
{
|
||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||
(*m_logger) << "filtered blocked ip\n";
|
||||
#endif
|
||||
// TODO: issue an info-alert when an ip is blocked
|
||||
continue;
|
||||
}
|
||||
|
||||
boost::shared_ptr<peer_connection> c(
|
||||
new peer_connection(*this, m_selector, s));
|
||||
|
@ -622,7 +630,7 @@ namespace libtorrent { namespace detail
|
|||
std::string msg = "cannot listen on the given interface '" + m_listen_interface.as_string() + "'";
|
||||
m_alerts.post_alert(listen_failed_alert(msg));
|
||||
}
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||
std::string msg = "cannot listen on the given interface '" + m_listen_interface.as_string() + "'";
|
||||
(*m_logger) << msg << "\n";
|
||||
#endif
|
||||
|
@ -811,7 +819,7 @@ namespace libtorrent { namespace detail
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||
boost::shared_ptr<logger> session_impl::create_log(std::string const& name)
|
||||
{
|
||||
// current options are file_logger, cout_logger and null_logger
|
||||
|
@ -897,6 +905,12 @@ namespace libtorrent
|
|||
+ peer_connection::num_supported_extensions, false);
|
||||
}
|
||||
|
||||
void session::set_ip_filter(ip_filter const& f)
|
||||
{
|
||||
boost::mutex::scoped_lock l(m_impl.m_mutex);
|
||||
m_impl.m_ip_filter = f;
|
||||
}
|
||||
|
||||
void session::set_peer_id(peer_id const& id)
|
||||
{
|
||||
boost::mutex::scoped_lock l(m_impl.m_mutex);
|
||||
|
|
|
@ -321,15 +321,13 @@ namespace libtorrent
|
|||
// connect to random peers from the list
|
||||
std::random_shuffle(peer_list.begin(), peer_list.end());
|
||||
|
||||
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
std::stringstream s;
|
||||
s << "TRACKER RESPONSE:\n"
|
||||
"interval: " << m_duration << "\n"
|
||||
"peers:\n";
|
||||
for (std::vector<peer_entry>::const_iterator i = peer_list.begin();
|
||||
i != peer_list.end();
|
||||
++i)
|
||||
i != peer_list.end(); ++i)
|
||||
{
|
||||
s << " " << std::setfill(' ') << std::setw(16) << i->ip
|
||||
<< " " << std::setw(5) << std::dec << i->port << " ";
|
||||
|
@ -340,8 +338,7 @@ namespace libtorrent
|
|||
#endif
|
||||
// for each of the peers we got from the tracker
|
||||
for (std::vector<peer_entry>::iterator i = peer_list.begin();
|
||||
i != peer_list.end();
|
||||
++i)
|
||||
i != peer_list.end(); ++i)
|
||||
{
|
||||
// don't make connections to ourself
|
||||
if (i->id == m_ses.get_peer_id())
|
||||
|
@ -349,6 +346,14 @@ namespace libtorrent
|
|||
|
||||
address a(i->ip.c_str(), i->port);
|
||||
|
||||
if (m_ses.m_ip_filter.access(a) == ip_filter::blocked)
|
||||
{
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
debug_log("blocked ip from tracker: " + i->ip);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
m_policy->peer_from_tracker(a, i->id);
|
||||
}
|
||||
|
||||
|
@ -632,42 +637,35 @@ namespace libtorrent
|
|||
m_picker->filtered_pieces(bitmask);
|
||||
}
|
||||
|
||||
//suggest using this function on single file in a torrent file
|
||||
//suggest using this function after filter_files() function
|
||||
//or change selective download policy casually during downloading progress
|
||||
//idea from Arvid and MooPolice
|
||||
//todo refactoring and improving the function body
|
||||
void torrent::filter_file(int index, bool filter)
|
||||
{
|
||||
// this call is only valid on torrents with metadata
|
||||
if (!valid_metadata()) return;
|
||||
|
||||
assert(index >= 0);
|
||||
assert(index < m_torrent_file.num_files());
|
||||
|
||||
entry::integer_type position = 0;
|
||||
assert(index >= 0);
|
||||
|
||||
if (m_torrent_file.num_pieces())
|
||||
{
|
||||
int piece_length = m_torrent_file.piece_length();
|
||||
entry::integer_type start = position;
|
||||
entry::integer_type start_position = 0;
|
||||
int start_piece_index = 0;
|
||||
int end_piece_index = 0;
|
||||
|
||||
for (int i = 0; i < index; ++i)
|
||||
{
|
||||
start = position;
|
||||
position += m_torrent_file.file_at(i).size;
|
||||
}
|
||||
int start_piece = int(start / piece_length);
|
||||
int last_piece = int(position / piece_length);
|
||||
|
||||
for (int filter_index = start_piece ; filter_index < last_piece ; ++filter_index)
|
||||
{
|
||||
filter_piece(filter_index, filter);
|
||||
}
|
||||
}
|
||||
// TODO: just skipping the first and last piece is not a good idea.
|
||||
// they should only be skipped if there are files that are wanted
|
||||
// that span those pieces. Maybe this function should be removed.
|
||||
for (int i = 0; i < index; ++i)
|
||||
start_position += m_torrent_file.file_at(i).size;
|
||||
|
||||
start_position = start_position + 1;
|
||||
|
||||
start_piece_index = start_position / m_torrent_file.piece_length();
|
||||
end_piece_index = start_piece_index + m_torrent_file.file_at(index).size/(m_torrent_file.piece_length());
|
||||
|
||||
for(int i = start_piece_index; i < end_piece_index; ++i)
|
||||
filter_piece(i, filter);
|
||||
}
|
||||
|
||||
//suggest using this function on a torrent file.
|
||||
//suggest using this function as a static globle selective download policy
|
||||
//"before" downloading progress
|
||||
void torrent::filter_files(std::vector<bool> const& bitmask)
|
||||
{
|
||||
// this call is only valid on torrents with metadata
|
||||
|
@ -685,7 +683,7 @@ namespace libtorrent
|
|||
// mark all pieces as filtered, then clear the bits for files
|
||||
// that should be downloaded
|
||||
std::vector<bool> piece_filter(m_torrent_file.num_pieces(), true);
|
||||
for (int i = 0; i < bitmask.size(); ++i)
|
||||
for (int i = 0; i < (int)bitmask.size(); ++i)
|
||||
{
|
||||
entry::integer_type start = position;
|
||||
position += m_torrent_file.file_at(i).size;
|
||||
|
|
|
@ -123,6 +123,7 @@ namespace libtorrent
|
|||
// constructor used for creating new torrents
|
||||
// will not contain any hashes, comments, creation date
|
||||
// just the necessary to use it with piece manager
|
||||
// used for torrents with no metadata
|
||||
torrent_info::torrent_info(sha1_hash const& info_hash)
|
||||
: m_piece_length(256 * 1024)
|
||||
, m_total_size(0)
|
||||
|
@ -440,7 +441,7 @@ namespace libtorrent
|
|||
return info;
|
||||
}
|
||||
|
||||
entry torrent_info::create_torrent() const
|
||||
entry torrent_info::create_torrent()
|
||||
{
|
||||
assert(m_piece_length > 0);
|
||||
|
||||
|
@ -490,9 +491,13 @@ namespace libtorrent
|
|||
dict["created by"] = m_created_by;
|
||||
|
||||
dict["info"] = create_info_metadata();
|
||||
|
||||
dict.sort();
|
||||
|
||||
entry const& info_section = dict["info"];
|
||||
std::vector<char> buf;
|
||||
bencode(std::back_inserter(buf), info_section);
|
||||
m_info_hash = hasher(&buf[0], buf.size()).final();
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue