Version: | 2.0.9 |
---|
Table of contents
- peer_request
- info_hash_t
- peer_info
- piece_block
- version()
- load_torrent_buffer() load_torrent_file() load_torrent_parsed()
- torrent_peer_equal()
- truncate_files()
- make_magnet_uri()
- parse_magnet_uri()
- enum protocol_version
- enum event_t
- enum socket_type_t
- enum portmap_transport
- enum portmap_protocol
- enum connection_type
- download_priority_t
- int
- char const*
- std::uint64_t
- pex_flags_t
- torrent_flags_t
- peer_class_info
- peer_class_type_filter
- a word of caution
- plugin-interface
- custom alerts
- peer_connection_handle
- bt_peer_connection_handle
- plugin
- torrent_plugin
- peer_plugin
- type()
- add_handshake()
- on_disconnect()
- on_connected()
- on_handshake()
- on_extension_handshake()
- on_not_interested() on_interested() on_have_all() on_dont_have() on_bitfield() on_request() on_allowed_fast() on_choke() on_have() on_have_none() on_unchoke()
- on_piece()
- sent_have() sent_piece() sent_not_interested() sent_interested() sent_unchoke()
- sent_payload()
- can_disconnect()
- on_extended()
- on_unknown_message()
- on_piece_failed() on_piece_pass()
- tick()
- write_request()
- crypto_plugin
- create_ut_metadata_plugin()
- create_smart_ban_plugin()
- create_ut_pex_plugin()
- client_data_t
- add_torrent_params
- announce_infohash
- announce_endpoint
- announce_entry
- settings_interface
- disk_observer
- open_file_state
- disk_interface
- new_torrent()
- remove_torrent()
- async_write() async_read()
- async_hash()
- async_hash2()
- async_move_storage()
- async_release_files()
- async_check_files()
- async_stop_torrent()
- async_rename_file()
- async_delete_files()
- async_set_file_priority()
- async_clear_piece()
- update_stats_counters()
- get_status()
- abort()
- submit_jobs()
- settings_updated()
- storage_holder
- buffer_allocator_interface
- disk_buffer_holder
- file_open_mode_t
- settings_pack
- set_int() set_bool() set_str()
- has_val()
- clear()
- clear()
- get_bool() get_int() get_str()
- enum type_bases
- enum mmap_write_mode_t
- enum suggest_mode_t
- enum choking_algorithm_t
- enum seed_choking_algorithm_t
- enum io_buffer_mode_t
- enum bandwidth_mixed_algo_t
- enum enc_policy
- enum enc_level
- enum proxy_type_t
- name_for_setting() setting_by_name()
- default_settings()
- high_performance_seed() min_memory_usage()
- generate_fingerprint()
- storage_params
- file_slice
- file_storage
- is_valid()
- reserve()
- add_file() add_file_borrow()
- rename_file()
- map_block()
- map_file()
- num_files()
- end_file()
- file_range()
- total_size()
- num_pieces() set_num_pieces()
- end_piece()
- last_piece()
- piece_range()
- set_piece_length() piece_length()
- piece_size()
- piece_size2()
- blocks_in_piece2()
- blocks_per_piece()
- name() set_name()
- swap()
- canonicalize()
- root() pad_file_at() file_offset() mtime() symlink() root_ptr() file_path() hash() file_size() file_name()
- file_num_blocks() file_piece_range() file_num_pieces()
- file_first_piece_node() file_first_block_node()
- file_path_hash()
- all_path_hashes()
- file_flags()
- file_absolute_path()
- file_index_at_offset() file_index_at_piece()
- file_index_for_root()
- piece_index_at_file()
- sanitize_symlinks()
- v2()
- default_disk_io_constructor()
- mmap_disk_io_constructor()
- posix_disk_io_constructor()
- disabled_disk_io_constructor()
- enum storage_mode_t
- enum status_t
- enum move_flags_t
- session_handle
- is_valid()
- session_state()
- get_torrent_status() refresh_torrent_status()
- post_torrent_updates()
- post_session_stats()
- post_dht_stats()
- set_dht_state()
- find_torrent() get_torrents()
- async_add_torrent() add_torrent()
- resume() is_paused() pause()
- is_dht_running()
- set_dht_storage()
- add_dht_node()
- dht_get_item()
- dht_get_item()
- dht_put_item()
- dht_put_item()
- dht_announce() dht_get_peers()
- dht_live_nodes()
- dht_sample_infohashes()
- dht_direct_request()
- add_extension()
- set_ip_filter() get_ip_filter()
- set_port_filter()
- listen_port() is_listening() ssl_listen_port()
- set_peer_class_filter() get_peer_class_filter()
- set_peer_class_type_filter() get_peer_class_type_filter()
- create_peer_class()
- delete_peer_class()
- set_peer_class() get_peer_class()
- remove_torrent()
- apply_settings() get_settings()
- pop_alerts() wait_for_alert() set_alert_notify()
- delete_port_mapping() add_port_mapping()
- reopen_network_sockets()
- native_handle()
- session_proxy
- session
- session_params
- read_session_params() write_session_params() write_session_params_buf()
- hasher
- hasher256
- bitfield
- alert
- dht_routing_bucket
- torrent_alert
- peer_alert
- tracker_alert
- torrent_removed_alert
- read_piece_alert
- file_completed_alert
- file_renamed_alert
- file_rename_failed_alert
- performance_alert
- state_changed_alert
- tracker_error_alert
- tracker_warning_alert
- scrape_reply_alert
- scrape_failed_alert
- tracker_reply_alert
- dht_reply_alert
- tracker_announce_alert
- hash_failed_alert
- peer_ban_alert
- peer_unsnubbed_alert
- peer_snubbed_alert
- peer_error_alert
- peer_connect_alert
- peer_disconnected_alert
- invalid_request_alert
- torrent_finished_alert
- piece_finished_alert
- request_dropped_alert
- block_timeout_alert
- block_finished_alert
- block_downloading_alert
- unwanted_block_alert
- storage_moved_alert
- storage_moved_failed_alert
- torrent_deleted_alert
- torrent_delete_failed_alert
- save_resume_data_alert
- save_resume_data_failed_alert
- torrent_paused_alert
- torrent_resumed_alert
- torrent_checked_alert
- url_seed_alert
- file_error_alert
- metadata_failed_alert
- metadata_received_alert
- udp_error_alert
- external_ip_alert
- listen_failed_alert
- listen_succeeded_alert
- portmap_error_alert
- portmap_alert
- portmap_log_alert
- fastresume_rejected_alert
- peer_blocked_alert
- dht_announce_alert
- dht_get_peers_alert
- cache_flushed_alert
- lsd_peer_alert
- trackerid_alert
- dht_bootstrap_alert
- torrent_error_alert
- torrent_need_cert_alert
- incoming_connection_alert
- add_torrent_alert
- state_update_alert
- session_stats_alert
- dht_error_alert
- dht_immutable_item_alert
- dht_mutable_item_alert
- dht_put_alert
- i2p_alert
- dht_outgoing_get_peers_alert
- log_alert
- torrent_log_alert
- peer_log_alert
- lsd_error_alert
- dht_lookup
- dht_stats_alert
- incoming_request_alert
- dht_log_alert
- dht_pkt_alert
- dht_get_peers_reply_alert
- dht_direct_response_alert
- picker_log_alert
- session_error_alert
- dht_live_nodes_alert
- session_stats_header_alert
- dht_sample_infohashes_alert
- block_uploaded_alert
- alerts_dropped_alert
- socks5_alert
- file_prio_alert
- oversized_file_alert
- torrent_conflict_alert
- peer_info_alert
- file_progress_alert
- piece_info_alert
- piece_availability_alert
- tracker_list_alert
- alert_cast()
- operation_name()
- enum operation_t
- int
- alert_category_t
- bdecode_node
- bdecode_node()
- operator=() bdecode_node()
- type()
- bool()
- non_owning()
- data_section() data_offset()
- list_int_value_at() list_at() list_size() list_string_value_at()
- dict_find() dict_find_string_value() dict_at() dict_find_int() dict_find_dict() dict_find_int_value() dict_find_string() dict_size() dict_find_list() dict_at_node()
- int_value()
- string_length() string_offset() string_ptr() string_value()
- clear()
- swap()
- reserve()
- switch_underlying_buffer()
- has_soft_error()
- enum type_t
- print_entry()
- bdecode()
- create_torrent
- create_torrent()
- generate() generate_buf()
- files()
- set_comment()
- set_creator()
- set_creation_date()
- set_hash()
- set_hash2()
- add_http_seed() add_url_seed()
- add_node()
- add_tracker()
- set_root_cert()
- priv() set_priv()
- num_pieces()
- piece_range()
- file_range()
- file_piece_range()
- total_size()
- piece_length() piece_size()
- add_similar_torrent() add_collection()
- add_files()
- set_piece_hashes()
- stats_metric
- counters
- session_stats_metrics()
- find_metric_idx()
- enum metric_type_t
- torrent_status
- storage_error
- gzip_category()
- i2p_category()
- bdecode_category()
- upnp_category()
- libtorrent_category()
- http_category()
- socks_category()
- pcp_category()
- enum error_code_enum
- enum i2p_error_code
- enum error_code_enum
- enum error_code_enum
- enum error_code_enum
- enum http_errors
- enum socks_error_code
- enum pcp_errors
- entry
- operator<<()
- bencode()
- ip_filter
- port_filter
- block_info
- partial_piece_info
- torrent_handle
- torrent_handle()
- add_piece()
- read_piece()
- have_piece()
- get_peer_info() post_peer_info()
- post_status() status()
- get_download_queue() post_download_queue()
- clear_piece_deadlines() set_piece_deadline() reset_piece_deadline()
- file_progress() post_file_progress()
- file_status()
- clear_error()
- post_trackers() replace_trackers() add_tracker() trackers()
- url_seeds() add_url_seed() remove_url_seed()
- add_http_seed() remove_http_seed() http_seeds()
- add_extension()
- set_metadata()
- is_valid()
- resume() pause()
- flags() unset_flags() set_flags()
- flush_cache()
- force_recheck()
- save_resume_data()
- need_save_resume_data()
- queue_position_bottom() queue_position_down() queue_position_up() queue_position() queue_position_top()
- queue_position_set()
- set_ssl_certificate() set_ssl_certificate_buffer()
- torrent_file_with_hashes() torrent_file()
- piece_layers()
- piece_availability() post_piece_availability()
- prioritize_pieces() piece_priority() get_piece_priorities()
- get_file_priorities() file_priority() prioritize_files()
- force_dht_announce() force_lsd_announce() force_reannounce()
- scrape_tracker()
- set_download_limit() upload_limit() download_limit() set_upload_limit()
- connect_peer()
- clear_peers()
- set_max_uploads() max_uploads()
- max_connections() set_max_connections()
- move_storage()
- rename_file()
- info_hash() info_hashes()
- operator==() operator!=() operator<()
- id()
- native_handle()
- userdata()
- in_session()
- hash_value()
- web_seed_entry
- load_torrent_limits
- torrent_info
- torrent_info()
- ~torrent_info()
- files() orig_files()
- rename_file()
- remap_files()
- add_tracker() trackers() clear_trackers()
- collections() similar_torrents()
- web_seeds() add_http_seed() add_url_seed() set_web_seeds()
- total_size()
- num_pieces() piece_length()
- blocks_per_piece()
- last_piece() end_piece() piece_range()
- info_hash() info_hashes()
- v1() v2()
- num_files()
- map_block()
- map_file()
- ssl_cert()
- is_valid()
- priv()
- is_i2p()
- piece_size()
- hash_for_piece() hash_for_piece_ptr()
- name()
- creation_date()
- creator()
- comment()
- nodes()
- add_node()
- parse_info_section()
- info()
- info_section()
- piece_layer()
- free_piece_layers()
- dht_state
- dht_storage_counters
- dht_storage_interface
- sign_mutable_item()
- dht_default_storage_constructor()
- announce_flags_t
- read_resume_data()
- write_resume_data() write_resume_data_buf()
- write_torrent_file() write_torrent_file_buf()
- write_torrent_flags_t
- ed25519_create_seed()
- ed25519_create_keypair()
- ed25519_sign()
- ed25519_verify()
- ed25519_add_scalar()
- ed25519_key_exchange()
peer_request
Declared in "libtorrent/peer_request.hpp"
represents a byte range within a piece. Internally this is is used for incoming piece requests.
struct peer_request { bool operator== (peer_request const& r) const; piece_index_t piece; int start; int length; };[report issue]
operator==()
bool operator== (peer_request const& r) const;
returns true if the right hand side peer_request refers to the same range as this does.
[report issue]- piece
- The index of the piece in which the range starts.
- start
- The byte offset within that piece where the range starts.
- length
- The size of the range, in bytes.
info_hash_t
Declared in "libtorrent/info_hash.hpp"
class holding the info-hash of a torrent. It can hold a v1 info-hash (SHA-1) or a v2 info-hash (SHA-256) or both.
Note
If has_v2() is false then the v1 hash might actually be a truncated v2 hash
struct info_hash_t { explicit info_hash_t (sha256_hash h2) noexcept; info_hash_t (sha1_hash h1, sha256_hash h2) noexcept; explicit info_hash_t (sha1_hash h1) noexcept; info_hash_t () noexcept = default; bool has (protocol_version v) const; bool has_v2 () const; bool has_v1 () const; sha1_hash get (protocol_version v) const; sha1_hash get_best () const; friend bool operator!= (info_hash_t const& lhs, info_hash_t const& rhs); friend bool operator== (info_hash_t const& lhs, info_hash_t const& rhs) noexcept; template <typename F> void for_each (F f) const; bool operator< (info_hash_t const& o) const; friend std::ostream& operator<< (std::ostream& os, info_hash_t const& ih); sha1_hash v1; sha256_hash v2; };[report issue]
info_hash_t()
explicit info_hash_t (sha256_hash h2) noexcept; info_hash_t (sha1_hash h1, sha256_hash h2) noexcept; explicit info_hash_t (sha1_hash h1) noexcept; info_hash_t () noexcept = default;
The default constructor creates an object that has neither a v1 or v2 hash.
For backwards compatibility, make it possible to construct directly from a v1 hash. This constructor allows implicit conversion from a v1 hash, but the implicitness is deprecated.
[report issue]has_v1() has_v2() has()
bool has (protocol_version v) const; bool has_v2 () const; bool has_v1 () const;
returns true if the corresponding info hash is present in this object.
[report issue]get()
sha1_hash get (protocol_version v) const;
returns the has for the specified protocol version
[report issue]get_best()
sha1_hash get_best () const;
returns the v2 (truncated) info-hash, if there is one, otherwise returns the v1 info-hash
[report issue]for_each()
template <typename F> void for_each (F f) const;
calls the function object f for each hash that is available. starting with v1. The signature of F is:
void(sha1_hash const&, protocol_version);[report issue]
peer_info
Declared in "libtorrent/peer_info.hpp"
holds information and statistics about one peer that libtorrent is connected to
struct peer_info { sha256_hash i2p_destination () const; std::string client; typed_bitfield<piece_index_t> pieces; std::int64_t total_download; std::int64_t total_upload; time_duration last_request; time_duration last_active; time_duration download_queue_time; static constexpr peer_flags_t interesting = 0_bit; static constexpr peer_flags_t choked = 1_bit; static constexpr peer_flags_t remote_interested = 2_bit; static constexpr peer_flags_t remote_choked = 3_bit; static constexpr peer_flags_t supports_extensions = 4_bit; static constexpr peer_flags_t outgoing_connection = 5_bit; static constexpr peer_flags_t local_connection = 5_bit; static constexpr peer_flags_t handshake = 6_bit; static constexpr peer_flags_t connecting = 7_bit; static constexpr peer_flags_t on_parole = 9_bit; static constexpr peer_flags_t seed = 10_bit; static constexpr peer_flags_t optimistic_unchoke = 11_bit; static constexpr peer_flags_t snubbed = 12_bit; static constexpr peer_flags_t upload_only = 13_bit; static constexpr peer_flags_t endgame_mode = 14_bit; static constexpr peer_flags_t holepunched = 15_bit; static constexpr peer_flags_t i2p_socket = 16_bit; static constexpr peer_flags_t utp_socket = 17_bit; static constexpr peer_flags_t ssl_socket = 18_bit; static constexpr peer_flags_t rc4_encrypted = 19_bit; static constexpr peer_flags_t plaintext_encrypted = 20_bit; peer_flags_t flags; static constexpr peer_source_flags_t tracker = 0_bit; static constexpr peer_source_flags_t dht = 1_bit; static constexpr peer_source_flags_t pex = 2_bit; static constexpr peer_source_flags_t lsd = 3_bit; static constexpr peer_source_flags_t resume_data = 4_bit; static constexpr peer_source_flags_t incoming = 5_bit; peer_source_flags_t source; int up_speed; int down_speed; int payload_up_speed; int payload_down_speed; peer_id pid; int queue_bytes; int request_timeout; int send_buffer_size; int used_send_buffer; int receive_buffer_size; int used_receive_buffer; int receive_buffer_watermark; int num_hashfails; int download_queue_length; int timed_out_requests; int busy_requests; int requests_in_buffer; int target_dl_queue_length; int upload_queue_length; int failcount; piece_index_t downloading_piece_index; int downloading_block_index; int downloading_progress; int downloading_total; static constexpr connection_type_t standard_bittorrent = 0_bit; static constexpr connection_type_t web_seed = 1_bit; static constexpr connection_type_t http_seed = 2_bit; connection_type_t connection_type; int pending_disk_bytes; int pending_disk_read_bytes; int send_quota; int receive_quota; int rtt; int num_pieces; int download_rate_peak; int upload_rate_peak; float progress; int progress_ppm; tcp::endpoint ip; tcp::endpoint local_endpoint; static constexpr bandwidth_state_flags_t bw_idle = 0_bit; static constexpr bandwidth_state_flags_t bw_limit = 1_bit; static constexpr bandwidth_state_flags_t bw_network = 2_bit; static constexpr bandwidth_state_flags_t bw_disk = 4_bit; bandwidth_state_flags_t read_state; bandwidth_state_flags_t write_state; };[report issue]
i2p_destination()
sha256_hash i2p_destination () const;
If this peer is an i2p peer, this function returns the destination address of the peer
[report issue]- client
- A human readable string describing the software at the other end of the connection. In some cases this information is not available, then it will contain a string that may give away something about which software is running in the other end. In the case of a web seed, the server type and version will be a part of this string. This is UTF-8 encoded.
- pieces
- a bitfield, with one bit per piece in the torrent. Each bit tells you if the peer has that piece (if it's set to 1) or if the peer miss that piece (set to 0).
- total_download total_upload
- the total number of bytes downloaded from and uploaded to this peer. These numbers do not include the protocol chatter, but only the payload data.
- last_request last_active
- the time since we last sent a request to this peer and since any transfer occurred with this peer
- download_queue_time
- the time until all blocks in the request queue will be downloaded
- interesting
- we are interested in pieces from this peer.
- choked
- we have choked this peer.
- remote_interested
- the peer is interested in us
- remote_choked
- the peer has choked us.
- supports_extensions
- means that this peer supports the extension protocol.
- outgoing_connection
- The connection was initiated by us, the peer has a listen port open, and that port is the same as in the address of this peer. If this flag is not set, this peer connection was opened by this peer connecting to us.
- local_connection
- deprecated synonym for outgoing_connection
- handshake
- The connection is opened, and waiting for the handshake. Until the handshake is done, the peer cannot be identified.
- connecting
- The connection is in a half-open state (i.e. it is being connected).
- on_parole
- The peer has participated in a piece that failed the hash check, and is now "on parole", which means we're only requesting whole pieces from this peer until it either fails that piece or proves that it doesn't send bad data.
- seed
- This peer is a seed (it has all the pieces).
- optimistic_unchoke
- This peer is subject to an optimistic unchoke. It has been unchoked for a while to see if it might unchoke us in return an earn an upload/unchoke slot. If it doesn't within some period of time, it will be choked and another peer will be optimistically unchoked.
- snubbed
- This peer has recently failed to send a block within the request timeout from when the request was sent. We're currently picking one block at a time from this peer.
- upload_only
- This peer has either explicitly (with an extension) or implicitly (by becoming a seed) told us that it will not downloading anything more, regardless of which pieces we have.
- endgame_mode
- This means the last time this peer picket a piece, it could not pick as many as it wanted because there were not enough free ones. i.e. all pieces this peer has were already requested from other peers.
- holepunched
- This flag is set if the peer was in holepunch mode when the connection succeeded. This typically only happens if both peers are behind a NAT and the peers connect via the NAT holepunch mechanism.
- i2p_socket
- indicates that this socket is running on top of the I2P transport.
- utp_socket
- indicates that this socket is a uTP socket
- ssl_socket
- indicates that this socket is running on top of an SSL (TLS) channel
- rc4_encrypted
- this connection is obfuscated with RC4
- plaintext_encrypted
- the handshake of this connection was obfuscated with a Diffie-Hellman exchange
- flags
- tells you in which state the peer is in. It is set to any combination of the peer_flags_t flags above.
- tracker
- The peer was received from the tracker.
- dht
- The peer was received from the kademlia DHT.
- pex
- The peer was received from the peer exchange extension.
- lsd
- The peer was received from the local service discovery (The peer is on the local network).
- resume_data
- The peer was added from the fast resume data.
- incoming
- we received an incoming connection from this peer
- source
- a combination of flags describing from which sources this peer was received. A combination of the peer_source_flags_t above.
- up_speed down_speed
- the current upload and download speed we have to and from this peer (including any protocol messages). updated about once per second
- payload_up_speed payload_down_speed
- The transfer rates of payload data only updated about once per second
- pid
- the peer's id as used in the bittorrent protocol. This id can be used to extract 'fingerprints' from the peer. Sometimes it can tell you which client the peer is using. See identify_client()_
- queue_bytes
- the number of bytes we have requested from this peer, but not yet received.
- request_timeout
- the number of seconds until the current front piece request will time out. This timeout can be adjusted through settings_pack::request_timeout. -1 means that there is not outstanding request.
- send_buffer_size used_send_buffer
- the number of bytes allocated and used for the peer's send buffer, respectively.
- receive_buffer_size used_receive_buffer receive_buffer_watermark
- the number of bytes allocated and used as receive buffer, respectively.
- num_hashfails
- the number of pieces this peer has participated in sending us that turned out to fail the hash check.
- download_queue_length
- this is the number of requests we have sent to this peer that we haven't got a response for yet
- timed_out_requests
- the number of block requests that have timed out, and are still in the download queue
- busy_requests
- the number of busy requests in the download queue. A busy request is a request for a block we've also requested from a different peer
- requests_in_buffer
- the number of requests messages that are currently in the send buffer waiting to be sent.
- target_dl_queue_length
- the number of requests that is tried to be maintained (this is typically a function of download speed)
- upload_queue_length
- the number of piece-requests we have received from this peer that we haven't answered with a piece yet.
- failcount
- the number of times this peer has "failed". i.e. failed to connect or disconnected us. The failcount is decremented when we see this peer in a tracker response or peer exchange message.
- downloading_piece_index downloading_block_index downloading_progress downloading_total
- You can know which piece, and which part of that piece, that is currently being downloaded from a specific peer by looking at these four members. downloading_piece_index is the index of the piece that is currently being downloaded. This may be set to -1 if there's currently no piece downloading from this peer. If it is >= 0, the other three members are valid. downloading_block_index is the index of the block (or sub-piece) that is being downloaded. downloading_progress is the number of bytes of this block we have received from the peer, and downloading_total is the total number of bytes in this block.
- standard_bittorrent
- Regular bittorrent connection
- web_seed
- HTTP connection using the BEP 19 protocol
- http_seed
- HTTP connection using the BEP 17 protocol
- connection_type
- the kind of connection this peer uses. See connection_type_t.
- pending_disk_bytes
- the number of bytes this peer has pending in the disk-io thread. Downloaded and waiting to be written to disk. This is what is capped by settings_pack::max_queued_disk_bytes.
- pending_disk_read_bytes
- number of outstanding bytes to read from disk
- send_quota receive_quota
- the number of bytes this peer has been assigned to be allowed to send and receive until it has to request more quota from the bandwidth manager.
- rtt
- an estimated round trip time to this peer, in milliseconds. It is estimated by timing the TCP connect(). It may be 0 for incoming connections.
- num_pieces
- the number of pieces this peer has.
- download_rate_peak upload_rate_peak
- the highest download and upload rates seen on this connection. They are given in bytes per second. This number is reset to 0 on reconnect.
- progress
- the progress of the peer in the range [0, 1]. This is always 0 when floating point operations are disabled, instead use progress_ppm.
- progress_ppm
- indicates the download progress of the peer in the range [0, 1000000] (parts per million).
- ip
- the IP-address to this peer. The type is an asio endpoint. For more info, see the asio documentation. This field is not valid for i2p peers. Instead use the i2p_destination() function.
- local_endpoint
- the IP and port pair the socket is bound to locally. i.e. the IP address of the interface it's going out over. This may be useful for multi-homed clients with multiple interfaces to the internet. This field is not valid for i2p peers.
- bw_idle
- The peer is not waiting for any external events to send or receive data.
- bw_limit
- The peer is waiting for the rate limiter.
- bw_network
- The peer has quota and is currently waiting for a network read or write operation to complete. This is the state all peers are in if there are no bandwidth limits.
- bw_disk
- The peer is waiting for the disk I/O thread to catch up writing buffers to disk before downloading more.
- read_state write_state
- bitmasks indicating what state this peer is in with regards to sending and receiving data. The states are defined as independent flags of type bandwidth_state_flags_t, in this class.
piece_block
Declared in "libtorrent/piece_block.hpp"
struct piece_block { piece_block () = default; piece_block (piece_index_t p_index, int b_index); bool operator< (piece_block const& b) const; bool operator== (piece_block const& b) const; bool operator!= (piece_block const& b) const; static const piece_block invalid; piece_index_t piece_index {0}; int block_index = 0; };[report issue]
version()
Declared in "libtorrent/version.hpp"
char const* version ();
returns the libtorrent version as string form in this format: "<major>.<minor>.<tiny>.<tag>"
[report issue]load_torrent_buffer() load_torrent_file() load_torrent_parsed()
Declared in "libtorrent/load_torrent.hpp"
add_torrent_params load_torrent_file ( std::string const& filename); add_torrent_params load_torrent_parsed ( bdecode_node const& torrent_file, load_torrent_limits const& cfg); add_torrent_params load_torrent_file ( std::string const& filename, load_torrent_limits const& cfg); add_torrent_params load_torrent_buffer ( span<char const> buffer); add_torrent_params load_torrent_buffer ( span<char const> buffer, load_torrent_limits const& cfg); add_torrent_params load_torrent_parsed ( bdecode_node const& torrent_file);
These functions load the content of a .torrent file into an add_torrent_params object. The immutable part of a torrent file (the info-dictionary) is stored in the ti field in the add_torrent_params object (as a torrent_info object). The returned object is suitable to be:
[report issue]
- added to a session via add_torrent() or async_add_torrent()
- saved as a .torrent_file via write_torrent_file()
- turned into a magnet link via make_magnet_uri()
torrent_peer_equal()
Declared in "libtorrent/torrent_peer.hpp"
inline bool torrent_peer_equal (torrent_peer const* lhs, torrent_peer const* rhs);[report issue]
truncate_files()
Declared in "libtorrent/truncate.hpp"
void truncate_files (file_storage const& fs, std::string const& save_path, storage_error& ec);
Truncates files larger than specified in the file_storage, saved under the specified save_path.
[report issue]make_magnet_uri()
Declared in "libtorrent/magnet_uri.hpp"
std::string make_magnet_uri (torrent_handle const& handle); std::string make_magnet_uri (torrent_info const& info); std::string make_magnet_uri (add_torrent_params const& atp);
Generates a magnet URI from the specified torrent.
Several fields from the add_torrent_params objects are recorded in the magnet link. In order to not include them, they have to be cleared before calling make_magnet_uri(). These fields are used:
ti, info_hashes, url_seeds, dht_nodes, file_priorities, trackers, name, peers.
Depending on what the use case for the resulting magnet link is, clearing peers and dht_nodes is probably a good idea if the add_torrent_params came from a running torrent. Those lists may be long and be ephemeral.
If none of the info_hashes or ti fields are set, there is not info-hash available, and a magnet link cannot be created. In this case make_magnet_uri() returns an empty string.
The recommended way to generate a magnet link from a torrent_handle is to call save_resume_data(), which will post a save_resume_data_alert containing an add_torrent_params object. This can then be passed to make_magnet_uri().
The overload that takes a torrent_handle will make blocking calls to query information about the torrent. If the torrent handle is invalid, an empty string is returned.
For more information about magnet links, see magnet links.
[report issue]parse_magnet_uri()
Declared in "libtorrent/magnet_uri.hpp"
void parse_magnet_uri (string_view uri, add_torrent_params& p, error_code& ec); add_torrent_params parse_magnet_uri (string_view uri); add_torrent_params parse_magnet_uri (string_view uri, error_code& ec);
This function parses out information from the magnet link and populates the add_torrent_params object. The overload that does not take an error_code reference will throw a system_error on error The overload taking an add_torrent_params reference will fill in the fields specified in the magnet URI.
[report issue]enum protocol_version
Declared in "libtorrent/info_hash.hpp"
name | value | description |
---|---|---|
V1 | 0 | The original BitTorrent version, using SHA-1 hashes |
V2 | 1 | Version 2 of the BitTorrent protocol, using SHA-256 hashes |
NUM | 2 |
enum event_t
Declared in "libtorrent/tracker_manager.hpp"
name | value | description |
---|---|---|
none | 0 | |
completed | 1 | |
started | 2 | |
stopped | 3 | |
paused | 4 |
enum socket_type_t
Declared in "libtorrent/socket_type.hpp"
name | value | description |
---|---|---|
tcp | 0 | |
socks5 | 1 | |
http | 2 | |
utp | 3 | |
i2p | 4 | |
tcp_ssl | 5 | |
socks5_ssl | 6 | |
http_ssl | 7 | |
utp_ssl | 8 |
enum portmap_transport
Declared in "libtorrent/portmap.hpp"
name | value | description |
---|---|---|
natpmp | 0 | natpmp can be NAT-PMP or PCP |
upnp | 1 |
enum portmap_protocol
Declared in "libtorrent/portmap.hpp"
name | value | description |
---|---|---|
none | 0 | |
tcp | 1 | |
udp | 2 |
enum connection_type
Declared in "libtorrent/peer_connection.hpp"
name | value | description |
---|---|---|
bittorrent | 0 | |
url_seed | 1 | |
http_seed | 2 |
download_priority_t
Declared in "libtorrent/download_priority.hpp"
- dont_download
- Don't download the file or piece. Partial pieces may still be downloaded when setting file priorities.
- default_priority
- The default priority for files and pieces.
- low_priority
- The lowest priority for files and pieces.
- top_priority
- The highest priority for files and pieces.
int
Declared in "libtorrent/version.hpp"
- version_major
- the major, minor and tiny versions of libtorrent
- version_minor
- the major, minor and tiny versions of libtorrent
- version_tiny
- the major, minor and tiny versions of libtorrent
char const*
Declared in "libtorrent/version.hpp"
- version_str
- the libtorrent version in string form
std::uint64_t
Declared in "libtorrent/version.hpp"
- version_revision
- the git commit of this libtorrent version
pex_flags_t
Declared in "libtorrent/pex_flags.hpp"
- pex_encryption
- the peer supports protocol encryption
- pex_seed
- the peer is a seed
- pex_utp
- the peer supports the uTP, transport protocol over UDP.
- pex_holepunch
- the peer supports the holepunch extension If this flag is received from a peer, it can be used as a rendezvous point in case direct connections to the peer fail
- pex_lt_v2
- protocol v2 this is not a standard flag, it is only used internally
torrent_flags_t
Declared in "libtorrent/torrent_flags.hpp"
- seed_mode
If seed_mode is set, libtorrent will assume that all files are present for this torrent and that they all match the hashes in the torrent file. Each time a peer requests to download a block, the piece is verified against the hash, unless it has been verified already. If a hash fails, the torrent will automatically leave the seed mode and recheck all the files. The use case for this mode is if a torrent is created and seeded, or if the user already know that the files are complete, this is a way to avoid the initial file checks, and significantly reduce the startup time.
Setting seed_mode on a torrent without metadata (a .torrent file) is a no-op and will be ignored.
It is not possible to set the seed_mode flag on a torrent after it has been added to a session. It is possible to clear it though.
- upload_mode
If upload_mode is set, the torrent will be initialized in upload-mode, which means it will not make any piece requests. This state is typically entered on disk I/O errors, and if the torrent is also auto managed, it will be taken out of this state periodically (see settings_pack::optimistic_disk_retry).
This mode can be used to avoid race conditions when adjusting priorities of pieces before allowing the torrent to start downloading.
If the torrent is auto-managed (auto_managed), the torrent will eventually be taken out of upload-mode, regardless of how it got there. If it's important to manually control when the torrent leaves upload mode, don't make it auto managed.
- share_mode
determines if the torrent should be added in share mode or not. Share mode indicates that we are not interested in downloading the torrent, but merely want to improve our share ratio (i.e. increase it). A torrent started in share mode will do its best to never download more than it uploads to the swarm. If the swarm does not have enough demand for upload capacity, the torrent will not download anything. This mode is intended to be safe to add any number of torrents to, without manual screening, without the risk of downloading more than is uploaded.
A torrent in share mode sets the priority to all pieces to 0, except for the pieces that are downloaded, when pieces are decided to be downloaded. This affects the progress bar, which might be set to "100% finished" most of the time. Do not change file or piece priorities for torrents in share mode, it will make it not work.
The share mode has one setting, the share ratio target, see settings_pack::share_mode_target for more info.
- apply_ip_filter
- determines if the IP filter should apply to this torrent or not. By default all torrents are subject to filtering by the IP filter (i.e. this flag is set by default). This is useful if certain torrents needs to be exempt for some reason, being an auto-update torrent for instance.
- paused
- specifies whether or not the torrent is paused. i.e. it won't connect to the tracker or any of the peers until it's resumed. Note that a paused torrent that also has the auto_managed flag set can be started at any time by libtorrent's queuing logic. See queuing.
- auto_managed
If the torrent is auto-managed (auto_managed), the torrent may be resumed at any point, regardless of how it paused. If it's important to manually control when the torrent is paused and resumed, don't make it auto managed.
If auto_managed is set, the torrent will be queued, started and seeded automatically by libtorrent. When this is set, the torrent should also be started as paused. The default queue order is the order the torrents were added. They are all downloaded in that order. For more details, see queuing.
- duplicate_is_error
- used in add_torrent_params to indicate that it's an error to attempt to add a torrent that's already in the session. If it's not considered an error, a handle to the existing torrent is returned. This flag is not saved by write_resume_data(), since it is only meant for adding torrents.
- update_subscribe
- on by default and means that this torrent will be part of state updates when calling post_torrent_updates(). This flag is not saved by write_resume_data().
- super_seeding
- sets the torrent into super seeding/initial seeding mode. If the torrent is not a seed, this flag has no effect.
- sequential_download
- sets the sequential download state for the torrent. In this mode the piece picker will pick pieces with low index numbers before pieces with high indices. The actual pieces that are picked depend on other factors still, such as which pieces a peer has and whether it is in parole mode or "prefer whole pieces"-mode. Sequential mode is not ideal for streaming media. For that, see set_piece_deadline() instead.
- stop_when_ready
When this flag is set, the torrent will force stop whenever it transitions from a non-data-transferring state into a data-transferring state (referred to as being ready to download or seed). This is useful for torrents that should not start downloading or seeding yet, but want to be made ready to do so. A torrent may need to have its files checked for instance, so it needs to be started and possibly queued for checking (auto-managed and started) but as soon as it's done, it should be stopped.
Force stopped means auto-managed is set to false and it's paused. As if the auto_manages flag is cleared and the paused flag is set on the torrent.
Note that the torrent may transition into a downloading state while setting this flag, and since the logic is edge triggered you may miss the edge. To avoid this race, if the torrent already is in a downloading state when this call is made, it will trigger the stop-when-ready immediately.
When the stop-when-ready logic fires, the flag is cleared. Any subsequent transitions between downloading and non-downloading states will not be affected, until this flag is set again.
The behavior is more robust when setting this flag as part of adding the torrent. See add_torrent_params.
The stop-when-ready flag fixes the inherent race condition of waiting for the state_changed_alert and then call pause(). The download/seeding will most likely start in between posting the alert and receiving the call to pause.
A downloading state is one where peers are being connected. Which means just downloading the metadata via the ut_metadata extension counts as a downloading state. In order to stop a torrent once the metadata has been downloaded, instead set all file priorities to dont_download
- override_trackers
- when this flag is set, the tracker list in the add_torrent_params object override any trackers from the torrent file. If the flag is not set, the trackers from the add_torrent_params object will be added to the list of trackers used by the torrent. This flag is set by read_resume_data() if there are trackers present in the resume data file. This effectively makes the trackers saved in the resume data take precedence over the original trackers. This includes if there's an empty list of trackers, to support the case where they were explicitly removed in the previous session. This flag is not saved by write_resume_data()
- override_web_seeds
- If this flag is set, the web seeds from the add_torrent_params object will override any web seeds in the torrent file. If it's not set, web seeds in the add_torrent_params object will be added to the list of web seeds used by the torrent. This flag is set by read_resume_data() if there are web seeds present in the resume data file. This effectively makes the web seeds saved in the resume data take precedence over the original ones. This includes if there's an empty list of web seeds, to support the case where they were explicitly removed in the previous session. This flag is not saved by write_resume_data()
- need_save_resume
if this flag is set (which it is by default) the torrent will be considered needing to save its resume data immediately, in the category if_metadata_changed. See resume_data_flags_t and save_resume_data() for details.
This flag is cleared by a successful call to save_resume_data() This flag is not saved by write_resume_data(), since it represents an ephemeral state of a running torrent.
- disable_dht
- set this flag to disable DHT for this torrent. This lets you have the DHT enabled for the whole client, and still have specific torrents not participating in it. i.e. not announcing to the DHT nor picking up peers from it.
- disable_lsd
- set this flag to disable local service discovery for this torrent.
- disable_pex
- set this flag to disable peer exchange for this torrent.
- no_verify_files
- if this flag is set, the resume data will be assumed to be correct without validating it against any files on disk. This may be used when restoring a session by loading resume data from disk. It will save time and also delay any hard disk errors until files are actually needed. If the resume data cannot be trusted, or if a torrent is added for the first time to some save path that may already have some of the files, this flag should not be set.
- default_dont_download
- default all file priorities to dont_download. This is useful for adding magnet links where the number of files is unknown, but the file_priorities is still set for some files. Any file not covered by the file_priorities list will be set to normal download priority, unless this flag is set, in which case they will be set to 0 (dont_download).
- i2p_torrent
- this flag makes the torrent be considered an "i2p torrent" for purposes of the allow_i2p_mixed setting. When mixing regular peers and i2p peers is disabled, i2p torrents won't add normal peers to its peer list. Note that non i2p torrents may still allow i2p peers (on the off-chance that a tracker return them and the session is configured with a SAM connection). This flag is set automatically when adding a torrent that has at least one tracker whose hostname ends with .i2p. It's also set by parse_magnet_uri() if the tracker list contains such URL.
- all
- all torrent flags combined. Can conveniently be used when creating masks for flags
peer_class_info
Declared in "libtorrent/peer_class.hpp"
holds settings for a peer class. Used in set_peer_class() and get_peer_class() calls.
struct peer_class_info { bool ignore_unchoke_slots; int connection_limit_factor; std::string label; int upload_limit; int download_limit; int upload_priority; int download_priority; };[report issue]
- ignore_unchoke_slots
- ignore_unchoke_slots determines whether peers should always unchoke a peer, regardless of the choking algorithm, or if it should honor the unchoke slot limits. It's used for local peers by default. If any of the peer classes a peer belongs to has this set to true, that peer will be unchoked at all times.
- connection_limit_factor
- adjusts the connection limit (global and per torrent) that applies to this peer class. By default, local peers are allowed to exceed the normal connection limit for instance. This is specified as a percent factor. 100 makes the peer class apply normally to the limit. 200 means as long as there are fewer connections than twice the limit, we accept this peer. This factor applies both to the global connection limit and the per-torrent limit. Note that if not used carefully one peer class can potentially completely starve out all other over time.
- label
- not used by libtorrent. It's intended as a potentially user-facing identifier of this peer class.
- upload_limit download_limit
- transfer rates limits for the whole peer class. They are specified in bytes per second and apply to the sum of all peers that are members of this class.
- upload_priority download_priority
- relative priorities used by the bandwidth allocator in the rate limiter. If no rate limits are in use, the priority is not used either. Priorities start at 1 (0 is not a valid priority) and may not exceed 255.
peer_class_type_filter
Declared in "libtorrent/peer_class_type_filter.hpp"
peer_class_type_filter is a simple container for rules for adding and subtracting peer-classes from peers. It is applied after the peer class filter is applied (which is based on the peer's IP address).
struct peer_class_type_filter { void remove (socket_type_t const st, peer_class_t const peer_class); void add (socket_type_t const st, peer_class_t const peer_class); void allow (socket_type_t const st, peer_class_t const peer_class); void disallow (socket_type_t const st, peer_class_t const peer_class); std::uint32_t apply (socket_type_t const st, std::uint32_t peer_class_mask); friend bool operator== (peer_class_type_filter const& lhs , peer_class_type_filter const& rhs); enum socket_type_t { tcp_socket, utp_socket, ssl_tcp_socket, ssl_utp_socket, i2p_socket, num_socket_types, }; };[report issue]
add() remove()
void remove (socket_type_t const st, peer_class_t const peer_class); void add (socket_type_t const st, peer_class_t const peer_class);
add() and remove() adds and removes a peer class to be added to new peers based on socket type.
[report issue]disallow() allow()
void allow (socket_type_t const st, peer_class_t const peer_class); void disallow (socket_type_t const st, peer_class_t const peer_class);
disallow() and allow() adds and removes a peer class to be removed from new peers based on socket type.
The peer_class argument cannot be greater than 31. The bitmasks representing peer classes in the peer_class_type_filter are 32 bits.
[report issue]apply()
std::uint32_t apply (socket_type_t const st, std::uint32_t peer_class_mask);
takes a bitmask of peer classes and returns a new bitmask of peer classes after the rules have been applied, based on the socket type argument (st).
[report issue]enum socket_type_t
Declared in "libtorrent/peer_class_type_filter.hpp"
name | value | description |
---|---|---|
tcp_socket | 0 | these match the socket types from socket_type.hpp shifted one down |
utp_socket | 1 | |
ssl_tcp_socket | 2 | |
ssl_utp_socket | 3 | |
i2p_socket | 4 | |
num_socket_types | 5 |
libtorrent has a plugin interface for implementing extensions to the protocol. These can be general extensions for transferring metadata or peer exchange extensions, or it could be used to provide a way to customize the protocol to fit a particular (closed) network.
In short, the plugin interface makes it possible to:
- register extension messages (sent in the extension handshake), see extensions.
- add data and parse data from the extension handshake.
- send extension messages and standard bittorrent messages.
- override or block the handling of standard bittorrent messages.
- save and restore state via the session state
- see all alerts that are posted
a word of caution
Writing your own plugin is a very easy way to introduce serious bugs such as dead locks and race conditions. Since a plugin has access to internal structures it is also quite easy to sabotage libtorrent's operation.
All the callbacks are always called from the libtorrent network thread. In case portions of your plugin are called from other threads, typically the main thread, you cannot use any of the member functions on the internal structures in libtorrent, since those require being called from the libtorrent network thread . Furthermore, you also need to synchronize your own shared data within the plugin, to make sure it is not accessed at the same time from the libtorrent thread (through a callback). If you need to send out a message from another thread, it is advised to use an internal queue, and do the actual sending in tick().
Since the plugin interface gives you easy access to internal structures, it is not supported as a stable API. Plugins should be considered specific to a specific version of libtorrent. Although, in practice the internals mostly don't change that dramatically.
plugin-interface
The plugin interface consists of three base classes that the plugin may implement. These are called plugin, torrent_plugin and peer_plugin. They are found in the <libtorrent/extensions.hpp> header.
These plugins are instantiated for each session, torrent and possibly each peer, respectively.
For plugins that only need per torrent state, it is enough to only implement torrent_plugin and pass a constructor function or function object to session::add_extension() or torrent_handle::add_extension() (if the torrent has already been started and you want to hook in the extension at run-time).
The signature of the function is:
std::shared_ptr<torrent_plugin> (*)(torrent_handle const&, client_data_t);
The second argument is the userdata passed to session::add_torrent() or torrent_handle::add_extension().
The function should return a std::shared_ptr<torrent_plugin> which may or may not be 0. If it is a nullptr, the extension is simply ignored for this torrent. If it is a valid pointer (to a class inheriting torrent_plugin), it will be associated with this torrent and callbacks will be made on torrent events.
For more elaborate plugins which require session wide state, you would implement plugin, construct an object (in a std::shared_ptr) and pass it in to session::add_extension().
custom alerts
Since plugins are running within internal libtorrent threads, one convenient way to communicate with the client is to post custom alerts.
The expected interface of any alert, apart from deriving from the alert base class, looks like this:
static const int alert_type = <unique alert ID>; virtual int type() const { return alert_type; } virtual std::string message() const; static const alert_category_t static_category = <bitmask of alert::category_t flags>; virtual alert_category_t category() const { return static_category; } virtual char const* what() const { return <string literal of the name of this alert>; }
The alert_type is used for the type-checking in alert_cast. It must not collide with any other alert. The built-in alerts in libtorrent will not use alert type IDs greater than user_alert_id. When defining your own alert, make sure it's greater than this constant.
type() is the run-time equivalence of the alert_type.
The message() virtual function is expected to construct a useful string representation of the alert and the event or data it represents. Something convenient to put in a log file for instance.
clone() is used internally to copy alerts. The suggested implementation of simply allocating a new instance as a copy of *this is all that's expected.
The static category is required for checking whether or not the category for a specific alert is enabled or not, without instantiating the alert. The category virtual function is the run-time equivalence.
The what() virtual function may simply be a string literal of the class name of your alert.
For more information, see the alert section.
[report issue]peer_connection_handle
Declared in "libtorrent/peer_connection_handle.hpp"
the peer_connection_handle class provides a handle to the internal peer connection object, to be used by plugins. This is a low level interface that may not be stable across libtorrent versions
struct peer_connection_handle { explicit peer_connection_handle (std::weak_ptr<peer_connection> impl); connection_type type () const; void add_extension (std::shared_ptr<peer_plugin>); peer_plugin const* find_plugin (string_view type) const; bool is_seed () const; bool upload_only () const; peer_id const& pid () const; bool has_piece (piece_index_t i) const; bool is_choked () const; bool is_interesting () const; bool is_peer_interested () const; bool has_peer_choked () const; void choke_this_peer (); void maybe_unchoke_this_peer (); void get_peer_info (peer_info& p) const; torrent_handle associated_torrent () const; tcp::endpoint const& remote () const; tcp::endpoint local_endpoint () const; void disconnect (error_code const& ec, operation_t op , disconnect_severity_t = peer_connection_interface::normal); bool is_outgoing () const; bool is_disconnecting () const; bool is_connecting () const; bool ignore_unchoke_slots () const; bool on_local_network () const; bool failed () const; bool should_log (peer_log_alert::direction_t direction) const; void peer_log (peer_log_alert::direction_t direction , char const* event, char const* fmt = "", ...) const TORRENT_FORMAT(4,5); bool can_disconnect (error_code const& ec) const; bool has_metadata () const; bool in_handshake () const; void send_buffer (char const* begin, int size); std::time_t last_seen_complete () const; time_point time_of_last_unchoke () const; bool operator< (peer_connection_handle const& o) const; bool operator!= (peer_connection_handle const& o) const; bool operator== (peer_connection_handle const& o) const; std::shared_ptr<peer_connection> native_handle () const; };[report issue]
bt_peer_connection_handle
Declared in "libtorrent/peer_connection_handle.hpp"
The bt_peer_connection_handle provides a handle to the internal bittorrent peer connection object to plugins. It's low level and may not be a stable API across libtorrent versions.
struct bt_peer_connection_handle : peer_connection_handle { explicit bt_peer_connection_handle (peer_connection_handle pc); bool packet_finished () const; bool support_extensions () const; bool supports_encryption () const; void switch_send_crypto (std::shared_ptr<crypto_plugin> crypto); void switch_recv_crypto (std::shared_ptr<crypto_plugin> crypto); std::shared_ptr<bt_peer_connection> native_handle () const; };[report issue]
plugin
Declared in "libtorrent/extensions.hpp"
this is the base class for a session plugin. One primary feature is that it is notified of all torrents that are added to the session, and can add its own torrent_plugins.
struct plugin { virtual feature_flags_t implemented_features (); virtual std::shared_ptr<torrent_plugin> new_torrent (torrent_handle const&, client_data_t); virtual void added (session_handle const&); virtual void abort (); virtual bool on_dht_request (string_view /* query */ , udp::endpoint const& /* source */, bdecode_node const& /* message */ , entry& /* response */); virtual void on_alert (alert const*); virtual bool on_unknown_torrent (info_hash_t const& /* info_hash */ , peer_connection_handle const& /* pc */, add_torrent_params& /* p */); virtual void on_tick (); virtual uint64_t get_unchoke_priority (peer_connection_handle const& /* peer */); virtual std::map<std::string, std::string> save_state () const; virtual void load_state (std::map<std::string, std::string> const&); static constexpr feature_flags_t optimistic_unchoke_feature = 1_bit; static constexpr feature_flags_t tick_feature = 2_bit; static constexpr feature_flags_t dht_request_feature = 3_bit; static constexpr feature_flags_t alert_feature = 4_bit; };[report issue]
implemented_features()
virtual feature_flags_t implemented_features ();
This function is expected to return a bitmask indicating which features this plugin implements. Some callbacks on this object may not be called unless the corresponding feature flag is returned here. Note that callbacks may still be called even if the corresponding feature is not specified in the return value here. See feature_flags_t for possible flags to return.
[report issue]new_torrent()
virtual std::shared_ptr<torrent_plugin> new_torrent (torrent_handle const&, client_data_t);
this is called by the session every time a new torrent is added. The torrent* points to the internal torrent object created for the new torrent. The client_data_t is the userdata pointer as passed in via add_torrent_params.
If the plugin returns a torrent_plugin instance, it will be added to the new torrent. Otherwise, return an empty shared_ptr to a torrent_plugin (the default).
[report issue]added()
virtual void added (session_handle const&);
called when plugin is added to a session
[report issue]abort()
virtual void abort ();
called when the session is aborted the plugin should perform any cleanup necessary to allow the session's destruction (e.g. cancel outstanding async operations)
[report issue]on_dht_request()
virtual bool on_dht_request (string_view /* query */ , udp::endpoint const& /* source */, bdecode_node const& /* message */ , entry& /* response */);
called when a dht request is received. If your plugin expects this to be called, make sure to include the flag dht_request_feature in the return value from implemented_features().
[report issue]on_alert()
virtual void on_alert (alert const*);
called when an alert is posted alerts that are filtered are not posted. If your plugin expects this to be called, make sure to include the flag alert_feature in the return value from implemented_features().
[report issue]on_unknown_torrent()
virtual bool on_unknown_torrent (info_hash_t const& /* info_hash */ , peer_connection_handle const& /* pc */, add_torrent_params& /* p */);
return true if the add_torrent_params should be added
[report issue]on_tick()
virtual void on_tick ();
called once per second. If your plugin expects this to be called, make sure to include the flag tick_feature in the return value from implemented_features().
[report issue]get_unchoke_priority()
virtual uint64_t get_unchoke_priority (peer_connection_handle const& /* peer */);
called when choosing peers to optimistically unchoke. The return value indicates the peer's priority for unchoking. Lower return values correspond to higher priority. Priorities above 2^63-1 are reserved. If your plugin has no priority to assign a peer it should return 2^64-1. If your plugin expects this to be called, make sure to include the flag optimistic_unchoke_feature in the return value from implemented_features(). If multiple plugins implement this function the lowest return value (i.e. the highest priority) is used.
[report issue]load_state()
virtual void load_state (std::map<std::string, std::string> const&);
called on startup while loading settings state from the session_params
[report issue]- optimistic_unchoke_feature
- include this bit if your plugin needs to alter the order of the optimistic unchoke of peers. i.e. have the on_optimistic_unchoke() callback be called.
- dht_request_feature
- include this bit if your plugin needs to have on_dht_request() called
- alert_feature
- include this bit if your plugin needs to have on_alert() called
torrent_plugin
Declared in "libtorrent/extensions.hpp"
Torrent plugins are associated with a single torrent and have a number of functions called at certain events. Many of its functions have the ability to change or override the default libtorrent behavior.
struct torrent_plugin { virtual std::shared_ptr<peer_plugin> new_connection (peer_connection_handle const&); virtual void on_piece_failed (piece_index_t); virtual void on_piece_pass (piece_index_t); virtual void tick (); virtual bool on_resume (); virtual bool on_pause (); virtual void on_files_checked (); virtual void on_state (torrent_status::state_t); virtual void on_add_peer (tcp::endpoint const&, peer_source_flags_t, add_peer_flags_t); static constexpr add_peer_flags_t first_time = 1_bit; static constexpr add_peer_flags_t filtered = 2_bit; };[report issue]
new_connection()
virtual std::shared_ptr<peer_plugin> new_connection (peer_connection_handle const&);
This function is called each time a new peer is connected to the torrent. You may choose to ignore this by just returning a default constructed shared_ptr (in which case you don't need to override this member function).
If you need an extension to the peer connection (which most plugins do) you are supposed to return an instance of your peer_plugin class. Which in turn will have its hook functions called on event specific to that peer.
The peer_connection_handle will be valid as long as the shared_ptr is being held by the torrent object. So, it is generally a good idea to not keep a shared_ptr to your own peer_plugin. If you want to keep references to it, use weak_ptr.
If this function throws an exception, the connection will be closed.
[report issue]on_piece_failed() on_piece_pass()
virtual void on_piece_failed (piece_index_t); virtual void on_piece_pass (piece_index_t);
These hooks are called when a piece passes the hash check or fails the hash check, respectively. The index is the piece index that was downloaded. It is possible to access the list of peers that participated in sending the piece through the torrent and the piece_picker.
[report issue]tick()
virtual void tick ();
This hook is called approximately once per second. It is a way of making it easy for plugins to do timed events, for sending messages or whatever.
[report issue]on_pause() on_resume()
virtual bool on_resume (); virtual bool on_pause ();
These hooks are called when the torrent is paused and resumed respectively. The return value indicates if the event was handled. A return value of true indicates that it was handled, and no other plugin after this one will have this hook function called, and the standard handler will also not be invoked. So, returning true effectively overrides the standard behavior of pause or resume.
Note that if you call pause() or resume() on the torrent from your handler it will recurse back into your handler, so in order to invoke the standard handler, you have to keep your own state on whether you want standard behavior or overridden behavior.
[report issue]on_files_checked()
virtual void on_files_checked ();
This function is called when the initial files of the torrent have been checked. If there are no files to check, this function is called immediately.
i.e. This function is always called when the torrent is in a state where it can start downloading.
[report issue]on_state()
virtual void on_state (torrent_status::state_t);
called when the torrent changes state the state is one of torrent_status::state_t enum members
[report issue]on_add_peer()
virtual void on_add_peer (tcp::endpoint const&, peer_source_flags_t, add_peer_flags_t);
called every time a new peer is added to the peer list. This is before the peer is connected to. For flags, see torrent_plugin::flags_t. The source argument refers to the source where we learned about this peer from. It's a bitmask, because many sources may have told us about the same peer. For peer source flags, see peer_info::peer_source_flags.
[report issue]- first_time
- this is the first time we see this peer
- filtered
- this peer was not added because it was filtered by the IP filter
peer_plugin
Declared in "libtorrent/extensions.hpp"
peer plugins are associated with a specific peer. A peer could be both a regular bittorrent peer (bt_peer_connection) or one of the web seed connections (web_peer_connection or http_seed_connection). In order to only attach to certain peers, make your torrent_plugin::new_connection only return a plugin for certain peer connection types
struct peer_plugin { virtual string_view type () const; virtual void add_handshake (entry&); virtual void on_disconnect (error_code const&); virtual void on_connected (); virtual bool on_handshake (span<char const>); virtual bool on_extension_handshake (bdecode_node const&); virtual bool on_dont_have (piece_index_t); virtual bool on_not_interested (); virtual bool on_request (peer_request const&); virtual bool on_choke (); virtual bool on_interested (); virtual bool on_allowed_fast (piece_index_t); virtual bool on_have_all (); virtual bool on_have (piece_index_t); virtual bool on_unchoke (); virtual bool on_bitfield (bitfield const& /*bitfield*/); virtual bool on_have_none (); virtual bool on_piece (peer_request const& /*piece*/ , span<char const> /*buf*/); virtual bool on_reject (peer_request const&); virtual bool on_suggest (piece_index_t); virtual bool on_cancel (peer_request const&); virtual void sent_request (peer_request const&); virtual void sent_suggest (piece_index_t); virtual void sent_reject_request (peer_request const&); virtual void sent_choke (); virtual void sent_have_none (); virtual void sent_allow_fast (piece_index_t); virtual void sent_have_all (); virtual void sent_cancel (peer_request const&); virtual void sent_piece (peer_request const&); virtual void sent_have (piece_index_t); virtual void sent_not_interested (); virtual void sent_unchoke (); virtual void sent_interested (); virtual void sent_payload (int /* bytes */); virtual bool can_disconnect (error_code const& /*ec*/); virtual bool on_extended (int /*length*/, int /*msg*/, span<char const> /*body*/); virtual bool on_unknown_message (int /*length*/, int /*msg*/, span<char const> /*body*/); virtual void on_piece_failed (piece_index_t); virtual void on_piece_pass (piece_index_t); virtual void tick (); virtual bool write_request (peer_request const&); };[report issue]
type()
virtual string_view type () const;
This function is expected to return the name of the plugin.
[report issue]add_handshake()
virtual void add_handshake (entry&);
can add entries to the extension handshake this is not called for web seeds
[report issue]on_disconnect()
virtual void on_disconnect (error_code const&);
called when the peer is being disconnected.
[report issue]on_connected()
virtual void on_connected ();
called when the peer is successfully connected. Note that incoming connections will have been connected by the time the peer plugin is attached to it, and won't have this hook called.
[report issue]on_handshake()
virtual bool on_handshake (span<char const>);
this is called when the initial bittorrent handshake is received. Returning false means that the other end doesn't support this extension and will remove it from the list of plugins. this is not called for web seeds
[report issue]on_extension_handshake()
virtual bool on_extension_handshake (bdecode_node const&);
called when the extension handshake from the other end is received if this returns false, it means that this extension isn't supported by this peer. It will result in this peer_plugin being removed from the peer_connection and destructed. this is not called for web seeds
[report issue]on_not_interested() on_interested() on_have_all() on_dont_have() on_bitfield() on_request() on_allowed_fast() on_choke() on_have() on_have_none() on_unchoke()
virtual bool on_dont_have (piece_index_t); virtual bool on_not_interested (); virtual bool on_request (peer_request const&); virtual bool on_choke (); virtual bool on_interested (); virtual bool on_allowed_fast (piece_index_t); virtual bool on_have_all (); virtual bool on_have (piece_index_t); virtual bool on_unchoke (); virtual bool on_bitfield (bitfield const& /*bitfield*/); virtual bool on_have_none ();
returning true from any of the message handlers indicates that the plugin has handled the message. it will break the plugin chain traversing and not let anyone else handle the message, including the default handler.
[report issue]on_piece()
virtual bool on_piece (peer_request const& /*piece*/ , span<char const> /*buf*/);
This function is called when the peer connection is receiving a piece. buf points (non-owning pointer) to the data in an internal immutable disk buffer. The length of the data is specified in the length member of the piece parameter. returns true to indicate that the piece is handled and the rest of the logic should be ignored.
[report issue]sent_have() sent_piece() sent_not_interested() sent_interested() sent_unchoke()
virtual void sent_piece (peer_request const&); virtual void sent_have (piece_index_t); virtual void sent_not_interested (); virtual void sent_unchoke (); virtual void sent_interested ();
called after a choke message has been sent to the peer
[report issue]sent_payload()
virtual void sent_payload (int /* bytes */);
called after piece data has been sent to the peer this can be used for stats book keeping
[report issue]can_disconnect()
virtual bool can_disconnect (error_code const& /*ec*/);
called when libtorrent think this peer should be disconnected. if the plugin returns false, the peer will not be disconnected.
[report issue]on_extended()
virtual bool on_extended (int /*length*/, int /*msg*/, span<char const> /*body*/);
called when an extended message is received. If returning true, the message is not processed by any other plugin and if false is returned the next plugin in the chain will receive it to be able to handle it. This is not called for web seeds. thus function may be called more than once per incoming message, but only the last of the calls will the body size equal the length. i.e. Every time another fragment of the message is received, this function will be called, until finally the whole message has been received. The purpose of this is to allow early disconnects for invalid messages and for reporting progress of receiving large messages.
[report issue]on_unknown_message()
virtual bool on_unknown_message (int /*length*/, int /*msg*/, span<char const> /*body*/);
this is not called for web seeds
[report issue]on_piece_failed() on_piece_pass()
virtual void on_piece_failed (piece_index_t); virtual void on_piece_pass (piece_index_t);
called when a piece that this peer participated in either fails or passes the hash_check
[report issue]write_request()
virtual bool write_request (peer_request const&);
called each time a request message is to be sent. If true is returned, the original request message won't be sent and no other plugin will have this function called.
[report issue]crypto_plugin
Declared in "libtorrent/extensions.hpp"
struct crypto_plugin { virtual void set_incoming_key (span<char const> key) = 0; virtual void set_outgoing_key (span<char const> key) = 0; encrypt (span<span<char>> /*send_vec*/) = 0; virtual std::tuple<int, int, int> decrypt (span<span<char>> /*receive_vec*/) = 0; };[report issue]
decrypt()
virtual std::tuple<int, int, int> decrypt (span<span<char>> /*receive_vec*/) = 0;
decrypt the provided buffers. returns is a tuple representing the values (consume, produce, packet_size)
consume is set to the number of bytes which should be trimmed from the head of the buffers, default is 0
produce is set to the number of bytes of payload which are now ready to be sent to the upper layer. default is the number of bytes passed in receive_vec
packet_size is set to the minimum number of bytes which must be read to advance the next step of decryption. default is 0
[report issue]create_ut_metadata_plugin()
Declared in "libtorrent/extensions/ut_metadata.hpp"
std::shared_ptr<torrent_plugin> create_ut_metadata_plugin (torrent_handle const&, client_data_t);
constructor function for the ut_metadata extension. The ut_metadata extension allows peers to request the .torrent file (or more specifically the info-dictionary of the .torrent file) from each other. This is the main building block in making magnet links work. This extension is enabled by default unless explicitly disabled in the session constructor.
This can either be passed in the add_torrent_params::extensions field, or via torrent_handle::add_extension().
[report issue]create_smart_ban_plugin()
Declared in "libtorrent/extensions/smart_ban.hpp"
std::shared_ptr<torrent_plugin> create_smart_ban_plugin (torrent_handle const&, client_data_t);
constructor function for the smart ban extension. The extension keeps track of the data peers have sent us for failing pieces and once the piece completes and passes the hash check bans the peers that turned out to have sent corrupt data. This function can either be passed in the add_torrent_params::extensions field, or via torrent_handle::add_extension().
[report issue]create_ut_pex_plugin()
Declared in "libtorrent/extensions/ut_pex.hpp"
std::shared_ptr<torrent_plugin> create_ut_pex_plugin (torrent_handle const&, client_data_t);
constructor function for the ut_pex extension. The ut_pex extension allows peers to gossip about their connections, allowing the swarm stay well connected and peers aware of more peers in the swarm. This extension is enabled by default unless explicitly disabled in the session constructor.
This can either be passed in the add_torrent_params::extensions field, or via torrent_handle::add_extension().
[report issue]client_data_t
Declared in "libtorrent/client_data.hpp"
A thin wrapper around a void pointer used as "user data". i.e. an opaque cookie passed in to libtorrent and returned on demand. It adds type-safety by requiring the same type be requested out of it as was assigned to it.
struct client_data_t { client_data_t () = default; explicit client_data_t (T* v); client_data_t& operator= (T* v); explicit operator T () const; T* get () const; client_data_t& operator= (void const*) = delete; client_data_t& operator= (void*) = delete; operator void* () const = delete; operator void const* () const = delete; template <typename T, typename U = typename std::enable_if<std::is_pointer<T>::value>::type> };[report issue]
operator=() void*() const*()
client_data_t& operator= (void const*) = delete; client_data_t& operator= (void*) = delete; operator void* () const = delete; operator void const* () const = delete;
we don't allow type-unsafe operations
[report issue]add_torrent_params
Declared in "libtorrent/add_torrent_params.hpp"
The add_torrent_params contains all the information in a .torrent file along with all information necessary to add that torrent to a session. The key fields when adding a torrent are:
- ti - the immutable info-dict part of the torrent
- info_hash - when you don't have the metadata (.torrent file). This uniquely identifies the torrent and can validate the info-dict when received from the swarm.
In order to add a torrent to a session, one of those fields must be set in addition to save_path. The add_torrent_params object can then be passed into one of the session::add_torrent() overloads or session::async_add_torrent().
If you only specify the info-hash, the torrent file will be downloaded from peers, which requires them to support the metadata extension. For the metadata extension to work, libtorrent must be built with extensions enabled (TORRENT_DISABLE_EXTENSIONS must not be defined). It also takes an optional name argument. This may be left empty in case no name should be assigned to the torrent. In case it's not, the name is used for the torrent as long as it doesn't have metadata. See torrent_handle::name.
The add_torrent_params is also used when requesting resume data for a torrent. It can be saved to and restored from a file and added back to a new session. For serialization and de-serialization of add_torrent_params objects, see read_resume_data() and write_resume_data().
The add_torrent_params is also used to represent a parsed .torrent file. It can be loaded via load_torrent_file(), load_torrent_buffer() and load_torrent_parsed(). It can be saved via write_torrent_file().
struct add_torrent_params { int version = LIBTORRENT_VERSION_NUM; std::shared_ptr<torrent_info> ti; aux::noexcept_movable<std::vector<std::string>> trackers; aux::noexcept_movable<std::vector<int>> tracker_tiers; aux::noexcept_movable<std::vector<std::pair<std::string, int>>> dht_nodes; std::string name; std::string save_path; storage_mode_t storage_mode = storage_mode_sparse; client_data_t userdata; aux::noexcept_movable<std::vector<download_priority_t>> file_priorities; std::string trackerid; torrent_flags_t flags = torrent_flags::default_flags; info_hash_t info_hashes; int max_uploads = -1; int max_connections = -1; int upload_limit = -1; int download_limit = -1; std::int64_t total_uploaded = 0; std::int64_t total_downloaded = 0; int active_time = 0; int finished_time = 0; int seeding_time = 0; std::time_t added_time = 0; std::time_t completed_time = 0; std::time_t last_seen_complete = 0; int num_complete = -1; int num_incomplete = -1; int num_downloaded = -1; aux::noexcept_movable<std::vector<std::string>> http_seeds; aux::noexcept_movable<std::vector<std::string>> url_seeds; aux::noexcept_movable<std::vector<tcp::endpoint>> peers; aux::noexcept_movable<std::vector<tcp::endpoint>> banned_peers; aux::noexcept_movable<std::map<piece_index_t, bitfield>> unfinished_pieces; typed_bitfield<piece_index_t> have_pieces; typed_bitfield<piece_index_t> verified_pieces; aux::noexcept_movable<std::vector<download_priority_t>> piece_priorities; aux::vector<std::vector<sha256_hash>, file_index_t> merkle_trees; aux::vector<std::vector<bool>, file_index_t> merkle_tree_mask; aux::vector<std::vector<bool>, file_index_t> verified_leaf_hashes; aux::noexcept_movable<std::map<file_index_t, std::string>> renamed_files; std::time_t last_download = 0; std::time_t last_upload = 0; };[report issue]
- version
- filled in by the constructor and should be left untouched. It is used for forward binary compatibility.
- ti
- torrent_info object with the torrent to add. Unless the info_hash is set, this is required to be initialized.
- trackers
- If the torrent doesn't have a tracker, but relies on the DHT to find peers, the trackers can specify tracker URLs for the torrent.
- tracker_tiers
- the tiers the URLs in trackers belong to. Trackers belonging to different tiers may be treated differently, as defined by the multi tracker extension. This is optional, if not specified trackers are assumed to be part of tier 0, or whichever the last tier was as iterating over the trackers.
- dht_nodes
- a list of hostname and port pairs, representing DHT nodes to be added to the session (if DHT is enabled). The hostname may be an IP address.
- name
- in case there's no other name in this torrent, this name will be used. The name out of the torrent_info object takes precedence if available.
- save_path
the path where the torrent is or will be stored.
Note
On windows this path (and other paths) are interpreted as UNC paths. This means they must use backslashes as directory separators and may not contain the special directories "." or "..".
Setting this to an absolute path performs slightly better than a relative path.
- storage_mode
- One of the values from storage_mode_t. For more information, see storage allocation.
- userdata
- The userdata parameter is optional and will be passed on to the extension constructor functions, if any (see torrent_handle::add_extension()). It will also be stored in the torrent object and can be retrieved by calling userdata().
- file_priorities
- can be set to control the initial file priorities when adding a torrent. The semantics are the same as for torrent_handle::prioritize_files(). The file priorities specified in here take precedence over those specified in the resume data, if any. If this vector of file priorities is shorter than the number of files in the torrent, the remaining files (not covered by this) will still have the default download priority. This default can be changed by setting the default_dont_download torrent_flag.
- trackerid
- the default tracker id to be used when announcing to trackers. By default this is empty, and no tracker ID is used, since this is an optional argument. If a tracker returns a tracker ID, that ID is used instead of this.
- flags
flags controlling aspects of this torrent and how it's added. See torrent_flags_t for details.
Note
The flags field is initialized with default flags by the constructor. In order to preserve default behavior when clearing or setting other flags, make sure to bitwise OR or in a flag or bitwise AND the inverse of a flag to clear it.
- info_hashes
- set this to the info hash of the torrent to add in case the info-hash is the only known property of the torrent. i.e. you don't have a .torrent file nor a magnet link. To add a magnet link, use parse_magnet_uri() to populate fields in the add_torrent_params object.
- max_uploads max_connections
max_uploads, max_connections, upload_limit, download_limit correspond to the set_max_uploads(), set_max_connections(), set_upload_limit() and set_download_limit() functions on torrent_handle. These values let you initialize these settings when the torrent is added, instead of calling these functions immediately following adding it.
-1 means unlimited on these settings just like their counterpart functions on torrent_handle
For fine grained control over rate limits, including making them apply to local peers, see peer classes.
- upload_limit download_limit
- the upload and download rate limits for this torrent, specified in bytes per second. -1 means unlimited.
- total_uploaded total_downloaded
- the total number of bytes uploaded and downloaded by this torrent so far.
- active_time finished_time seeding_time
- the number of seconds this torrent has spent in started, finished and seeding state so far, respectively.
- added_time completed_time
- if set to a non-zero value, this is the posix time of when this torrent was first added, including previous runs/sessions. If set to zero, the internal added_time will be set to the time of when add_torrent() is called.
- last_seen_complete
- if set to non-zero, initializes the time (expressed in posix time) when we last saw a seed or peers that together formed a complete copy of the torrent. If left set to zero, the internal counterpart to this field will be updated when we see a seed or a distributed copies >= 1.0.
- num_complete num_incomplete num_downloaded
these field can be used to initialize the torrent's cached scrape data. The scrape data is high level metadata about the current state of the swarm, as returned by the tracker (either when announcing to it or by sending a specific scrape request). num_complete is the number of peers in the swarm that are seeds, or have every piece in the torrent. num_incomplete is the number of peers in the swarm that do not have every piece. num_downloaded is the number of times the torrent has been downloaded (not initiated, but the number of times a download has completed).
Leaving any of these values set to -1 indicates we don't know, or we have not received any scrape data.
- http_seeds url_seeds
URLs can be added to these two lists to specify additional web seeds to be used by the torrent. If the flag_override_web_seeds is set, these will be the _only_ ones to be used. i.e. any web seeds found in the .torrent file will be overridden.
http_seeds expects URLs to web servers implementing the original HTTP seed specification BEP 17.
url_seeds expects URLs to regular web servers, aka "get right" style, specified in BEP 19.
- peers
- peers to add to the torrent, to be tried to be connected to as bittorrent peers.
- banned_peers
- peers banned from this torrent. The will not be connected to
- unfinished_pieces
- this is a map of partially downloaded piece. The key is the piece index and the value is a bitfield where each bit represents a 16 kiB block. A set bit means we have that block.
- have_pieces
- this is a bitfield indicating which pieces we already have of this torrent.
- verified_pieces
- when in seed_mode, pieces with a set bit in this bitfield have been verified to be valid. Other pieces will be verified the first time a peer requests it.
- piece_priorities
- this sets the priorities for each individual piece in the torrent. Each element in the vector represent the piece with the same index. If you set both file- and piece priorities, file priorities will take precedence.
- merkle_trees
- v2 hashes, if known
- merkle_tree_mask
- if set, indicates which hashes are included in the corresponding vector of merkle_trees. These bitmasks always cover the full tree, a cleared bit means the hash is all zeros (i.e. not set) and set bit means the next hash in the corresponding vector in merkle_trees is the hash for that node. This is an optimization to avoid storing a lot of zeros.
- verified_leaf_hashes
- bit-fields indicating which v2 leaf hashes have been verified against the root hash. If this vector is empty and merkle_trees is non-empty it implies that all hashes in merkle_trees are verified.
- renamed_files
- this is a map of file indices in the torrent and new filenames to be applied before the torrent is added.
- last_download last_upload
- the posix time of the last time payload was received or sent for this torrent, respectively. A value of 0 means we don't know when we last uploaded or downloaded, or we have never uploaded or downloaded any payload for this torrent.
announce_infohash
Declared in "libtorrent/announce_entry.hpp"
struct announce_infohash { std::string message; error_code last_error; int scrape_incomplete = -1; int scrape_complete = -1; int scrape_downloaded = -1; std::uint8_t fails : 7; bool updating : 1; bool start_sent : 1; bool complete_sent : 1; };[report issue]
- message
- if this tracker has returned an error or warning message that message is stored here
- last_error
- if this tracker failed the last time it was contacted this error code specifies what error occurred
- scrape_incomplete scrape_complete scrape_downloaded
- if this tracker has returned scrape data, these fields are filled in with valid numbers. Otherwise they are set to -1. incomplete counts the number of current downloaders. complete counts the number of current peers completed the download, or "seeds". downloaded is the cumulative number of completed downloads.
- fails
- the number of times in a row we have failed to announce to this tracker.
- updating
- true while we're waiting for a response from the tracker.
- start_sent
- set to true when we get a valid response from an announce with event=started. If it is set, we won't send start in the subsequent announces.
- complete_sent
- set to true when we send a event=completed.
announce_endpoint
Declared in "libtorrent/announce_entry.hpp"
announces are sent to each tracker using every listen socket this class holds information about one listen socket for one tracker
struct announce_endpoint { announce_endpoint (); tcp::endpoint local_endpoint; aux::array<announce_infohash, num_protocols, protocol_version> info_hashes; bool enabled = true; };[report issue]
- local_endpoint
- the local endpoint of the listen interface associated with this endpoint
- info_hashes
- info_hashes[0] is the v1 info hash (SHA1) info_hashes[1] is the v2 info hash (truncated SHA-256)
- enabled
- set to false to not announce from this endpoint
announce_entry
Declared in "libtorrent/announce_entry.hpp"
this class holds information about one bittorrent tracker, as it relates to a specific torrent.
struct announce_entry { ~announce_entry (); announce_entry& operator= (announce_entry const&) &; explicit announce_entry (string_view u); announce_entry (announce_entry const&); announce_entry (); enum tracker_source { source_torrent, source_client, source_magnet_link, source_tex, }; std::string url; std::string trackerid; std::vector<announce_endpoint> endpoints; std::uint8_t tier = 0; std::uint8_t fail_limit = 0; std::uint8_t source:4; bool verified:1; };[report issue]
announce_entry() operator=() ~announce_entry()
~announce_entry (); announce_entry& operator= (announce_entry const&) &; explicit announce_entry (string_view u); announce_entry (announce_entry const&); announce_entry ();
constructs a tracker announce entry with u as the URL.
[report issue]enum tracker_source
Declared in "libtorrent/announce_entry.hpp"
name | value | description |
---|---|---|
source_torrent | 1 | the tracker was part of the .torrent file |
source_client | 2 | the tracker was added programmatically via the add_tracker() function |
source_magnet_link | 4 | the tracker was part of a magnet link |
source_tex | 8 | the tracker was received from the swarm via tracker exchange |
- url
- tracker URL as it appeared in the torrent file
- trackerid
- the current &trackerid= argument passed to the tracker. this is optional and is normally empty (in which case no trackerid is sent).
- endpoints
- each local listen socket (endpoint) will announce to the tracker. This list contains state per endpoint.
- tier
- the tier this tracker belongs to
- fail_limit
- the max number of failures to announce to this tracker in a row, before this tracker is not used anymore. 0 means unlimited
- source
- a bitmask specifying which sources we got this tracker from.
- verified
- set to true the first time we receive a valid response from this tracker.
The disk I/O can be customized in libtorrent. In previous versions, the customization was at the level of each torrent. Now, the customization point is at the session level. All torrents added to a session will use the same disk I/O subsystem, as determined by the disk_io_constructor (in session_params).
This allows the disk subsystem to also customize threading and disk job management.
To customize the disk subsystem, implement disk_interface and provide a factory function to the session constructor (via session_params).
Example use:
struct temp_storage { explicit temp_storage(lt::file_storage const& fs) : m_files(fs) {} lt::span<char const> readv(lt::peer_request const r, lt::storage_error& ec) const { auto const i = m_file_data.find(r.piece); if (i == m_file_data.end()) { ec.operation = lt::operation_t::file_read; ec.ec = boost::asio::error::eof; return {}; } if (int(i->second.size()) <= r.start) { ec.operation = lt::operation_t::file_read; ec.ec = boost::asio::error::eof; return {}; } return { i->second.data() + r.start, std::min(r.length, int(i->second.size()) - r.start) }; } void writev(lt::span<char const> const b, lt::piece_index_t const piece, int const offset) { auto& data = m_file_data[piece]; if (data.empty()) { // allocate the whole piece, otherwise we'll invalidate the pointers // we have returned back to libtorrent int const size = piece_size(piece); data.resize(std::size_t(size)); } TORRENT_ASSERT(offset + b.size() <= int(data.size())); std::memcpy(data.data() + offset, b.data(), std::size_t(b.size())); } lt::sha1_hash hash(lt::piece_index_t const piece , lt::span<lt::sha256_hash> const block_hashes, lt::storage_error& ec) const { auto const i = m_file_data.find(piece); if (i == m_file_data.end()) { ec.operation = lt::operation_t::file_read; ec.ec = boost::asio::error::eof; return {}; } if (!block_hashes.empty()) { int const piece_size2 = m_files.piece_size2(piece); int const blocks_in_piece2 = m_files.blocks_in_piece2(piece); char const* buf = i->second.data(); std::int64_t offset = 0; for (int k = 0; k < blocks_in_piece2; ++k) { lt::hasher256 h2; std::ptrdiff_t const len2 = std::min(lt::default_block_size, int(piece_size2 - offset)); h2.update({ buf, len2 }); buf += len2; offset += len2; block_hashes[k] = h2.final(); } } return lt::hasher(i->second).final(); } lt::sha256_hash hash2(lt::piece_index_t const piece, int const offset, lt::storage_error& ec) { auto const i = m_file_data.find(piece); if (i == m_file_data.end()) { ec.operation = lt::operation_t::file_read; ec.ec = boost::asio::error::eof; return {}; } int const piece_size = m_files.piece_size2(piece); std::ptrdiff_t const len = std::min(lt::default_block_size, piece_size - offset); lt::span<char const> b = {i->second.data() + offset, len}; return lt::hasher256(b).final(); } private: int piece_size(lt::piece_index_t piece) const { int const num_pieces = static_cast<int>((m_files.total_size() + m_files.piece_length() - 1) / m_files.piece_length()); return static_cast<int>(piece) < num_pieces - 1 ? m_files.piece_length() : static_cast<int>(m_files.total_size() - std::int64_t(num_pieces - 1) * m_files.piece_length()); } lt::file_storage const& m_files; std::map<lt::piece_index_t, std::vector<char>> m_file_data; }; lt::storage_index_t pop(std::vector<lt::storage_index_t>& q) { TORRENT_ASSERT(!q.empty()); lt::storage_index_t const ret = q.back(); q.pop_back(); return ret; } struct temp_disk_io final : lt::disk_interface , lt::buffer_allocator_interface { explicit temp_disk_io(lt::io_context& ioc): m_ioc(ioc) {} void settings_updated() override {} lt::storage_holder new_torrent(lt::storage_params const& params , std::shared_ptr<void> const&) override { lt::storage_index_t const idx = m_free_slots.empty() ? m_torrents.end_index() : pop(m_free_slots); auto storage = std::make_unique<temp_storage>(params.files); if (idx == m_torrents.end_index()) m_torrents.emplace_back(std::move(storage)); else m_torrents[idx] = std::move(storage); return lt::storage_holder(idx, *this); } void remove_torrent(lt::storage_index_t const idx) override { m_torrents[idx].reset(); m_free_slots.push_back(idx); } void abort(bool) override {} void async_read(lt::storage_index_t storage, lt::peer_request const& r , std::function<void(lt::disk_buffer_holder block, lt::storage_error const& se)> handler , lt::disk_job_flags_t) override { // this buffer is owned by the storage. It will remain valid for as // long as the torrent remains in the session. We don't need any lifetime // management of it. lt::storage_error error; lt::span<char const> b = m_torrents[storage]->readv(r, error); post(m_ioc, [handler, error, b, this] { handler(lt::disk_buffer_holder(*this, const_cast<char*>(b.data()), int(b.size())), error); }); } bool async_write(lt::storage_index_t storage, lt::peer_request const& r , char const* buf, std::shared_ptr<lt::disk_observer> , std::function<void(lt::storage_error const&)> handler , lt::disk_job_flags_t) override { lt::span<char const> const b = { buf, r.length }; m_torrents[storage]->writev(b, r.piece, r.start); post(m_ioc, [=]{ handler(lt::storage_error()); }); return false; } void async_hash(lt::storage_index_t storage, lt::piece_index_t const piece , lt::span<lt::sha256_hash> block_hashes, lt::disk_job_flags_t , std::function<void(lt::piece_index_t, lt::sha1_hash const&, lt::storage_error const&)> handler) override { lt::storage_error error; lt::sha1_hash const hash = m_torrents[storage]->hash(piece, block_hashes, error); post(m_ioc, [=]{ handler(piece, hash, error); }); } void async_hash2(lt::storage_index_t storage, lt::piece_index_t const piece , int const offset, lt::disk_job_flags_t , std::function<void(lt::piece_index_t, lt::sha256_hash const&, lt::storage_error const&)> handler) override { lt::storage_error error; lt::sha256_hash const hash = m_torrents[storage]->hash2(piece, offset, error); post(m_ioc, [=]{ handler(piece, hash, error); }); } void async_move_storage(lt::storage_index_t, std::string p, lt::move_flags_t , std::function<void(lt::status_t, std::string const&, lt::storage_error const&)> handler) override { post(m_ioc, [=]{ handler(lt::status_t::fatal_disk_error, p , lt::storage_error(lt::error_code(boost::system::errc::operation_not_supported, lt::system_category()))); }); } void async_release_files(lt::storage_index_t, std::function<void()>) override {} void async_delete_files(lt::storage_index_t, lt::remove_flags_t , std::function<void(lt::storage_error const&)> handler) override { post(m_ioc, [=]{ handler(lt::storage_error()); }); } void async_check_files(lt::storage_index_t , lt::add_torrent_params const* , lt::aux::vector<std::string, lt::file_index_t> , std::function<void(lt::status_t, lt::storage_error const&)> handler) override { post(m_ioc, [=]{ handler(lt::status_t::no_error, lt::storage_error()); }); } void async_rename_file(lt::storage_index_t , lt::file_index_t const idx , std::string const name , std::function<void(std::string const&, lt::file_index_t, lt::storage_error const&)> handler) override { post(m_ioc, [=]{ handler(name, idx, lt::storage_error()); }); } void async_stop_torrent(lt::storage_index_t, std::function<void()> handler) override { post(m_ioc, handler); } void async_set_file_priority(lt::storage_index_t , lt::aux::vector<lt::download_priority_t, lt::file_index_t> prio , std::function<void(lt::storage_error const& , lt::aux::vector<lt::download_priority_t, lt::file_index_t>)> handler) override { post(m_ioc, [=]{ handler(lt::storage_error(lt::error_code( boost::system::errc::operation_not_supported, lt::system_category())), std::move(prio)); }); } void async_clear_piece(lt::storage_index_t, lt::piece_index_t index , std::function<void(lt::piece_index_t)> handler) override { post(m_ioc, [=]{ handler(index); }); } // implements buffer_allocator_interface void free_disk_buffer(char*) override { // never free any buffer. We only return buffers owned by the storage // object } void update_stats_counters(lt::counters&) const override {} std::vector<lt::open_file_state> get_status(lt::storage_index_t) const override { return {}; } void submit_jobs() override {} private: lt::aux::vector<std::shared_ptr<temp_storage>, lt::storage_index_t> m_torrents; // slots that are unused in the m_torrents vector std::vector<lt::storage_index_t> m_free_slots; // callbacks are posted on this lt::io_context& m_ioc; }; std::unique_ptr<lt::disk_interface> temp_disk_constructor( lt::io_context& ioc, lt::settings_interface const&, lt::counters&) { return std::make_unique<temp_disk_io>(ioc); }[report issue]
settings_interface
Declared in "libtorrent/settings_pack.hpp"
the common interface to settings_pack and the internal representation of settings.
struct settings_interface { virtual bool has_val (int name) const = 0; virtual void set_int (int name, int val) = 0; virtual void set_bool (int name, bool val) = 0; virtual void set_str (int name, std::string val) = 0; virtual bool get_bool (int name) const = 0; virtual int get_int (int name) const = 0; virtual std::string const& get_str (int name) const = 0; };[report issue]
disk_observer
Declared in "libtorrent/disk_observer.hpp"
struct disk_observer { virtual void on_disk () = 0; };[report issue]
on_disk()
virtual void on_disk () = 0;
called when the disk cache size has dropped below the low watermark again and we can resume downloading from peers
[report issue]open_file_state
Declared in "libtorrent/disk_interface.hpp"
this contains information about a file that's currently open by the libtorrent disk I/O subsystem. It's associated with a single torrent.
struct open_file_state { file_index_t file_index; file_open_mode_t open_mode; time_point last_use; };[report issue]
- file_index
- the index of the file this entry refers to into the file_storage file list of this torrent. This starts indexing at 0.
- open_mode
open_mode is a bitmask of the file flags this file is currently opened with. For possible flags, see file_open_mode_t.
Note that the read/write mode is not a bitmask. The two least significant bits are used to represent the read/write mode. Those bits can be masked out using the rw_mask constant.
- last_use
- a (high precision) timestamp of when the file was last used.
disk_interface
Declared in "libtorrent/disk_interface.hpp"
The disk_interface is the customization point for disk I/O in libtorrent. implement this interface and provide a factory function to the session constructor use custom disk I/O. All functions on the disk subsystem (implementing disk_interface) are called from within libtorrent's network thread. For disk I/O to be performed in a separate thread, the disk subsystem has to manage that itself.
Although the functions are called async_*, they do not technically have to be asynchronous, but they support being asynchronous, by expecting the result passed back into a callback. The callbacks must be posted back onto the network thread via the io_context object passed into the constructor. The callbacks will be run in the network thread.
struct disk_interface { virtual storage_holder new_torrent (storage_params const& p , std::shared_ptr<void> const& torrent) = 0; virtual void remove_torrent (storage_index_t) = 0; virtual void async_read (storage_index_t storage, peer_request const& r , std::function<void(disk_buffer_holder, storage_error const&)> handler , disk_job_flags_t flags = {}) = 0; virtual bool async_write (storage_index_t storage, peer_request const& r , char const* buf, std::shared_ptr<disk_observer> o , std::function<void(storage_error const&)> handler , disk_job_flags_t flags = {}) = 0; virtual void async_hash (storage_index_t storage, piece_index_t piece, span<sha256_hash> v2 , disk_job_flags_t flags , std::function<void(piece_index_t, sha1_hash const&, storage_error const&)> handler) = 0; virtual void async_hash2 (storage_index_t storage, piece_index_t piece, int offset, disk_job_flags_t flags , std::function<void(piece_index_t, sha256_hash const&, storage_error const&)> handler) = 0; virtual void async_move_storage (storage_index_t storage, std::string p, move_flags_t flags , std::function<void(status_t, std::string const&, storage_error const&)> handler) = 0; virtual void async_release_files (storage_index_t storage , std::function<void()> handler = std::function<void()>()) = 0; virtual void async_check_files (storage_index_t storage , add_torrent_params const* resume_data , aux::vector<std::string, file_index_t> links , std::function<void(status_t, storage_error const&)> handler) = 0; virtual void async_stop_torrent (storage_index_t storage , std::function<void()> handler = std::function<void()>()) = 0; virtual void async_rename_file (storage_index_t storage , file_index_t index, std::string name , std::function<void(std::string const&, file_index_t, storage_error const&)> handler) = 0; virtual void async_delete_files (storage_index_t storage, remove_flags_t options , std::function<void(storage_error const&)> handler) = 0; virtual void async_set_file_priority (storage_index_t storage , aux::vector<download_priority_t, file_index_t> prio , std::function<void(storage_error const& , aux::vector<download_priority_t, file_index_t>)> handler) = 0; virtual void async_clear_piece (storage_index_t storage, piece_index_t index , std::function<void(piece_index_t)> handler) = 0; virtual void update_stats_counters (counters& c) const = 0; virtual std::vector<open_file_state> get_status (storage_index_t) const = 0; virtual void abort (bool wait) = 0; virtual void submit_jobs () = 0; virtual void settings_updated () = 0; static constexpr disk_job_flags_t force_copy = 0_bit; static constexpr disk_job_flags_t sequential_access = 3_bit; static constexpr disk_job_flags_t volatile_read = 4_bit; static constexpr disk_job_flags_t v1_hash = 5_bit; static constexpr disk_job_flags_t flush_piece = 7_bit; };[report issue]
new_torrent()
virtual storage_holder new_torrent (storage_params const& p , std::shared_ptr<void> const& torrent) = 0;
this is called when a new torrent is added. The shared_ptr can be used to hold the internal torrent object alive as long as there are outstanding disk operations on the storage. The returned storage_holder is an owning reference to the underlying storage that was just created. It is fundamentally a storage_index_t
[report issue]remove_torrent()
virtual void remove_torrent (storage_index_t) = 0;
remove the storage with the specified index. This is not expected to delete any files from disk, just to clean up any resources associated with the specified storage.
[report issue]async_write() async_read()
virtual void async_read (storage_index_t storage, peer_request const& r , std::function<void(disk_buffer_holder, storage_error const&)> handler , disk_job_flags_t flags = {}) = 0; virtual bool async_write (storage_index_t storage, peer_request const& r , char const* buf, std::shared_ptr<disk_observer> o , std::function<void(storage_error const&)> handler , disk_job_flags_t flags = {}) = 0;
perform a read or write operation from/to the specified storage index and the specified request. When the operation completes, call handler possibly with a disk_buffer_holder, holding the buffer with the result. Flags may be set to affect the read operation. See disk_job_flags_t.
The disk_observer is a callback to indicate that the store buffer/disk write queue is below the watermark to let peers start writing buffers to disk again. When async_write() returns true, indicating the write queue is full, the peer will stop further writes and wait for the passed-in disk_observer to be notified before resuming.
Note that for async_read, the peer_request (r) is not necessarily aligned to blocks (but it is most of the time). However, all writes (passed to async_write) are guaranteed to be block aligned.
[report issue]async_hash()
virtual void async_hash (storage_index_t storage, piece_index_t piece, span<sha256_hash> v2 , disk_job_flags_t flags , std::function<void(piece_index_t, sha1_hash const&, storage_error const&)> handler) = 0;
Compute hash(es) for the specified piece. Unless the v1_hash flag is set (in flags), the SHA-1 hash of the whole piece does not need to be computed.
The v2 span is optional and can be empty, which means v2 hashes should not be computed. If v2 is non-empty it must be at least large enough to hold all v2 blocks in the piece, and this function will fill in the span with the SHA-256 block hashes of the piece.
[report issue]async_hash2()
virtual void async_hash2 (storage_index_t storage, piece_index_t piece, int offset, disk_job_flags_t flags , std::function<void(piece_index_t, sha256_hash const&, storage_error const&)> handler) = 0;
computes the v2 hash (SHA-256) of a single block. The block at offset in piece piece.
[report issue]async_move_storage()
virtual void async_move_storage (storage_index_t storage, std::string p, move_flags_t flags , std::function<void(status_t, std::string const&, storage_error const&)> handler) = 0;
called to request the files for the specified storage/torrent be moved to a new location. It is the disk I/O object's responsibility to synchronize this with any currently outstanding disk operations to the storage. Whether files are replaced at the destination path or not is controlled by flags (see move_flags_t).
[report issue]async_release_files()
virtual void async_release_files (storage_index_t storage , std::function<void()> handler = std::function<void()>()) = 0;
This is called on disk I/O objects to request they close all open files for the specified storage/torrent. If file handles are not pooled/cached, it can be a no-op. For truly asynchronous disk I/O, this should provide at least one point in time when all files are closed. It is possible that later asynchronous operations will re-open some of the files, by the time this completion handler is called, that's fine.
[report issue]async_check_files()
virtual void async_check_files (storage_index_t storage , add_torrent_params const* resume_data , aux::vector<std::string, file_index_t> links , std::function<void(status_t, storage_error const&)> handler) = 0;
this is called when torrents are added to validate their resume data against the files on disk. This function is expected to do a few things:
if links is non-empty, it contains a string for each file in the torrent. The string being a path to an existing identical file. The default behavior is to create hard links of those files into the storage of the new torrent (specified by storage). An empty string indicates that there is no known identical file. This is part of the "mutable torrent" feature, where files can be reused from other torrents.
The resume_data points the resume data passed in by the client.
If the resume_data->flags field has the seed_mode flag set, all files/pieces are expected to be on disk already. This should be verified. Not just the existence of the file, but also that it has the correct size.
Any file with a piece set in the resume_data->have_pieces bitmask should exist on disk, this should be verified. Pad files and files with zero priority may be skipped.
[report issue]async_stop_torrent()
virtual void async_stop_torrent (storage_index_t storage , std::function<void()> handler = std::function<void()>()) = 0;
This is called when a torrent is stopped. It gives the disk I/O object an opportunity to flush any data to disk that's currently kept cached. This function should at least do the same thing as async_release_files().
[report issue]async_rename_file()
virtual void async_rename_file (storage_index_t storage , file_index_t index, std::string name , std::function<void(std::string const&, file_index_t, storage_error const&)> handler) = 0;
This function is called when the name of a file in the specified storage has been requested to be renamed. The disk I/O object is responsible for renaming the file without racing with other potentially outstanding operations against the file (such as read, write, move, etc.).
[report issue]async_delete_files()
virtual void async_delete_files (storage_index_t storage, remove_flags_t options , std::function<void(storage_error const&)> handler) = 0;
This function is called when some file(s) on disk have been requested to be removed by the client. storage indicates which torrent is referred to. See session_handle for remove_flags_t flags indicating which files are to be removed. e.g. session_handle::delete_files - delete all files session_handle::delete_partfile - only delete part file.
[report issue]async_set_file_priority()
virtual void async_set_file_priority (storage_index_t storage , aux::vector<download_priority_t, file_index_t> prio , std::function<void(storage_error const& , aux::vector<download_priority_t, file_index_t>)> handler) = 0;
This is called to set the priority of some or all files. Changing the priority from or to 0 may involve moving data to and from the partfile. The disk I/O object is responsible for correctly synchronizing this work to not race with any potentially outstanding asynchronous operations affecting these files.
prio is a vector of the file priority for all files. If it's shorter than the total number of files in the torrent, they are assumed to be set to the default priority.
[report issue]async_clear_piece()
virtual void async_clear_piece (storage_index_t storage, piece_index_t index , std::function<void(piece_index_t)> handler) = 0;
This is called when a piece fails the hash check, to ensure there are no outstanding disk operations to the piece before blocks are re-requested from peers to overwrite the existing blocks. The disk I/O object does not need to perform any action other than synchronize with all outstanding disk operations to the specified piece before posting the result back.
[report issue]update_stats_counters()
virtual void update_stats_counters (counters& c) const = 0;
update_stats_counters() is called to give the disk storage an opportunity to update gauges in the c stats counters, that aren't updated continuously as operations are performed. This is called before a snapshot of the counters are passed to the client.
[report issue]get_status()
virtual std::vector<open_file_state> get_status (storage_index_t) const = 0;
Return a list of all the files that are currently open for the specified storage/torrent. This is is just used for the client to query the currently open files, and which modes those files are open in.
[report issue]abort()
virtual void abort (bool wait) = 0;
this is called when the session is starting to shut down. The disk I/O object is expected to flush any outstanding write jobs, cancel hash jobs and initiate tearing down of any internal threads. If wait is true, this should be asynchronous. i.e. this call should not return until all threads have stopped and all jobs have either been aborted or completed and the disk I/O object is ready to be destructed.
[report issue]submit_jobs()
virtual void submit_jobs () = 0;
This will be called after a batch of disk jobs has been issues (via the async_* ). It gives the disk I/O object an opportunity to notify any potential condition variables to wake up the disk thread(s). The async_* calls can of course also notify condition variables, but doing it in this call allows for batching jobs, by issuing the notification once for a collection of jobs.
[report issue]settings_updated()
virtual void settings_updated () = 0;
This is called to notify the disk I/O object that the settings have been updated. In the disk io constructor, a settings_interface reference is passed in. Whenever these settings are updated, this function is called to allow the disk I/O object to react to any changed settings relevant to its operations.
[report issue]- force_copy
- force making a copy of the cached block, rather than getting a reference to a block already in the cache. This is used the block is expected to be overwritten very soon, by async_write()`, and we need access to the previous content.
- sequential_access
- hint that there may be more disk operations with sequential access to the file
- volatile_read
- don't keep the read block in cache. This is a hint that this block is unlikely to be read again anytime soon, and caching it would be wasteful.
- v1_hash
- compute a v1 piece hash. This is only used by the async_hash() call. If this flag is not set in the async_hash() call, the SHA-1 piece hash does not need to be computed.
- flush_piece
- this flag instructs a hash job that we just completed this piece, and it should be flushed to disk
storage_holder
Declared in "libtorrent/disk_interface.hpp"
a unique, owning, reference to the storage of a torrent in a disk io subsystem (class that implements disk_interface). This is held by the internal libtorrent torrent object to tie the storage object allocated for a torrent to the lifetime of the internal torrent object. When a torrent is removed from the session, this holder is destructed and will inform the disk object.
struct storage_holder { storage_holder () = default; ~storage_holder (); storage_holder (storage_index_t idx, disk_interface& disk_io); explicit operator bool () const; operator storage_index_t () const; void reset (); storage_holder& operator= (storage_holder const&) = delete; storage_holder (storage_holder const&) = delete; storage_holder (storage_holder&& rhs) noexcept; storage_holder& operator= (storage_holder&& rhs) noexcept; };[report issue]
buffer_allocator_interface
Declared in "libtorrent/disk_buffer_holder.hpp"
the interface for freeing disk buffers, used by the disk_buffer_holder. when implementing disk_interface, this must also be implemented in order to return disk buffers back to libtorrent
struct buffer_allocator_interface { virtual void free_disk_buffer (char* b) = 0; };[report issue]
disk_buffer_holder
Declared in "libtorrent/disk_buffer_holder.hpp"
The disk buffer holder acts like a unique_ptr that frees a disk buffer when it's destructed
If this buffer holder is moved-from, default constructed or reset, data() will return nullptr.
struct disk_buffer_holder { disk_buffer_holder (disk_buffer_holder&&) noexcept; disk_buffer_holder& operator= (disk_buffer_holder&&) & noexcept; disk_buffer_holder& operator= (disk_buffer_holder const&) = delete; disk_buffer_holder (disk_buffer_holder const&) = delete; disk_buffer_holder (buffer_allocator_interface& alloc , char* buf, int sz) noexcept; disk_buffer_holder () noexcept = default; ~disk_buffer_holder (); char* data () const noexcept; void reset (); void swap (disk_buffer_holder& h) noexcept; bool is_mutable () const noexcept; explicit operator bool () const noexcept; std::ptrdiff_t size () const; };[report issue]
disk_buffer_holder()
disk_buffer_holder (buffer_allocator_interface& alloc , char* buf, int sz) noexcept;
construct a buffer holder that will free the held buffer using a disk buffer pool directly (there's only one disk_buffer_pool per session)
[report issue]disk_buffer_holder()
disk_buffer_holder () noexcept = default;
default construct a holder that does not own any buffer
[report issue]data()
char* data () const noexcept;
return a pointer to the held buffer, if any. Otherwise returns nullptr.
[report issue]reset()
void reset ();
free the held disk buffer, if any, and clear the holder. This sets the holder object to a default-constructed state
[report issue]swap()
void swap (disk_buffer_holder& h) noexcept;
swap pointers of two disk buffer holders.
[report issue]is_mutable()
bool is_mutable () const noexcept;
if this returns true, the buffer may not be modified in place
[report issue]bool()
explicit operator bool () const noexcept;
implicitly convertible to true if the object is currently holding a buffer
[report issue]file_open_mode_t
Declared in "libtorrent/disk_interface.hpp"
- read_only
- open the file for reading only
- write_only
- open the file for writing only
- read_write
- open the file for reading and writing
- rw_mask
- the mask for the bits determining read or write mode
- sparse
- open the file in sparse mode (if supported by the filesystem).
- no_atime
- don't update the access timestamps on the file (if supported by the operating system and filesystem). this generally improves disk performance.
- random_access
- open the file for random access. This disables read-ahead logic
- mmapped
- the file is memory mapped
You have some control over session configuration through the session::apply_settings() member function. To change one or more configuration options, create a settings_pack object and fill it with the settings to be set and pass it in to session::apply_settings().
The settings_pack object is a collection of settings updates that are applied to the session when passed to session::apply_settings(). It's empty when constructed.
You have control over proxy and authorization settings and also the user-agent that will be sent to the tracker. The user-agent will also be used to identify the client with other peers.
Each configuration option is named with an enum value inside the settings_pack class. These are the available settings:
[report issue]settings_pack
Declared in "libtorrent/settings_pack.hpp"
The settings_pack struct, contains the names of all settings as enum values. These values are passed in to the set_str(), set_int(), set_bool() functions, to specify the setting to change.
The settings_pack only stores values for settings that have been explicitly set on this object. However, it can still be queried for settings that have not been set and returns the default value for those settings.
name | type | default |
---|---|---|
user_agent | string | libtorrent/ |
this is the client identification to the tracker. The recommended format of this string is: "client-name/client-version libtorrent/libtorrent-version". This name will not only be used when making HTTP requests, but also when sending extended headers to peers that support that extension. It may not contain r or n
name | type | default |
---|---|---|
announce_ip | string | nullptr |
announce_ip is the ip address passed along to trackers as the &ip= parameter. If left as the default, that parameter is omitted.
Note
This setting is only meant for very special cases where a seed is running on the same host as the tracker, and the tracker accepts the IP parameter (which normal trackers don't). Do not set this option unless you also control the tracker.
name | type | default |
---|---|---|
handshake_client_version | string | nullptr |
this is the client name and version identifier sent to peers in the handshake message. If this is an empty string, the user_agent is used instead. This string must be a UTF-8 encoded unicode string.
name | type | default |
---|---|---|
outgoing_interfaces | string |
This controls which IP address outgoing TCP peer connections are bound to, in addition to controlling whether such connections are also bound to a specific network interface/adapter (bind-to-device).
This string is a comma-separated list of IP addresses and interface names. An empty string will not bind TCP sockets to a device, and let the network stack assign the local address.
A list of names will be used to bind outgoing TCP sockets in a round-robin fashion. An IP address will simply be used to bind() the socket. An interface name will attempt to bind the socket to that interface. If that fails, or is unsupported, one of the IP addresses configured for that interface is used to bind() the socket to. If the interface or adapter doesn't exist, the outgoing peer connection will fail with an error message suggesting the device cannot be found. Adapter names on Unix systems are of the form "eth0", "eth1", "tun0", etc. This may be useful for clients that are multi-homed. Binding an outgoing connection to a local IP does not necessarily make the connection via the associated NIC/Adapter.
When outgoing interfaces are specified, incoming connections or packets sent to a local interface or IP that's not in this list will be rejected with a peer_blocked_alert with invalid_local_interface as the reason.
Note that these are just interface/adapter names or IP addresses. There are no ports specified in this list. IPv6 addresses without port should be specified without enclosing [, ].
name | type | default |
---|---|---|
listen_interfaces | string | 0.0.0.0:6881,[::]:6881 |
a comma-separated list of (IP or device name, port) pairs. These are the listen ports that will be opened for accepting incoming uTP and TCP peer connections. These are also used for outgoing uTP and UDP tracker connections and DHT nodes.
It is possible to listen on multiple interfaces and multiple ports. Binding to port 0 will make the operating system pick the port.
Note
There are reasons to stick to the same port across sessions, which would mean only using port 0 on the first start, and recording the port that was picked for subsequent startups. Trackers, the DHT and other peers will remember the port they see you use and hand that port out to other peers trying to connect to you, as well as trying to connect to you themselves.
A port that has an "s" suffix will accept SSL peer connections. (note that SSL sockets are only available in builds with SSL support)
A port that has an "l" suffix will be considered a local network. i.e. it's assumed to only be able to reach hosts in the same local network as the IP address (based on the netmask associated with the IP, queried from the operating system).
if binding fails, the listen_failed_alert is posted. Once a socket binding succeeds (if it does), the listen_succeeded_alert is posted. There may be multiple failures before a success.
If a device name that does not exist is configured, no listen socket will be opened for that interface. If this is the only interface configured, it will be as if no listen ports are configured.
If no listen ports are configured (e.g. listen_interfaces is an empty string), networking will be disabled. No DHT will start, no outgoing uTP or tracker connections will be made. No incoming TCP or uTP connections will be accepted. (outgoing TCP connections will still be possible, depending on settings_pack::outgoing_interfaces).
For example: [::1]:8888 - will only accept connections on the IPv6 loopback address on port 8888.
eth0:4444,eth1:4444 - will accept connections on port 4444 on any IP address bound to device eth0 or eth1.
[::]:0s - will accept SSL connections on a port chosen by the OS. And not accept non-SSL connections at all.
0.0.0.0:6881,[::]:6881 - binds to all interfaces on port 6881.
10.0.1.13:6881l - binds to the local IP address, port 6881, but only allow talking to peers on the same local network. The netmask is queried from the operating system. Interfaces marked l are not announced to trackers, unless the tracker is also on the same local network.
Windows OS network adapter device name must be specified with GUID. It can be obtained from "netsh lan show interfaces" command output. GUID must be uppercased string embraced in curly brackets. {E4F0B674-0DFC-48BB-98A5-2AA730BDB6D6}:7777 - will accept connections on port 7777 on adapter with this GUID.
For more information, see the Multi-homed hosts section.
name | type | default |
---|---|---|
proxy_hostname | string |
when using a proxy, this is the hostname where the proxy is running see proxy_type. Note that when using a proxy, the settings_pack::listen_interfaces setting is overridden and only a single interface is created, just to contact the proxy. This means a proxy cannot be combined with SSL torrents or multiple listen interfaces. This proxy listen interface will not accept incoming TCP connections, will not map ports with any gateway and will not enable local service discovery. All traffic is supposed to be channeled through the proxy.
name | type | default |
---|---|---|
proxy_username | string | |
proxy_password | string |
when using a proxy, these are the credentials (if any) to use when connecting to it. see proxy_type
name | type | default |
---|---|---|
i2p_hostname | string |
sets the i2p SAM bridge to connect to. set the port with the i2p_port setting. Unless this is set, i2p torrents are not supported. This setting is separate from the other proxy settings since i2p torrents and their peers are orthogonal. You can have i2p peers as well as regular peers via a proxy.
name | type | default |
---|---|---|
peer_fingerprint | string | -LT2090- |
this is the fingerprint for the client. It will be used as the prefix to the peer_id. If this is 20 bytes (or longer) it will be truncated to 20 bytes and used as the entire peer-id
There is a utility function, generate_fingerprint() that can be used to generate a standard client peer ID fingerprint prefix.
name | type | default |
---|---|---|
dht_bootstrap_nodes | string | dht.libtorrent.org:25401 |
This is a comma-separated list of IP port-pairs. They will be added to the DHT node (if it's enabled) as back-up nodes in case we don't know of any.
Changing these after the DHT has been started may not have any effect until the DHT is restarted.
name | type | default |
---|---|---|
allow_multiple_connections_per_ip | bool | false |
determines if connections from the same IP address as existing connections should be rejected or not. Rejecting multiple connections from the same IP address will prevent abusive behavior by peers. The logic for determining whether connections are to the same peer is more complicated with this enabled, and more likely to fail in some edge cases. It is not recommended to enable this feature.
name | type | default |
---|---|---|
send_redundant_have | bool | true |
send_redundant_have controls if have messages will be sent to peers that already have the piece. This is typically not necessary, but it might be necessary for collecting statistics in some cases.
name | type | default |
---|---|---|
use_dht_as_fallback | bool | false |
use_dht_as_fallback determines how the DHT is used. If this is true, the DHT will only be used for torrents where all trackers in its tracker list has failed. Either by an explicit error message or a time out. If this is false, the DHT is used regardless of if the trackers fail or not.
name | type | default |
---|---|---|
upnp_ignore_nonrouters | bool | false |
upnp_ignore_nonrouters indicates whether or not the UPnP implementation should ignore any broadcast response from a device whose address is not on our subnet. i.e. it's a way to not talk to other people's routers by mistake.
name | type | default |
---|---|---|
use_parole_mode | bool | true |
use_parole_mode specifies if parole mode should be used. Parole mode means that peers that participate in pieces that fail the hash check are put in a mode where they are only allowed to download whole pieces. If the whole piece a peer in parole mode fails the hash check, it is banned. If a peer participates in a piece that passes the hash check, it is taken out of parole mode.
name | type | default |
---|---|---|
auto_manage_prefer_seeds | bool | false |
if true, prefer seeding torrents when determining which torrents to give active slots to. If false, give preference to downloading torrents
name | type | default |
---|---|---|
dont_count_slow_torrents | bool | true |
if dont_count_slow_torrents is true, torrents without any payload transfers are not subject to the active_seeds and active_downloads limits. This is intended to make it more likely to utilize all available bandwidth, and avoid having torrents that don't transfer anything block the active slots.
name | type | default |
---|---|---|
close_redundant_connections | bool | true |
close_redundant_connections specifies whether libtorrent should close connections where both ends have no utility in keeping the connection open. For instance if both ends have completed their downloads, there's no point in keeping it open.
name | type | default |
---|---|---|
prioritize_partial_pieces | bool | false |
If prioritize_partial_pieces is true, partial pieces are picked before pieces that are more rare. If false, rare pieces are always prioritized, unless the number of partial pieces is growing out of proportion.
name | type | default |
---|---|---|
rate_limit_ip_overhead | bool | true |
if set to true, the estimated TCP/IP overhead is drained from the rate limiters, to avoid exceeding the limits with the total traffic
name | type | default |
---|---|---|
announce_to_all_tiers | bool | false |
announce_to_all_trackers | bool | false |
announce_to_all_trackers controls how multi tracker torrents are treated. If this is set to true, all trackers in the same tier are announced to in parallel. If all trackers in tier 0 fails, all trackers in tier 1 are announced as well. If it's set to false, the behavior is as defined by the multi tracker specification.
announce_to_all_tiers also controls how multi tracker torrents are treated. When this is set to true, one tracker from each tier is announced to. This is the uTorrent behavior. To be compliant with the Multi-tracker specification, set it to false.
name | type | default |
---|---|---|
prefer_udp_trackers | bool | true |
prefer_udp_trackers: true means that trackers may be rearranged in a way that udp trackers are always tried before http trackers for the same hostname. Setting this to false means that the tracker's tier is respected and there's no preference of one protocol over another.
name | type | default |
---|---|---|
disable_hash_checks | bool | false |
when set to true, all data downloaded from peers will be assumed to be correct, and not tested to match the hashes in the torrent this is only useful for simulation and testing purposes (typically combined with disabled_storage)
name | type | default |
---|---|---|
allow_i2p_mixed | bool | false |
if this is true, i2p torrents are allowed to also get peers from other sources than the tracker, and connect to regular IPs, not providing any anonymization. This may be useful if the user is not interested in the anonymization of i2p, but still wants to be able to connect to i2p peers.
name | type | default |
---|---|---|
no_atime_storage | bool | true |
no_atime_storage this is a Linux-only option and passes in the O_NOATIME to open() when opening files. This may lead to some disk performance improvements.
name | type | default |
---|---|---|
incoming_starts_queued_torrents | bool | false |
incoming_starts_queued_torrents. If a torrent has been paused by the auto managed feature in libtorrent, i.e. the torrent is paused and auto managed, this feature affects whether or not it is automatically started on an incoming connection. The main reason to queue torrents, is not to make them unavailable, but to save on the overhead of announcing to the trackers, the DHT and to avoid spreading one's unchoke slots too thin. If a peer managed to find us, even though we're no in the torrent anymore, this setting can make us start the torrent and serve it.
name | type | default |
---|---|---|
report_true_downloaded | bool | false |
when set to true, the downloaded counter sent to trackers will include the actual number of payload bytes downloaded including redundant bytes. If set to false, it will not include any redundancy bytes
name | type | default |
---|---|---|
strict_end_game_mode | bool | true |
strict_end_game_mode controls when a block may be requested twice. If this is true, a block may only be requested twice when there's at least one request to every piece that's left to download in the torrent. This may slow down progress on some pieces sometimes, but it may also avoid downloading a lot of redundant bytes. If this is false, libtorrent attempts to use each peer connection to its max, by always requesting something, even if it means requesting something that has been requested from another peer already.
name | type | default |
---|---|---|
enable_outgoing_utp | bool | true |
enable_incoming_utp | bool | true |
enable_outgoing_tcp | bool | true |
enable_incoming_tcp | bool | true |
Enables incoming and outgoing, TCP and uTP peer connections. false is disabled and true is enabled. When outgoing connections are disabled, libtorrent will simply not make outgoing peer connections with the specific transport protocol. Disabled incoming peer connections will simply be rejected. These options only apply to peer connections, not tracker- or any other kinds of connections.
name | type | default |
---|---|---|
no_recheck_incomplete_resume | bool | false |
no_recheck_incomplete_resume determines if the storage should check the whole files when resume data is incomplete or missing or whether it should simply assume we don't have any of the data. If false, any existing files will be checked. By setting this setting to true, the files won't be checked, but will go straight to download mode.
name | type | default |
---|---|---|
anonymous_mode | bool | false |
anonymous_mode: When set to true, the client tries to hide its identity to a certain degree.
- A generic user-agent will be used for trackers (except for private torrents).
- Your local IPv4 and IPv6 address won't be sent as query string parameters to private trackers.
- If announce_ip is configured, it will not be sent to trackers
- The client version will not be sent to peers in the extension handshake.
name | type | default |
---|---|---|
report_web_seed_downloads | bool | true |
specifies whether downloads from web seeds is reported to the tracker or not. Turning it off also excludes web seed traffic from other stats and download rate reporting via the libtorrent API.
name | type | default |
---|---|---|
seeding_outgoing_connections | bool | true |
seeding_outgoing_connections determines if seeding (and finished) torrents should attempt to make outgoing connections or not. It may be set to false in very specific applications where the cost of making outgoing connections is high, and there are no or small benefits of doing so. For instance, if no nodes are behind a firewall or a NAT, seeds don't need to make outgoing connections.
name | type | default |
---|---|---|
no_connect_privileged_ports | bool | false |
when this is true, libtorrent will not attempt to make outgoing connections to peers whose port is < 1024. This is a safety precaution to avoid being part of a DDoS attack
name | type | default |
---|---|---|
smooth_connects | bool | true |
smooth_connects means the number of connection attempts per second may be limited to below the connection_speed, in case we're close to bump up against the limit of number of connections. The intention of this setting is to more evenly distribute our connection attempts over time, instead of attempting to connect in batches, and timing them out in batches.
name | type | default |
---|---|---|
always_send_user_agent | bool | false |
always send user-agent in every web seed request. If false, only the first request per http connection will include the user agent
name | type | default |
---|---|---|
apply_ip_filter_to_trackers | bool | true |
apply_ip_filter_to_trackers determines whether the IP filter applies to trackers as well as peers. If this is set to false, trackers are exempt from the IP filter (if there is one). If no IP filter is set, this setting is irrelevant.
name | type | default |
---|---|---|
ban_web_seeds | bool | true |
when true, web seeds sending bad data will be banned
name | type | default |
---|---|---|
support_share_mode | bool | true |
if false, prevents libtorrent to advertise share-mode support
name | type | default |
---|---|---|
report_redundant_bytes | bool | true |
if this is true, the number of redundant bytes is sent to the tracker
name | type | default |
---|---|---|
listen_system_port_fallback | bool | true |
if this is true, libtorrent will fall back to listening on a port chosen by the operating system (i.e. binding to port 0). If a failure is preferred, set this to false.
name | type | default |
---|---|---|
announce_crypto_support | bool | true |
when this is true, and incoming encrypted connections are enabled, &supportcrypt=1 is included in http tracker announces
name | type | default |
---|---|---|
enable_upnp | bool | true |
Starts and stops the UPnP service. When started, the listen port and the DHT port are attempted to be forwarded on local UPnP router devices.
The upnp object returned by start_upnp() can be used to add and remove arbitrary port mappings. Mapping status is returned through the portmap_alert and the portmap_error_alert. The object will be valid until stop_upnp() is called. See upnp and nat pmp.
name | type | default |
---|---|---|
enable_natpmp | bool | true |
Starts and stops the NAT-PMP service. When started, the listen port and the DHT port are attempted to be forwarded on the router through NAT-PMP.
The natpmp object returned by start_natpmp() can be used to add and remove arbitrary port mappings. Mapping status is returned through the portmap_alert and the portmap_error_alert. The object will be valid until stop_natpmp() is called. See upnp and nat pmp.
name | type | default |
---|---|---|
enable_lsd | bool | true |
Starts and stops Local Service Discovery. This service will broadcast the info-hashes of all the non-private torrents on the local network to look for peers on the same swarm within multicast reach.
name | type | default |
---|---|---|
enable_dht | bool | true |
starts the dht node and makes the trackerless service available to torrents.
name | type | default |
---|---|---|
prefer_rc4 | bool | false |
if the allowed encryption level is both, setting this to true will prefer RC4 if both methods are offered, plain text otherwise
name | type | default |
---|---|---|
proxy_hostnames | bool | true |
if true, hostname lookups are done via the configured proxy (if any). This is only supported by SOCKS5 and HTTP.
name | type | default |
---|---|---|
proxy_peer_connections | bool | true |
if true, peer connections are made (and accepted) over the configured proxy, if any. Web seeds as well as regular bittorrent peer connections are considered "peer connections". Anything transporting actual torrent payload (trackers and DHT traffic are not considered peer connections).
name | type | default |
---|---|---|
auto_sequential | bool | true |
if this setting is true, torrents with a very high availability of pieces (and seeds) are downloaded sequentially. This is more efficient for the disk I/O. With many seeds, the download order is unlikely to matter anyway
name | type | default |
---|---|---|
proxy_tracker_connections | bool | true |
if true, tracker connections are made over the configured proxy, if any.
name | type | default |
---|---|---|
enable_ip_notifier | bool | true |
Starts and stops the internal IP table route changes notifier.
The current implementation supports multiple platforms, and it is recommended to have it enable, but you may want to disable it if it's supported but unreliable, or if you have a better way to detect the changes. In the later case, you should manually call session_handle::reopen_network_sockets to ensure network changes are taken in consideration.
name | type | default |
---|---|---|
dht_prefer_verified_node_ids | bool | true |
when this is true, nodes whose IDs are derived from their source IP according to BEP 42 are preferred in the routing table.
name | type | default |
---|---|---|
dht_restrict_routing_ips | bool | true |
determines if the routing table entries should restrict entries to one per IP. This defaults to true, which helps mitigate some attacks on the DHT. It prevents adding multiple nodes with IPs with a very close CIDR distance.
when set, nodes whose IP address that's in the same /24 (or /64 for IPv6) range in the same routing table bucket. This is an attempt to mitigate node ID spoofing attacks also restrict any IP to only have a single entry in the whole routing table
name | type | default |
---|---|---|
dht_restrict_search_ips | bool | true |
determines if DHT searches should prevent adding nodes with IPs with very close CIDR distance. This also defaults to true and helps mitigate certain attacks on the DHT.
name | type | default |
---|---|---|
dht_extended_routing_table | bool | true |
makes the first buckets in the DHT routing table fit 128, 64, 32 and 16 nodes respectively, as opposed to the standard size of 8. All other buckets have size 8 still.
name | type | default |
---|---|---|
dht_aggressive_lookups | bool | true |
slightly changes the lookup behavior in terms of how many outstanding requests we keep. Instead of having branch factor be a hard limit, we always keep branch factor outstanding requests to the closest nodes. i.e. every time we get results back with closer nodes, we query them right away. It lowers the lookup times at the cost of more outstanding queries.
name | type | default |
---|---|---|
dht_privacy_lookups | bool | false |
when set, perform lookups in a way that is slightly more expensive, but which minimizes the amount of information leaked about you.
name | type | default |
---|---|---|
dht_enforce_node_id | bool | false |
when set, node's whose IDs that are not correctly generated based on its external IP are ignored. When a query arrives from such node, an error message is returned with a message saying "invalid node ID".
name | type | default |
---|---|---|
dht_ignore_dark_internet | bool | true |
ignore DHT messages from parts of the internet we wouldn't expect to see any traffic from
name | type | default |
---|---|---|
dht_read_only | bool | false |
when set, the other nodes won't keep this node in their routing tables, it's meant for low-power and/or ephemeral devices that cannot support the DHT, it is also useful for mobile devices which are sensitive to network traffic and battery life. this node no longer responds to 'query' messages, and will place a 'ro' key (value = 1) in the top-level message dictionary of outgoing query messages.
name | type | default |
---|---|---|
piece_extent_affinity | bool | false |
when this is true, create an affinity for downloading 4 MiB extents of adjacent pieces. This is an attempt to achieve better disk I/O throughput by downloading larger extents of bytes, for torrents with small piece sizes
name | type | default |
---|---|---|
validate_https_trackers | bool | true |
when set to true, the certificate of HTTPS trackers and HTTPS web seeds will be validated against the system's certificate store (as defined by OpenSSL). If the system does not have a certificate store, this option may have to be disabled in order to get trackers and web seeds to work).
name | type | default |
---|---|---|
ssrf_mitigation | bool | true |
when enabled, tracker and web seed requests are subject to certain restrictions.
An HTTP(s) tracker requests to localhost (loopback) must have the request path start with "/announce". This is the conventional bittorrent tracker request. Any other HTTP(S) tracker request to loopback will be rejected. This applies to trackers that redirect to loopback as well.
Web seeds that end up on the client's local network (i.e. in a private IP address range) may not include query string arguments. This applies to web seeds redirecting to the local network as well.
Web seeds on global IPs (i.e. not local network) may not redirect to a local network address
name | type | default |
---|---|---|
allow_idna | bool | false |
when disabled, any tracker or web seed with an IDNA hostname (internationalized domain name) is ignored. This is a security precaution to avoid various unicode encoding attacks that might happen at the application level.
name | type | default |
---|---|---|
enable_set_file_valid_data | bool | false |
when set to true, enables the attempt to use SetFileValidData() to pre-allocate disk space. This system call will only work when running with Administrator privileges on Windows, and so this setting is only relevant in that scenario. Using SetFileValidData() poses a security risk, as it may reveal previously deleted information from the disk.
name | type | default |
---|---|---|
socks5_udp_send_local_ep | bool | false |
When using a SOCKS5 proxy, UDP traffic is routed through the proxy by sending a UDP ASSOCIATE command. If this option is true, the UDP ASSOCIATE command will include the IP address and listen port to the local UDP socket. This indicates to the proxy which source endpoint to expect our packets from. The benefit is that incoming packets can be forwarded correctly, before any outgoing packets are sent. The risk is that if there's a NAT between the client and the proxy, the IP address specified in the protocol may not be valid from the proxy's point of view.
name | type | default |
---|---|---|
tracker_completion_timeout | int | 30 |
tracker_completion_timeout is the number of seconds the tracker connection will wait from when it sent the request until it considers the tracker to have timed-out.
name | type | default |
---|---|---|
tracker_receive_timeout | int | 10 |
tracker_receive_timeout is the number of seconds to wait to receive any data from the tracker. If no data is received for this number of seconds, the tracker will be considered as having timed out. If a tracker is down, this is the kind of timeout that will occur.
name | type | default |
---|---|---|
stop_tracker_timeout | int | 5 |
stop_tracker_timeout is the number of seconds to wait when sending a stopped message before considering a tracker to have timed out. This is usually shorter, to make the client quit faster. If the value is set to 0, the connections to trackers with the stopped event are suppressed.
name | type | default |
---|---|---|
tracker_maximum_response_length | int | 1024*1024 |
this is the maximum number of bytes in a tracker response. If a response size passes this number of bytes it will be rejected and the connection will be closed. On gzipped responses this size is measured on the uncompressed data. So, if you get 20 bytes of gzip response that'll expand to 2 megabytes, it will be interrupted before the entire response has been uncompressed (assuming the limit is lower than 2 MiB).
name | type | default |
---|---|---|
piece_timeout | int | 20 |
the number of seconds from a request is sent until it times out if no piece response is returned.
name | type | default |
---|---|---|
request_timeout | int | 60 |
the number of seconds one block (16 kiB) is expected to be received within. If it's not, the block is requested from a different peer
name | type | default |
---|---|---|
request_queue_time | int | 3 |
the length of the request queue given in the number of seconds it should take for the other end to send all the pieces. i.e. the actual number of requests depends on the download rate and this number.
name | type | default |
---|---|---|
max_allowed_in_request_queue | int | 2000 |
the number of outstanding block requests a peer is allowed to queue up in the client. If a peer sends more requests than this (before the first one has been sent) the last request will be dropped. the higher this is, the faster upload speeds the client can get to a single peer.
name | type | default |
---|---|---|
max_out_request_queue | int | 500 |
max_out_request_queue is the maximum number of outstanding requests to send to a peer. This limit takes precedence over request_queue_time. i.e. no matter the download speed, the number of outstanding requests will never exceed this limit.
name | type | default |
---|---|---|
whole_pieces_threshold | int | 20 |
if a whole piece can be downloaded in this number of seconds, or less, the peer_connection will prefer to request whole pieces at a time from this peer. The benefit of this is to better utilize disk caches by doing localized accesses and also to make it easier to identify bad peers if a piece fails the hash check.
name | type | default |
---|---|---|
peer_timeout | int | 120 |
peer_timeout is the number of seconds the peer connection should wait (for any activity on the peer connection) before closing it due to time out. 120 seconds is specified in the protocol specification. After half the time out, a keep alive message is sent.
name | type | default |
---|---|---|
urlseed_timeout | int | 20 |
same as peer_timeout, but only applies to url-seeds. this is usually set lower, because web servers are expected to be more reliable.
name | type | default |
---|---|---|
urlseed_pipeline_size | int | 5 |
controls the pipelining size of url and http seeds. i.e. the number of HTTP request to keep outstanding before waiting for the first one to complete. It's common for web servers to limit this to a relatively low number, like 5
name | type | default |
---|---|---|
urlseed_wait_retry | int | 30 |
number of seconds until a new retry of a url-seed takes place. Default retry value for http-seeds that don't provide a valid retry-after header.
name | type | default |
---|---|---|
file_pool_size | int | 40 |
sets the upper limit on the total number of files this session will keep open. The reason why files are left open at all is that some anti virus software hooks on every file close, and scans the file for viruses. deferring the closing of the files will be the difference between a usable system and a completely hogged down system. Most operating systems also has a limit on the total number of file descriptors a process may have open.
name | type | default |
---|---|---|
max_failcount | int | 3 |
max_failcount is the maximum times we try to connect to a peer before stop connecting again. If a peer succeeds, the failure counter is reset. If a peer is retrieved from a peer source (other than DHT) the failcount is decremented by one, allowing another try.
name | type | default |
---|---|---|
min_reconnect_time | int | 60 |
the number of seconds to wait to reconnect to a peer. this time is multiplied with the failcount.
name | type | default |
---|---|---|
peer_connect_timeout | int | 15 |
peer_connect_timeout the number of seconds to wait after a connection attempt is initiated to a peer until it is considered as having timed out. This setting is especially important in case the number of half-open connections are limited, since stale half-open connection may delay the connection of other peers considerably.
name | type | default |
---|---|---|
connection_speed | int | 30 |
connection_speed is the number of connection attempts that are made per second. If a number < 0 is specified, it will default to 200 connections per second. If 0 is specified, it means don't make outgoing connections at all.
name | type | default |
---|---|---|
inactivity_timeout | int | 600 |
if a peer is uninteresting and uninterested for longer than this number of seconds, it will be disconnected.
name | type | default |
---|---|---|
unchoke_interval | int | 15 |
unchoke_interval is the number of seconds between chokes/unchokes. On this interval, peers are re-evaluated for being choked/unchoked. This is defined as 30 seconds in the protocol, and it should be significantly longer than what it takes for TCP to ramp up to it's max rate.
name | type | default |
---|---|---|
optimistic_unchoke_interval | int | 30 |
optimistic_unchoke_interval is the number of seconds between each optimistic unchoke. On this timer, the currently optimistically unchoked peer will change.
name | type | default |
---|---|---|
num_want | int | 200 |
num_want is the number of peers we want from each tracker request. It defines what is sent as the &num_want= parameter to the tracker.
name | type | default |
---|---|---|
initial_picker_threshold | int | 4 |
initial_picker_threshold specifies the number of pieces we need before we switch to rarest first picking. The first initial_picker_threshold pieces in any torrent are picked at random , the following pieces are picked in rarest first order.
name | type | default |
---|---|---|
allowed_fast_set_size | int | 5 |
the number of allowed pieces to send to peers that supports the fast extensions
name | type | default |
---|---|---|
suggest_mode | int | settings_pack::no_piece_suggestions |
suggest_mode controls whether or not libtorrent will send out suggest messages to create a bias of its peers to request certain pieces. The modes are:
- no_piece_suggestions which will not send out suggest messages.
- suggest_read_cache which will send out suggest messages for the most recent pieces that are in the read cache.
name | type | default |
---|---|---|
max_queued_disk_bytes | int | 1024 * 1024 |
max_queued_disk_bytes is the maximum number of bytes, to be written to disk, that can wait in the disk I/O thread queue. This queue is only for waiting for the disk I/O thread to receive the job and either write it to disk or insert it in the write cache. When this limit is reached, the peer connections will stop reading data from their sockets, until the disk thread catches up. Setting this too low will severely limit your download rate.
name | type | default |
---|---|---|
handshake_timeout | int | 10 |
the number of seconds to wait for a handshake response from a peer. If no response is received within this time, the peer is disconnected.
name | type | default |
---|---|---|
send_buffer_low_watermark | int | 10 * 1024 |
send_buffer_watermark | int | 500 * 1024 |
send_buffer_watermark_factor | int | 50 |
send_buffer_low_watermark the minimum send buffer target size (send buffer includes bytes pending being read from disk). For good and snappy seeding performance, set this fairly high, to at least fit a few blocks. This is essentially the initial window size which will determine how fast we can ramp up the send rate
if the send buffer has fewer bytes than send_buffer_watermark, we'll read another 16 kiB block onto it. If set too small, upload rate capacity will suffer. If set too high, memory will be wasted. The actual watermark may be lower than this in case the upload rate is low, this is the upper limit.
the current upload rate to a peer is multiplied by this factor to get the send buffer watermark. The factor is specified as a percentage. i.e. 50 -> 0.5 This product is clamped to the send_buffer_watermark setting to not exceed the max. For high speed upload, this should be set to a greater value than 100. For high capacity connections, setting this higher can improve upload performance and disk throughput. Setting it too high may waste RAM and create a bias towards read jobs over write jobs.
name | type | default |
---|---|---|
choking_algorithm | int | settings_pack::fixed_slots_choker |
seed_choking_algorithm | int | settings_pack::round_robin |
choking_algorithm specifies which algorithm to use to determine how many peers to unchoke. The unchoking algorithm for downloading torrents is always "tit-for-tat", i.e. the peers we download the fastest from are unchoked.
The options for choking algorithms are defined in the choking_algorithm_t enum.
seed_choking_algorithm controls the seeding unchoke behavior. i.e. How we select which peers to unchoke for seeding torrents. Since a seeding torrent isn't downloading anything, the tit-for-tat mechanism cannot be used. The available options are defined in the seed_choking_algorithm_t enum.
name | type | default |
---|---|---|
disk_io_write_mode | int | DISK_WRITE_MODE |
disk_io_read_mode | int | settings_pack::enable_os_cache |
determines how files are opened when they're in read only mode versus read and write mode. The options are:
- enable_os_cache
- Files are opened normally, with the OS caching reads and writes.
- disable_os_cache
- This opens all files in no-cache mode. This corresponds to the OS not letting blocks for the files linger in the cache. This makes sense in order to avoid the bittorrent client to potentially evict all other processes' cache by simply handling high throughput and large files. If libtorrent's read cache is disabled, enabling this may reduce performance.
- write_through
- flush pieces to disk as they complete validation.
One reason to disable caching is that it may help the operating system from growing its file cache indefinitely.
name | type | default |
---|---|---|
outgoing_port | int | 0 |
num_outgoing_ports | int | 0 |
this is the first port to use for binding outgoing connections to. This is useful for users that have routers that allow QoS settings based on local port. when binding outgoing connections to specific ports, num_outgoing_ports is the size of the range. It should be more than a few
Warning
setting outgoing ports will limit the ability to keep multiple connections to the same client, even for different torrents. It is not recommended to change this setting. Its main purpose is to use as an escape hatch for cheap routers with QoS capability but can only classify flows based on port numbers.
It is a range instead of a single port because of the problems with failing to reconnect to peers if a previous socket to that peer and port is in TIME_WAIT state.
name | type | default |
---|---|---|
peer_dscp | int | 0x04 |
peer_dscp determines the DSCP field in the IP header of every packet sent to peers (including web seeds). 0x0 means no marking, 0x04 represents Lower Effort. For more details see RFC 8622.
peer_tos is the backwards compatible name for this setting.
name | type | default |
---|---|---|
active_downloads | int | 3 |
active_seeds | int | 5 |
active_checking | int | 1 |
active_dht_limit | int | 88 |
active_tracker_limit | int | 1600 |
active_lsd_limit | int | 60 |
active_limit | int | 500 |
for auto managed torrents, these are the limits they are subject to. If there are too many torrents some of the auto managed ones will be paused until some slots free up. active_downloads and active_seeds controls how many active seeding and downloading torrents the queuing mechanism allows. The target number of active torrents is min(active_downloads + active_seeds, active_limit). active_downloads and active_seeds are upper limits on the number of downloading torrents and seeding torrents respectively. Setting the value to -1 means unlimited.
For example if there are 10 seeding torrents and 10 downloading torrents, and active_downloads is 4 and active_seeds is 4, there will be 4 seeds active and 4 downloading torrents. If the settings are active_downloads = 2 and active_seeds = 4, then there will be 2 downloading torrents and 4 seeding torrents active. Torrents that are not auto managed are not counted against these limits.
active_checking is the limit of number of simultaneous checking torrents.
active_limit is a hard limit on the number of active (auto managed) torrents. This limit also applies to slow torrents.
active_dht_limit is the max number of torrents to announce to the DHT.
active_tracker_limit is the max number of torrents to announce to their trackers.
active_lsd_limit is the max number of torrents to announce to the local network over the local service discovery protocol.
You can have more torrents active, even though they are not announced to the DHT, lsd or their tracker. If some peer knows about you for any reason and tries to connect, it will still be accepted, unless the torrent is paused, which means it won't accept any connections.
name | type | default |
---|---|---|
auto_manage_interval | int | 30 |
auto_manage_interval is the number of seconds between the torrent queue is updated, and rotated.
name | type | default |
---|---|---|
seed_time_limit | int | 24 * 60 * 60 |
this is the limit on the time a torrent has been an active seed (specified in seconds) before it is considered having met the seed limit criteria. See queuing.
name | type | default |
---|---|---|
auto_scrape_interval | int | 1800 |
auto_scrape_min_interval | int | 300 |
auto_scrape_interval is the number of seconds between scrapes of queued torrents (auto managed and paused torrents). Auto managed torrents that are paused, are scraped regularly in order to keep track of their downloader/seed ratio. This ratio is used to determine which torrents to seed and which to pause.
auto_scrape_min_interval is the minimum number of seconds between any automatic scrape (regardless of torrent). In case there are a large number of paused auto managed torrents, this puts a limit on how often a scrape request is sent.
name | type | default |
---|---|---|
max_peerlist_size | int | 3000 |
max_paused_peerlist_size | int | 1000 |
max_peerlist_size is the maximum number of peers in the list of known peers. These peers are not necessarily connected, so this number should be much greater than the maximum number of connected peers. Peers are evicted from the cache when the list grows passed 90% of this limit, and once the size hits the limit, peers are no longer added to the list. If this limit is set to 0, there is no limit on how many peers we'll keep in the peer list.
max_paused_peerlist_size is the max peer list size used for torrents that are paused. This can be used to save memory for paused torrents, since it's not as important for them to keep a large peer list.
name | type | default |
---|---|---|
min_announce_interval | int | 5 * 60 |
this is the minimum allowed announce interval for a tracker. This is specified in seconds and is used as a sanity check on what is returned from a tracker. It mitigates hammering mis-configured trackers.
name | type | default |
---|---|---|
auto_manage_startup | int | 60 |
this is the number of seconds a torrent is considered active after it was started, regardless of upload and download speed. This is so that newly started torrents are not considered inactive until they have a fair chance to start downloading.
name | type | default |
---|---|---|
seeding_piece_quota | int | 20 |
seeding_piece_quota is the number of pieces to send to a peer, when seeding, before rotating in another peer to the unchoke set.
name | type | default |
---|---|---|
max_rejects | int | 50 |
max_rejects is the number of piece requests we will reject in a row while a peer is choked before the peer is considered abusive and is disconnected.
name | type | default |
---|---|---|
recv_socket_buffer_size | int | 0 |
send_socket_buffer_size | int | 0 |
specifies the buffer sizes set on peer sockets. 0 means the OS default (i.e. don't change the buffer sizes). The socket buffer sizes are changed using setsockopt() with SOL_SOCKET/SO_RCVBUF and SO_SNDBUFFER.
Note that uTP peers share a single UDP socket buffer for each of the listen_interfaces, along with DHT and UDP tracker traffic. If the buffer size is too small for the combined traffic through the socket, packets may be dropped.
name | type | default |
---|---|---|
max_peer_recv_buffer_size | int | 2 * 1024 * 1024 |
the max number of bytes a single peer connection's receive buffer is allowed to grow to.
name | type | default |
---|---|---|
optimistic_disk_retry | int | 10 * 60 |
optimistic_disk_retry is the number of seconds from a disk write errors occur on a torrent until libtorrent will take it out of the upload mode, to test if the error condition has been fixed.
libtorrent will only do this automatically for auto managed torrents.
You can explicitly take a torrent out of upload only mode using set_upload_mode().
name | type | default |
---|---|---|
max_suggest_pieces | int | 16 |
max_suggest_pieces is the max number of suggested piece indices received from a peer that's remembered. If a peer floods suggest messages, this limit prevents libtorrent from using too much RAM.
name | type | default |
---|---|---|
local_service_announce_interval | int | 5 * 60 |
local_service_announce_interval is the time between local network announces for a torrent. This interval is specified in seconds.
name | type | default |
---|---|---|
dht_announce_interval | int | 15 * 60 |
dht_announce_interval is the number of seconds between announcing torrents to the distributed hash table (DHT).
name | type | default |
---|---|---|
udp_tracker_token_expiry | int | 60 |
udp_tracker_token_expiry is the number of seconds libtorrent will keep UDP tracker connection tokens around for. This is specified to be 60 seconds. The higher this value is, the fewer packets have to be sent to the UDP tracker. In order for higher values to work, the tracker needs to be configured to match the expiration time for tokens.
name | type | default |
---|---|---|
num_optimistic_unchoke_slots | int | 0 |
num_optimistic_unchoke_slots is the number of optimistic unchoke slots to use. Having a higher number of optimistic unchoke slots mean you will find the good peers faster but with the trade-off to use up more bandwidth. 0 means automatic, where libtorrent opens up 20% of your allowed upload slots as optimistic unchoke slots.
name | type | default |
---|---|---|
max_pex_peers | int | 50 |
the max number of peers we accept from pex messages from a single peer. this limits the number of concurrent peers any of our peers claims to be connected to. If they claim to be connected to more than this, we'll ignore any peer that exceeds this limit
name | type | default |
---|---|---|
tick_interval | int | 500 |
tick_interval specifies the number of milliseconds between internal ticks. This is the frequency with which bandwidth quota is distributed to peers. It should not be more than one second (i.e. 1000 ms). Setting this to a low value (around 100) means higher resolution bandwidth quota distribution, setting it to a higher value saves CPU cycles.
name | type | default |
---|---|---|
share_mode_target | int | 3 |
share_mode_target specifies the target share ratio for share mode torrents. If set to 3, we'll try to upload 3 times as much as we download. Setting this very high, will make it very conservative and you might end up not downloading anything ever (and not affecting your share ratio). It does not make any sense to set this any lower than 2. For instance, if only 3 peers need to download the rarest piece, it's impossible to download a single piece and upload it more than 3 times. If the share_mode_target is set to more than 3, nothing is downloaded.
name | type | default |
---|---|---|
upload_rate_limit | int | 0 |
download_rate_limit | int | 0 |
upload_rate_limit and download_rate_limit sets the session-global limits of upload and download rate limits, in bytes per second. By default peers on the local network are not rate limited.
A value of 0 means unlimited.
For fine grained control over rate limits, including making them apply to local peers, see peer classes.
name | type | default |
---|---|---|
dht_upload_rate_limit | int | 8000 |
the number of bytes per second (on average) the DHT is allowed to send. If the incoming requests causes to many bytes to be sent in responses, incoming requests will be dropped until the quota has been replenished.
name | type | default |
---|---|---|
unchoke_slots_limit | int | 8 |
unchoke_slots_limit is the max number of unchoked peers in the session. The number of unchoke slots may be ignored depending on what choking_algorithm is set to. Setting this limit to -1 means unlimited, i.e. all peers will always be unchoked.
name | type | default |
---|---|---|
connections_limit | int | 200 |
connections_limit sets a global limit on the number of connections opened. The number of connections is set to a hard minimum of at least two per torrent, so if you set a too low connections limit, and open too many torrents, the limit will not be met.
name | type | default |
---|---|---|
connections_slack | int | 10 |
connections_slack is the number of incoming connections exceeding the connection limit to accept in order to potentially replace existing ones.
name | type | default |
---|---|---|
utp_target_delay | int | 100 |
utp_gain_factor | int | 3000 |
utp_min_timeout | int | 500 |
utp_syn_resends | int | 2 |
utp_fin_resends | int | 2 |
utp_num_resends | int | 3 |
utp_connect_timeout | int | 3000 |
utp_loss_multiplier | int | 50 |
utp_target_delay is the target delay for uTP sockets in milliseconds. A high value will make uTP connections more aggressive and cause longer queues in the upload bottleneck. It cannot be too low, since the noise in the measurements would cause it to send too slow. utp_gain_factor is the number of bytes the uTP congestion window can increase at the most in one RTT. If this is set too high, the congestion controller reacts too hard to noise and will not be stable, if it's set too low, it will react slow to congestion and not back off as fast.
utp_min_timeout is the shortest allowed uTP socket timeout, specified in milliseconds. The timeout depends on the RTT of the connection, but is never smaller than this value. A connection times out when every packet in a window is lost, or when a packet is lost twice in a row (i.e. the resent packet is lost as well).
The shorter the timeout is, the faster the connection will recover from this situation, assuming the RTT is low enough. utp_syn_resends is the number of SYN packets that are sent (and timed out) before giving up and closing the socket. utp_num_resends is the number of times a packet is sent (and lost or timed out) before giving up and closing the connection. utp_connect_timeout is the number of milliseconds of timeout for the initial SYN packet for uTP connections. For each timed out packet (in a row), the timeout is doubled. utp_loss_multiplier controls how the congestion window is changed when a packet loss is experienced. It's specified as a percentage multiplier for cwnd. Do not change this value unless you know what you're doing. Never set it higher than 100.
name | type | default |
---|---|---|
mixed_mode_algorithm | int | settings_pack::peer_proportional |
The mixed_mode_algorithm determines how to treat TCP connections when there are uTP connections. Since uTP is designed to yield to TCP, there's an inherent problem when using swarms that have both TCP and uTP connections. If nothing is done, uTP connections would often be starved out for bandwidth by the TCP connections. This mode is prefer_tcp. The peer_proportional mode simply looks at the current throughput and rate limits all TCP connections to their proportional share based on how many of the connections are TCP. This works best if uTP connections are not rate limited by the global rate limiter (which they aren't by default).
name | type | default |
---|---|---|
listen_queue_size | int | 5 |
listen_queue_size is the value passed in to listen() for the listen socket. It is the number of outstanding incoming connections to queue up while we're not actively waiting for a connection to be accepted. 5 should be sufficient for any normal client. If this is a high performance server which expects to receive a lot of connections, or used in a simulator or test, it might make sense to raise this number. It will not take affect until the listen_interfaces settings is updated.
name | type | default |
---|---|---|
torrent_connect_boost | int | 30 |
torrent_connect_boost is the number of peers to try to connect to immediately when the first tracker response is received for a torrent. This is a boost to given to new torrents to accelerate them starting up. The normal connect scheduler is run once every second, this allows peers to be connected immediately instead of waiting for the session tick to trigger connections. This may not be set higher than 255.
name | type | default |
---|---|---|
alert_queue_size | int | 2000 |
alert_queue_size is the maximum number of alerts queued up internally. If alerts are not popped, the queue will eventually fill up to this level. Once the alert queue is full, additional alerts will be dropped, and not delivered to the client. Once the client drains the queue, new alerts may be delivered again. In order to know that alerts have been dropped, see session_handle::dropped_alerts().
name | type | default |
---|---|---|
max_metadata_size | int | 3 * 1024 * 10240 |
max_metadata_size is the maximum allowed size (in bytes) to be received by the metadata extension, i.e. magnet links.
name | type | default |
---|---|---|
hashing_threads | int | 1 |
hashing_threads is the number of disk I/O threads to use for piece hash verification. These threads are in addition to the regular disk I/O threads specified by settings_pack::aio_threads. These threads are only used for full checking of torrents. The hash checking done while downloading are done by the regular disk I/O threads. The hasher threads do not only compute hashes, but also perform the read from disk. On storage optimal for sequential access, such as hard drives, this setting should be set to 1, which is also the default.
name | type | default |
---|---|---|
checking_mem_usage | int | 256 |
the number of blocks to keep outstanding at any given time when checking torrents. Higher numbers give faster re-checks but uses more memory. Specified in number of 16 kiB blocks
name | type | default |
---|---|---|
predictive_piece_announce | int | 0 |
if set to > 0, pieces will be announced to other peers before they are fully downloaded (and before they are hash checked). The intention is to gain 1.5 potential round trip times per downloaded piece. When non-zero, this indicates how many milliseconds in advance pieces should be announced, before they are expected to be completed.
name | type | default |
---|---|---|
aio_threads | int | 10 |
for some aio back-ends, aio_threads specifies the number of io-threads to use.
name | type | default |
---|---|---|
tracker_backoff | int | 250 |
tracker_backoff determines how aggressively to back off from retrying failing trackers. This value determines x in the following formula, determining the number of seconds to wait until the next retry:
delay = 5 + 5 * x / 100 * fails^2
This setting may be useful to make libtorrent more or less aggressive in hitting trackers.
name | type | default |
---|---|---|
share_ratio_limit | int | 200 |
seed_time_ratio_limit | int | 700 |
when a seeding torrent reaches either the share ratio (bytes up / bytes down) or the seed time ratio (seconds as seed / seconds as downloader) or the seed time limit (seconds as seed) it is considered done, and it will leave room for other torrents. These are specified as percentages. Torrents that are considered done will still be allowed to be seeded, they just won't have priority anymore. For more, see queuing.
name | type | default |
---|---|---|
peer_turnover | int | 4 |
peer_turnover_cutoff | int | 90 |
peer_turnover_interval | int | 300 |
peer_turnover is the percentage of peers to disconnect every turnover peer_turnover_interval (if we're at the peer limit), this is specified in percent when we are connected to more than limit * peer_turnover_cutoff peers disconnect peer_turnover fraction of the peers. It is specified in percent peer_turnover_interval is the interval (in seconds) between optimistic disconnects if the disconnects happen and how many peers are disconnected is controlled by peer_turnover and peer_turnover_cutoff
name | type | default |
---|---|---|
connect_seed_every_n_download | int | 10 |
this setting controls the priority of downloading torrents over seeding or finished torrents when it comes to making peer connections. Peer connections are throttled by the connection_speed and the half-open connection limit. This makes peer connections a limited resource. Torrents that still have pieces to download are prioritized by default, to avoid having many seeding torrents use most of the connection attempts and only give one peer every now and then to the downloading torrent. libtorrent will loop over the downloading torrents to connect a peer each, and every n:th connection attempt, a finished torrent is picked to be allowed to connect to a peer. This setting controls n.
name | type | default |
---|---|---|
max_http_recv_buffer_size | int | 4*1024*204 |
the max number of bytes to allow an HTTP response to be when announcing to trackers or downloading .torrent files via the url provided in add_torrent_params.
name | type | default |
---|---|---|
max_retry_port_bind | int | 10 |
if binding to a specific port fails, should the port be incremented by one and tried again? This setting specifies how many times to retry a failed port bind
name | type | default |
---|---|---|
alert_mask | int | int |
a bitmask combining flags from alert_category_t defining which kinds of alerts to receive
name | type | default |
---|---|---|
out_enc_policy | int | settings_pack::pe_enabled |
in_enc_policy | int | settings_pack::pe_enabled |
control the settings for incoming and outgoing connections respectively. see enc_policy enum for the available options. Keep in mind that protocol encryption degrades performance in several respects:
- It prevents "zero copy" disk buffers being sent to peers, since each peer needs to mutate the data (i.e. encrypt it) the data must be copied per peer connection rather than sending the same buffer to multiple peers.
- The encryption itself requires more CPU than plain bittorrent protocol. The highest cost is the Diffie Hellman exchange on connection setup.
- The encryption handshake adds several round-trips to the connection setup, and delays transferring data.
name | type | default |
---|---|---|
allowed_enc_level | int | settings_pack::pe_both |
determines the encryption level of the connections. This setting will adjust which encryption scheme is offered to the other peer, as well as which encryption scheme is selected by the client. See enc_level enum for options.
name | type | default |
---|---|---|
inactive_down_rate | int | 2048 |
inactive_up_rate | int | 2048 |
the download and upload rate limits for a torrent to be considered active by the queuing mechanism. A torrent whose download rate is less than inactive_down_rate and whose upload rate is less than inactive_up_rate for auto_manage_startup seconds, is considered inactive, and another queued torrent may be started. This logic is disabled if dont_count_slow_torrents is false.
name | type | default |
---|---|---|
proxy_type | int | settings_pack::none |
proxy to use. see proxy_type_t.
name | type | default |
---|---|---|
proxy_port | int | 0 |
the port of the proxy server
name | type | default |
---|---|---|
i2p_port | int | 0 |
sets the i2p SAM bridge port to connect to. set the hostname with the i2p_hostname setting.
name | type | default |
---|---|---|
urlseed_max_request_bytes | int | 16 * 1024 * 1024 |
The maximum request range of an url seed in bytes. This value defines the largest possible sequential web seed request. Lower values are possible but will be ignored if they are lower then piece size. This value should be related to your download speed to prevent libtorrent from creating too many expensive http requests per second. You can select a value as high as you want but keep in mind that libtorrent can't create parallel requests if the first request did already select the whole file. If you combine bittorrent seeds with web seeds and pick strategies like rarest first you may find your web seed requests split into smaller parts because we don't download already picked pieces twice.
name | type | default |
---|---|---|
web_seed_name_lookup_retry | int | 1800 |
time to wait until a new retry of a web seed name lookup
name | type | default |
---|---|---|
close_file_interval | int | CLOSE_FILE_INTERVAL |
the number of seconds between closing the file opened the longest ago. 0 means to disable the feature. The purpose of this is to periodically close files to trigger the operating system flushing disk cache. Specifically it has been observed to be required on windows to not have the disk cache grow indefinitely. This defaults to 240 seconds on windows, and disabled on other systems.
name | type | default |
---|---|---|
utp_cwnd_reduce_timer | int | 100 |
When uTP experiences packet loss, it will reduce the congestion window, and not reduce it again for this many milliseconds, even if experiencing another lost packet.
name | type | default |
---|---|---|
max_web_seed_connections | int | 3 |
the max number of web seeds to have connected per torrent at any given time.
name | type | default |
---|---|---|
resolver_cache_timeout | int | 1200 |
the number of seconds before the internal host name resolver considers a cache value timed out, negative values are interpreted as zero.
name | type | default |
---|---|---|
send_not_sent_low_watermark | int | 16384 |
specify the not-sent low watermark for socket send buffers. This corresponds to the, Linux-specific, TCP_NOTSENT_LOWAT TCP socket option.
name | type | default |
---|---|---|
rate_choker_initial_threshold | int | 1024 |
the rate based choker compares the upload rate to peers against a threshold that increases proportionally by its size for every peer it visits, visiting peers in decreasing upload rate. The number of upload slots is determined by the number of peers whose upload rate exceeds the threshold. This option sets the start value for this threshold. A higher value leads to fewer unchoke slots, a lower value leads to more.
name | type | default |
---|---|---|
upnp_lease_duration | int | 3600 |
The expiration time of UPnP port-mappings, specified in seconds. 0 means permanent lease. Some routers do not support expiration times on port-maps (nor correctly returning an error indicating lack of support). In those cases, set this to 0. Otherwise, don't set it any lower than 5 minutes.
name | type | default |
---|---|---|
max_concurrent_http_announces | int | 50 |
limits the number of concurrent HTTP tracker announces. Once the limit is hit, tracker requests are queued and issued when an outstanding announce completes.
name | type | default |
---|---|---|
dht_max_peers_reply | int | 100 |
the maximum number of peers to send in a reply to get_peers
name | type | default |
---|---|---|
dht_search_branching | int | 5 |
the number of concurrent search request the node will send when announcing and refreshing the routing table. This parameter is called alpha in the kademlia paper
name | type | default |
---|---|---|
dht_max_fail_count | int | 20 |
the maximum number of failed tries to contact a node before it is removed from the routing table. If there are known working nodes that are ready to replace a failing node, it will be replaced immediately, this limit is only used to clear out nodes that don't have any node that can replace them.
name | type | default |
---|---|---|
dht_max_torrents | int | 2000 |
the total number of torrents to track from the DHT. This is simply an upper limit to make sure malicious DHT nodes cannot make us allocate an unbounded amount of memory.
name | type | default |
---|---|---|
dht_max_dht_items | int | 700 |
max number of items the DHT will store
name | type | default |
---|---|---|
dht_max_peers | int | 500 |
the max number of peers to store per torrent (for the DHT)
name | type | default |
---|---|---|
dht_max_torrent_search_reply | int | 20 |
the max number of torrents to return in a torrent search query to the DHT
name | type | default |
---|---|---|
dht_block_timeout | int | 5 * 60 |
the number of seconds a DHT node is banned if it exceeds the rate limit. The rate limit is averaged over 10 seconds to allow for bursts above the limit.
name | type | default |
---|---|---|
dht_block_ratelimit | int | 5 |
the max number of packets per second a DHT node is allowed to send without getting banned.
name | type | default |
---|---|---|
dht_item_lifetime | int | 0 |
the number of seconds a immutable/mutable item will be expired. default is 0, means never expires.
name | type | default |
---|---|---|
dht_sample_infohashes_interval | int | 21600 |
the info-hashes sample recomputation interval (in seconds). The node will precompute a subset of the tracked info-hashes and return that instead of calculating it upon each request. The permissible range is between 0 and 21600 seconds (inclusive).
name | type | default |
---|---|---|
dht_max_infohashes_sample_count | int | 20 |
the maximum number of elements in the sampled subset of info-hashes. If this number is too big, expect the DHT storage implementations to clamp it in order to allow UDP packets go through
name | type | default |
---|---|---|
max_piece_count | int | 0x200000 |
max_piece_count is the maximum allowed number of pieces in metadata received via magnet links. Loading large torrents (with more pieces than the default limit) may also require passing in a higher limit to read_resume_data() and torrent_info::parse_info_section(), if those are used.
name | type | default |
---|---|---|
metadata_token_limit | int | 2500000 |
when receiving metadata (torrent file) from peers, this is the max number of bencoded tokens we're willing to parse. This limit is meant to prevent DoS attacks on peers. For very large torrents, this limit may have to be raised.
name | type | default |
---|---|---|
disk_write_mode | int | settings_pack::mmap_write_mode_t::auto_mmap_write |
controls whether disk writes will be made through a memory mapped file or via normal write calls. This only affects the mmap_disk_io. When saving to a non-local drive (network share, NFS or NAS) using memory mapped files is most likely inferior. When writing to a local SSD (especially in DAX mode) using memory mapped files likely gives the best performance. The values for this setting are specified as mmap_write_mode_t.
name | type | default |
---|---|---|
mmap_file_size_cutoff | int | 40 |
when using mmap_disk_io, files smaller than this number of blocks will not be memory mapped, but will use normal pread/pwrite operations. This file size limit is specified in 16 kiB blocks.
name | type | default |
---|---|---|
i2p_inbound_quantity | int | 3 |
i2p_outbound_quantity | int | 3 |
i2p_inbound_length | int | 3 |
i2p_outbound_length | int | 3 |
Configures the SAM session quantity of I2P inbound and outbound tunnels [1..16]. number of hops for I2P inbound and outbound tunnels [0..7] Changing these will not trigger a reconnect to the SAM bridge, they will take effect the next time the SAM connection is re-established (by restarting or changing i2p_hostname or i2p_port).
struct settings_pack final : settings_interface { friend void apply_pack_impl (settings_pack const* , aux::session_settings_single_thread& , std::vector<void(aux::session_impl::*)()>*); void set_str (int name, std::string val) override; void set_int (int name, flags::bitfield_flag<Type, Tag> const val); void set_int (int name, int val) override; void set_bool (int name, bool val) override; bool has_val (int name) const override; void clear (); void clear (int name); bool get_bool (int name) const override; int get_int (int name) const override; std::string const& get_str (int name) const override; void for_each (Fun&& f) const; enum type_bases { string_type_base, int_type_base, bool_type_base, type_mask, index_mask, }; enum mmap_write_mode_t { always_pwrite, always_mmap_write, auto_mmap_write, }; enum suggest_mode_t { no_piece_suggestions, suggest_read_cache, }; enum choking_algorithm_t { fixed_slots_choker, rate_based_choker, deprecated_bittyrant_choker, }; enum seed_choking_algorithm_t { round_robin, fastest_upload, anti_leech, }; enum io_buffer_mode_t { enable_os_cache, deprecated_disable_os_cache_for_aligned_files, disable_os_cache, write_through, }; enum bandwidth_mixed_algo_t { prefer_tcp, peer_proportional, }; enum enc_policy { pe_forced, pe_enabled, pe_disabled, }; enum enc_level { pe_plaintext, pe_rc4, pe_both, }; enum proxy_type_t { none, socks4, socks5, socks5_pw, http, http_pw, }; };[report issue]
set_int() set_bool() set_str()
void set_str (int name, std::string val) override; void set_int (int name, flags::bitfield_flag<Type, Tag> const val); void set_int (int name, int val) override; void set_bool (int name, bool val) override;
set a configuration option in the settings_pack. name is one of the enum values from string_types, int_types or bool_types. They must match the respective type of the set_* function.
[report issue]has_val()
bool has_val (int name) const override;
queries whether the specified configuration option has a value set in this pack. name can be any enumeration value from string_types, int_types or bool_types.
[report issue]get_bool() get_int() get_str()
bool get_bool (int name) const override; int get_int (int name) const override; std::string const& get_str (int name) const override;
queries the current configuration option from the settings_pack. name is one of the enumeration values from string_types, int_types or bool_types. The enum value must match the type of the get_* function. If the specified setting field has not been set, the default value is returned.
[report issue]enum type_bases
Declared in "libtorrent/settings_pack.hpp"
name | value | description |
---|---|---|
string_type_base | 0 | |
int_type_base | 16384 | |
bool_type_base | 32768 | |
type_mask | 49152 | |
index_mask | 16383 |
enum mmap_write_mode_t
Declared in "libtorrent/settings_pack.hpp"
name | value | description |
---|---|---|
always_pwrite | 0 | disable writing to disk via mmap, always use normal write calls |
always_mmap_write | 1 | prefer using memory mapped files for disk writes (at least for large files where it might make sense) |
auto_mmap_write | 2 | determine whether to use pwrite or memory mapped files for disk writes depending on the kind of storage behind the save path |
enum suggest_mode_t
Declared in "libtorrent/settings_pack.hpp"
name | value | description |
---|---|---|
no_piece_suggestions | 0 | |
suggest_read_cache | 1 |
enum choking_algorithm_t
Declared in "libtorrent/settings_pack.hpp"
name | value | description |
---|---|---|
fixed_slots_choker | 0 | This is the traditional choker with a fixed number of unchoke slots (as specified by settings_pack::unchoke_slots_limit). |
rate_based_choker | 2 | This opens up unchoke slots based on the upload rate achieved to peers. The more slots that are opened, the marginal upload rate required to open up another slot increases. Configure the initial threshold with settings_pack::rate_choker_initial_threshold. For more information, see rate based choking. |
deprecated_bittyrant_choker | 3 |
enum seed_choking_algorithm_t
Declared in "libtorrent/settings_pack.hpp"
name | value | description |
---|---|---|
round_robin | 0 | which round-robins the peers that are unchoked when seeding. This distributes the upload bandwidth uniformly and fairly. It minimizes the ability for a peer to download everything without redistributing it. |
fastest_upload | 1 | unchokes the peers we can send to the fastest. This might be a bit more reliable in utilizing all available capacity. |
anti_leech | 2 | prioritizes peers who have just started or are just about to finish the download. The intention is to force peers in the middle of the download to trade with each other. This does not just take into account the pieces a peer is reporting having downloaded, but also the pieces we have sent to it. |
enum io_buffer_mode_t
Declared in "libtorrent/settings_pack.hpp"
name | value | description |
---|---|---|
enable_os_cache | 0 | |
deprecated_disable_os_cache_for_aligned_files | 1 | |
disable_os_cache | 2 | |
write_through | 3 |
enum bandwidth_mixed_algo_t
Declared in "libtorrent/settings_pack.hpp"
name | value | description |
---|---|---|
prefer_tcp | 0 | disables the mixed mode bandwidth balancing |
peer_proportional | 1 | does not throttle uTP, throttles TCP to the same proportion of throughput as there are TCP connections |
enum enc_policy
Declared in "libtorrent/settings_pack.hpp"
name | value | description |
---|---|---|
pe_forced | 0 | Only encrypted connections are allowed. Incoming connections that are not encrypted are closed and if the encrypted outgoing connection fails, a non-encrypted retry will not be made. |
pe_enabled | 1 | encrypted connections are enabled, but non-encrypted connections are allowed. An incoming non-encrypted connection will be accepted, and if an outgoing encrypted connection fails, a non- encrypted connection will be tried. |
pe_disabled | 2 | only non-encrypted connections are allowed. |
enum enc_level
Declared in "libtorrent/settings_pack.hpp"
name | value | description |
---|---|---|
pe_plaintext | 1 | use only plain text encryption |
pe_rc4 | 2 | use only RC4 encryption |
pe_both | 3 | allow both |
enum proxy_type_t
Declared in "libtorrent/settings_pack.hpp"
name | value | description |
---|---|---|
none | 0 | No proxy server is used and all other fields are ignored. |
socks4 | 1 | The server is assumed to be a SOCKS4 server that requires a username. |
socks5 | 2 | The server is assumed to be a SOCKS5 server (RFC 1928) that does not require any authentication. The username and password are ignored. |
socks5_pw | 3 | The server is assumed to be a SOCKS5 server that supports plain text username and password authentication (RFC 1929). The username and password specified may be sent to the proxy if it requires. |
http | 4 | The server is assumed to be an HTTP proxy. If the transport used for the connection is non-HTTP, the server is assumed to support the CONNECT method. i.e. for web seeds and HTTP trackers, a plain proxy will suffice. The proxy is assumed to not require authorization. The username and password will not be used. |
http_pw | 5 | The server is assumed to be an HTTP proxy that requires user authorization. The username and password will be sent to the proxy. |
name_for_setting() setting_by_name()
Declared in "libtorrent/settings_pack.hpp"
int setting_by_name (string_view name); char const* name_for_setting (int s);
converts a setting integer (from the enums string_types, int_types or bool_types) to a string, and vice versa.
[report issue]default_settings()
Declared in "libtorrent/settings_pack.hpp"
settings_pack default_settings ();
returns a settings_pack with every setting set to its default value
[report issue]high_performance_seed() min_memory_usage()
Declared in "libtorrent/session.hpp"
settings_pack high_performance_seed (); settings_pack min_memory_usage ();
The default values of the session settings are set for a regular bittorrent client running on a desktop system. There are functions that can set the session settings to pre set settings for other environments. These can be used for the basis, and should be tweaked to fit your needs better.
min_memory_usage returns settings that will use the minimal amount of RAM, at the potential expense of upload and download performance. It adjusts the socket buffer sizes, disables the disk cache, lowers the send buffer watermarks so that each connection only has at most one block in use at any one time. It lowers the outstanding blocks send to the disk I/O thread so that connections only have one block waiting to be flushed to disk at any given time. It lowers the max number of peers in the peer list for torrents. It performs multiple smaller reads when it hashes pieces, instead of reading it all into memory before hashing.
This configuration is intended to be the starting point for embedded devices. It will significantly reduce memory usage.
high_performance_seed returns settings optimized for a seed box, serving many peers and that doesn't do any downloading. It has a 128 MB disk cache and has a limit of 400 files in its file pool. It support fast upload rates by allowing large send buffers.
[report issue]generate_fingerprint()
Declared in "libtorrent/fingerprint.hpp"
std::string generate_fingerprint (std::string name , int major, int minor = 0, int revision = 0, int tag = 0);
This is a utility function to produce a client ID fingerprint formatted to the most common convention. The fingerprint can be set via the peer_fingerprint setting, in settings_pack.
The name string should contain exactly two characters. These are the characters unique to your client, used to identify it. Make sure not to clash with anybody else. Here are some taken id's:
id chars | client |
---|---|
LT | libtorrent (default) |
UT | uTorrent |
UM | uTorrent Mac |
qB | qBittorrent |
BP | BitTorrent Pro |
BT | BitTorrent |
DE | Deluge |
AZ | Azureus |
TL | Tribler |
There's an informal directory of client id's here.
The major, minor, revision and tag parameters are used to identify the version of your client.
[report issue]storage_params
Declared in "libtorrent/storage_defs.hpp"
a parameter pack used to construct the storage for a torrent, used in disk_interface
struct storage_params { storage_params (file_storage const& f, file_storage const* mf , std::string const& sp, storage_mode_t const sm , aux::vector<download_priority_t, file_index_t> const& prio , sha1_hash const& ih); file_storage const& files; file_storage const* mapped_files = nullptr; std::string const& path; storage_mode_t mode {storage_mode_sparse}; aux::vector<download_priority_t, file_index_t> const& priorities; sha1_hash info_hash; };[report issue]
file_slice
Declared in "libtorrent/file_storage.hpp"
represents a window of a file in a torrent.
The file_index refers to the index of the file (in the torrent_info). To get the path and filename, use file_path() and give the file_index as argument. The offset is the byte offset in the file where the range starts, and size is the number of bytes this range is. The size + offset will never be greater than the file size.
struct file_slice { file_index_t file_index; std::int64_t offset; std::int64_t size; };[report issue]
- file_index
- the index of the file
- offset
- the offset from the start of the file, in bytes
- size
- the size of the window, in bytes
file_storage
Declared in "libtorrent/file_storage.hpp"
The file_storage class represents a file list and the piece size. Everything necessary to interpret a regular bittorrent storage file structure.
class file_storage { bool is_valid () const; void reserve (int num_files); void add_file_borrow (string_view filename , std::string const& path, std::int64_t file_size , file_flags_t file_flags = {}, char const* filehash = nullptr , std::int64_t mtime = 0, string_view symlink_path = string_view() , char const* root_hash = nullptr); void add_file_borrow (error_code& ec, string_view filename , std::string const& path, std::int64_t file_size , file_flags_t file_flags = {}, char const* filehash = nullptr , std::int64_t mtime = 0, string_view symlink_path = string_view() , char const* root_hash = nullptr); void add_file (std::string const& path, std::int64_t file_size , file_flags_t file_flags = {} , std::time_t mtime = 0, string_view symlink_path = string_view() , char const* root_hash = nullptr); void add_file (error_code& ec, std::string const& path, std::int64_t file_size , file_flags_t file_flags = {} , std::time_t mtime = 0, string_view symlink_path = string_view() , char const* root_hash = nullptr); void rename_file (file_index_t index, std::string const& new_filename); std::vector<file_slice> map_block (piece_index_t piece, std::int64_t offset , std::int64_t size) const; peer_request map_file (file_index_t file, std::int64_t offset, int size) const; int num_files () const noexcept; file_index_t end_file () const noexcept; index_range<file_index_t> file_range () const noexcept; std::int64_t total_size () const; int num_pieces () const; void set_num_pieces (int n); piece_index_t end_piece () const; piece_index_t last_piece () const; index_range<piece_index_t> piece_range () const noexcept; void set_piece_length (int l); int piece_length () const; int piece_size (piece_index_t index) const; int piece_size2 (piece_index_t index) const; int blocks_in_piece2 (piece_index_t index) const; int blocks_per_piece () const; std::string const& name () const; void set_name (std::string const& n); void swap (file_storage& ti) noexcept; void canonicalize (); char const* root_ptr (file_index_t const index) const; sha1_hash hash (file_index_t index) const; std::string symlink (file_index_t index) const; std::string file_path (file_index_t index, std::string const& save_path = "") const; bool pad_file_at (file_index_t index) const; std::time_t mtime (file_index_t index) const; string_view file_name (file_index_t index) const; std::int64_t file_offset (file_index_t index) const; sha256_hash root (file_index_t index) const; std::int64_t file_size (file_index_t index) const; int file_num_pieces (file_index_t index) const; int file_num_blocks (file_index_t index) const; index_range<piece_index_t::diff_type> file_piece_range (file_index_t) const; int file_first_piece_node (file_index_t index) const; int file_first_block_node (file_index_t index) const; std::uint32_t file_path_hash (file_index_t index, std::string const& save_path) const; void all_path_hashes (std::unordered_set<std::uint32_t>& table) const; file_flags_t file_flags (file_index_t index) const; bool file_absolute_path (file_index_t index) const; file_index_t file_index_at_offset (std::int64_t offset) const; file_index_t file_index_at_piece (piece_index_t piece) const; file_index_t file_index_for_root (sha256_hash const& root_hash) const; piece_index_t piece_index_at_file (file_index_t f) const; void sanitize_symlinks (); bool v2 () const; static constexpr file_flags_t flag_pad_file = 0_bit; static constexpr file_flags_t flag_hidden = 1_bit; static constexpr file_flags_t flag_executable = 2_bit; static constexpr file_flags_t flag_symlink = 3_bit; };[report issue]
is_valid()
bool is_valid () const;
returns true if the piece length has been initialized on the file_storage. This is typically taken as a proxy of whether the file_storage as a whole is initialized or not.
[report issue]reserve()
void reserve (int num_files);
allocates space for num_files in the internal file list. This can be used to avoid reallocating the internal file list when the number of files to be added is known up-front.
[report issue]add_file() add_file_borrow()
void add_file_borrow (string_view filename , std::string const& path, std::int64_t file_size , file_flags_t file_flags = {}, char const* filehash = nullptr , std::int64_t mtime = 0, string_view symlink_path = string_view() , char const* root_hash = nullptr); void add_file_borrow (error_code& ec, string_view filename , std::string const& path, std::int64_t file_size , file_flags_t file_flags = {}, char const* filehash = nullptr , std::int64_t mtime = 0, string_view symlink_path = string_view() , char const* root_hash = nullptr); void add_file (std::string const& path, std::int64_t file_size , file_flags_t file_flags = {} , std::time_t mtime = 0, string_view symlink_path = string_view() , char const* root_hash = nullptr); void add_file (error_code& ec, std::string const& path, std::int64_t file_size , file_flags_t file_flags = {} , std::time_t mtime = 0, string_view symlink_path = string_view() , char const* root_hash = nullptr);
Adds a file to the file storage. The add_file_borrow version expects that filename is the file name (without a path) of the file that's being added. This memory is borrowed, i.e. it is the caller's responsibility to make sure it stays valid throughout the lifetime of this file_storage object or any copy of it. The same thing applies to filehash, which is an optional pointer to a 20 byte binary SHA-1 hash of the file.
if filename is empty, the filename from path is used and not borrowed.
The path argument is the full path (in the torrent file) to the file to add. Note that this is not supposed to be an absolute path, but it is expected to include the name of the torrent as the first path element.
file_size is the size of the file in bytes.
The file_flags argument sets attributes on the file. The file attributes is an extension and may not work in all bittorrent clients.
For possible file attributes, see file_storage::flags_t.
The mtime argument is optional and can be set to 0. If non-zero, it is the posix time of the last modification time of this file.
symlink_path is the path the file is a symlink to. To make this a symlink you also need to set the file_storage::flag_symlink file flag.
root_hash is an optional pointer to a 32 byte SHA-256 hash, being the merkle tree root hash for this file. This is only used for v2 torrents. If the root hash is specified for one file, it has to be specified for all, otherwise this function will fail. Note that the buffer root_hash points to must out-live the file_storage object, it will not be copied. This parameter is only used when loading torrents, that already have their file hashes computed. When creating torrents, the file hashes will be computed by the piece hashes.
If more files than one are added, certain restrictions to their paths apply. In a multi-file file storage (torrent), all files must share the same root directory.
That is, the first path element of all files must be the same. This shared path element is also set to the name of the torrent. It can be changed by calling set_name.
The overloads that take an error_code reference will report failures via that variable, otherwise system_error is thrown.
[report issue]rename_file()
void rename_file (file_index_t index, std::string const& new_filename);
renames the file at index to new_filename. Keep in mind that filenames are expected to be UTF-8 encoded.
[report issue]map_block()
std::vector<file_slice> map_block (piece_index_t piece, std::int64_t offset , std::int64_t size) const;
returns a list of file_slice objects representing the portions of files the specified piece index, byte offset and size range overlaps. this is the inverse mapping of map_file().
Preconditions of this function is that the input range is within the torrents address space. piece may not be negative and
piece * piece_size + offset + size
may not exceed the total size of the torrent.
[report issue]map_file()
peer_request map_file (file_index_t file, std::int64_t offset, int size) const;
returns a peer_request representing the piece index, byte offset and size the specified file range overlaps. This is the inverse mapping over map_block(). Note that the peer_request return type is meant to hold bittorrent block requests, which may not be larger than 16 kiB. Mapping a range larger than that may return an overflown integer.
[report issue]num_files()
int num_files () const noexcept;
returns the number of files in the file_storage
[report issue]end_file()
file_index_t end_file () const noexcept;
returns the index of the one-past-end file in the file storage
[report issue]file_range()
index_range<file_index_t> file_range () const noexcept;
returns an implementation-defined type that can be used as the container in a range-for loop. Where the values are the indices of all files in the file_storage.
[report issue]total_size()
std::int64_t total_size () const;
returns the total number of bytes all the files in this torrent spans
[report issue]num_pieces() set_num_pieces()
int num_pieces () const; void set_num_pieces (int n);
set and get the number of pieces in the torrent
[report issue]end_piece()
piece_index_t end_piece () const;
returns the index of the one-past-end piece in the file storage
[report issue]last_piece()
piece_index_t last_piece () const;
returns the index of the last piece in the torrent. The last piece is special in that it may be smaller than the other pieces (and the other pieces are all the same size).
[report issue]piece_range()
index_range<piece_index_t> piece_range () const noexcept;
returns an implementation-defined type that can be used as the container in a range-for loop. Where the values are the indices of all pieces in the file_storage.
[report issue]set_piece_length() piece_length()
void set_piece_length (int l); int piece_length () const;
set and get the size of each piece in this torrent. It must be a power of two and at least 16 kiB.
[report issue]piece_size()
int piece_size (piece_index_t index) const;
returns the piece size of index. This will be the same as piece_length(), except for the last piece, which may be shorter.
[report issue]piece_size2()
int piece_size2 (piece_index_t index) const;
Returns the size of the given piece. If the piece spans multiple files, only the first file is considered part of the piece. This is used for v2 torrents, where all files are piece aligned and padded. i.e. The pad files are not considered part of the piece for this purpose.
[report issue]blocks_in_piece2()
int blocks_in_piece2 (piece_index_t index) const;
returns the number of blocks in the specified piece, for v2 torrents.
[report issue]blocks_per_piece()
int blocks_per_piece () const;
returns the number of blocks there are in the typical piece. There may be fewer in the last piece)
[report issue]name() set_name()
std::string const& name () const; void set_name (std::string const& n);
set and get the name of this torrent. For multi-file torrents, this is also the name of the root directory all the files are stored in.
[report issue]canonicalize()
void canonicalize ();
arrange files and padding to match the canonical form required by BEP 52
[report issue]root() pad_file_at() file_offset() mtime() symlink() root_ptr() file_path() hash() file_size() file_name()
char const* root_ptr (file_index_t const index) const; sha1_hash hash (file_index_t index) const; std::string symlink (file_index_t index) const; std::string file_path (file_index_t index, std::string const& save_path = "") const; bool pad_file_at (file_index_t index) const; std::time_t mtime (file_index_t index) const; string_view file_name (file_index_t index) const; std::int64_t file_offset (file_index_t index) const; sha256_hash root (file_index_t index) const; std::int64_t file_size (file_index_t index) const;
These functions are used to query attributes of files at a given index.
The hash() is a SHA-1 hash of the file, or 0 if none was provided in the torrent file. This can potentially be used to join a bittorrent network with other file sharing networks.
root() returns the SHA-256 merkle tree root of the specified file, in case this is a v2 torrent. Otherwise returns zeros. root_ptr() returns a pointer to the SHA-256 merkle tree root hash for the specified file. The pointer points into storage referred to when the file was added, it is not owned by this object. Torrents that are not v2 torrents return nullptr.
The mtime() is the modification time is the posix time when a file was last modified when the torrent was created, or 0 if it was not included in the torrent file.
file_path() returns the full path to a file.
file_size() returns the size of a file.
pad_file_at() returns true if the file at the given index is a pad-file.
file_name() returns just the name of the file, whereas file_path() returns the path (inside the torrent file) with the filename appended.
file_offset() returns the byte offset within the torrent file where this file starts. It can be used to map the file to a piece index (given the piece size).
[report issue]file_num_blocks() file_piece_range() file_num_pieces()
int file_num_pieces (file_index_t index) const; int file_num_blocks (file_index_t index) const; index_range<piece_index_t::diff_type> file_piece_range (file_index_t) const;
Returns the number of pieces or blocks the file at index spans, under the assumption that the file is aligned to the start of a piece. This is only meaningful for v2 torrents, where files are guaranteed such alignment. These numbers are used to size and navigate the merkle hash tree for each file.
[report issue]file_first_piece_node() file_first_block_node()
int file_first_piece_node (file_index_t index) const; int file_first_block_node (file_index_t index) const;
index of first piece node in the merkle tree
[report issue]file_path_hash()
std::uint32_t file_path_hash (file_index_t index, std::string const& save_path) const;
returns the crc32 hash of file_path(index)
[report issue]all_path_hashes()
void all_path_hashes (std::unordered_set<std::uint32_t>& table) const;
this will add the CRC32 hash of all directory entries to the table. No filename will be included, just directories. Every depth of directories are added separately to allow test for collisions with files at all levels. i.e. if one path in the torrent is foo/bar/baz, the CRC32 hashes for foo, foo/bar and foo/bar/baz will be added to the set.
[report issue]file_flags()
file_flags_t file_flags (file_index_t index) const;
returns a bitmask of flags from file_flags_t that apply to file at index.
[report issue]file_absolute_path()
bool file_absolute_path (file_index_t index) const;
returns true if the file at the specified index has been renamed to have an absolute path, i.e. is not anchored in the save path of the torrent.
[report issue]file_index_at_offset() file_index_at_piece()
file_index_t file_index_at_offset (std::int64_t offset) const; file_index_t file_index_at_piece (piece_index_t piece) const;
returns the index of the file at the given offset in the torrent
[report issue]file_index_for_root()
file_index_t file_index_for_root (sha256_hash const& root_hash) const;
finds the file with the given root hash and returns its index if there is no file with the root hash, file_index_t{-1} is returned
[report issue]piece_index_at_file()
piece_index_t piece_index_at_file (file_index_t f) const;
returns the piece index the given file starts at
[report issue]sanitize_symlinks()
void sanitize_symlinks ();
validate any symlinks, to ensure they all point to other files or directories inside this storage. Any invalid symlinks are updated to point to themselves.
[report issue]v2()
bool v2 () const;
returns true if this torrent contains v2 metadata.
[report issue]- flag_pad_file
- the file is a pad file. It's required to contain zeros at it will not be saved to disk. Its purpose is to make the following file start on a piece boundary.
- flag_hidden
- this file has the hidden attribute set. This is primarily a windows attribute
- flag_executable
- this file has the executable attribute set.
- flag_symlink
- this file is a symbolic link. It should have a link target string associated with it.
default_disk_io_constructor()
Declared in "libtorrent/session.hpp"
std::unique_ptr<disk_interface> default_disk_io_constructor ( io_context& ios, settings_interface const&, counters& cnt);
the constructor function for the default storage. On systems that support memory mapped files (and a 64 bit address space) the memory mapped storage will be constructed, otherwise the portable posix storage.
[report issue]mmap_disk_io_constructor()
Declared in "libtorrent/mmap_disk_io.hpp"
std::unique_ptr<disk_interface> mmap_disk_io_constructor ( io_context& ios, settings_interface const&, counters& cnt);
constructs a memory mapped file disk I/O object.
[report issue]posix_disk_io_constructor()
Declared in "libtorrent/posix_disk_io.hpp"
std::unique_ptr<disk_interface> posix_disk_io_constructor ( io_context& ios, settings_interface const&, counters& cnt);
this is a simple posix disk I/O back-end, used for systems that don't have a 64 bit virtual address space or don't support memory mapped files. It's implemented using portable C file functions and is single-threaded.
[report issue]disabled_disk_io_constructor()
Declared in "libtorrent/disabled_disk_io.hpp"
std::unique_ptr<disk_interface> disabled_disk_io_constructor ( io_context& ios, settings_interface const&, counters& cnt);
creates a disk io object that discards all data written to it, and only returns zero-buffers when read from. May be useful for testing and benchmarking.
[report issue]enum storage_mode_t
Declared in "libtorrent/storage_defs.hpp"
name | value | description |
---|---|---|
storage_mode_allocate | 0 | All pieces will be written to their final position, all files will be allocated in full when the torrent is first started. This mode minimizes fragmentation but could be a costly operation. |
storage_mode_sparse | 1 | All pieces will be written to the place where they belong and sparse files will be used. This is the recommended, and default mode. |
enum status_t
Declared in "libtorrent/storage_defs.hpp"
name | value | description |
---|---|---|
no_error | 0 | |
fatal_disk_error | 1 | |
need_full_check | 2 | |
file_exist | 3 | |
oversized_file | 16 | this is not an enum value, but a flag that can be set in the return from async_check_files, in case an existing file was found larger than specified in the torrent. i.e. it has garbage at the end the status_t field is used for this to preserve ABI. |
enum move_flags_t
Declared in "libtorrent/storage_defs.hpp"
name | value | description |
---|---|---|
always_replace_files | 0 | replace any files in the destination when copying or moving the storage |
fail_if_exist | 1 | if any files that we want to copy exist in the destination exist, fail the whole operation and don't perform any copy or move. There is an inherent race condition in this mode. The files are checked for existence before the operation starts. In between the check and performing the copy, the destination files may be created, in which case they are replaced. |
dont_replace | 2 | if any file exist in the target, take those files instead of the ones we may have in the source. |
session_handle
Declared in "libtorrent/session_handle.hpp"
this class provides a non-owning handle to a session and a subset of the interface of the session class. If the underlying session is destructed any handle to it will no longer be valid. is_valid() will return false and any operation on it will throw a system_error exception, with error code invalid_session_handle.
struct session_handle { bool is_valid () const; session_params session_state (save_state_flags_t flags = save_state_flags_t::all()) const; std::vector<torrent_status> get_torrent_status ( std::function<bool(torrent_status const&)> const& pred , status_flags_t flags = {}) const; void refresh_torrent_status (std::vector<torrent_status>* ret , status_flags_t flags = {}) const; void post_torrent_updates (status_flags_t flags = status_flags_t::all()); void post_session_stats (); void post_dht_stats (); void set_dht_state (dht::dht_state const& st); void set_dht_state (dht::dht_state&& st); torrent_handle find_torrent (sha1_hash const& info_hash) const; std::vector<torrent_handle> get_torrents () const; torrent_handle add_torrent (add_torrent_params const& params, error_code& ec); void async_add_torrent (add_torrent_params&& params); void async_add_torrent (add_torrent_params const& params); torrent_handle add_torrent (add_torrent_params&& params, error_code& ec); torrent_handle add_torrent (add_torrent_params&& params); torrent_handle add_torrent (add_torrent_params const& params); void resume (); bool is_paused () const; void pause (); bool is_dht_running () const; void set_dht_storage (dht::dht_storage_constructor_type sc); void add_dht_node (std::pair<std::string, int> const& node); void dht_get_item (sha1_hash const& target); void dht_get_item (std::array<char, 32> key , std::string salt = std::string()); sha1_hash dht_put_item (entry data); void dht_put_item (std::array<char, 32> key , std::function<void(entry&, std::array<char, 64>& , std::int64_t&, std::string const&)> cb , std::string salt = std::string()); void dht_get_peers (sha1_hash const& info_hash); void dht_announce (sha1_hash const& info_hash, int port = 0, dht::announce_flags_t flags = {}); void dht_live_nodes (sha1_hash const& nid); void dht_sample_infohashes (udp::endpoint const& ep, sha1_hash const& target); void dht_direct_request (udp::endpoint const& ep, entry const& e, client_data_t userdata = {}); void add_extension (std::function<std::shared_ptr<torrent_plugin>( torrent_handle const&, client_data_t)> ext); void add_extension (std::shared_ptr<plugin> ext); void set_ip_filter (ip_filter f); ip_filter get_ip_filter () const; void set_port_filter (port_filter const& f); bool is_listening () const; unsigned short listen_port () const; unsigned short ssl_listen_port () const; ip_filter get_peer_class_filter () const; void set_peer_class_filter (ip_filter const& f); peer_class_type_filter get_peer_class_type_filter () const; void set_peer_class_type_filter (peer_class_type_filter const& f); peer_class_t create_peer_class (char const* name); void delete_peer_class (peer_class_t cid); void set_peer_class (peer_class_t cid, peer_class_info const& pci); peer_class_info get_peer_class (peer_class_t cid) const; void remove_torrent (const torrent_handle&, remove_flags_t = {}); settings_pack get_settings () const; void apply_settings (settings_pack&&); void apply_settings (settings_pack const&); alert* wait_for_alert (time_duration max_wait); void pop_alerts (std::vector<alert*>* alerts); void set_alert_notify (std::function<void()> const& fun); std::vector<port_mapping_t> add_port_mapping (portmap_protocol t, int external_port, int local_port); void delete_port_mapping (port_mapping_t handle); void reopen_network_sockets (reopen_network_flags_t options = reopen_map_ports); std::shared_ptr<aux::session_impl> native_handle () const; static constexpr save_state_flags_t save_settings = 0_bit; static constexpr save_state_flags_t save_dht_state = 2_bit; static constexpr save_state_flags_t save_extension_state = 11_bit; static constexpr save_state_flags_t save_ip_filter = 12_bit; static constexpr peer_class_t global_peer_class_id {0}; static constexpr peer_class_t tcp_peer_class_id {1}; static constexpr peer_class_t local_peer_class_id {2}; static constexpr remove_flags_t delete_files = 0_bit; static constexpr remove_flags_t delete_partfile = 1_bit; static constexpr session_flags_t paused = 2_bit; static constexpr portmap_protocol udp = portmap_protocol::udp; static constexpr portmap_protocol tcp = portmap_protocol::tcp; static constexpr reopen_network_flags_t reopen_map_ports = 0_bit; };[report issue]
is_valid()
bool is_valid () const;
returns true if this handle refers to a valid session object. If the session has been destroyed, all session_handle objects will expire and not be valid.
[report issue]session_state()
session_params session_state (save_state_flags_t flags = save_state_flags_t::all()) const;
returns the current session state. This can be passed to write_session_params() to save the state to disk and restored using read_session_params() when constructing a new session. The kind of state that's included is all settings, the DHT routing table, possibly plugin-specific state. the flags parameter can be used to only save certain parts of the session state
[report issue]get_torrent_status() refresh_torrent_status()
std::vector<torrent_status> get_torrent_status ( std::function<bool(torrent_status const&)> const& pred , status_flags_t flags = {}) const; void refresh_torrent_status (std::vector<torrent_status>* ret , status_flags_t flags = {}) const;
Note
these calls are potentially expensive and won't scale well with lots of torrents. If you're concerned about performance, consider using post_torrent_updates() instead.
get_torrent_status returns a vector of the torrent_status for every torrent which satisfies pred, which is a predicate function which determines if a torrent should be included in the returned set or not. Returning true means it should be included and false means excluded. The flags argument is the same as to torrent_handle::status(). Since pred is guaranteed to be called for every torrent, it may be used to count the number of torrents of different categories as well.
refresh_torrent_status takes a vector of torrent_status structs (for instance the same vector that was returned by get_torrent_status() ) and refreshes the status based on the handle member. It is possible to use this function by first setting up a vector of default constructed torrent_status objects, only initializing the handle member, in order to request the torrent status for multiple torrents in a single call. This can save a significant amount of time if you have a lot of torrents.
Any torrent_status object whose handle member is not referring to a valid torrent are ignored.
The intended use of these functions is to start off by calling get_torrent_status() to get a list of all torrents that match your criteria. Then call refresh_torrent_status() on that list. This will only refresh the status for the torrents in your list, and thus ignore all other torrents you might be running. This may save a significant amount of time, especially if the number of torrents you're interested in is small. In order to keep your list of interested torrents up to date, you can either call get_torrent_status() from time to time, to include torrents you might have become interested in since the last time. In order to stop refreshing a certain torrent, simply remove it from the list.
[report issue]post_torrent_updates()
void post_torrent_updates (status_flags_t flags = status_flags_t::all());
This functions instructs the session to post the state_update_alert, containing the status of all torrents whose state changed since the last time this function was called.
Only torrents who has the state subscription flag set will be included. This flag is on by default. See add_torrent_params. the flags argument is the same as for torrent_handle::status(). see status_flags_t in torrent_handle.
[report issue]post_session_stats()
void post_session_stats ();
This function will post a session_stats_alert object, containing a snapshot of the performance counters from the internals of libtorrent. To interpret these counters, query the session via session_stats_metrics().
For more information, see the session statistics section.
[report issue]post_dht_stats()
void post_dht_stats ();
This will cause a dht_stats_alert to be posted.
[report issue]set_dht_state()
void set_dht_state (dht::dht_state const& st); void set_dht_state (dht::dht_state&& st);
set the DHT state for the session. This will be taken into account the next time the DHT is started, as if it had been passed in via the session_params on startup.
[report issue]find_torrent() get_torrents()
torrent_handle find_torrent (sha1_hash const& info_hash) const; std::vector<torrent_handle> get_torrents () const;
find_torrent() looks for a torrent with the given info-hash. In case there is such a torrent in the session, a torrent_handle to that torrent is returned. In case the torrent cannot be found, an invalid torrent_handle is returned.
See torrent_handle::is_valid() to know if the torrent was found or not.
get_torrents() returns a vector of torrent_handles to all the torrents currently in the session.
[report issue]async_add_torrent() add_torrent()
torrent_handle add_torrent (add_torrent_params const& params, error_code& ec); void async_add_torrent (add_torrent_params&& params); void async_add_torrent (add_torrent_params const& params); torrent_handle add_torrent (add_torrent_params&& params, error_code& ec); torrent_handle add_torrent (add_torrent_params&& params); torrent_handle add_torrent (add_torrent_params const& params);
You add torrents through the add_torrent() function where you give an object with all the parameters. The add_torrent() overloads will block until the torrent has been added (or failed to be added) and returns an error code and a torrent_handle. In order to add torrents more efficiently, consider using async_add_torrent() which returns immediately, without waiting for the torrent to add. Notification of the torrent being added is sent as add_torrent_alert.
The overload that does not take an error_code throws an exception on error and is not available when building without exception support. The torrent_handle returned by add_torrent() can be used to retrieve information about the torrent's progress, its peers etc. It is also used to abort a torrent.
If the torrent you are trying to add already exists in the session (is either queued for checking, being checked or downloading) add_torrent() will throw system_error which derives from std::exception unless duplicate_is_error is set to false. In that case, add_torrent() will return the handle to the existing torrent.
The add_torrent_params class has a flags field. It can be used to control what state the new torrent will be added in. Common flags to want to control are torrent_flags::paused and torrent_flags::auto_managed. In order to add a magnet link that will just download the metadata, but no payload, set the torrent_flags::upload_mode flag.
Special consideration has to be taken when adding hybrid torrents (i.e. torrents that are BitTorrent v2 torrents that are backwards compatible with v1). For more details, see BitTorrent v2 torrents.
[report issue]resume() is_paused() pause()
void resume (); bool is_paused () const; void pause ();
Pausing the session has the same effect as pausing every torrent in it, except that torrents will not be resumed by the auto-manage mechanism. Resuming will restore the torrents to their previous paused state. i.e. the session pause state is separate from the torrent pause state. A torrent is inactive if it is paused or if the session is paused.
[report issue]is_dht_running()
bool is_dht_running () const;
is_dht_running() returns true if the DHT support has been started and false otherwise.
[report issue]set_dht_storage()
void set_dht_storage (dht::dht_storage_constructor_type sc);
set_dht_storage set a dht custom storage constructor function to be used internally when the dht is created.
Since the dht storage is a critical component for the dht behavior, this function will only be effective the next time the dht is started. If you never touch this feature, a default map-memory based storage is used.
If you want to make sure the dht is initially created with your custom storage, create a session with the setting settings_pack::enable_dht to false, set your constructor function and call apply_settings with settings_pack::enable_dht to true.
[report issue]add_dht_node()
void add_dht_node (std::pair<std::string, int> const& node);
add_dht_node takes a host name and port pair. That endpoint will be pinged, and if a valid DHT reply is received, the node will be added to the routing table.
[report issue]dht_get_item()
void dht_get_item (sha1_hash const& target);
query the DHT for an immutable item at the target hash. the result is posted as a dht_immutable_item_alert.
[report issue]dht_get_item()
void dht_get_item (std::array<char, 32> key , std::string salt = std::string());
query the DHT for a mutable item under the public key key. this is an ed25519 key. salt is optional and may be left as an empty string if no salt is to be used. if the item is found in the DHT, a dht_mutable_item_alert is posted.
[report issue]dht_put_item()
sha1_hash dht_put_item (entry data);
store the given bencoded data as an immutable item in the DHT. the returned hash is the key that is to be used to look the item up again. It's just the SHA-1 hash of the bencoded form of the structure.
[report issue]dht_put_item()
void dht_put_item (std::array<char, 32> key , std::function<void(entry&, std::array<char, 64>& , std::int64_t&, std::string const&)> cb , std::string salt = std::string());
store a mutable item. The key is the public key the blob is to be stored under. The optional salt argument is a string that is to be mixed in with the key when determining where in the DHT the value is to be stored. The callback function is called from within the libtorrent network thread once we've found where to store the blob, possibly with the current value stored under the key. The values passed to the callback functions are:
- entry& value
- the current value stored under the key (may be empty). Also expected to be set to the value to be stored by the function.
- std::array<char,64>& signature
- the signature authenticating the current value. This may be zeros if there is currently no value stored. The function is expected to fill in this buffer with the signature of the new value to store. To generate the signature, you may want to use the sign_mutable_item function.
- std::int64_t& seq
- current sequence number. May be zero if there is no current value. The function is expected to set this to the new sequence number of the value that is to be stored. Sequence numbers must be monotonically increasing. Attempting to overwrite a value with a lower or equal sequence number will fail, even if the signature is correct.
- std::string const& salt
- this is the salt that was used for this put call.
Since the callback function cb is called from within libtorrent, it is critical to not perform any blocking operations. Ideally not even locking a mutex. Pass any data required for this function along with the function object's context and make the function entirely self-contained. The only reason data blob's value is computed via a function instead of just passing in the new value is to avoid race conditions. If you want to update the value in the DHT, you must first retrieve it, then modify it, then write it back. The way the DHT works, it is natural to always do a lookup before storing and calling the callback in between is convenient.
[report issue]dht_announce() dht_get_peers()
void dht_get_peers (sha1_hash const& info_hash); void dht_announce (sha1_hash const& info_hash, int port = 0, dht::announce_flags_t flags = {});
dht_get_peers() will issue a DHT get_peer request to the DHT for the specified info-hash. The response (the peers) will be posted back in a dht_get_peers_reply_alert.
dht_announce() will issue a DHT announce request to the DHT to the specified info-hash, advertising the specified port. If the port is left at its default, 0, the port will be implied by the DHT message's source port (which may improve connectivity through a NAT).
Both these functions are exposed for advanced custom use of the DHT. All torrents eligible to be announce to the DHT will be automatically, by libtorrent.
For possible flags, see announce_flags_t.
[report issue]dht_live_nodes()
void dht_live_nodes (sha1_hash const& nid);
Retrieve all the live DHT (identified by nid) nodes. All the nodes id and endpoint will be returned in the list of nodes in the alert dht_live_nodes_alert. Since this alert is a response to an explicit call, it will always be posted, regardless of the alert mask.
[report issue]dht_sample_infohashes()
void dht_sample_infohashes (udp::endpoint const& ep, sha1_hash const& target);
Query the DHT node specified by ep to retrieve a sample of the info-hashes that the node currently have in their storage. The target is included for iterative lookups so that indexing nodes can perform a key space traversal with a single RPC per node by adjusting the target value for each RPC. It has no effect on the returned sample value. The result is posted as a dht_sample_infohashes_alert.
[report issue]dht_direct_request()
void dht_direct_request (udp::endpoint const& ep, entry const& e, client_data_t userdata = {});
Send an arbitrary DHT request directly to the specified endpoint. This function is intended for use by plugins. When a response is received or the request times out, a dht_direct_response_alert will be posted with the response (if any) and the userdata pointer passed in here. Since this alert is a response to an explicit call, it will always be posted, regardless of the alert mask.
[report issue]add_extension()
void add_extension (std::function<std::shared_ptr<torrent_plugin>( torrent_handle const&, client_data_t)> ext); void add_extension (std::shared_ptr<plugin> ext);
This function adds an extension to this session. The argument is a function object that is called with a torrent_handle and which should return a std::shared_ptr<torrent_plugin>. To write custom plugins, see libtorrent plugins. For the typical bittorrent client all of these extensions should be added. The main plugins implemented in libtorrent are:
- uTorrent metadata
- Allows peers to download the metadata (.torrent files) from the swarm directly. Makes it possible to join a swarm with just a tracker and info-hash.
#include <libtorrent/extensions/ut_metadata.hpp> ses.add_extension(<::create_ut_metadata_plugin);
- uTorrent peer exchange
- Exchanges peers between clients.
#include <libtorrent/extensions/ut_pex.hpp> ses.add_extension(<::create_ut_pex_plugin);
- smart ban plugin
- A plugin that, with a small overhead, can ban peers that sends bad data with very high accuracy. Should eliminate most problems on poisoned torrents.
#include <libtorrent/extensions/smart_ban.hpp> ses.add_extension(<::create_smart_ban_plugin);[report issue]
set_ip_filter() get_ip_filter()
void set_ip_filter (ip_filter f); ip_filter get_ip_filter () const;
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.
Each time a peer is blocked because of the IP filter, a peer_blocked_alert is generated. get_ip_filter() Returns the ip_filter currently in the session. See ip_filter.
[report issue]set_port_filter()
void set_port_filter (port_filter const& f);
apply port_filter f to incoming and outgoing peers. a port filter will reject making outgoing peer connections to certain remote ports. The main intention is to be able to avoid triggering certain anti-virus software by connecting to SMTP, FTP ports.
[report issue]listen_port() is_listening() ssl_listen_port()
bool is_listening () const; unsigned short listen_port () const; unsigned short ssl_listen_port () const;
is_listening() will tell you whether or not the session has successfully opened a listening port. If it hasn't, this function will return false, and then you can set a new settings_pack::listen_interfaces to try another interface and port to bind to.
listen_port() returns the port we ended up listening on.
[report issue]set_peer_class_filter() get_peer_class_filter()
ip_filter get_peer_class_filter () const; void set_peer_class_filter (ip_filter const& f);
Sets the peer class filter for this session. All new peer connections will take this into account and be added to the peer classes specified by this filter, based on the peer's IP address.
The ip-filter essentially maps an IP -> uint32. Each bit in that 32 bit integer represents a peer class. The least significant bit represents class 0, the next bit class 1 and so on.
For more info, see ip_filter.
For example, to make all peers in the range 200.1.1.0 - 200.1.255.255 belong to their own peer class, apply the following filter:
ip_filter f = ses.get_peer_class_filter(); peer_class_t my_class = ses.create_peer_class("200.1.x.x IP range"); f.add_rule(make_address("200.1.1.0"), make_address("200.1.255.255") , 1 << static_cast<std::uint32_t>(my_class)); ses.set_peer_class_filter(f);
This setting only applies to new connections, it won't affect existing peer connections.
This function is limited to only peer class 0-31, since there are only 32 bits in the IP range mapping. Only the set bits matter; no peer class will be removed from a peer as a result of this call, peer classes are only added.
The peer_class argument cannot be greater than 31. The bitmasks representing peer classes in the peer_class_filter are 32 bits.
The get_peer_class_filter() function returns the current filter.
For more information, see peer classes.
[report issue]set_peer_class_type_filter() get_peer_class_type_filter()
peer_class_type_filter get_peer_class_type_filter () const; void set_peer_class_type_filter (peer_class_type_filter const& f);
Sets and gets the peer class type filter. This is controls automatic peer class assignments to peers based on what kind of socket it is.
It does not only support assigning peer classes, it also supports removing peer classes based on socket type.
The order of these rules being applied are:
- peer-class IP filter
- peer-class type filter, removing classes
- peer-class type filter, adding classes
For more information, see peer classes.
[report issue]create_peer_class()
peer_class_t create_peer_class (char const* name);
Creates a new peer class (see peer classes) with the given name. The returned integer is the new peer class identifier. Peer classes may have the same name, so each invocation of this function creates a new class and returns a unique identifier.
Identifiers are assigned from low numbers to higher. So if you plan on using certain peer classes in a call to set_peer_class_filter(), make sure to create those early on, to get low identifiers.
For more information on peer classes, see peer classes.
[report issue]delete_peer_class()
void delete_peer_class (peer_class_t cid);
This call dereferences the reference count of the specified peer class. When creating a peer class it's automatically referenced by 1. If you want to recycle a peer class, you may call this function. You may only call this function once per peer class you create. Calling it more than once for the same class will lead to memory corruption.
Since peer classes are reference counted, this function will not remove the peer class if it's still assigned to torrents or peers. It will however remove it once the last peer and torrent drops their references to it.
There is no need to call this function for custom peer classes. All peer classes will be properly destructed when the session object destructs.
For more information on peer classes, see peer classes.
[report issue]set_peer_class() get_peer_class()
void set_peer_class (peer_class_t cid, peer_class_info const& pci); peer_class_info get_peer_class (peer_class_t cid) const;
These functions queries information from a peer class and updates the configuration of a peer class, respectively.
cid must refer to an existing peer class. If it does not, the return value of get_peer_class() is undefined.
set_peer_class() sets all the information in the peer_class_info object in the specified peer class. There is no option to only update a single property.
A peer or torrent belonging to more than one class, the highest priority among any of its classes is the one that is taken into account.
For more information, see peer classes.
[report issue]remove_torrent()
void remove_torrent (const torrent_handle&, remove_flags_t = {});
remove_torrent() will close all peer connections associated with the torrent and tell the tracker that we've stopped participating in the swarm. This operation cannot fail. When it completes, you will receive a torrent_removed_alert.
remove_torrent() is non-blocking, but will remove the torrent from the session synchronously. Calling session_handle::add_torrent() immediately afterward with the same torrent will succeed. Note that this creates a new handle which is not equal to the removed one.
The optional second argument options can be used to delete all the files downloaded by this torrent. To do so, pass in the value session_handle::delete_files. Once the torrent is deleted, a torrent_deleted_alert is posted.
The torrent_handle remains valid for some time after remove_torrent() is called. It will become invalid only after all libtorrent tasks (such as I/O tasks) release their references to the torrent. Until this happens, torrent_handle::is_valid() will return true, and other calls such as torrent_handle::status() will succeed. Because of this, and because remove_torrent() is non-blocking, the following sequence usually succeeds (does not throw system_error): .. code:: c++
session.remove_handle(handle); handle.save_resume_data();
Note that when a queued or downloading torrent is removed, its position in the download queue is vacated and every subsequent torrent in the queue has their queue positions updated. This can potentially cause a large state_update to be posted. When removing all torrents, it is advised to remove them from the back of the queue, to minimize the shifting.
[report issue]apply_settings() get_settings()
settings_pack get_settings () const; void apply_settings (settings_pack&&); void apply_settings (settings_pack const&);
Applies the settings specified by the settings_pack s. This is an asynchronous operation that will return immediately and actually apply the settings to the main thread of libtorrent some time later.
[report issue]pop_alerts() wait_for_alert() set_alert_notify()
alert* wait_for_alert (time_duration max_wait); void pop_alerts (std::vector<alert*>* alerts); void set_alert_notify (std::function<void()> const& fun);
Alerts is the main mechanism for libtorrent to report errors and events. pop_alerts fills in the vector passed to it with pointers to new alerts. The session still owns these alerts and they will stay valid until the next time pop_alerts is called. You may not delete the alert objects.
It is safe to call pop_alerts from multiple different threads, as long as the alerts themselves are not accessed once another thread calls pop_alerts. Doing this requires manual synchronization between the popping threads.
wait_for_alert will block the current thread for max_wait time duration, or until another alert is posted. If an alert is available at the time of the call, it returns immediately. The returned alert pointer is the head of the alert queue. wait_for_alert does not pop alerts from the queue, it merely peeks at it. The returned alert will stay valid until pop_alerts is called twice. The first time will pop it and the second will free it.
If there is no alert in the queue and no alert arrives within the specified timeout, wait_for_alert returns nullptr.
In the python binding, wait_for_alert takes the number of milliseconds to wait as an integer.
The alert queue in the session will not grow indefinitely. Make sure to pop periodically to not miss notifications. To control the max number of alerts that's queued by the session, see settings_pack::alert_queue_size.
Some alerts are considered so important that they are posted even when the alert queue is full. Some alerts are considered mandatory and cannot be disabled by the alert_mask. For instance, save_resume_data_alert and save_resume_data_failed_alert are always posted, regardless of the alert mask.
To control which alerts are posted, set the alert_mask (settings_pack::alert_mask).
If the alert queue fills up to the point where alerts are dropped, this will be indicated by a alerts_dropped_alert, which contains a bitmask of which types of alerts were dropped. Generally it is a good idea to make sure the alert queue is large enough, the alert_mask doesn't have unnecessary categories enabled and to call pop_alert() frequently, to avoid alerts being dropped.
the set_alert_notify function lets the client set a function object to be invoked every time the alert queue goes from having 0 alerts to 1 alert. This function is called from within libtorrent, it may be the main thread, or it may be from within a user call. The intention of of the function is that the client wakes up its main thread, to poll for more alerts using pop_alerts(). If the notify function fails to do so, it won't be called again, until pop_alerts is called for some other reason. For instance, it could signal an eventfd, post a message to an HWND or some other main message pump. The actual retrieval of alerts should not be done in the callback. In fact, the callback should not block. It should not perform any expensive work. It really should just notify the main application thread.
The type of an alert is returned by the polymorphic function alert::type() but can also be queries from a concrete type via T::alert_type, as a static constant.
[report issue]delete_port_mapping() add_port_mapping()
std::vector<port_mapping_t> add_port_mapping (portmap_protocol t, int external_port, int local_port); void delete_port_mapping (port_mapping_t handle);
add_port_mapping adds one or more port forwards on UPnP and/or NAT-PMP, whichever is enabled. A mapping is created for each listen socket in the session. The return values are all handles referring to the port mappings that were just created. Pass them to delete_port_mapping() to remove them.
[report issue]reopen_network_sockets()
void reopen_network_sockets (reopen_network_flags_t options = reopen_map_ports);
Instructs the session to reopen all listen and outgoing sockets.
It's useful in the case your platform doesn't support the built in IP notifier mechanism, or if you have a better more reliable way to detect changes in the IP routing table.
[report issue]native_handle()
std::shared_ptr<aux::session_impl> native_handle () const;
This function is intended only for use by plugins. This type does not have a stable API and should be relied on as little as possible.
[report issue]- save_settings
- saves settings (i.e. the settings_pack)
- save_dht_state
- saves dht state such as nodes and node-id, possibly accelerating joining the DHT if provided at next session startup.
- save_extension_state
- load or save state from plugins
- save_ip_filter
- load or save the IP filter set on the session
- global_peer_class_id tcp_peer_class_id local_peer_class_id
- built-in peer classes
- delete_files
- delete the files belonging to the torrent from disk. including the part-file, if there is one
- delete_partfile
- delete just the part-file associated with this torrent
- paused
- when set, the session will start paused. Call session_handle::resume() to start
- udp tcp
- protocols used by add_port_mapping()
- reopen_map_ports
- This option indicates if the ports are mapped using natpmp and upnp. If mapping was already made, they are deleted and added again. This only works if natpmp and/or upnp are configured to be enable.
session_proxy
Declared in "libtorrent/session.hpp"
this is a holder for the internal session implementation object. Once the session destruction is explicitly initiated, this holder is used to synchronize the completion of the shutdown. The lifetime of this object may outlive session, causing the session destructor to not block. The session_proxy destructor will block however, until the underlying session is done shutting down.
struct session_proxy { session_proxy (session_proxy const&); session_proxy (); ~session_proxy (); session_proxy& operator= (session_proxy&&) & noexcept; session_proxy (session_proxy&&) noexcept; session_proxy& operator= (session_proxy const&) &; };[report issue]
~session_proxy() operator=() session_proxy()
session_proxy (session_proxy const&); session_proxy (); ~session_proxy (); session_proxy& operator= (session_proxy&&) & noexcept; session_proxy (session_proxy&&) noexcept; session_proxy& operator= (session_proxy const&) &;
default constructor, does not refer to any session implementation object.
[report issue]session
Declared in "libtorrent/session.hpp"
The session holds all state that spans multiple torrents. Among other things it runs the network loop and manages all torrents. 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.
You have some control over session configuration through the session_handle::apply_settings() member function. To change one or more configuration options, create a settings_pack. object and fill it with the settings to be set and pass it in to session::apply_settings().
see apply_settings().
struct session : session_handle { explicit session (session_params const& params); explicit session (session_params&& params); session (); session (session_params const& params, session_flags_t flags); session (session_params&& params, session_flags_t flags); session (session_params&& params, io_context& ios); session (session_params&& params, io_context& ios, session_flags_t); session (session_params const& params, io_context& ios); session (session_params const& params, io_context& ios, session_flags_t); ~session (); session_proxy abort (); };[report issue]
session()
explicit session (session_params const& params); explicit session (session_params&& params); session (); session (session_params const& params, session_flags_t flags); session (session_params&& params, session_flags_t flags);
Constructs the session objects which acts as the container of torrents. In order to avoid a race condition between starting the session and configuring it, you can pass in a session_params object. Its settings will take effect before the session starts up.
The overloads taking flags can be used to start a session in paused mode (by passing in session::paused). Note that add_default_plugins do not have an affect on constructors that take a session_params object. It already contains the plugins to use.
[report issue]session()
session (session_params&& params, io_context& ios); session (session_params&& params, io_context& ios, session_flags_t); session (session_params const& params, io_context& ios); session (session_params const& params, io_context& ios, session_flags_t);
Overload of the constructor that takes an external io_context to run the session object on. This is primarily useful for tests that may want to run multiple sessions on a single io_context, or low resource systems where additional threads are expensive and sharing an io_context with other events is fine.
Warning
The session object does not cleanly terminate with an external io_context. The io_context::run() call must have returned before it's safe to destruct the session. Which means you MUST call session::abort() and save the session_proxy first, then destruct the session object, then sync with the io_context, then destruct the session_proxy object.
~session()
~session ();
The destructor of session will notify all trackers that our torrents have been shut down. If some trackers are down, they will time out. All this before the destructor of session returns. So, it's advised that any kind of interface (such as windows) are closed before destructing the session object. Because it can take a few second for it to finish. The timeout can be set with apply_settings().
[report issue]abort()
session_proxy abort ();
In case you want to destruct the session asynchronously, you can request a session destruction proxy. If you don't do this, the destructor of the session object will block while the trackers are contacted. If you keep one session_proxy to the session when destructing it, the destructor will not block, but start to close down the session, the destructor of the proxy will then synchronize the threads. So, the destruction of the session is performed from the session destructor call until the session_proxy destructor call. The session_proxy does not have any operations on it (since the session is being closed down, no operations are allowed on it). The only valid operation is calling the destructor:
struct session_proxy {};[report issue]
session_params
Declared in "libtorrent/session_params.hpp"
The session_params is a parameters pack for configuring the session before it's started.
struct session_params { session_params (settings_pack const& sp); session_params (settings_pack&& sp); session_params (); session_params (settings_pack&& sp , std::vector<std::shared_ptr<plugin>> exts); session_params (settings_pack const& sp , std::vector<std::shared_ptr<plugin>> exts); settings_pack settings; std::vector<std::shared_ptr<plugin>> extensions; dht::dht_state dht_state; dht::dht_storage_constructor_type dht_storage_constructor; disk_io_constructor_type disk_io_constructor; std::map<std::string, std::string> ext_state; libtorrent::ip_filter ip_filter; };[report issue]
session_params()
session_params (settings_pack const& sp); session_params (settings_pack&& sp); session_params ();
This constructor can be used to start with the default plugins (ut_metadata, ut_pex and smart_ban). Pass a settings_pack to set the initial settings when the session starts.
[report issue]session_params()
session_params (settings_pack&& sp , std::vector<std::shared_ptr<plugin>> exts); session_params (settings_pack const& sp , std::vector<std::shared_ptr<plugin>> exts);
This constructor helps to configure the set of initial plugins to be added to the session before it's started.
[report issue]- settings
- The settings to configure the session with
- extensions
- the plugins to add to the session as it is constructed
- dht_state
- DHT node ID and node addresses to bootstrap the DHT with.
- dht_storage_constructor
- function object to construct the storage object for DHT items.
- disk_io_constructor
- function object to create the disk I/O subsystem. Defaults to default_disk_io_constructor.
- ext_state
- this container can be used by extensions/plugins to store settings. It's primarily here to make it convenient to save and restore state across sessions, using read_session_params() and write_session_params().
- ip_filter
- the IP filter to use for the session. This restricts which peers are allowed to connect. As if passed to set_ip_filter().
read_session_params() write_session_params() write_session_params_buf()
Declared in "libtorrent/session_params.hpp"
session_params read_session_params (bdecode_node const& e , save_state_flags_t flags = save_state_flags_t::all()); entry write_session_params (session_params const& sp , save_state_flags_t flags = save_state_flags_t::all()); std::vector<char> write_session_params_buf (session_params const& sp , save_state_flags_t flags = save_state_flags_t::all()); session_params read_session_params (span<char const> buf , save_state_flags_t flags = save_state_flags_t::all());
These functions serialize and de-serialize a session_params object to and from bencoded form. The session_params object is used to initialize a new session using the state from a previous one (or by programmatically configure the session up-front). The flags parameter can be used to only save and load certain aspects of the session's state. The _buf suffix indicates the function operates on buffer rather than the bencoded structure. The torrents in a session are not part of the session_params state, they have to be restored separately.
[report issue]hasher
Declared in "libtorrent/hasher.hpp"
this is a SHA-1 hash class.
You use it by first instantiating it, then call update() to feed it with data. i.e. you don't have to keep the entire buffer of which you want to create the hash in memory. You can feed the hasher parts of it at a time. When You have fed the hasher with all the data, you call final() and it will return the sha1-hash of the data.
The constructor that takes a char const* and an integer will construct the sha1 context and feed it the data passed in.
If you want to reuse the hasher object once you have created a hash, you have to call reset() to reinitialize it.
The built-in software version of sha1-algorithm was implemented by Steve Reid and released as public domain. For more info, see src/sha1.cpp.
class hasher { hasher (); explicit hasher (span<char const> data); hasher& operator= (hasher const&) &; hasher (hasher const&); hasher (char const* data, int len); hasher& update (span<char const> data); hasher& update (char const* data, int len); sha1_hash final (); void reset (); };[report issue]
hasher() operator=()
explicit hasher (span<char const> data); hasher& operator= (hasher const&) &; hasher (hasher const&); hasher (char const* data, int len);
this is the same as default constructing followed by a call to update(data, len).
[report issue]update()
hasher& update (span<char const> data); hasher& update (char const* data, int len);
append the following bytes to what is being hashed
[report issue]final()
sha1_hash final ();
returns the SHA-1 digest of the buffers previously passed to update() and the hasher constructor.
[report issue]reset()
void reset ();
restore the hasher state to be as if the hasher has just been default constructed.
[report issue]hasher256
Declared in "libtorrent/hasher.hpp"
class hasher256 { hasher256 (); hasher256 (hasher256 const&); hasher256 (char const* data, int len); hasher256& operator= (hasher256 const&) &; explicit hasher256 (span<char const> data); hasher256& update (span<char const> data); hasher256& update (char const* data, int len); sha256_hash final (); void reset (); ~hasher256 (); };[report issue]
operator=() hasher256()
hasher256 (hasher256 const&); hasher256 (char const* data, int len); hasher256& operator= (hasher256 const&) &; explicit hasher256 (span<char const> data);
this is the same as default constructing followed by a call to update(data, len).
[report issue]update()
hasher256& update (span<char const> data); hasher256& update (char const* data, int len);
append the following bytes to what is being hashed
[report issue]final()
sha256_hash final ();
returns the SHA-1 digest of the buffers previously passed to update() and the hasher constructor.
[report issue]reset()
void reset ();
restore the hasher state to be as if the hasher has just been default constructed.
[report issue]bitfield
Declared in "libtorrent/bitfield.hpp"
The bitfield type stores any number of bits as a bitfield in a heap allocated array.
struct bitfield { bitfield (bitfield&& rhs) noexcept = default; bitfield (bitfield const& rhs); explicit bitfield (int bits); bitfield (char const* b, int bits); bitfield (int bits, bool val); bitfield () noexcept = default; void assign (char const* b, int const bits); bool operator[] (int index) const noexcept; bool get_bit (int index) const noexcept; void set_bit (int index) noexcept; void clear_bit (int index) noexcept; bool all_set () const noexcept; bool none_set () const noexcept; int size () const noexcept; int num_words () const noexcept; int num_bytes () const noexcept; bool empty () const noexcept; char const* data () const noexcept; char* data () noexcept; void swap (bitfield& rhs) noexcept; int count () const noexcept; int find_first_set () const noexcept; int find_last_clear () const noexcept; bool operator== (lt::bitfield const& rhs) const; };[report issue]
bitfield()
bitfield (bitfield&& rhs) noexcept = default; bitfield (bitfield const& rhs); explicit bitfield (int bits); bitfield (char const* b, int bits); bitfield (int bits, bool val); bitfield () noexcept = default;
constructs a new bitfield. The default constructor creates an empty bitfield. bits is the size of the bitfield (specified in bits). val is the value to initialize the bits to. If not specified all bits are initialized to 0.
The constructor taking a pointer b and bits copies a bitfield from the specified buffer, and bits number of bits (rounded up to the nearest byte boundary).
[report issue]assign()
void assign (char const* b, int const bits);
copy bitfield from buffer b of bits number of bits, rounded up to the nearest byte boundary.
[report issue]get_bit() operator[]()
bool operator[] (int index) const noexcept; bool get_bit (int index) const noexcept;
query bit at index. Returns true if bit is 1, otherwise false.
[report issue]set_bit() clear_bit()
void set_bit (int index) noexcept; void clear_bit (int index) noexcept;
set bit at index to 0 (clear_bit) or 1 (set_bit).
[report issue]all_set()
bool all_set () const noexcept;
returns true if all bits in the bitfield are set
[report issue]none_set()
bool none_set () const noexcept;
returns true if no bit in the bitfield is set
[report issue]num_words()
int num_words () const noexcept;
returns the number of 32 bit words are needed to represent all bits in this bitfield.
[report issue]num_bytes()
int num_bytes () const noexcept;
returns the number of bytes needed to represent all bits in this bitfield
[report issue]data()
char const* data () const noexcept; char* data () noexcept;
returns a pointer to the internal buffer of the bitfield, or nullptr if it's empty.
[report issue]swap()
void swap (bitfield& rhs) noexcept;
swaps the bit-fields two variables refer to
[report issue]count()
int count () const noexcept;
count the number of bits in the bitfield that are set to 1.
[report issue]find_first_set()
int find_first_set () const noexcept;
returns the index of the first set bit in the bitfield, i.e. 1 bit.
[report issue]find_last_clear()
int find_last_clear () const noexcept;
returns the index to the last cleared bit in the bitfield, i.e. 0 bit.
The pop_alerts() function on session is the main interface for retrieving alerts (warnings, messages and errors from libtorrent). If no alerts have been posted by libtorrent pop_alerts() will return an empty list.
By default, only errors are reported. settings_pack::alert_mask can be used to specify which kinds of events should be reported. The alert mask is a combination of the alert_category_t flags in the alert class.
Every alert belongs to one or more category. There is a cost associated with posting alerts. Only alerts that belong to an enabled category are posted. Setting the alert bitmask to 0 will disable all alerts (except those that are non-discardable). Alerts that are responses to API calls such as save_resume_data() and post_session_stats() are non-discardable and will be posted even if their category is disabled.
There are other alert base classes that some alerts derive from, all the alerts that are generated for a specific torrent are derived from torrent_alert, and tracker events derive from tracker_alert.
Alerts returned by pop_alerts() are only valid until the next call to pop_alerts(). You may not copy an alert object to access it after the next call to pop_alerts(). Internal members of alerts also become invalid once pop_alerts() is called again.
[report issue]alert
Declared in "libtorrent/alert.hpp"
The alert class is the base class that specific messages are derived from. alert types are not copyable, and cannot be constructed by the client. The pointers returned by libtorrent are short lived (the details are described under session_handle::pop_alerts())
struct alert { time_point timestamp () const; virtual int type () const noexcept = 0; virtual char const* what () const noexcept = 0; virtual std::string message () const = 0; virtual alert_category_t category () const noexcept = 0; static constexpr alert_category_t error_notification = 0_bit; static constexpr alert_category_t peer_notification = 1_bit; static constexpr alert_category_t port_mapping_notification = 2_bit; static constexpr alert_category_t storage_notification = 3_bit; static constexpr alert_category_t tracker_notification = 4_bit; static constexpr alert_category_t connect_notification = 5_bit; static constexpr alert_category_t status_notification = 6_bit; static constexpr alert_category_t ip_block_notification = 8_bit; static constexpr alert_category_t performance_warning = 9_bit; static constexpr alert_category_t dht_notification = 10_bit; static constexpr alert_category_t session_log_notification = 13_bit; static constexpr alert_category_t torrent_log_notification = 14_bit; static constexpr alert_category_t peer_log_notification = 15_bit; static constexpr alert_category_t incoming_request_notification = 16_bit; static constexpr alert_category_t dht_log_notification = 17_bit; static constexpr alert_category_t dht_operation_notification = 18_bit; static constexpr alert_category_t port_mapping_log_notification = 19_bit; static constexpr alert_category_t picker_log_notification = 20_bit; static constexpr alert_category_t file_progress_notification = 21_bit; static constexpr alert_category_t piece_progress_notification = 22_bit; static constexpr alert_category_t upload_notification = 23_bit; static constexpr alert_category_t block_progress_notification = 24_bit; static constexpr alert_category_t all_categories = alert_category_t::all(); };[report issue]
timestamp()
time_point timestamp () const;
a timestamp is automatically created in the constructor
[report issue]type()
virtual int type () const noexcept = 0;
returns an integer that is unique to this alert type. It can be compared against a specific alert by querying a static constant called alert_type in the alert. It can be used to determine the run-time type of an alert* in order to cast to that alert type and access specific members.
e.g:
std::vector<alert*> alerts; ses.pop_alerts(&alerts); for (alert* a : alerts) { switch (a->type()) { case read_piece_alert::alert_type: { auto* p = static_cast<read_piece_alert*>(a); if (p->ec) { // read_piece failed break; } // use p break; } case file_renamed_alert::alert_type: { // etc... } } }[report issue]
what()
virtual char const* what () const noexcept = 0;
returns a string literal describing the type of the alert. It does not include any information that might be bundled with the alert.
[report issue]message()
virtual std::string message () const = 0;
generate a string describing the alert and the information bundled with it. This is mainly intended for debug and development use. It is not suitable to use this for applications that may be localized. Instead, handle each alert type individually and extract and render the information from the alert depending on the locale.
[report issue]category()
virtual alert_category_t category () const noexcept = 0;
returns a bitmask specifying which categories this alert belong to.
[report issue]dht_routing_bucket
Declared in "libtorrent/alert_types.hpp"
struct to hold information about a single DHT routing table bucket
struct dht_routing_bucket { int num_nodes; int num_replacements; int last_active; };[report issue]
- num_nodes num_replacements
- the total number of nodes and replacement nodes in the routing table
- last_active
- number of seconds since last activity
torrent_alert
Declared in "libtorrent/alert_types.hpp"
This is a base class for alerts that are associated with a specific torrent. It contains a handle to the torrent.
Note that by the time the client receives a torrent_alert, its handle member may be invalid.
struct torrent_alert : alert { std::string message () const override; char const* torrent_name () const; torrent_handle handle; };[report issue]
message()
std::string message () const override;
returns the message associated with this alert
[report issue]- handle
- The torrent_handle pointing to the torrent this alert is associated with.
peer_alert
Declared in "libtorrent/alert_types.hpp"
The peer alert is a base class for alerts that refer to a specific peer. It includes all the information to identify the peer. i.e. ip and peer-id.
struct peer_alert : torrent_alert { std::string message () const override; aux::noexcept_movable<tcp::endpoint> endpoint; peer_id pid; };[report issue]
- endpoint
- The peer's IP address and port.
- pid
- the peer ID, if known.
tracker_alert
Declared in "libtorrent/alert_types.hpp"
This is a base class used for alerts that are associated with a specific tracker. It derives from torrent_alert since a tracker is also associated with a specific torrent.
struct tracker_alert : torrent_alert { std::string message () const override; char const* tracker_url () const; aux::noexcept_movable<tcp::endpoint> local_endpoint; };[report issue]
tracker_url()
char const* tracker_url () const;
returns a 0-terminated string of the tracker's URL
[report issue]- local_endpoint
- endpoint of the listen interface being announced
torrent_removed_alert
Declared in "libtorrent/alert_types.hpp"
The torrent_removed_alert is posted whenever a torrent is removed. Since the torrent handle in its base class will usually be invalid (since the torrent is already removed) it has the info hash as a member, to identify it. It's posted when the alert_category::status bit is set in the alert_mask.
Note that the handle remains valid for some time after torrent_removed_alert is posted, as long as some internal libtorrent task (such as an I/O task) refers to it. Additionally, other alerts like save_resume_data_alert may be posted after torrent_removed_alert. To synchronize on whether the torrent has been removed or not, call torrent_handle::in_session(). This will return true before torrent_removed_alert is posted, and false afterward.
Even though the handle member doesn't point to an existing torrent anymore, it is still useful for comparing to other handles, which may also no longer point to existing torrents, but to the same non-existing torrents.
The torrent_handle acts as a weak_ptr, even though its object no longer exists, it can still compare equal to another weak pointer which points to the same non-existent object.
struct torrent_removed_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; info_hash_t info_hashes; client_data_t userdata; };[report issue]
- userdata
- 'userdata` as set in add_torrent_params at torrent creation. This can be used to associate this torrent with related data in the client application more efficiently than info_hashes.
read_piece_alert
Declared in "libtorrent/alert_types.hpp"
This alert is posted when the asynchronous read operation initiated by a call to torrent_handle::read_piece() is completed. If the read failed, the torrent is paused and an error state is set and the buffer member of the alert is 0. If successful, buffer points to a buffer containing all the data of the piece. piece is the piece index that was read. size is the number of bytes that was read.
If the operation fails, error will indicate what went wrong.
struct read_piece_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::storage; error_code const error; boost::shared_array<char> const buffer; piece_index_t const piece; int const size; };[report issue]
file_completed_alert
Declared in "libtorrent/alert_types.hpp"
This is posted whenever an individual file completes its download. i.e. All pieces overlapping this file have passed their hash check.
struct file_completed_alert final : torrent_alert { std::string message () const override; file_index_t const index; };[report issue]
- index
- refers to the index of the file that completed.
file_renamed_alert
Declared in "libtorrent/alert_types.hpp"
This is posted as a response to a torrent_handle::rename_file() call, if the rename operation succeeds.
struct file_renamed_alert final : torrent_alert { std::string message () const override; char const* new_name () const; char const* old_name () const; static constexpr alert_category_t static_category = alert_category::storage; file_index_t const index; };[report issue]
new_name() old_name()
char const* new_name () const; char const* old_name () const;
returns the new and previous file name, respectively.
[report issue]- index
- refers to the index of the file that was renamed,
file_rename_failed_alert
Declared in "libtorrent/alert_types.hpp"
This is posted as a response to a torrent_handle::rename_file() call, if the rename operation failed.
struct file_rename_failed_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::storage; file_index_t const index; error_code const error; };[report issue]
- index error
- refers to the index of the file that was supposed to be renamed, error is the error code returned from the filesystem.
performance_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a limit is reached that might have a negative impact on upload or download rate performance.
struct performance_alert final : torrent_alert { std::string message () const override; enum performance_warning_t { outstanding_disk_buffer_limit_reached, outstanding_request_limit_reached, upload_limit_too_low, download_limit_too_low, send_buffer_watermark_too_low, too_many_optimistic_unchoke_slots, too_high_disk_queue_limit, aio_limit_reached, deprecated_bittyrant_with_no_uplimit, too_few_outgoing_ports, too_few_file_descriptors, num_warnings, }; static constexpr alert_category_t static_category = alert_category::performance_warning; performance_warning_t const warning_code; };[report issue]
enum performance_warning_t
Declared in "libtorrent/alert_types.hpp"
name | value | description |
---|---|---|
outstanding_disk_buffer_limit_reached | 0 | This warning means that the number of bytes queued to be written to disk exceeds the max disk byte queue setting (settings_pack::max_queued_disk_bytes). This might restrict the download rate, by not queuing up enough write jobs to the disk I/O thread. When this alert is posted, peer connections are temporarily stopped from downloading, until the queued disk bytes have fallen below the limit again. Unless your max_queued_disk_bytes setting is already high, you might want to increase it to get better performance. |
outstanding_request_limit_reached | 1 | This is posted when libtorrent would like to send more requests to a peer, but it's limited by settings_pack::max_out_request_queue. The queue length libtorrent is trying to achieve is determined by the download rate and the assumed round-trip-time (settings_pack::request_queue_time). The assumed round-trip-time is not limited to just the network RTT, but also the remote disk access time and message handling time. It defaults to 3 seconds. The target number of outstanding requests is set to fill the bandwidth-delay product (assumed RTT times download rate divided by number of bytes per request). When this alert is posted, there is a risk that the number of outstanding requests is too low and limits the download rate. You might want to increase the max_out_request_queue setting. |
upload_limit_too_low | 2 | This warning is posted when the amount of TCP/IP overhead is greater than the upload rate limit. When this happens, the TCP/IP overhead is caused by a much faster download rate, triggering TCP ACK packets. These packets eat into the rate limit specified to libtorrent. When the overhead traffic is greater than the rate limit, libtorrent will not be able to send any actual payload, such as piece requests. This means the download rate will suffer, and new requests can be sent again. There will be an equilibrium where the download rate, on average, is about 20 times the upload rate limit. If you want to maximize the download rate, increase the upload rate limit above 5% of your download capacity. |
download_limit_too_low | 3 | This is the same warning as upload_limit_too_low but referring to the download limit instead of upload. This suggests that your download rate limit is much lower than your upload capacity. Your upload rate will suffer. To maximize upload rate, make sure your download rate limit is above 5% of your upload capacity. |
send_buffer_watermark_too_low | 4 | We're stalled on the disk. We want to write to the socket, and we can write but our send buffer is empty, waiting to be refilled from the disk. This either means the disk is slower than the network connection or that our send buffer watermark is too small, because we can send it all before the disk gets back to us. The number of bytes that we keep outstanding, requested from the disk, is calculated as follows: min(512, max(upload_rate * send_buffer_watermark_factor / 100, send_buffer_watermark)) If you receive this alert, you might want to either increase your send_buffer_watermark or send_buffer_watermark_factor. |
too_many_optimistic_unchoke_slots | 5 | If the half (or more) of all upload slots are set as optimistic unchoke slots, this warning is issued. You probably want more regular (rate based) unchoke slots. |
too_high_disk_queue_limit | 6 | If the disk write queue ever grows larger than half of the cache size, this warning is posted. The disk write queue eats into the total disk cache and leaves very little left for the actual cache. This causes the disk cache to oscillate in evicting large portions of the cache before allowing peers to download any more, onto the disk write queue. Either lower max_queued_disk_bytes or increase cache_size. |
aio_limit_reached | 7 | |
deprecated_bittyrant_with_no_uplimit | 8 | |
too_few_outgoing_ports | 9 | This is generated if outgoing peer connections are failing because of address in use errors, indicating that settings_pack::outgoing_ports is set and is too small of a range. Consider not using the outgoing_ports setting at all, or widen the range to include more ports. |
too_few_file_descriptors | 10 | |
num_warnings | 11 |
state_changed_alert
Declared in "libtorrent/alert_types.hpp"
Generated whenever a torrent changes its state.
struct state_changed_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; torrent_status::state_t const state; torrent_status::state_t const prev_state; };[report issue]
- state
- the new state of the torrent.
- prev_state
- the previous state.
tracker_error_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated on tracker time outs, premature disconnects, invalid response or a HTTP response other than "200 OK". From the alert you can get the handle to the torrent the tracker belongs to.
struct tracker_error_alert final : tracker_alert { std::string message () const override; char const* failure_reason () const; static constexpr alert_category_t static_category = alert_category::tracker | alert_category::error; int const times_in_row; error_code const error; operation_t op; protocol_version version; };[report issue]
failure_reason()
char const* failure_reason () const;
if the tracker sent a "failure reason" string, it will be returned here.
[report issue]- times_in_row
- This member says how many times in a row this tracker has failed.
- error
- the error code indicating why the tracker announce failed. If it is is lt::errors::tracker_failure the failure_reason() might contain a more detailed description of why the tracker rejected the request. HTTP status codes indicating errors are also set in this field.
- version
- the bittorrent protocol version that was announced
tracker_warning_alert
Declared in "libtorrent/alert_types.hpp"
This alert is triggered if the tracker reply contains a warning field. Usually this means that the tracker announce was successful, but the tracker has a message to the client.
struct tracker_warning_alert final : tracker_alert { std::string message () const override; char const* warning_message () const; static constexpr alert_category_t static_category = alert_category::tracker | alert_category::error; protocol_version version; };[report issue]
warning_message()
char const* warning_message () const;
the message associated with this warning
[report issue]- version
- the bittorrent protocol version that was announced
scrape_reply_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a scrape request succeeds.
struct scrape_reply_alert final : tracker_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::tracker; int const incomplete; int const complete; protocol_version version; };[report issue]
- incomplete complete
- the data returned in the scrape response. These numbers may be -1 if the response was malformed.
- version
- the bittorrent protocol version that was scraped
scrape_failed_alert
Declared in "libtorrent/alert_types.hpp"
If a scrape request fails, this alert is generated. This might be due to the tracker timing out, refusing connection or returning an http response code indicating an error.
struct scrape_failed_alert final : tracker_alert { std::string message () const override; char const* error_message () const; static constexpr alert_category_t static_category = alert_category::tracker | alert_category::error; error_code const error; protocol_version version; };[report issue]
error_message()
char const* error_message () const;
if the error indicates there is an associated message, this returns that message. Otherwise and empty string.
[report issue]- error
- the error itself. This may indicate that the tracker sent an error message (error::tracker_failure), in which case it can be retrieved by calling error_message().
- version
- the bittorrent protocol version that was scraped
tracker_reply_alert
Declared in "libtorrent/alert_types.hpp"
This alert is only for informational purpose. It is generated when a tracker announce succeeds. It is generated regardless what kind of tracker was used, be it UDP, HTTP or the DHT.
struct tracker_reply_alert final : tracker_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::tracker; int const num_peers; protocol_version version; };[report issue]
- num_peers
- tells how many peers the tracker returned in this response. This is not expected to be greater than the num_want settings. These are not necessarily all new peers, some of them may already be connected.
- version
- the bittorrent protocol version that was announced
dht_reply_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated each time the DHT receives peers from a node. num_peers is the number of peers we received in this packet. Typically these packets are received from multiple DHT nodes, and so the alerts are typically generated a few at a time.
struct dht_reply_alert final : tracker_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::dht | alert_category::tracker; int const num_peers; };[report issue]
tracker_announce_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated each time a tracker announce is sent (or attempted to be sent). There are no extra data members in this alert. The url can be found in the base class however.
struct tracker_announce_alert final : tracker_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::tracker; event_t const event; protocol_version version; };[report issue]
- event
- specifies what event was sent to the tracker. See event_t.
- version
- the bittorrent protocol version that is announced
hash_failed_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a finished piece fails its hash check. You can get the handle to the torrent which got the failed piece and the index of the piece itself from the alert.
struct hash_failed_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; piece_index_t const piece_index; };[report issue]
peer_ban_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a peer is banned because it has sent too many corrupt pieces to us. ip is the endpoint to the peer that was banned.
struct peer_ban_alert final : peer_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::peer; };[report issue]
peer_unsnubbed_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a peer is un-snubbed. Essentially when it was snubbed for stalling sending data, and now it started sending data again.
struct peer_unsnubbed_alert final : peer_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::peer; };[report issue]
peer_snubbed_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a peer is snubbed, when it stops sending data when we request it.
struct peer_snubbed_alert final : peer_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::peer; };[report issue]
peer_error_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a peer sends invalid data over the peer-peer protocol. The peer will be disconnected, but you get its ip address from the alert, to identify it.
struct peer_error_alert final : peer_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::peer; operation_t op; error_code const error; };[report issue]
- op
- a 0-terminated string of the low-level operation that failed, or nullptr if there was no low level disk operation.
- error
- tells you what error caused this alert.
peer_connect_alert
Declared in "libtorrent/alert_types.hpp"
This alert is posted every time an incoming peer connection both successfully passes the protocol handshake and is associated with a torrent, or an outgoing peer connection attempt succeeds. For arbitrary incoming connections, see incoming_connection_alert.
struct peer_connect_alert final : peer_alert { std::string message () const override; enum direction_t { in, out, }; static constexpr alert_category_t static_category = alert_category::connect; direction_t direction; socket_type_t socket_type; };[report issue]
enum direction_t
Declared in "libtorrent/alert_types.hpp"
name | value | description |
---|---|---|
in | 0 | |
out | 1 |
- direction
- Tells you if the peer was incoming or outgoing
peer_disconnected_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a peer is disconnected for any reason (other than the ones covered by peer_error_alert ).
struct peer_disconnected_alert final : peer_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::connect; socket_type_t const socket_type; operation_t const op; error_code const error; close_reason_t const reason; };[report issue]
- socket_type
- the kind of socket this peer was connected over
- op
- the operation or level where the error occurred. Specified as an value from the operation_t enum. Defined in operations.hpp.
- error
- tells you what error caused peer to disconnect.
- reason
- the reason the peer disconnected (if specified)
invalid_request_alert
Declared in "libtorrent/alert_types.hpp"
This is a debug alert that is generated by an incoming invalid piece request. ip is the address of the peer and the request is the actual incoming request from the peer. See peer_request for more info.
struct invalid_request_alert final : peer_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::peer; peer_request const request; bool const we_have; bool const peer_interested; bool const withheld; };[report issue]
- request
- the request we received from the peer
- we_have
- true if we have this piece
- peer_interested
- true if the peer indicated that it was interested to download before sending the request
- withheld
- if this is true, the peer is not allowed to download this piece because of super-seeding rules.
torrent_finished_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a torrent switches from being a downloader to a seed. It will only be generated once per torrent. It contains a torrent_handle to the torrent in question.
struct torrent_finished_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; };[report issue]
piece_finished_alert
Declared in "libtorrent/alert_types.hpp"
this alert is posted every time a piece completes downloading and passes the hash check. This alert derives from torrent_alert which contains the torrent_handle to the torrent the piece belongs to. Note that being downloaded and passing the hash check may happen before the piece is also fully flushed to disk. So torrent_handle::have_piece() may still return false
struct piece_finished_alert final : torrent_alert { std::string message () const override; piece_index_t const piece_index; };[report issue]
- piece_index
- the index of the piece that finished
request_dropped_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a peer rejects or ignores a piece request.
struct request_dropped_alert final : peer_alert { std::string message () const override; int const block_index; piece_index_t const piece_index; };[report issue]
block_timeout_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a block request times out.
struct block_timeout_alert final : peer_alert { std::string message () const override; int const block_index; piece_index_t const piece_index; };[report issue]
block_finished_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a block request receives a response.
struct block_finished_alert final : peer_alert { std::string message () const override; int const block_index; piece_index_t const piece_index; };[report issue]
block_downloading_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a block request is sent to a peer.
struct block_downloading_alert final : peer_alert { std::string message () const override; int const block_index; piece_index_t const piece_index; };[report issue]
unwanted_block_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a block is received that was not requested or whose request timed out.
struct unwanted_block_alert final : peer_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::peer; int const block_index; piece_index_t const piece_index; };[report issue]
storage_moved_alert
Declared in "libtorrent/alert_types.hpp"
The storage_moved_alert is generated when all the disk IO has completed and the files have been moved, as an effect of a call to torrent_handle::move_storage. This is useful to synchronize with the actual disk. The storage_path() member return the new path of the storage.
struct storage_moved_alert final : torrent_alert { std::string message () const override; char const* storage_path () const; char const* old_path () const; static constexpr alert_category_t static_category = alert_category::storage; };[report issue]
storage_path() old_path()
char const* storage_path () const; char const* old_path () const;
the path the torrent was moved to and from, respectively.
[report issue]storage_moved_failed_alert
Declared in "libtorrent/alert_types.hpp"
The storage_moved_failed_alert is generated when an attempt to move the storage, via torrent_handle::move_storage(), fails.
struct storage_moved_failed_alert final : torrent_alert { std::string message () const override; char const* file_path () const; static constexpr alert_category_t static_category = alert_category::storage; error_code const error; operation_t op; };[report issue]
file_path()
char const* file_path () const;
If the error happened for a specific file, this returns its path.
[report issue]- op
- this indicates what underlying operation caused the error
torrent_deleted_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a request to delete the files of a torrent complete.
This alert is posted in the alert_category::storage category, and that bit needs to be set in the alert_mask.
struct torrent_deleted_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::storage; info_hash_t info_hashes; };[report issue]
- info_hashes
- The info-hash of the torrent that was just deleted. Most of the time the torrent_handle in the torrent_alert will be invalid by the time this alert arrives, since the torrent is being deleted. The info_hashes member is hence the main way of identifying which torrent just completed the delete.
torrent_delete_failed_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a request to delete the files of a torrent fails. Just removing a torrent from the session cannot fail
struct torrent_delete_failed_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::storage | alert_category::error; error_code const error; info_hash_t info_hashes; };[report issue]
- error
- tells you why it failed.
- info_hashes
- the info hash of the torrent whose files failed to be deleted
save_resume_data_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated as a response to a torrent_handle::save_resume_data request. It is generated once the disk IO thread is done writing the state for this torrent.
struct save_resume_data_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::storage; add_torrent_params params; };[report issue]
- params
the params object is populated with the torrent file whose resume data was saved. It is suitable to be:
- added to a session with add_torrent() or async_add_torrent()
- saved to disk with write_resume_data()
- turned into a magnet link with make_magnet_uri()
- saved as a .torrent file with write_torrent_file()
save_resume_data_failed_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated instead of save_resume_data_alert if there was an error generating the resume data. error describes what went wrong.
struct save_resume_data_failed_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::storage | alert_category::error; error_code const error; };[report issue]
- error
- the error code from the resume_data failure
torrent_paused_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated as a response to a torrent_handle::pause request. It is generated once all disk IO is complete and the files in the torrent have been closed. This is useful for synchronizing with the disk.
struct torrent_paused_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; };[report issue]
torrent_resumed_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated as a response to a torrent_handle::resume() request. It is generated when a torrent goes from a paused state to an active state.
struct torrent_resumed_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; };[report issue]
torrent_checked_alert
Declared in "libtorrent/alert_types.hpp"
This alert is posted when a torrent completes checking. i.e. when it transitions out of the checking files state into a state where it is ready to start downloading
struct torrent_checked_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; };[report issue]
url_seed_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a HTTP seed name lookup fails.
struct url_seed_alert final : torrent_alert { std::string message () const override; char const* server_url () const; char const* error_message () const; static constexpr alert_category_t static_category = alert_category::peer | alert_category::error; error_code const error; };[report issue]
error_message()
char const* error_message () const;
in case the web server sent an error message, this function returns it.
[report issue]- error
- the error the web seed encountered. If this is not set, the server sent an error message, call error_message().
file_error_alert
Declared in "libtorrent/alert_types.hpp"
If the storage fails to read or write files that it needs access to, this alert is generated and the torrent is paused.
struct file_error_alert final : torrent_alert { std::string message () const override; char const* filename () const; static constexpr alert_category_t static_category = alert_category::status | alert_category::storage; error_code const error; operation_t op; };[report issue]
filename()
char const* filename () const;
the file that experienced the error
[report issue]- error
- the error code describing the error.
- op
- indicates which underlying operation caused the error
metadata_failed_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when the metadata has been completely received and the info-hash failed to match it. i.e. the metadata that was received was corrupt. libtorrent will automatically retry to fetch it in this case. This is only relevant when running a torrent-less download, with the metadata extension provided by libtorrent.
struct metadata_failed_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::error; error_code const error; };[report issue]
- error
- indicates what failed when parsing the metadata. This error is what's returned from lazy_bdecode().
metadata_received_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when the metadata has been completely received and the torrent can start downloading. It is not generated on torrents that are started with metadata, but only those that needs to download it from peers (when utilizing the libtorrent extension).
There are no additional data members in this alert.
Typically, when receiving this alert, you would want to save the torrent file in order to load it back up again when the session is restarted. Here's an example snippet of code to do that:
torrent_handle h = alert->handle(); std::shared_ptr<torrent_info const> ti = h.torrent_file(); create_torrent ct(*ti); entry te = ct.generate(); std::vector<char> buffer; bencode(std::back_inserter(buffer), te); FILE* f = fopen((to_hex(ti->info_hashes().get_best().to_string()) + ".torrent").c_str(), "wb+"); if (f) { fwrite(&buffer[0], 1, buffer.size(), f); fclose(f); }
struct metadata_received_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; };[report issue]
udp_error_alert
Declared in "libtorrent/alert_types.hpp"
This alert is posted when there is an error on a UDP socket. The UDP sockets are used for all uTP, DHT and UDP tracker traffic. They are global to the session.
struct udp_error_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::error; aux::noexcept_movable<udp::endpoint> endpoint; operation_t operation; error_code const error; };[report issue]
- endpoint
- the source address associated with the error (if any)
- operation
- the operation that failed
- error
- the error code describing the error
external_ip_alert
Declared in "libtorrent/alert_types.hpp"
Whenever libtorrent learns about the machines external IP, this alert is generated. The external IP address can be acquired from the tracker (if it supports that) or from peers that supports the extension protocol. The address can be accessed through the external_address member.
struct external_ip_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; aux::noexcept_movable<address> external_address; };[report issue]
- external_address
- the IP address that is believed to be our external IP
listen_failed_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when none of the ports, given in the port range, to session can be opened for listening. The listen_interface member is the interface that failed, error is the error code describing the failure.
In the case an endpoint was created before generating the alert, it is represented by address and port. The combinations of socket type and operation in which such address and port are not valid are: accept - i2p accept - socks5 enum_if - tcp
libtorrent may sometimes try to listen on port 0, if all other ports failed. Port 0 asks the operating system to pick a port that's free). If that fails you may see a listen_failed_alert with port 0 even if you didn't ask to listen on it.
struct listen_failed_alert final : alert { std::string message () const override; char const* listen_interface () const; static constexpr alert_category_t static_category = alert_category::status | alert_category::error; error_code const error; operation_t op; lt::socket_type_t const socket_type; aux::noexcept_movable<lt::address> address; int const port; };[report issue]
listen_interface()
char const* listen_interface () const;
the network device libtorrent attempted to listen on, or the IP address
[report issue]- error
- the error the system returned
- op
- the underlying operation that failed
- socket_type
- the type of listen socket this alert refers to.
- address
- the address libtorrent attempted to listen on see alert documentation for validity of this value
- port
- the port libtorrent attempted to listen on see alert documentation for validity of this value
listen_succeeded_alert
Declared in "libtorrent/alert_types.hpp"
This alert is posted when the listen port succeeds to be opened on a particular interface. address and port is the endpoint that successfully was opened for listening.
struct listen_succeeded_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; aux::noexcept_movable<lt::address> address; int const port; lt::socket_type_t const socket_type; };[report issue]
- address
- the address libtorrent ended up listening on. This address refers to the local interface.
- port
- the port libtorrent ended up listening on.
- socket_type
- the type of listen socket this alert refers to.
portmap_error_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a NAT router was successfully found but some part of the port mapping request failed. It contains a text message that may help the user figure out what is wrong. This alert is not generated in case it appears the client is not running on a NAT:ed network or if it appears there is no NAT router that can be remote controlled to add port mappings.
struct portmap_error_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::port_mapping | alert_category::error; port_mapping_t const mapping; portmap_transport map_transport; aux::noexcept_movable<address> local_address; error_code const error; };[report issue]
- mapping
- refers to the mapping index of the port map that failed, i.e. the index returned from add_mapping().
- map_transport
- UPnP or NAT-PMP
- local_address
- the local network the port mapper is running on
- error
- tells you what failed.
portmap_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a NAT router was successfully found and a port was successfully mapped on it. On a NAT:ed network with a NAT-PMP capable router, this is typically generated once when mapping the TCP port and, if DHT is enabled, when the UDP port is mapped.
struct portmap_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::port_mapping; port_mapping_t const mapping; int const external_port; portmap_protocol const map_protocol; portmap_transport const map_transport; aux::noexcept_movable<address> local_address; };[report issue]
- mapping
- refers to the mapping index of the port map that failed, i.e. the index returned from add_mapping().
- external_port
- the external port allocated for the mapping.
- local_address
- the local network the port mapper is running on
portmap_log_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated to log informational events related to either UPnP or NAT-PMP. They contain a log line and the type (0 = NAT-PMP and 1 = UPnP). Displaying these messages to an end user is only useful for debugging the UPnP or NAT-PMP implementation. This alert is only posted if the alert_category::port_mapping_log flag is enabled in the alert mask.
struct portmap_log_alert final : alert { std::string message () const override; char const* log_message () const; static constexpr alert_category_t static_category = alert_category::port_mapping_log; portmap_transport const map_transport; aux::noexcept_movable<address> local_address; };[report issue]
log_message()
char const* log_message () const;
the message associated with this log line
[report issue]- local_address
- the local network the port mapper is running on
fastresume_rejected_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a fast resume file has been passed to add_torrent() but the files on disk did not match the fast resume file. The error_code explains the reason why the resume file was rejected.
struct fastresume_rejected_alert final : torrent_alert { std::string message () const override; char const* file_path () const; static constexpr alert_category_t static_category = alert_category::status | alert_category::error; error_code error; operation_t op; };[report issue]
file_path()
char const* file_path () const;
If the error happened to a specific file, this returns the path to it.
[report issue]- op
- the underlying operation that failed
peer_blocked_alert
Declared in "libtorrent/alert_types.hpp"
This alert is posted when an incoming peer connection, or a peer that's about to be added to our peer list, is blocked for some reason. This could be any of:
- the IP filter
- i2p mixed mode restrictions (a normal peer is not allowed on an i2p swarm)
- the port filter
- the peer has a low port and no_connect_privileged_ports is enabled
- the protocol of the peer is blocked (uTP/TCP blocking)
struct peer_blocked_alert final : peer_alert { std::string message () const override; enum reason_t { ip_filter, port_filter, i2p_mixed, privileged_ports, utp_disabled, tcp_disabled, invalid_local_interface, ssrf_mitigation, }; static constexpr alert_category_t static_category = alert_category::ip_block; int const reason; };[report issue]
enum reason_t
Declared in "libtorrent/alert_types.hpp"
name | value | description |
---|---|---|
ip_filter | 0 | |
port_filter | 1 | |
i2p_mixed | 2 | |
privileged_ports | 3 | |
utp_disabled | 4 | |
tcp_disabled | 5 | |
invalid_local_interface | 6 | |
ssrf_mitigation | 7 |
- reason
- the reason for the peer being blocked. Is one of the values from the reason_t enum.
dht_announce_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a DHT node announces to an info-hash on our DHT node. It belongs to the alert_category::dht category.
struct dht_announce_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::dht; aux::noexcept_movable<address> ip; int port; sha1_hash info_hash; };[report issue]
dht_get_peers_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when a DHT node sends a get_peers message to our DHT node. It belongs to the alert_category::dht category.
struct dht_get_peers_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::dht; sha1_hash info_hash; };[report issue]
cache_flushed_alert
Declared in "libtorrent/alert_types.hpp"
This alert is posted when the disk cache has been flushed for a specific torrent as a result of a call to torrent_handle::flush_cache(). This alert belongs to the alert_category::storage category, which must be enabled to let this alert through. The alert is also posted when removing a torrent from the session, once the outstanding cache flush is complete and the torrent does no longer have any files open.
struct cache_flushed_alert final : torrent_alert { static constexpr alert_category_t static_category = alert_category::storage; };[report issue]
lsd_peer_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when we receive a local service discovery message from a peer for a torrent we're currently participating in.
struct lsd_peer_alert final : peer_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::peer; };[report issue]
trackerid_alert
Declared in "libtorrent/alert_types.hpp"
This alert is posted whenever a tracker responds with a trackerid. The tracker ID is like a cookie. libtorrent will store the tracker ID for this tracker and repeat it in subsequent announces.
struct trackerid_alert final : tracker_alert { std::string message () const override; char const* tracker_id () const; static constexpr alert_category_t static_category = alert_category::status; };[report issue]
dht_bootstrap_alert
Declared in "libtorrent/alert_types.hpp"
This alert is posted when the initial DHT bootstrap is done.
struct dht_bootstrap_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::dht; };[report issue]
torrent_error_alert
Declared in "libtorrent/alert_types.hpp"
This is posted whenever a torrent is transitioned into the error state. If the error code is duplicate_torrent (error_code_enum) error, it suggests two magnet links ended up resolving to the same hybrid torrent. For more details, see BitTorrent v2 torrents.
struct torrent_error_alert final : torrent_alert { std::string message () const override; char const* filename () const; static constexpr alert_category_t static_category = alert_category::error | alert_category::status; error_code const error; };[report issue]
filename()
char const* filename () const;
the filename (or object) the error occurred on.
[report issue]- error
- specifies which error the torrent encountered.
torrent_need_cert_alert
Declared in "libtorrent/alert_types.hpp"
This is always posted for SSL torrents. This is a reminder to the client that the torrent won't work unless torrent_handle::set_ssl_certificate() is called with a valid certificate. Valid certificates MUST be signed by the SSL certificate in the .torrent file.
struct torrent_need_cert_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; };[report issue]
incoming_connection_alert
Declared in "libtorrent/alert_types.hpp"
The incoming connection alert is posted every time we successfully accept an incoming connection, through any mean. The most straight-forward ways of accepting incoming connections are through the TCP listen socket and the UDP listen socket for uTP sockets. However, connections may also be accepted through a Socks5 or i2p listen socket, or via an SSL listen socket.
struct incoming_connection_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::peer; socket_type_t socket_type; aux::noexcept_movable<tcp::endpoint> endpoint; };[report issue]
- socket_type
- tells you what kind of socket the connection was accepted
- endpoint
- is the IP address and port the connection came from.
add_torrent_alert
Declared in "libtorrent/alert_types.hpp"
This alert is always posted when a torrent was attempted to be added and contains the return status of the add operation. The torrent handle of the new torrent can be found as the handle member in the base class. If adding the torrent failed, error contains the error code.
struct add_torrent_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; add_torrent_params params; error_code error; };[report issue]
- params
This contains copies of the most important fields from the original add_torrent_params object, passed to add_torrent() or async_add_torrent(). Specifically, these fields are copied:
- version
- ti
- name
- save_path
- userdata
- tracker_id
- flags
- info_hash
the info_hash field will be updated with the info-hash of the torrent specified by ti.
- error
- set to the error, if one occurred while adding the torrent.
state_update_alert
Declared in "libtorrent/alert_types.hpp"
This alert is only posted when requested by the user, by calling session::post_torrent_updates() on the session. It contains the torrent status of all torrents that changed since last time this message was posted. Its category is alert_category::status, but it's not subject to filtering, since it's only manually posted anyway.
struct state_update_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; std::vector<torrent_status> status; };[report issue]
- status
- contains the torrent status of all torrents that changed since last time this message was posted. Note that you can map a torrent status to a specific torrent via its handle member. The receiving end is suggested to have all torrents sorted by the torrent_handle or hashed by it, for efficient updates.
session_stats_alert
Declared in "libtorrent/alert_types.hpp"
The session_stats_alert is posted when the user requests session statistics by calling post_session_stats() on the session object. This alert does not have a category, since it's only posted in response to an API call. It is not subject to the alert_mask filter.
the message() member function returns a string representation of the values that properly match the line returned in session_stats_header_alert::message().
this specific output is parsed by tools/parse_session_stats.py if this is changed, that parser should also be changed
struct session_stats_alert final : alert { std::string message () const override; span<std::int64_t const> counters () const; static constexpr alert_category_t static_category = {}; };[report issue]
counters()
span<std::int64_t const> counters () const;
An array are a mix of counters and gauges, which meanings can be queries via the session_stats_metrics() function on the session. The mapping from a specific metric to an index into this array is constant for a specific version of libtorrent, but may differ for other versions. The intended usage is to request the mapping, i.e. call session_stats_metrics(), once on startup, and then use that mapping to interpret these values throughout the process' runtime.
For more information, see the session statistics section.
[report issue]dht_error_alert
Declared in "libtorrent/alert_types.hpp"
posted when something fails in the DHT. This is not necessarily a fatal error, but it could prevent proper operation
struct dht_error_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::error | alert_category::dht; error_code error; operation_t op; };[report issue]
- error
- the error code
- op
- the operation that failed
dht_immutable_item_alert
Declared in "libtorrent/alert_types.hpp"
this alert is posted as a response to a call to session::get_item(), specifically the overload for looking up immutable items in the DHT.
struct dht_immutable_item_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::dht; sha1_hash target; entry item; };[report issue]
- target
- the target hash of the immutable item. This must match the SHA-1 hash of the bencoded form of item.
- item
- the data for this item
dht_mutable_item_alert
Declared in "libtorrent/alert_types.hpp"
this alert is posted as a response to a call to session::get_item(), specifically the overload for looking up mutable items in the DHT.
struct dht_mutable_item_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::dht; std::array<char, 32> key; std::array<char, 64> signature; std::int64_t seq; std::string salt; entry item; bool authoritative; };[report issue]
- key
- the public key that was looked up
- signature
- the signature of the data. This is not the signature of the plain encoded form of the item, but it includes the sequence number and possibly the hash as well. See the dht_store document for more information. This is primarily useful for echoing back in a store request.
- seq
- the sequence number of this item
- salt
- the salt, if any, used to lookup and store this item. If no salt was used, this is an empty string
- item
- the data for this item
- authoritative
- the last response for mutable data is authoritative.
dht_put_alert
Declared in "libtorrent/alert_types.hpp"
this is posted when a DHT put operation completes. This is useful if the client is waiting for a put to complete before shutting down for instance.
struct dht_put_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::dht; sha1_hash target; std::array<char, 32> public_key; std::array<char, 64> signature; std::string salt; std::int64_t seq; int num_success; };[report issue]
- target
- the target hash the item was stored under if this was an immutable item.
- public_key signature salt seq
- if a mutable item was stored, these are the public key, signature, salt and sequence number the item was stored under.
- num_success
- DHT put operation usually writes item to k nodes, maybe the node is stale so no response, or the node doesn't support 'put', or the token for write is out of date, etc. num_success is the number of successful responses we got from the puts.
i2p_alert
Declared in "libtorrent/alert_types.hpp"
this alert is used to report errors in the i2p SAM connection
struct i2p_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::error; error_code error; };[report issue]
- error
- the error that occurred in the i2p SAM connection
dht_outgoing_get_peers_alert
Declared in "libtorrent/alert_types.hpp"
This alert is generated when we send a get_peers request It belongs to the alert_category::dht category.
struct dht_outgoing_get_peers_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::dht; sha1_hash info_hash; sha1_hash obfuscated_info_hash; aux::noexcept_movable<udp::endpoint> endpoint; };[report issue]
- info_hash
- the info_hash of the torrent we're looking for peers for.
- obfuscated_info_hash
- if this was an obfuscated lookup, this is the info-hash target actually sent to the node.
- endpoint
- the endpoint we're sending this query to
log_alert
Declared in "libtorrent/alert_types.hpp"
This alert is posted by some session wide event. Its main purpose is trouble shooting and debugging. It's not enabled by the default alert mask and is enabled by the alert_category::session_log bit. Furthermore, it's by default disabled as a build configuration.
struct log_alert final : alert { std::string message () const override; char const* log_message () const; static constexpr alert_category_t static_category = alert_category::session_log; };[report issue]
torrent_log_alert
Declared in "libtorrent/alert_types.hpp"
This alert is posted by torrent wide events. It's meant to be used for trouble shooting and debugging. It's not enabled by the default alert mask and is enabled by the alert_category::torrent_log bit. By default it is disabled as a build configuration.
struct torrent_log_alert final : torrent_alert { std::string message () const override; char const* log_message () const; static constexpr alert_category_t static_category = alert_category::torrent_log; };[report issue]
peer_log_alert
Declared in "libtorrent/alert_types.hpp"
This alert is posted by events specific to a peer. It's meant to be used for trouble shooting and debugging. It's not enabled by the default alert mask and is enabled by the alert_category::peer_log bit. By default it is disabled as a build configuration.
struct peer_log_alert final : peer_alert { std::string message () const override; char const* log_message () const; enum direction_t { incoming_message, outgoing_message, incoming, outgoing, info, }; static constexpr alert_category_t static_category = alert_category::peer_log; char const* event_type; direction_t direction; };[report issue]
enum direction_t
Declared in "libtorrent/alert_types.hpp"
name | value | description |
---|---|---|
incoming_message | 0 | |
outgoing_message | 1 | |
incoming | 2 | |
outgoing | 3 | |
info | 4 |
- event_type
- string literal indicating the kind of event. For messages, this is the message name.
lsd_error_alert
Declared in "libtorrent/alert_types.hpp"
posted if the local service discovery socket fails to start properly. it's categorized as alert_category::error.
struct lsd_error_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::error; aux::noexcept_movable<address> local_address; error_code error; };[report issue]
- local_address
- the local network the corresponding local service discovery is running on
- error
- The error code
dht_lookup
Declared in "libtorrent/alert_types.hpp"
holds statistics about a current dht_lookup operation. a DHT lookup is the traversal of nodes, looking up a set of target nodes in the DHT for retrieving and possibly storing information in the DHT
struct dht_lookup { char const* type; int outstanding_requests; int timeouts; int responses; int branch_factor; int nodes_left; int last_sent; int first_timeout; sha1_hash target; };[report issue]
- type
- string literal indicating which kind of lookup this is
- outstanding_requests
- the number of outstanding request to individual nodes this lookup has right now
- timeouts
- the total number of requests that have timed out so far for this lookup
- responses
- the total number of responses we have received for this lookup so far for this lookup
- branch_factor
- the branch factor for this lookup. This is the number of nodes we keep outstanding requests to in parallel by default. when nodes time out we may increase this.
- nodes_left
- the number of nodes left that could be queries for this lookup. Many of these are likely to be part of the trail while performing the lookup and would never end up actually being queried.
- last_sent
- the number of seconds ago the last message was sent that's still outstanding
- first_timeout
- the number of outstanding requests that have exceeded the short timeout and are considered timed out in the sense that they increased the branch factor
- target
- the node-id or info-hash target for this lookup
dht_stats_alert
Declared in "libtorrent/alert_types.hpp"
contains current DHT state. Posted in response to session::post_dht_stats().
struct dht_stats_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = {}; std::vector<dht_lookup> active_requests; std::vector<dht_routing_bucket> routing_table; sha1_hash nid; aux::noexcept_movable<udp::endpoint> local_endpoint; };[report issue]
- active_requests
- a vector of the currently running DHT lookups.
- routing_table
- contains information about every bucket in the DHT routing table.
- nid
- the node ID of the DHT node instance
- local_endpoint
- the local socket this DHT node is running on
incoming_request_alert
Declared in "libtorrent/alert_types.hpp"
posted every time an incoming request from a peer is accepted and queued up for being serviced. This alert is only posted if the alert_category::incoming_request flag is enabled in the alert mask.
struct incoming_request_alert final : peer_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::incoming_request; peer_request req; };[report issue]
- req
- the request this peer sent to us
dht_log_alert
Declared in "libtorrent/alert_types.hpp"
debug logging of the DHT when alert_category::dht_log is set in the alert mask.
struct dht_log_alert final : alert { std::string message () const override; char const* log_message () const; enum dht_module_t { tracker, node, routing_table, rpc_manager, traversal, }; static constexpr alert_category_t static_category = alert_category::dht_log; dht_module_t module; };[report issue]
enum dht_module_t
Declared in "libtorrent/alert_types.hpp"
name | value | description |
---|---|---|
tracker | 0 | |
node | 1 | |
routing_table | 2 | |
rpc_manager | 3 | |
traversal | 4 |
- module
- the module, or part, of the DHT that produced this log message.
dht_pkt_alert
Declared in "libtorrent/alert_types.hpp"
This alert is posted every time a DHT message is sent or received. It is only posted if the alert_category::dht_log alert category is enabled. It contains a verbatim copy of the message.
struct dht_pkt_alert final : alert { std::string message () const override; span<char const> pkt_buf () const; enum direction_t { incoming, outgoing, }; static constexpr alert_category_t static_category = alert_category::dht_log; direction_t direction; aux::noexcept_movable<udp::endpoint> node; };[report issue]
pkt_buf()
span<char const> pkt_buf () const;
returns a pointer to the packet buffer and size of the packet, respectively. This buffer is only valid for as long as the alert itself is valid, which is owned by libtorrent and reclaimed whenever pop_alerts() is called on the session.
[report issue]enum direction_t
Declared in "libtorrent/alert_types.hpp"
name | value | description |
---|---|---|
incoming | 0 | |
outgoing | 1 |
- direction
- whether this is an incoming or outgoing packet.
- node
- the DHT node we received this packet from, or sent this packet to (depending on direction).
dht_get_peers_reply_alert
Declared in "libtorrent/alert_types.hpp"
Posted when we receive a response to a DHT get_peers request.
struct dht_get_peers_reply_alert final : alert { std::string message () const override; int num_peers () const; std::vector<tcp::endpoint> peers () const; static constexpr alert_category_t static_category = alert_category::dht_operation; sha1_hash info_hash; };[report issue]
dht_direct_response_alert
Declared in "libtorrent/alert_types.hpp"
This is posted exactly once for every call to session_handle::dht_direct_request. If the request failed, response() will return a default constructed bdecode_node.
struct dht_direct_response_alert final : alert { std::string message () const override; bdecode_node response () const; static constexpr alert_category_t static_category = alert_category::dht; client_data_t userdata; aux::noexcept_movable<udp::endpoint> endpoint; };[report issue]
picker_log_alert
Declared in "libtorrent/alert_types.hpp"
this is posted when one or more blocks are picked by the piece picker, assuming the verbose piece picker logging is enabled (see alert_category::picker_log).
struct picker_log_alert final : peer_alert { std::string message () const override; std::vector<piece_block> blocks () const; static constexpr alert_category_t static_category = alert_category::picker_log; static constexpr picker_flags_t partial_ratio = 0_bit; static constexpr picker_flags_t prioritize_partials = 1_bit; static constexpr picker_flags_t rarest_first_partials = 2_bit; static constexpr picker_flags_t rarest_first = 3_bit; static constexpr picker_flags_t reverse_rarest_first = 4_bit; static constexpr picker_flags_t suggested_pieces = 5_bit; static constexpr picker_flags_t prio_sequential_pieces = 6_bit; static constexpr picker_flags_t sequential_pieces = 7_bit; static constexpr picker_flags_t reverse_pieces = 8_bit; static constexpr picker_flags_t time_critical = 9_bit; static constexpr picker_flags_t random_pieces = 10_bit; static constexpr picker_flags_t prefer_contiguous = 11_bit; static constexpr picker_flags_t reverse_sequential = 12_bit; static constexpr picker_flags_t backup1 = 13_bit; static constexpr picker_flags_t backup2 = 14_bit; static constexpr picker_flags_t end_game = 15_bit; static constexpr picker_flags_t extent_affinity = 16_bit; picker_flags_t const picker_flags; };[report issue]
- picker_flags
- this is a bitmask of which features were enabled for this particular pick. The bits are defined in the picker_flags_t enum.
session_error_alert
Declared in "libtorrent/alert_types.hpp"
this alert is posted when the session encounters a serious error, potentially fatal
struct session_error_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::error; error_code const error; };[report issue]
- error
- The error code, if one is associated with this error
dht_live_nodes_alert
Declared in "libtorrent/alert_types.hpp"
posted in response to a call to session::dht_live_nodes(). It contains the live nodes from the DHT routing table of one of the DHT nodes running locally.
struct dht_live_nodes_alert final : alert { std::string message () const override; int num_nodes () const; std::vector<std::pair<sha1_hash, udp::endpoint>> nodes () const; static constexpr alert_category_t static_category = alert_category::dht; sha1_hash node_id; };[report issue]
num_nodes() nodes()
int num_nodes () const; std::vector<std::pair<sha1_hash, udp::endpoint>> nodes () const;
the number of nodes in the routing table and the actual nodes.
[report issue]- node_id
- the local DHT node's node-ID this routing table belongs to
session_stats_header_alert
Declared in "libtorrent/alert_types.hpp"
The session_stats_header alert is posted the first time post_session_stats() is called
the message() member function returns a string representation of the header that properly match the stats values string returned in session_stats_alert::message().
this specific output is parsed by tools/parse_session_stats.py if this is changed, that parser should also be changed
struct session_stats_header_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = {}; };[report issue]
dht_sample_infohashes_alert
Declared in "libtorrent/alert_types.hpp"
posted as a response to a call to session::dht_sample_infohashes() with the information from the DHT response message.
struct dht_sample_infohashes_alert final : alert { std::string message () const override; std::vector<sha1_hash> samples () const; int num_samples () const; int num_nodes () const; std::vector<std::pair<sha1_hash, udp::endpoint>> nodes () const; static constexpr alert_category_t static_category = alert_category::dht_operation; sha1_hash node_id; aux::noexcept_movable<udp::endpoint> endpoint; time_duration const interval; int const num_infohashes; };[report issue]
num_samples() samples()
std::vector<sha1_hash> samples () const; int num_samples () const;
returns the number of info-hashes returned by the node, as well as the actual info-hashes. num_samples() is more efficient than samples().size().
[report issue]nodes()
std::vector<std::pair<sha1_hash, udp::endpoint>> nodes () const;
This is the set of more DHT nodes returned by the request.
The information is included so that indexing nodes can perform a key space traversal with a single RPC per node by adjusting the target value for each RPC.
[report issue]- node_id
- id of the node the request was sent to (and this response was received from)
- endpoint
- the node the request was sent to (and this response was received from)
- interval
- the interval to wait before making another request to this node
- num_infohashes
- This field indicates how many info-hash keys are currently in the node's storage. If the value is larger than the number of returned samples it indicates that the indexer may obtain additional samples after waiting out the interval.
block_uploaded_alert
Declared in "libtorrent/alert_types.hpp"
This alert is posted when a block intended to be sent to a peer is placed in the send buffer. Note that if the connection is closed before the send buffer is sent, the alert may be posted without the bytes having been sent to the peer. It belongs to the alert_category::upload category.
struct block_uploaded_alert final : peer_alert { std::string message () const override; int const block_index; piece_index_t const piece_index; };[report issue]
alerts_dropped_alert
Declared in "libtorrent/alert_types.hpp"
this alert is posted to indicate to the client that some alerts were dropped. Dropped meaning that the alert failed to be delivered to the client. The most common cause of such failure is that the internal alert queue grew too big (controlled by alert_queue_size).
struct alerts_dropped_alert final : alert { std::string message () const override; static_assert (num_alert_types <= abi_alert_count, "need to increase bitset. This is an ABI break"); static constexpr alert_category_t static_category = alert_category::error; std::bitset<abi_alert_count> dropped_alerts; };[report issue]
- dropped_alerts
- a bitmask indicating which alerts were dropped. Each bit represents the alert type ID, where bit 0 represents whether any alert of type 0 has been dropped, and so on.
socks5_alert
Declared in "libtorrent/alert_types.hpp"
this alert is posted with SOCKS5 related errors, when a SOCKS5 proxy is configured. It's enabled with the alert_category::error alert category.
struct socks5_alert final : alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::error; error_code error; operation_t op; aux::noexcept_movable<tcp::endpoint> ip; };[report issue]
- error
- the error
- op
- the operation that failed
- ip
- the endpoint configured as the proxy
file_prio_alert
Declared in "libtorrent/alert_types.hpp"
posted when a prioritize_files() or file_priority() update of the file priorities complete, which requires a round-trip to the disk thread.
If the disk operation fails this alert won't be posted, but a file_error_alert is posted instead, and the torrent is stopped.
struct file_prio_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::storage; error_code error; operation_t op; };[report issue]
- error
- the error
- op
- the operation that failed
oversized_file_alert
Declared in "libtorrent/alert_types.hpp"
this alert may be posted when the initial checking of resume data and files on disk (just existence, not piece hashes) completes. If a file belonging to the torrent is found on disk, but is larger than the file in the torrent, that's when this alert is posted. the client may want to call truncate_files() in that case, or perhaps interpret it as a sign that some other file is in the way, that shouldn't be overwritten.
struct oversized_file_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::storage; };[report issue]
torrent_conflict_alert
Declared in "libtorrent/alert_types.hpp"
this alert is posted when two separate torrents (magnet links) resolve to the same torrent, thus causing the same torrent being added twice. In that case, both torrents enter an error state with duplicate_torrent as the error code. This alert is posted containing the metadata. For more information, see BitTorrent v2 torrents. The torrent this alert originated from was the one that downloaded the
metadata (i.e. the handle member from the torrent_alert base class).
struct torrent_conflict_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::error; torrent_handle conflicting_torrent; std::shared_ptr<torrent_info> metadata; };[report issue]
- conflicting_torrent
- the handle to the torrent in conflict. The swarm associated with this torrent handle did not download the metadata, but the downloaded metadata collided with this swarm's info-hash.
- metadata
- the metadata that was received by one of the torrents in conflict. One way to resolve the conflict is to remove both failing torrents and re-add it using this metadata
peer_info_alert
Declared in "libtorrent/alert_types.hpp"
posted when torrent_handle::post_peer_info() is called
struct peer_info_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; std::vector<lt::peer_info> peer_info; };[report issue]
- peer_info
- the list of the currently connected peers
file_progress_alert
Declared in "libtorrent/alert_types.hpp"
posted when torrent_handle::post_file_progress() is called
struct file_progress_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::file_progress; aux::vector<std::int64_t, file_index_t> files; };[report issue]
- files
- the list of the files in the torrent
piece_info_alert
Declared in "libtorrent/alert_types.hpp"
posted when torrent_handle::post_download_queue() is called
struct piece_info_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::piece_progress; std::vector<partial_piece_info> piece_info; std::vector<block_info> block_data; };[report issue]
- piece_info
- info about pieces being downloaded for the torrent
- block_data
- storage for block_info pointers in partial_piece_info objects
piece_availability_alert
Declared in "libtorrent/alert_types.hpp"
posted when torrent_handle::post_piece_availability() is called
struct piece_availability_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; std::vector<int> piece_availability; };[report issue]
- piece_availability
- info about pieces being downloaded for the torrent
tracker_list_alert
Declared in "libtorrent/alert_types.hpp"
posted when torrent_handle::post_trackers() is called
struct tracker_list_alert final : torrent_alert { std::string message () const override; static constexpr alert_category_t static_category = alert_category::status; std::vector<announce_entry> trackers; };[report issue]
- trackers
- list of trackers and their status for the torrent
alert_cast()
Declared in "libtorrent/alert.hpp"
template <typename T> T* alert_cast (alert* a); template <typename T> T const* alert_cast (alert const* a);
When you get an alert, you can use alert_cast<> to attempt to cast the pointer to a specific alert type, in order to query it for more information.
Note
alert_cast<> can only cast to an exact alert type, not a base class
operation_name()
Declared in "libtorrent/operations.hpp"
char const* operation_name (operation_t op);
maps an operation id (from peer_error_alert and peer_disconnected_alert) to its name. See operation_t for the constants
[report issue]enum operation_t
Declared in "libtorrent/operations.hpp"
name | value | description |
---|---|---|
unknown | 0 | the error was unexpected and it is unknown which operation caused it |
bittorrent | 1 | this is used when the bittorrent logic determines to disconnect |
iocontrol | 2 | a call to iocontrol failed |
getpeername | 3 | a call to getpeername() failed (querying the remote IP of a connection) |
getname | 4 | a call to getname failed (querying the local IP of a connection) |
alloc_recvbuf | 5 | an attempt to allocate a receive buffer failed |
alloc_sndbuf | 6 | an attempt to allocate a send buffer failed |
file_write | 7 | writing to a file failed |
file_read | 8 | reading from a file failed |
file | 9 | a non-read and non-write file operation failed |
sock_write | 10 | a socket write operation failed |
sock_read | 11 | a socket read operation failed |
sock_open | 12 | a call to open(), to create a socket socket failed |
sock_bind | 13 | a call to bind() on a socket failed |
available | 14 | an attempt to query the number of bytes available to read from a socket failed |
encryption | 15 | a call related to bittorrent protocol encryption failed |
connect | 16 | an attempt to connect a socket failed |
ssl_handshake | 17 | establishing an SSL connection failed |
get_interface | 18 | a connection failed to satisfy the bind interface setting |
sock_listen | 19 | a call to listen() on a socket |
sock_bind_to_device | 20 | a call to the ioctl to bind a socket to a specific network device or adapter |
sock_accept | 21 | a call to accept() on a socket |
parse_address | 22 | convert a string into a valid network address |
enum_if | 23 | enumeration network devices or adapters |
file_stat | 24 | invoking stat() on a file |
file_copy | 25 | copying a file |
file_fallocate | 26 | allocating storage for a file |
file_hard_link | 27 | creating a hard link |
file_remove | 28 | removing a file |
file_rename | 29 | renaming a file |
file_open | 30 | opening a file |
mkdir | 31 | creating a directory |
check_resume | 32 | check fast resume data against files on disk |
exception | 33 | an unknown exception |
alloc_cache_piece | 34 | allocate space for a piece in the cache |
partfile_move | 35 | move a part-file |
partfile_read | 36 | read from a part file |
partfile_write | 37 | write to a part-file |
hostname_lookup | 38 | a hostname lookup |
symlink | 39 | create or read a symlink |
handshake | 40 | handshake with a peer or server |
sock_option | 41 | set socket option |
enum_route | 42 | enumeration of network routes |
file_seek | 43 | moving read/write position in a file, operation_t::hostname_lookup |
timer | 44 | an async wait operation on a timer |
file_mmap | 45 | call to mmap() (or windows counterpart) |
file_truncate | 46 | call to ftruncate() (or SetEndOfFile() on windows) |
int
Declared in "libtorrent/alert_types.hpp"
- user_alert_id
- user defined alerts should use IDs greater than this
- num_alert_types
- this constant represents "max_alert_index" + 1
alert_category_t
Declared in "libtorrent/alert.hpp"
- error
Enables alerts that report an error. This includes:
- tracker errors
- tracker warnings
- file errors
- resume data failures
- web seed errors
- .torrent files errors
- listen socket errors
- port mapping errors
- peer
- Enables alerts when peers send invalid requests, get banned or snubbed.
- port_mapping
- Enables alerts for port mapping events. For NAT-PMP and UPnP.
- storage
- Enables alerts for events related to the storage. File errors and synchronization events for moving the storage, renaming files etc.
- tracker
- Enables all tracker events. Includes announcing to trackers, receiving responses, warnings and errors.
- connect
- Low level alerts for when peers are connected and disconnected.
- status
- Enables alerts for when a torrent or the session changes state.
- ip_block
- Alerts when a peer is blocked by the ip blocker or port blocker.
- performance_warning
- Alerts when some limit is reached that might limit the download or upload rate.
- dht
- Alerts on events in the DHT node. For incoming searches or bootstrapping being done etc.
- stats
- If you enable these alerts, you will receive a stats_alert approximately once every second, for every active torrent. These alerts contain all statistics counters for the interval since the lasts stats alert.
- session_log
- Enables debug logging alerts. These are available unless libtorrent was built with logging disabled (TORRENT_DISABLE_LOGGING). The alerts being posted are log_alert and are session wide.
- torrent_log
- Enables debug logging alerts for torrents. These are available unless libtorrent was built with logging disabled (TORRENT_DISABLE_LOGGING). The alerts being posted are torrent_log_alert and are torrent wide debug events.
- peer_log
- Enables debug logging alerts for peers. These are available unless libtorrent was built with logging disabled (TORRENT_DISABLE_LOGGING). The alerts being posted are peer_log_alert and low-level peer events and messages.
- incoming_request
- enables the incoming_request_alert.
- dht_log
- enables dht_log_alert, debug logging for the DHT
- dht_operation
- enable events from pure dht operations not related to torrents
- port_mapping_log
- enables port mapping log events. This log is useful for debugging the UPnP or NAT-PMP implementation
- picker_log
- enables verbose logging from the piece picker.
- file_progress
- alerts when files complete downloading
- piece_progress
- alerts when pieces complete downloading or fail hash check
- upload
- alerts when we upload blocks to other peers
- block_progress
- alerts on individual blocks being requested, downloading, finished, rejected, time-out and cancelled. This is likely to post alerts at a high rate.
- all
The full bitmask, representing all available categories.
since the enum is signed, make sure this isn't interpreted as -1. For instance, boost.python does that and fails when assigning it to an unsigned parameter.
bdecode_node
Declared in "libtorrent/bdecode.hpp"
Sometimes it's important to get a non-owning reference to the root node ( to be able to copy it as a reference for instance). For that, use the non_owning() member function.
There are 5 different types of nodes, see type_t.
struct bdecode_node { bdecode_node () = default; bdecode_node (bdecode_node&&) noexcept; bdecode_node& operator= (bdecode_node const&) &; bdecode_node& operator= (bdecode_node&&) & = default; bdecode_node (bdecode_node const&); type_t type () const noexcept; explicit operator bool () const noexcept; bdecode_node non_owning () const; span<char const> data_section () const noexcept; std::ptrdiff_t data_offset () const noexcept; std::int64_t list_int_value_at (int i , std::int64_t default_val = 0) const; string_view list_string_value_at (int i , string_view default_val = string_view()) const; bdecode_node list_at (int i) const; int list_size () const; bdecode_node dict_find_dict (string_view key) const; std::pair<bdecode_node, bdecode_node> dict_at_node (int i) const; bdecode_node dict_find_list (string_view key) const; int dict_size () const; bdecode_node dict_find (string_view key) const; bdecode_node dict_find_string (string_view key) const; bdecode_node dict_find_int (string_view key) const; string_view dict_find_string_value (string_view key , string_view default_value = string_view()) const; std::int64_t dict_find_int_value (string_view key , std::int64_t default_val = 0) const; std::pair<string_view, bdecode_node> dict_at (int i) const; std::int64_t int_value () const; int string_length () const; std::ptrdiff_t string_offset () const; char const* string_ptr () const; string_view string_value () const; void clear (); void swap (bdecode_node& n); void reserve (int tokens); void switch_underlying_buffer (char const* buf) noexcept; bool has_soft_error (span<char> error) const; enum type_t { none_t, dict_t, list_t, string_t, int_t, }; };[report issue]
bdecode_node()
bdecode_node () = default;
creates a default constructed node, it will have the type none_t.
[report issue]operator=() bdecode_node()
bdecode_node (bdecode_node&&) noexcept; bdecode_node& operator= (bdecode_node const&) &; bdecode_node& operator= (bdecode_node&&) & = default; bdecode_node (bdecode_node const&);
For owning nodes, the copy will create a copy of the tree, but the underlying buffer remains the same.
[report issue]non_owning()
bdecode_node non_owning () const;
return a non-owning reference to this node. This is useful to refer to the root node without copying it in assignments.
[report issue]data_section() data_offset()
span<char const> data_section () const noexcept; std::ptrdiff_t data_offset () const noexcept;
returns the buffer and length of the section in the original bencoded buffer where this node is defined. For a dictionary for instance, this starts with d and ends with e, and has all the content of the dictionary in between. the data_offset() function returns the byte-offset to this node in, starting from the beginning of the buffer that was parsed.
[report issue]list_int_value_at() list_at() list_size() list_string_value_at()
std::int64_t list_int_value_at (int i , std::int64_t default_val = 0) const; string_view list_string_value_at (int i , string_view default_val = string_view()) const; bdecode_node list_at (int i) const; int list_size () const;
functions with the list_ prefix operate on lists. These functions are only valid if type() == list_t. list_at() returns the item in the list at index i. i may not be greater than or equal to the size of the list. size() returns the size of the list.
[report issue]dict_find() dict_find_string_value() dict_at() dict_find_int() dict_find_dict() dict_find_int_value() dict_find_string() dict_size() dict_find_list() dict_at_node()
bdecode_node dict_find_dict (string_view key) const; std::pair<bdecode_node, bdecode_node> dict_at_node (int i) const; bdecode_node dict_find_list (string_view key) const; int dict_size () const; bdecode_node dict_find (string_view key) const; bdecode_node dict_find_string (string_view key) const; bdecode_node dict_find_int (string_view key) const; string_view dict_find_string_value (string_view key , string_view default_value = string_view()) const; std::int64_t dict_find_int_value (string_view key , std::int64_t default_val = 0) const; std::pair<string_view, bdecode_node> dict_at (int i) const;
Functions with the dict_ prefix operates on dictionaries. They are only valid if type() == dict_t. In case a key you're looking up contains a 0 byte, you cannot use the 0-terminated string overloads, but have to use string_view instead. dict_find_list will return a valid bdecode_node if the key is found _and_ it is a list. Otherwise it will return a default-constructed bdecode_node.
Functions with the _value suffix return the value of the node directly, rather than the nodes. In case the node is not found, or it has a different type, a default value is returned (which can be specified).
dict_at() returns the (key, value)-pair at the specified index in a dictionary. Keys are only allowed to be strings. dict_at_node() also returns the (key, value)-pair, but the key is returned as a bdecode_node (and it will always be a string).
[report issue]int_value()
std::int64_t int_value () const;
this function is only valid if type() == int_t. It returns the value of the integer.
[report issue]string_length() string_offset() string_ptr() string_value()
int string_length () const; std::ptrdiff_t string_offset () const; char const* string_ptr () const; string_view string_value () const;
these functions are only valid if type() == string_t. They return the string values. Note that string_ptr() is not 0-terminated. string_length() returns the number of bytes in the string. string_offset() returns the byte offset from the start of the parsed bencoded buffer this string can be found.
[report issue]clear()
void clear ();
resets the bdecoded_node to a default constructed state. If this is an owning node, the tree is freed and all child nodes are invalidated.
[report issue]reserve()
void reserve (int tokens);
preallocate memory for the specified numbers of tokens. This is useful if you know approximately how many tokens are in the file you are about to parse. Doing so will save realloc operations while parsing. You should only call this on the root node, before passing it in to bdecode().
[report issue]switch_underlying_buffer()
void switch_underlying_buffer (char const* buf) noexcept;
this buffer MUST be identical to the one originally parsed. This operation is only defined on owning root nodes, i.e. the one passed in to decode().
[report issue]has_soft_error()
bool has_soft_error (span<char> error) const;
returns true if there is a non-fatal error in the bencoding of this node or its children
[report issue]enum type_t
Declared in "libtorrent/bdecode.hpp"
name | value | description |
---|---|---|
none_t | 0 | uninitialized or default constructed. This is also used to indicate that a node was not found in some cases. |
dict_t | 1 | a dictionary node. The dict_find_ functions are valid. |
list_t | 2 | a list node. The list_ functions are valid. |
string_t | 3 | a string node, the string_ functions are valid. |
int_t | 4 | an integer node. The int_ functions are valid. |
print_entry()
Declared in "libtorrent/bdecode.hpp"
std::string print_entry (bdecode_node const& e , bool single_line = false, int indent = 0);
print the bencoded structure in a human-readable format to a string that's returned.
[report issue]bdecode()
Declared in "libtorrent/bdecode.hpp"
bdecode_node bdecode (span<char const> buffer , int depth_limit = 100, int token_limit = 2000000); bdecode_node bdecode (span<char const> buffer , error_code& ec, int* error_pos = nullptr, int depth_limit = 100 , int token_limit = 2000000); int bdecode (char const* start, char const* end, bdecode_node& ret , error_code& ec, int* error_pos = nullptr, int depth_limit = 100 , int token_limit = 2000000);
This function decodes/parses bdecoded data (for example a .torrent file). The data structure is returned in the ret argument. the buffer to parse is specified by the start of the buffer as well as the end, i.e. one byte past the end. If the buffer fails to parse, the function returns a non-zero value and fills in ec with the error code. The optional argument error_pos, if set to non-nullptr, will be set to the byte offset into the buffer where the parse failure occurred.
depth_limit specifies the max number of nested lists or dictionaries are allowed in the data structure. (This affects the stack usage of the function, be careful not to set it too high).
token_limit is the max number of tokens allowed to be parsed from the buffer. This is simply a sanity check to not have unbounded memory usage.
The resulting bdecode_node is an owning node. That means it will be holding the whole parsed tree. When iterating lists and dictionaries, those bdecode_node objects will simply have references to the root or owning bdecode_node. If the root node is destructed, all other nodes that refer to anything in that tree become invalid.
However, the underlying buffer passed in to this function (start, end) must also remain valid while the bdecoded tree is used. The parsed tree produced by this function does not copy any data out of the buffer, but simply produces references back into it.
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:
- first the files that will be part of the torrent are determined.
- the torrent properties are set, such as tracker url, web seeds, DHT nodes etc.
- Read through all the files in the torrent, SHA-1 all the data and set the piece hashes.
- The torrent is bencoded into a file or buffer.
If there are a lot of files and or deep directory hierarchies to traverse, step one can be time consuming.
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.
All of these classes and functions are declared by including libtorrent/create_torrent.hpp.
example:
file_storage fs; // recursively adds files in directories add_files(fs, "./my_torrent"); create_torrent t(fs); t.add_tracker("http://my.tracker.com/announce"); t.set_creator("libtorrent example"); // reads the files and calculates the hashes set_piece_hashes(t, "."); ofstream out("my_torrent.torrent", std::ios_base::binary); std::vector<char> buf = t.generate_buf(); out.write(buf.data(), buf.size()); // alternatively, generate an entry and encode it directly to an ostream // iterator bencode(std::ostream_iterator<char>(out), t.generate());[report issue]
create_torrent
Declared in "libtorrent/create_torrent.hpp"
This class holds state for creating a torrent. After having added all information to it, call create_torrent::generate() to generate the torrent. The entry that's returned can then be bencoded into a .torrent file using bencode().
struct create_torrent { explicit create_torrent (torrent_info const& ti); explicit create_torrent (file_storage& fs, int piece_size = 0 , create_flags_t flags = {}); std::vector<char> generate_buf () const; entry generate () const; file_storage const& files () const; void set_comment (char const* str); void set_creator (char const* str); void set_creation_date (std::time_t timestamp); void set_hash (piece_index_t index, sha1_hash const& h); void set_hash2 (file_index_t file, piece_index_t::diff_type piece, sha256_hash const& h); void add_http_seed (string_view url); void add_url_seed (string_view url); void add_node (std::pair<std::string, int> node); void add_tracker (string_view url, int tier = 0); void set_root_cert (string_view cert); void set_priv (bool p); bool priv () const; bool is_v1_only () const; bool is_v2_only () const; int num_pieces () const; piece_index_t end_piece () const; index_range<piece_index_t> piece_range () const noexcept; file_index_t end_file () const; index_range<file_index_t> file_range () const noexcept; index_range<piece_index_t::diff_type> file_piece_range (file_index_t f); std::int64_t total_size () const; int piece_length () const; int piece_size (piece_index_t i) const; void add_similar_torrent (sha1_hash ih); void add_collection (string_view c); static constexpr create_flags_t modification_time = 2_bit; static constexpr create_flags_t symlinks = 3_bit; static constexpr create_flags_t v2_only = 5_bit; static constexpr create_flags_t v1_only = 6_bit; static constexpr create_flags_t canonical_files = 7_bit; static constexpr create_flags_t no_attributes = 8_bit; static constexpr create_flags_t canonical_files_no_tail_padding = 9_bit; };[report issue]
create_torrent()
explicit create_torrent (torrent_info const& ti); explicit create_torrent (file_storage& fs, int piece_size = 0 , create_flags_t flags = {});
The piece_size is the size of each piece in bytes. It must be a power of 2 and a minimum of 16 kiB. If a piece size of 0 is specified, a piece_size will be set automatically.
The flags arguments specifies options for the torrent creation. It can be any combination of the flags defined by create_flags_t.
The file_storage (fs) parameter defines the files, sizes and their properties for the torrent to be created. Set this up first, before passing it to the create_torrent constructor.
The overload that takes a torrent_info 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 create_torrent::generate(). This means that none of the member functions of create_torrent that affects the content of the info dictionary (such as set_hash()), will have any affect. Instead of using this overload, consider using write_torrent_file() instead.
Warning
The file_storage and torrent_info objects must stay alive for the entire duration of the create_torrent object.
generate() generate_buf()
std::vector<char> generate_buf () const; entry generate () const;
This function will generate the .torrent file as a bencode tree, or a bencoded into a buffer. In order to encode the entry into a flat file, use the bencode() function.
The function returning an entry may be useful to add custom entries to the torrent file before bencoding it and saving it to disk.
Whether the resulting torrent object is v1, v2 or hybrid depends on whether any of the v1_only or v2_only flags were set on the constructor. If neither were set, the resulting torrent depends on which hashes were set. If both v1 and v2 hashes were set, a hybrid torrent is created.
Any failure will cause this function to throw system_error, with an appropriate error message. These are the reasons this call may throw:
- the file storage has 0 files
- the total size of the file storage is 0 bytes (i.e. it only has empty files)
- not all v1 hashes (set_hash()) and not all v2 hashes (set_hash2()) were set
- for v2 torrents, you may not have a directory with the same name as a file. If that's encountered in the file storage, generate() fails.
files()
file_storage const& files () const;
returns an immutable reference to the file_storage used to create the torrent from.
[report issue]set_comment()
void set_comment (char const* str);
Sets the comment for the torrent. The string str should be utf-8 encoded. The comment in a torrent file is optional.
[report issue]set_creator()
void set_creator (char const* str);
Sets the creator of the torrent. The string str should be utf-8 encoded. This is optional.
[report issue]set_creation_date()
void set_creation_date (std::time_t timestamp);
sets the "creation time" field. Defaults to the system clock at the time of construction of the create_torrent object. The timestamp is specified in seconds, posix time. If the creation date is set to 0, the "creation date" field will be omitted from the generated torrent.
[report issue]set_hash()
void set_hash (piece_index_t index, sha1_hash const& h);
This sets the SHA-1 hash for the specified piece (index). 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 set_piece_hashes(). A SHA-1 hash of all zeros is internally used to indicate a hash that has not been set. Setting such hash will not be considered set when calling generate(). This function will throw std::system_error if it is called on an object constructed with the v2_only flag.
[report issue]set_hash2()
void set_hash2 (file_index_t file, piece_index_t::diff_type piece, sha256_hash const& h);
sets the bittorrent v2 hash for file file of the piece piece. piece is relative to the first piece of the file, starting at 0. The first piece in the file can be computed with file_storage::file_index_at_piece(). The hash, h, is the root of the merkle tree formed by the piece's 16 kiB blocks. Note that piece sizes must be powers-of-2, so all per-piece merkle trees are complete. A SHA-256 hash of all zeros is internally used to indicate a hash that has not been set. Setting such hash will not be considered set when calling generate(). This function will throw std::system_error if it is called on an object constructed with the v1_only flag.
[report issue]add_http_seed() add_url_seed()
void add_http_seed (string_view url); void add_url_seed (string_view url);
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.
The second function, add_http_seed() adds an HTTP seed instead.
[report issue]add_node()
void add_node (std::pair<std::string, int> node);
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.
[report issue]add_tracker()
void add_tracker (string_view url, int tier = 0);
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 http:// 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.
[report issue]set_root_cert()
void set_root_cert (string_view cert);
This function sets an X.509 certificate in PEM format to the torrent. This makes the torrent an SSL torrent. 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 ssl torrents.
The string is not the path to the cert, it's the actual content of the certificate.
[report issue]priv() set_priv()
void set_priv (bool p); bool priv () const;
Sets and queries the private flag of the torrent. Torrents with the private flag set ask the client to not use any other sources than the tracker for peers, and to not use DHT to advertise itself publicly, only the tracker.
[report issue]num_pieces()
int num_pieces () const;
returns the number of pieces in the associated file_storage object.
[report issue]piece_range()
index_range<piece_index_t> piece_range () const noexcept;
all piece indices in the torrent to be created
[report issue]file_range()
index_range<file_index_t> file_range () const noexcept;
all file indices in the torrent to be created
[report issue]file_piece_range()
index_range<piece_index_t::diff_type> file_piece_range (file_index_t f);
for v2 and hybrid torrents only, the pieces in the specified file, specified as delta from the first piece in the file. i.e. the first index is 0.
[report issue]total_size()
std::int64_t total_size () const;
the total number of bytes of all files and pad files
[report issue]piece_length() piece_size()
int piece_length () const; int piece_size (piece_index_t i) const;
piece_length() returns the piece size of all pieces but the last one. piece_size() returns the size of the specified piece. these functions are just forwarding to the associated file_storage.
[report issue]add_similar_torrent() add_collection()
void add_similar_torrent (sha1_hash ih); void add_collection (string_view c);
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 BEP 38.
[report issue]- modification_time
- 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.
- symlinks
- 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.
- v2_only
- Do not generate v1 metadata. The resulting torrent will only be usable by clients which support v2. This requires setting all v2 hashes, with set_hash2() before calling generate(). Setting v1 hashes (with set_hash()) is an error with this flag set.
- v1_only
- do not generate v2 metadata or enforce v2 alignment and padding rules this is mainly for tests, not recommended for production use. This requires setting all v1 hashes, with set_hash(), before calling generate(). Setting v2 hashes (with set_hash2()) is an error with this flag set.
- canonical_files
- This flag only affects v1-only torrents, and is only relevant together with the v1_only_flag. This flag will force the same file order and padding as a v2 (or hybrid) torrent would have. It has the effect of ordering files and inserting pad files to align them with piece boundaries.
- no_attributes
- passing this flag to add_files() will ignore file attributes (such as executable or hidden) when adding the files to the file storage. Since not all filesystems and operating systems support all file attributes the resulting torrent may differ depending on where it's created. If it's important for torrents to be created consistently across systems, this flag should be set.
- canonical_files_no_tail_padding
- this flag enforces the file layout to be canonical according to the bittorrent v2 specification (just like the canonical_files flag) with the one exception that tail padding is not added to the last file. This behavior deviates from the specification but was the way libtorrent created torrents in version up to and including 2.0.7. This flag is here for backwards compatibility.
add_files()
Declared in "libtorrent/create_torrent.hpp"
void add_files (file_storage& fs, std::string const& file , std::function<bool(std::string)> p, create_flags_t flags = {}); void add_files (file_storage& fs, std::string const& file , create_flags_t flags = {});
Adds the file specified by path to the file_storage object. In case path refers to a directory, files will be added recursively from the directory.
If specified, the predicate p is called once for every file and directory that is encountered. Files for which p returns true are added, and directories for which p returns true are traversed. p must have the following signature:
bool Pred(std::string const& 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.
The ".." directory is never traversed.
The flags argument should be the same as the flags passed to the create_torrent constructor.
[report issue]set_piece_hashes()
Declared in "libtorrent/create_torrent.hpp"
inline void set_piece_hashes (create_torrent& t, std::string const& p, error_code& ec); inline void set_piece_hashes (create_torrent& t, std::string const& p , std::function<void(piece_index_t)> const& f); inline void set_piece_hashes (create_torrent& t, std::string const& p , settings_interface const& settings , std::function<void(piece_index_t)> const& f); void set_piece_hashes (create_torrent& t, std::string const& p , std::function<void(piece_index_t)> const& f, error_code& ec); void set_piece_hashes (create_torrent& t, std::string const& p , settings_interface const& settings, disk_io_constructor_type disk_io , std::function<void(piece_index_t)> const& f, error_code& ec); void set_piece_hashes (create_torrent& t, std::string const& p , settings_interface const& settings , std::function<void(piece_index_t)> const& f, error_code& ec); inline void set_piece_hashes (create_torrent& t, std::string const& p);
This function will assume that the files added to the torrent file exists at path p, read those files and hash the content and set the hashes in the create_torrent object. The optional function f is called in between every hash that is set. f must have the following signature:
void Fun(piece_index_t);
The overloads taking a settings_pack may be used to configure the underlying disk access. Such as settings_pack::aio_threads.
The overloads that don't take an error_code& may throw an exception in case of a file error, the other overloads sets the error code to reflect the error, if any.
[report issue]stats_metric
Declared in "libtorrent/session_stats.hpp"
describes one statistics metric from the session. For more information, see the session statistics section.
struct stats_metric { char const* name; int value_index; metric_type_t type; };[report issue]
- name
- the name of the counter or gauge
- value_index type
- the index into the session stats array, where the underlying value of this counter or gauge is found. The session stats array is part of the session_stats_alert object.
counters
Declared in "libtorrent/performance_counters.hpp"
struct counters { counters () ; counters& operator= (counters const&) & ; counters (counters const&) ; std::int64_t operator[] (int i) const ; std::int64_t inc_stats_counter (int c, std::int64_t value = 1) ; void blend_stats_counter (int c, std::int64_t value, int ratio) ; void set_value (int c, std::int64_t value) ; };[report issue]
inc_stats_counter() operator[]()
std::int64_t operator[] (int i) const ; std::int64_t inc_stats_counter (int c, std::int64_t value = 1) ;
returns the new value
[report issue]session_stats_metrics()
Declared in "libtorrent/session_stats.hpp"
std::vector<stats_metric> session_stats_metrics ();
This free function returns the list of available metrics exposed by libtorrent's statistics API. Each metric has a name and a value index. The value index is the index into the array in session_stats_alert where this metric's value can be found when the session stats is sampled (by calling post_session_stats()).
[report issue]find_metric_idx()
Declared in "libtorrent/session_stats.hpp"
int find_metric_idx (string_view name);
given a name of a metric, this function returns the counter index of it, or -1 if it could not be found. The counter index is the index into the values array returned by session_stats_alert.
[report issue]enum metric_type_t
Declared in "libtorrent/session_stats.hpp"
name | value | description |
---|---|---|
counter | 0 | |
gauge | 1 |
torrent_status
Declared in "libtorrent/torrent_status.hpp"
holds a snapshot of the status of a torrent, as queried by torrent_handle::status().
struct torrent_status { bool operator== (torrent_status const& st) const; enum state_t { checking_files, downloading_metadata, downloading, finished, seeding, unused_enum_for_backwards_compatibility_allocating, checking_resume_data, }; torrent_handle handle; error_code errc; file_index_t error_file = torrent_status::error_file_none; static constexpr file_index_t error_file_none {-1}; static constexpr file_index_t error_file_ssl_ctx {-3}; static constexpr file_index_t error_file_metadata {-4}; static constexpr file_index_t error_file_exception {-5}; static constexpr file_index_t error_file_partfile {-6}; std::string save_path; std::string name; std::weak_ptr<const torrent_info> torrent_file; time_duration next_announce = seconds{0}; std::string current_tracker; std::int64_t total_download = 0; std::int64_t total_upload = 0; std::int64_t total_payload_download = 0; std::int64_t total_payload_upload = 0; std::int64_t total_failed_bytes = 0; std::int64_t total_redundant_bytes = 0; typed_bitfield<piece_index_t> pieces; typed_bitfield<piece_index_t> verified_pieces; std::int64_t total_done = 0; std::int64_t total = 0; std::int64_t total_wanted_done = 0; std::int64_t total_wanted = 0; std::int64_t all_time_upload = 0; std::int64_t all_time_download = 0; std::time_t added_time = 0; std::time_t completed_time = 0; std::time_t last_seen_complete = 0; storage_mode_t storage_mode = storage_mode_sparse; float progress = 0.f; int progress_ppm = 0; queue_position_t queue_position {}; int download_rate = 0; int upload_rate = 0; int download_payload_rate = 0; int upload_payload_rate = 0; int num_seeds = 0; int num_peers = 0; int num_complete = -1; int num_incomplete = -1; int list_seeds = 0; int list_peers = 0; int connect_candidates = 0; int num_pieces = 0; int distributed_full_copies = 0; int distributed_fraction = 0; float distributed_copies = 0.f; int block_size = 0; int num_uploads = 0; int num_connections = 0; int uploads_limit = 0; int connections_limit = 0; int up_bandwidth_queue = 0; int down_bandwidth_queue = 0; int seed_rank = 0; state_t state = checking_resume_data; bool need_save_resume = false; bool is_seeding = false; bool is_finished = false; bool has_metadata = false; bool has_incoming = false; bool moving_storage = false; bool announcing_to_trackers = false; bool announcing_to_lsd = false; bool announcing_to_dht = false; info_hash_t info_hashes; time_point last_upload; time_point last_download; seconds active_duration; seconds finished_duration; seconds seeding_duration; torrent_flags_t flags {}; };[report issue]
operator==()
bool operator== (torrent_status const& st) const;
compares if the torrent status objects come from the same torrent. i.e. only the torrent_handle field is compared.
[report issue]enum state_t
Declared in "libtorrent/torrent_status.hpp"
name | value | description |
---|---|---|
checking_files | 1 | The torrent has not started its download yet, and is currently checking existing files. |
downloading_metadata | 2 | The torrent is trying to download metadata from peers. This implies the ut_metadata extension is in use. |
downloading | 3 | The torrent is being downloaded. This is the state most torrents will be in most of the time. The progress meter will tell how much of the files that has been downloaded. |
finished | 4 | In this state the torrent has finished downloading but still doesn't have the entire torrent. i.e. some pieces are filtered and won't get downloaded. |
seeding | 5 | In this state the torrent has finished downloading and is a pure seeder. |
unused_enum_for_backwards_compatibility_allocating | 6 | If the torrent was started in full allocation mode, this indicates that the (disk) storage for the torrent is allocated. |
checking_resume_data | 7 | The torrent is currently checking the fast resume data and comparing it to the files on disk. This is typically completed in a fraction of a second, but if you add a large number of torrents at once, they will queue up. |
- handle
- a handle to the torrent whose status the object represents.
- errc
- may be set to an error code describing why the torrent was paused, in case it was paused by an error. If the torrent is not paused or if it's paused but not because of an error, this error_code is not set. if the error is attributed specifically to a file, error_file is set to the index of that file in the .torrent file.
- error_file
- if the torrent is stopped because of an disk I/O error, this field contains the index of the file in the torrent that encountered the error. If the error did not originate in a file in the torrent, there are a few special values this can be set to: error_file_none, error_file_ssl_ctx, error_file_exception, error_file_partfile or error_file_metadata;
- error_file_none
- special values for error_file to describe which file or component encountered the error (errc). the error did not occur on a file
- error_file_ssl_ctx
- the error occurred setting up the SSL context
- error_file_metadata
- the error occurred while loading the metadata for the torrent
- error_file_exception
- there was a serious error reported in this torrent. The error code or a torrent log alert may provide more information.
- error_file_partfile
- the error occurred with the partfile
- save_path
- the path to the directory where this torrent's files are stored. It's typically the path as was given to async_add_torrent() or add_torrent() when this torrent was started. This field is only included if the torrent status is queried with torrent_handle::query_save_path.
- name
- the name of the torrent. Typically this is derived from the .torrent file. In case the torrent was started without metadata, and hasn't completely received it yet, it returns the name given to it when added to the session. See session::add_torrent. This field is only included if the torrent status is queried with torrent_handle::query_name.
- torrent_file
- set to point to the torrent_info object for this torrent. It's only included if the torrent status is queried with torrent_handle::query_torrent_file.
- next_announce
- the time until the torrent will announce itself to the tracker.
- current_tracker
- the URL of the last working tracker. If no tracker request has been successful yet, it's set to an empty string.
- total_download total_upload
- the number of bytes downloaded and uploaded to all peers, accumulated, this session only. The session is considered to restart when a torrent is paused and restarted again. When a torrent is paused, these counters are reset to 0. If you want complete, persistent, stats, see all_time_upload and all_time_download.
- total_payload_download total_payload_upload
- counts the amount of bytes send and received this session, but only the actual payload data (i.e the interesting data), these counters ignore any protocol overhead. The session is considered to restart when a torrent is paused and restarted again. When a torrent is paused, these counters are reset to 0.