.. include:: header.rst

`home`__

__ reference.html

.. contents:: Table of contents
  :depth: 2
  :backlinks: none

.. raw:: html

	<a name="session_handle"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:class+session_handle&labels=documentation&body=Documentation+under+heading+%22class+session_handle%22+could+be+improved">report issue</a>]</span>



session_handle
--------------

Declared in "`libtorrent/session_handle.hpp`__"


__ include/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.


__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Torrent_Info.html#is_valid()


.. parsed-literal::
	

	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;
	   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 const& params, error\_code& ec);
	   torrent_handle **add_torrent** (add\_torrent\_params&& params);
	   torrent_handle **add_torrent** (add\_torrent\_params const& params);
	   void **async_add_torrent** (add\_torrent\_params&& params);
	   bool **is_paused** () const;
	   void **pause** ();
	   void **resume** ();
	   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_announce** (sha1\_hash const& info\_hash, int port = 0, dht\:\:announce\_flags\_t flags = {});
	   void **dht_get_peers** (sha1\_hash const& info\_hash);
	   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);
	   unsigned short **ssl_listen_port** () const;
	   bool **is_listening** () const;
	   unsigned short **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);
	   peer_class_info **get_peer_class** (peer\_class\_t cid) const;
	   void **set_peer_class** (peer\_class\_t cid, peer\_class\_info const& pci);
	   void **remove_torrent** (const torrent\_handle&, remove\_flags\_t = {});
	   void **apply_settings** (settings\_pack const&);
	   settings_pack **get_settings** () const;
	   void **apply_settings** (settings\_pack&&);
	   void **set_alert_notify** (std\:\:function<void()> const& fun);
	   void **pop_alerts** (std\:\:vector<alert\*>\* alerts);
	   alert\* **wait_for_alert** (time\_duration max\_wait);
	   void **delete_port_mapping** (port\_mapping\_t handle);
	   std::vector<port_mapping_t> **add_port_mapping** (portmap\_protocol t, int external\_port, int local\_port);
	   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;
	};

.. raw:: html

	<a name="is_valid()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bis_valid%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bis_valid%28%29%5D%22+could+be+improved">report issue</a>]</span>



is_valid()
..........

.. parsed-literal::
	
	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.


__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session_handle

.. raw:: html

	<a name="session_state()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bsession_state%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bsession_state%28%29%5D%22+could+be+improved">report issue</a>]</span>



session_state()
...............

.. parsed-literal::
	
	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


__ reference-Session.html#session
__ reference-Session.html#write_session_params()
__ reference-Session.html#read_session_params()
__ reference-Session.html#session
__ reference-Session.html#session

.. raw:: html

	<a name="get_torrent_status()"></a>
	<a name="refresh_torrent_status()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bget_torrent_status%28%29+refresh_torrent_status%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bget_torrent_status%28%29+refresh_torrent_status%28%29%5D%22+could+be+improved">report issue</a>]</span>



get_torrent_status() refresh_torrent_status()
.............................................

.. parsed-literal::
	
	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.


__ reference-Torrent_Status.html#torrent_status
__ reference-Torrent_Handle.html#status()
__ reference-Torrent_Status.html#torrent_status
__ reference-Session.html#get_torrent_status()
__ reference-Torrent_Status.html#torrent_status

.. raw:: html

	<a name="post_torrent_updates()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bpost_torrent_updates%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bpost_torrent_updates%28%29%5D%22+could+be+improved">report issue</a>]</span>



post_torrent_updates()
......................

