<p>The plugin interface consists of two base classes that the plugin may
implement. These are called <ttclass="docutils literal"><spanclass="pre">torrent_plugin</span></tt> and <ttclass="docutils literal"><spanclass="pre">peer_plugin</span></tt>. They are
both found in the <ttclass="docutils literal"><spanclass="pre"><libtorrent/extensions.hpp></span></tt> header.</p>
<p>These plugins are instantiated for each torrent and possibly each peer,
<p>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
<ttclass="docutils literal"><spanclass="pre">shared_ptr</span></tt> (in which case you don't need to override this member
function).</p>
<p>If you need an extension to the peer connection (which most plugins do) you
are supposed to return an instance of your <ttclass="docutils literal"><spanclass="pre">peer_plugin</span></tt> class. Which in
turn will have its hook functions called on event specific to that peer.</p>
<p>The <ttclass="docutils literal"><spanclass="pre">peer_connection</span></tt> will be valid as long as the <ttclass="docutils literal"><spanclass="pre">shared_ptr</span></tt> is being
held by the torrent object. So, it is generally a good idea to not keep a
<ttclass="docutils literal"><spanclass="pre">shared_ptr</span></tt> to your own peer_plugin. If you want to keep references to it,
use <ttclass="docutils literal"><spanclass="pre">weak_ptr</span></tt>.</p>
<p>If this function throws an exception, the connection will be closed.</p>
<p>These hooks are called when a piece passes the hash check or fails the hash
check, respectively. The <ttclass="docutils literal"><spanclass="pre">index</span></tt> is the piece index that was downloaded.
It is possible to access the list of peers that participated in sending the
piece through the <ttclass="docutils literal"><spanclass="pre">torrent</span></tt> and the <ttclass="docutils literal"><spanclass="pre">piece_picker</span></tt>.</p>
<p>These hooks are called when the torrent is paused and unpaused respectively.
The return value indicates if the event was handled. A return value of
<ttclass="docutils literal"><spanclass="pre">true</span></tt> 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 unpause.</p>
<p>Note that if you call <ttclass="docutils literal"><spanclass="pre">pause()</span></tt> or <ttclass="docutils literal"><spanclass="pre">resume()</span></tt> 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