.. parsed-literal::
	
	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`__.


__ reference-Session.html#session
__ reference-Alerts.html#state_update_alert
__ reference-Add_Torrent.html#add_torrent_params
__ reference-Torrent_Handle.html#status()
__ reference-Torrent_Handle.html#torrent_handle

.. raw:: html

	<a name="post_session_stats()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bpost_session_stats%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bpost_session_stats%28%29%5D%22+could+be+improved">report issue</a>]</span>



post_session_stats()
....................

.. parsed-literal::
	
	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.


__ reference-Alerts.html#session_stats_alert
__ reference-Stats.html#counters
__ reference-Stats.html#counters
__ reference-Session.html#session
__ reference-Stats.html#session_stats_metrics()
__ manual-ref.html#session-statistics

.. raw:: html

	<a name="post_dht_stats()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bpost_dht_stats%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bpost_dht_stats%28%29%5D%22+could+be+improved">report issue</a>]</span>



post_dht_stats()
................

.. parsed-literal::
	
	void **post_dht_stats** ();
	

This will cause a `dht_stats_alert`__ to be posted.


__ reference-Alerts.html#dht_stats_alert

.. raw:: html

	<a name="set_dht_state()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bset_dht_state%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bset_dht_state%28%29%5D%22+could+be+improved">report issue</a>]</span>



set_dht_state()
...............

.. parsed-literal::
	
	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.


__ reference-Session.html#session
__ reference-Session.html#session_params

.. raw:: html

	<a name="get_torrents()"></a>
	<a name="find_torrent()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bget_torrents%28%29+find_torrent%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bget_torrents%28%29+find_torrent%28%29%5D%22+could+be+improved">report issue</a>]</span>



get_torrents() find_torrent()
.............................

.. parsed-literal::
	
	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`__.


__ reference-Session.html#session
__ reference-Torrent_Handle.html#torrent_handle
__ reference-Torrent_Handle.html#torrent_handle
__ reference-Session.html#session

.. raw:: html

	<a name="async_add_torrent()"></a>
	<a name="add_torrent()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Basync_add_torrent%28%29+add_torrent%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Basync_add_torrent%28%29+add_torrent%28%29%5D%22+could+be+improved">report issue</a>]</span>



async_add_torrent() add_torrent()
.................................

.. parsed-literal::
	
	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 const& params, error\_code& ec);
	torrent_handle **add_torrent** (add\_torrent\_params&& params);
	torrent_handle **add_torrent** (add\_torrent\_params const& params);
	void **async_add_torrent** (add\_torrent\_params&& 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`__.


__ reference-Session.html#add_torrent()
__ reference-Session.html#add_torrent()
__ reference-Torrent_Handle.html#torrent_handle
__ reference-Session.html#async_add_torrent()
__ reference-Alerts.html#add_torrent_alert
__ reference-Torrent_Handle.html#torrent_handle
__ reference-Session.html#add_torrent()
__ reference-Session.html#session
__ reference-Session.html#add_torrent()
__ reference-Add_Torrent.html#add_torrent_params
__ manual-ref.html#bittorrent-v2-torrents

.. raw:: html

	<a name="resume()"></a>
	<a name="pause()"></a>
	<a name="is_paused()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bresume%28%29+pause%28%29+is_paused%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bresume%28%29+pause%28%29+is_paused%28%29%5D%22+could+be+improved">report issue</a>]</span>



resume() pause() is_paused()
............................

.. parsed-literal::
	
	bool **is_paused** () const;
	void **pause** ();
	void **resume** ();
	

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.


__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session

.. raw:: html

	<a name="is_dht_running()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bis_dht_running%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bis_dht_running%28%29%5D%22+could+be+improved">report issue</a>]</span>



is_dht_running()
................

.. parsed-literal::
	
	bool **is_dht_running** () const;
	

``is_dht_running()`` returns true if the DHT support has been started
and false otherwise.



.. raw:: html

	<a name="set_dht_storage()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bset_dht_storage%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bset_dht_storage%28%29%5D%22+could+be+improved">report issue</a>]</span>



set_dht_storage()
.................

.. parsed-literal::
	
	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.


__ reference-Session.html#session

.. raw:: html

	<a name="add_dht_node()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Badd_dht_node%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Badd_dht_node%28%29%5D%22+could+be+improved">report issue</a>]</span>



add_dht_node()
..............

.. parsed-literal::
	
	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.



.. raw:: html

	<a name="dht_get_item()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bdht_get_item%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bdht_get_item%28%29%5D%22+could+be+improved">report issue</a>]</span>



dht_get_item()
..............

.. parsed-literal::
	
	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`__.


__ reference-Alerts.html#dht_immutable_item_alert

.. raw:: html

	<a name="dht_get_item()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bdht_get_item%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bdht_get_item%28%29%5D%22+could+be+improved">report issue</a>]</span>



dht_get_item()
..............

.. parsed-literal::
	
	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.


__ reference-Alerts.html#dht_mutable_item_alert

.. raw:: html

	<a name="dht_put_item()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bdht_put_item%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bdht_put_item%28%29%5D%22+could+be+improved">report issue</a>]</span>



dht_put_item()
..............

.. parsed-literal::
	
	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.



.. raw:: html

	<a name="dht_put_item()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bdht_put_item%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bdht_put_item%28%29%5D%22+could+be+improved">report issue</a>]</span>



dht_put_item()
..............

.. parsed-literal::
	
	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.



.. raw:: html

	<a name="dht_announce()"></a>
	<a name="dht_get_peers()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bdht_announce%28%29+dht_get_peers%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bdht_announce%28%29+dht_get_peers%28%29%5D%22+could+be+improved">report issue</a>]</span>



dht_announce() dht_get_peers()
..............................

.. parsed-literal::
	
	void **dht_announce** (sha1\_hash const& info\_hash, int port = 0, dht\:\:announce\_flags\_t flags = {});
	void **dht_get_peers** (sha1\_hash const& info\_hash);
	

``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`__.


__ reference-Alerts.html#dht_get_peers_reply_alert
__ reference-DHT.html#announce_flags_t

.. raw:: html

	<a name="dht_live_nodes()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bdht_live_nodes%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bdht_live_nodes%28%29%5D%22+could+be+improved">report issue</a>]</span>



dht_live_nodes()
................

.. parsed-literal::
	
	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.


__ reference-Alerts.html#alert
__ reference-Alerts.html#alert
__ reference-Alerts.html#alert

.. raw:: html

	<a name="dht_sample_infohashes()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bdht_sample_infohashes%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bdht_sample_infohashes%28%29%5D%22+could+be+improved">report issue</a>]</span>



dht_sample_infohashes()
.......................

.. parsed-literal::
	
	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``.



.. raw:: html

	<a name="dht_direct_request()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bdht_direct_request%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bdht_direct_request%28%29%5D%22+could+be+improved">report issue</a>]</span>



dht_direct_request()
....................

.. parsed-literal::
	
	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.


__ reference-Alerts.html#dht_direct_response_alert
__ reference-Alerts.html#alert
__ reference-Alerts.html#alert

.. raw:: html

	<a name="add_extension()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Badd_extension%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Badd_extension%28%29%5D%22+could+be+improved">report issue</a>]</span>



add_extension()
...............

.. parsed-literal::
	
	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.

.. code:: c++

	#include <libtorrent/extensions/ut_metadata.hpp>
	ses.add_extension(&lt::create_ut_metadata_plugin);

uTorrent peer exchange
	Exchanges peers between clients.

.. code:: c++

	#include <libtorrent/extensions/ut_pex.hpp>
	ses.add_extension(&lt::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.

.. code:: c++

	#include <libtorrent/extensions/smart_ban.hpp>
	ses.add_extension(&lt::create_smart_ban_plugin);


.. _`libtorrent plugins`: reference-Plugins.html


__ reference-Session.html#session
__ reference-Plugins.html#plugin
__ reference-Plugins.html#plugin

.. raw:: html

	<a name="set_ip_filter()"></a>
	<a name="get_ip_filter()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bset_ip_filter%28%29+get_ip_filter%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bset_ip_filter%28%29+get_ip_filter%28%29%5D%22+could+be+improved">report issue</a>]</span>



set_ip_filter() get_ip_filter()
...............................

.. parsed-literal::
	
	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`__.


__ reference-Filter.html#ip_filter
__ reference-Alerts.html#peer_blocked_alert
__ reference-Filter.html#ip_filter
__ reference-Session.html#session
__ reference-Filter.html#ip_filter

.. raw:: html

	<a name="set_port_filter()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bset_port_filter%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bset_port_filter%28%29%5D%22+could+be+improved">report issue</a>]</span>



set_port_filter()
.................

.. parsed-literal::
	
	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.


__ reference-Filter.html#port_filter

.. raw:: html

	<a name="is_listening()"></a>
	<a name="listen_port()"></a>
	<a name="ssl_listen_port()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bis_listening%28%29+listen_port%28%29+ssl_listen_port%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bis_listening%28%29+listen_port%28%29+ssl_listen_port%28%29%5D%22+could+be+improved">report issue</a>]</span>



is_listening() listen_port() ssl_listen_port()
..............................................

.. parsed-literal::
	
	unsigned short **ssl_listen_port** () const;
	bool **is_listening** () const;
	unsigned short **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.


__ reference-Session.html#session
__ reference-Settings.html#listen_interfaces

.. raw:: html

	<a name="get_peer_class_filter()"></a>
	<a name="set_peer_class_filter()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bget_peer_class_filter%28%29+set_peer_class_filter%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bget_peer_class_filter%28%29+set_peer_class_filter%28%29%5D%22+could+be+improved">report issue</a>]</span>



get_peer_class_filter() set_peer_class_filter()
...............................................

.. parsed-literal::
	
	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:

.. code:: c++

	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`__.


__ reference-Session.html#session
__ reference-Filter.html#ip_filter
__ manual-ref.html#peer-classes

.. raw:: html

	<a name="get_peer_class_type_filter()"></a>
	<a name="set_peer_class_type_filter()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bget_peer_class_type_filter%28%29+set_peer_class_type_filter%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bget_peer_class_type_filter%28%29+set_peer_class_type_filter%28%29%5D%22+could+be+improved">report issue</a>]</span>



get_peer_class_type_filter() set_peer_class_type_filter()
.........................................................

.. parsed-literal::
	
	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:

1. peer-class IP filter
2. peer-class type filter, removing classes
3. peer-class type filter, adding classes

For more information, see `peer classes`__.


__ manual-ref.html#peer-classes

.. raw:: html

	<a name="create_peer_class()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bcreate_peer_class%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bcreate_peer_class%28%29%5D%22+could+be+improved">report issue</a>]</span>



create_peer_class()
...................

.. parsed-literal::
	
	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`__.


__ manual-ref.html#peer-classes
__ reference-Session.html#set_peer_class_filter()
__ manual-ref.html#peer-classes

.. raw:: html

	<a name="delete_peer_class()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bdelete_peer_class%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bdelete_peer_class%28%29%5D%22+could+be+improved">report issue</a>]</span>



delete_peer_class()
...................

.. parsed-literal::
	
	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`__.


__ reference-Session.html#session
__ manual-ref.html#peer-classes

.. raw:: html

	<a name="get_peer_class()"></a>
	<a name="set_peer_class()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bget_peer_class%28%29+set_peer_class%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bget_peer_class%28%29+set_peer_class%28%29%5D%22+could+be+improved">report issue</a>]</span>



get_peer_class() set_peer_class()
.................................

.. parsed-literal::
	
	peer_class_info **get_peer_class** (peer\_class\_t cid) const;
	void **set_peer_class** (peer\_class\_t cid, peer\_class\_info const& pci);
	

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`__.


__ reference-PeerClass.html#peer_class_info
__ manual-ref.html#peer-classes

.. raw:: html

	<a name="remove_torrent()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bremove_torrent%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bremove_torrent%28%29%5D%22+could+be+improved">report issue</a>]</span>



remove_torrent()
................

.. parsed-literal::
	
	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.


__ reference-Alerts.html#torrent_removed_alert
__ reference-Custom_Storage.html#remove_torrent()
__ reference-Session.html#session
__ reference-Session.html#add_torrent()
__ reference-Alerts.html#torrent_deleted_alert
__ reference-Torrent_Handle.html#torrent_handle
__ reference-Custom_Storage.html#remove_torrent()
__ reference-Torrent_Handle.html#is_valid()
__ reference-Torrent_Handle.html#status()
__ reference-Custom_Storage.html#remove_torrent()

.. raw:: html

	<a name="get_settings()"></a>
	<a name="apply_settings()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bget_settings%28%29+apply_settings%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bget_settings%28%29+apply_settings%28%29%5D%22+could+be+improved">report issue</a>]</span>



get_settings() apply_settings()
...............................

.. parsed-literal::
	
	void **apply_settings** (settings\_pack const&);
	settings_pack **get_settings** () const;
	void **apply_settings** (settings\_pack&&);
	

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.


__ reference-Settings.html#settings_pack

.. raw:: html

	<a name="set_alert_notify()"></a>
	<a name="wait_for_alert()"></a>
	<a name="pop_alerts()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bset_alert_notify%28%29+wait_for_alert%28%29+pop_alerts%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bset_alert_notify%28%29+wait_for_alert%28%29+pop_alerts%28%29%5D%22+could+be+improved">report issue</a>]</span>



set_alert_notify() wait_for_alert() pop_alerts()
................................................

.. parsed-literal::
	
	void **set_alert_notify** (std\:\:function<void()> const& fun);
	void **pop_alerts** (std\:\:vector<alert\*>\* alerts);
	alert\* **wait_for_alert** (time\_duration max\_wait);
	

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.


__ reference-Session.html#session
__ reference-Alerts.html#alert
__ reference-Alerts.html#alert
__ reference-Alerts.html#alert
__ reference-Alerts.html#alert
__ reference-Alerts.html#alert
__ reference-Alerts.html#alert
__ reference-Alerts.html#alert
__ reference-Alerts.html#alert
__ reference-Alerts.html#alert
__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Alerts.html#alert
__ reference-Alerts.html#save_resume_data_alert
__ reference-Alerts.html#save_resume_data_failed_alert
__ reference-Alerts.html#alert
__ reference-Settings.html#alert_mask
__ reference-Alerts.html#alert
__ reference-Alerts.html#alerts_dropped_alert
__ reference-Alerts.html#alert
__ reference-Alerts.html#alert
__ reference-Alerts.html#alert
__ reference-Alerts.html#alert

.. raw:: html

	<a name="add_port_mapping()"></a>
	<a name="delete_port_mapping()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Badd_port_mapping%28%29+delete_port_mapping%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Badd_port_mapping%28%29+delete_port_mapping%28%29%5D%22+could+be+improved">report issue</a>]</span>



add_port_mapping() delete_port_mapping()
........................................

.. parsed-literal::
	
	void **delete_port_mapping** (port\_mapping\_t handle);
	std::vector<port_mapping_t> **add_port_mapping** (portmap\_protocol t, int external\_port, int local\_port);
	

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.


__ reference-Session.html#session
__ reference-Session.html#delete_port_mapping()

.. raw:: html

	<a name="reopen_network_sockets()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Breopen_network_sockets%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Breopen_network_sockets%28%29%5D%22+could+be+improved">report issue</a>]</span>



reopen_network_sockets()
........................

.. parsed-literal::
	
	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.


__ reference-Session.html#session

.. raw:: html

	<a name="native_handle()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bnative_handle%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bnative_handle%28%29%5D%22+could+be+improved">report issue</a>]</span>



native_handle()
...............

.. parsed-literal::
	
	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.



.. raw:: html

	<a name="save_settings"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bsave_settings%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bsave_settings%5D%22+could+be+improved">report issue</a>]</span>


save_settings
	saves settings (i.e. the `settings_pack`__)
	

__ reference-Settings.html#settings_pack

.. raw:: html

	<a name="save_dht_state"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bsave_dht_state%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bsave_dht_state%5D%22+could+be+improved">report issue</a>]</span>


save_dht_state
	saves dht state such as nodes and node-id, possibly accelerating
	joining the DHT if provided at next `session`__ startup.
	

__ reference-Session.html#session

.. raw:: html

	<a name="save_extension_state"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bsave_extension_state%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bsave_extension_state%5D%22+could+be+improved">report issue</a>]</span>


save_extension_state
	load or save state from plugins
	


.. raw:: html

	<a name="save_ip_filter"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bsave_ip_filter%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bsave_ip_filter%5D%22+could+be+improved">report issue</a>]</span>


save_ip_filter
	load or save the IP filter set on the `session`__
	

__ reference-Session.html#session

.. raw:: html

	<a name="global_peer_class_id"></a>
	<a name="tcp_peer_class_id"></a>
	<a name="local_peer_class_id"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bglobal_peer_class_id+tcp_peer_class_id+local_peer_class_id%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bglobal_peer_class_id+tcp_peer_class_id+local_peer_class_id%5D%22+could+be+improved">report issue</a>]</span>


global_peer_class_id tcp_peer_class_id local_peer_class_id
	built-in peer classes
	


.. raw:: html

	<a name="delete_files"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bdelete_files%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bdelete_files%5D%22+could+be+improved">report issue</a>]</span>


delete_files
	delete the files belonging to the torrent from disk.
	including the part-file, if there is one
	


.. raw:: html

	<a name="delete_partfile"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bdelete_partfile%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bdelete_partfile%5D%22+could+be+improved">report issue</a>]</span>


delete_partfile
	delete just the part-file associated with this torrent
	


.. raw:: html

	<a name="paused"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Bpaused%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Bpaused%5D%22+could+be+improved">report issue</a>]</span>


paused
	when set, the `session`__ will start paused. Call
	`session_handle::resume()`__ to start
	

__ reference-Session.html#session
__ reference-Session.html#resume()

.. raw:: html

	<a name="udp"></a>
	<a name="tcp"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Budp+tcp%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Budp+tcp%5D%22+could+be+improved">report issue</a>]</span>


udp tcp
	protocols used by `add_port_mapping()`__
	

__ reference-Session.html#add_port_mapping()

.. raw:: html

	<a name="reopen_map_ports"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_handle%3A%3A%5Breopen_map_ports%5D&labels=documentation&body=Documentation+under+heading+%22session_handle%3A%3A%5Breopen_map_ports%5D%22+could+be+improved">report issue</a>]</span>


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.
	


.. raw:: html

	<a name="session_proxy"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:class+session_proxy&labels=documentation&body=Documentation+under+heading+%22class+session_proxy%22+could+be+improved">report issue</a>]</span>



session_proxy
-------------

Declared in "`libtorrent/session.hpp`__"


__ include/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.


__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session_proxy
__ reference-Session.html#session


.. parsed-literal::
	

	struct session_proxy
	{
	   session_proxy& **operator=** (session\_proxy&&) & noexcept;
	   **session_proxy** ();
	   **session_proxy** (session\_proxy&&) noexcept;
	   **session_proxy** (session\_proxy const&);
	   **~session_proxy** ();
	   session_proxy& **operator=** (session\_proxy const&) &;
	};

.. raw:: html

	<a name="operator=()"></a>
	<a name="session_proxy()"></a>
	<a name="~session_proxy()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_proxy%3A%3A%5Boperator%3D%28%29+session_proxy%28%29+~session_proxy%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_proxy%3A%3A%5Boperator%3D%28%29+session_proxy%28%29+~session_proxy%28%29%5D%22+could+be+improved">report issue</a>]</span>



operator=() session_proxy() ~session_proxy()
............................................

.. parsed-literal::
	
	session_proxy& **operator=** (session\_proxy&&) & noexcept;
	**session_proxy** ();
	**session_proxy** (session\_proxy&&) noexcept;
	**session_proxy** (session\_proxy const&);
	**~session_proxy** ();
	session_proxy& **operator=** (session\_proxy const&) &;
	

default constructor, does not refer to any `session`__
implementation object.


__ reference-Session.html#session

.. raw:: html

	<a name="session"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:class+session&labels=documentation&body=Documentation+under+heading+%22class+session%22+could+be+improved">report issue</a>]</span>



session
-------

Declared in "`libtorrent/session.hpp`__"


__ include/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()`__.


__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Settings.html#settings_pack
__ reference-Session.html#apply_settings()


.. parsed-literal::
	

	struct session : session_handle
	{
	   explicit **session** (session\_params const& params);
	   **session** (session\_params const& params, session\_flags\_t flags);
	   **session** (session\_params&& params, session\_flags\_t flags);
	   **session** ();
	   explicit **session** (session\_params&& params);
	   **session** (session\_params&& params, io\_context& ios);
	   **session** (session\_params const& params, io\_context& ios, session\_flags\_t);
	   **session** (session\_params const& params, io\_context& ios);
	   **session** (session\_params&& params, io\_context& ios, session\_flags\_t);
	   **~session** ();
	   session_proxy **abort** ();
	};

.. raw:: html

	<a name="session()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session%3A%3A%5Bsession%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session%3A%3A%5Bsession%28%29%5D%22+could+be+improved">report issue</a>]</span>



session()
.........

.. parsed-literal::
	
	explicit **session** (session\_params const& params);
	**session** (session\_params const& params, session\_flags\_t flags);
	**session** (session\_params&& params, session\_flags\_t flags);
	**session** ();
	explicit **session** (session\_params&& params);
	

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.


__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session_params
__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session_params

.. raw:: html

	<a name="session()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session%3A%3A%5Bsession%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session%3A%3A%5Bsession%28%29%5D%22+could+be+improved">report issue</a>]</span>



session()
.........

.. parsed-literal::
	
	**session** (session\_params&& params, io\_context& ios);
	**session** (session\_params const& params, io\_context& ios, session\_flags\_t);
	**session** (session\_params const& params, io\_context& ios);
	**session** (session\_params&& 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.


__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#abort()
__ reference-Session.html#session_proxy
__ reference-Session.html#session
__ reference-Session.html#session_proxy

.. raw:: html

	<a name="~session()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session%3A%3A%5B~session%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session%3A%3A%5B~session%28%29%5D%22+could+be+improved">report issue</a>]</span>



~session()
..........

.. parsed-literal::
	
	**~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()`__.


__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#apply_settings()

.. raw:: html

	<a name="abort()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session%3A%3A%5Babort%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session%3A%3A%5Babort%28%29%5D%22+could+be+improved">report issue</a>]</span>



abort()
.......

.. parsed-literal::
	
	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 {};


__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session

.. raw:: html

	<a name="session_params"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:class+session_params&labels=documentation&body=Documentation+under+heading+%22class+session_params%22+could+be+improved">report issue</a>]</span>



session_params
--------------

Declared in "`libtorrent/session_params.hpp`__"


__ include/libtorrent/session_params.hpp

The `session_params`__ is a parameters pack for configuring the `session`__
before it's started.


__ reference-Session.html#session_params
__ reference-Session.html#session


.. parsed-literal::
	

	struct session_params
	{
	   **session_params** ();
	   **session_params** (settings\_pack&& sp);
	   **session_params** (settings\_pack const& sp);
	   **session_params** (settings\_pack const& sp
	      , std\:\:vector<std\:\:shared\_ptr<plugin>> exts);
	   **session_params** (settings\_pack&& 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;
	};

.. raw:: html

	<a name="session_params()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_params%3A%3A%5Bsession_params%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_params%3A%3A%5Bsession_params%28%29%5D%22+could+be+improved">report issue</a>]</span>



session_params()
................

.. parsed-literal::
	
	**session_params** ();
	**session_params** (settings\_pack&& sp);
	**session_params** (settings\_pack const& sp);
	

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.


__ reference-Settings.html#settings_pack
__ reference-Session.html#session

.. raw:: html

	<a name="session_params()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_params%3A%3A%5Bsession_params%28%29%5D&labels=documentation&body=Documentation+under+heading+%22session_params%3A%3A%5Bsession_params%28%29%5D%22+could+be+improved">report issue</a>]</span>



session_params()
................

.. parsed-literal::
	
	**session_params** (settings\_pack const& sp
	      , std\:\:vector<std\:\:shared\_ptr<plugin>> exts);
	**session_params** (settings\_pack&& 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.


__ reference-Session.html#session

.. raw:: html

	<a name="settings"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_params%3A%3A%5Bsettings%5D&labels=documentation&body=Documentation+under+heading+%22session_params%3A%3A%5Bsettings%5D%22+could+be+improved">report issue</a>]</span>


settings
	The settings to configure the `session`__ with
	

__ reference-Session.html#session

.. raw:: html

	<a name="extensions"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_params%3A%3A%5Bextensions%5D&labels=documentation&body=Documentation+under+heading+%22session_params%3A%3A%5Bextensions%5D%22+could+be+improved">report issue</a>]</span>


extensions
	the plugins to add to the `session`__ as it is constructed
	

__ reference-Session.html#session

.. raw:: html

	<a name="dht_state"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_params%3A%3A%5Bdht_state%5D&labels=documentation&body=Documentation+under+heading+%22session_params%3A%3A%5Bdht_state%5D%22+could+be+improved">report issue</a>]</span>


dht_state
	DHT node ID and node addresses to bootstrap the DHT with.
	


.. raw:: html

	<a name="dht_storage_constructor"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_params%3A%3A%5Bdht_storage_constructor%5D&labels=documentation&body=Documentation+under+heading+%22session_params%3A%3A%5Bdht_storage_constructor%5D%22+could+be+improved">report issue</a>]</span>


dht_storage_constructor
	function object to construct the storage object for DHT items.
	


.. raw:: html

	<a name="disk_io_constructor"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_params%3A%3A%5Bdisk_io_constructor%5D&labels=documentation&body=Documentation+under+heading+%22session_params%3A%3A%5Bdisk_io_constructor%5D%22+could+be+improved">report issue</a>]</span>


disk_io_constructor
	function object to create the disk I/O subsystem. Defaults to
	default_disk_io_constructor.
	


.. raw:: html

	<a name="ext_state"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_params%3A%3A%5Bext_state%5D&labels=documentation&body=Documentation+under+heading+%22session_params%3A%3A%5Bext_state%5D%22+could+be+improved">report issue</a>]</span>


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()`__.
	

__ reference-Session.html#read_session_params()
__ reference-Session.html#write_session_params()

.. raw:: html

	<a name="ip_filter"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:session_params%3A%3A%5Bip_filter%5D&labels=documentation&body=Documentation+under+heading+%22session_params%3A%3A%5Bip_filter%5D%22+could+be+improved">report issue</a>]</span>


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()`__.
	

__ reference-Session.html#session
__ reference-Session.html#set_ip_filter()

.. raw:: html

	<a name="write_session_params_buf()"></a>
	<a name="write_session_params()"></a>
	<a name="read_session_params()"></a>

.. raw:: html

	<span class="report-issue">[<a href="http://github.com/arvidn/libtorrent/issues/new?title=docs:write_session_params_buf%28%29+write_session_params%28%29+read_session_params%28%29&labels=documentation&body=Documentation+under+heading+%22write_session_params_buf%28%29+write_session_params%28%29+read_session_params%28%29%22+could+be+improved">report issue</a>]</span>



write_session_params_buf() write_session_params() read_session_params()
-----------------------------------------------------------------------

Declared in "`libtorrent/session_params.hpp`__"


__ include/libtorrent/session_params.hpp

.. parsed-literal::
	
	entry **write_session_params** (session\_params const& sp
	   , save\_state\_flags\_t flags = save\_state\_flags\_t\:\:all());
	session_params **read_session_params** (bdecode\_node const& e
	   , 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.


__ reference-Session.html#session_params
__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session
__ reference-Session.html#session_params



.. _`BEP 3`: https://www.bittorrent.org/beps/bep_0003.html
.. _`BEP 17`: https://www.bittorrent.org/beps/bep_0017.html
.. _extensions: manual-ref.html#extensions
.. _`BEP 52`: https://www.bittorrent.org/beps/bep_0052.html
.. _`BEP 19`: https://www.bittorrent.org/beps/bep_0019.html
.. _`BEP 38`: https://www.bittorrent.org/beps/bep_0038.html
.. _`rate based choking`: manual-ref.html#rate-based-choking
.. _`BEP 42`: https://www.bittorrent.org/beps/bep_0042.html
