fixes bug where priorities where lost when force-rechecking.
[libtorrent.git] / include / libtorrent / extensions.hpp
blobb06a0fc74f59ee8e03f95611e2ed097255b88024
1 /*
3 Copyright (c) 2006, Arvid Norberg
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the distribution.
15 * Neither the name of the author nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE.
33 #ifndef TORRENT_EXTENSIONS_HPP_INCLUDED
34 #define TORRENT_EXTENSIONS_HPP_INCLUDED
36 #ifndef TORRENT_DISABLE_EXTENSIONS
38 #ifdef _MSC_VER
39 #pragma warning(push, 1)
40 #endif
42 #include <boost/shared_ptr.hpp>
44 #ifdef _MSC_VER
45 #pragma warning(pop)
46 #endif
48 #include <vector>
49 #include "libtorrent/config.hpp"
50 #include "libtorrent/buffer.hpp"
52 namespace libtorrent
54 struct peer_plugin;
55 class bt_peer_connection;
56 struct peer_request;
57 class peer_connection;
58 class entry;
59 struct lazy_entry;
60 struct disk_buffer_holder;
61 struct bitfield;
63 struct TORRENT_EXPORT torrent_plugin
65 virtual ~torrent_plugin() {}
66 // throwing an exception closes the connection
67 // returning a 0 pointer is valid and will not add
68 // the peer_plugin to the peer_connection
69 virtual boost::shared_ptr<peer_plugin> new_connection(peer_connection*)
70 { return boost::shared_ptr<peer_plugin>(); }
72 virtual void on_piece_pass(int index) {}
73 virtual void on_piece_failed(int index) {}
75 // called aproximately once every second
76 virtual void tick() {}
78 // if true is returned, it means the handler handled the event,
79 // and no other plugins will have their handlers called, and the
80 // default behavior will be skipped
81 virtual bool on_pause() { return false; }
82 virtual bool on_resume() { return false;}
84 // this is called when the initial checking of
85 // files is completed.
86 virtual void on_files_checked() {}
89 struct TORRENT_EXPORT peer_plugin
91 virtual ~peer_plugin() {}
93 // can add entries to the extension handshake
94 // this is not called for web seeds
95 virtual void add_handshake(entry&) {}
97 // throwing an exception from any of the handlers (except add_handshake)
98 // closes the connection
100 // this is called when the initial BT handshake is received. Returning false
101 // means that the other end doesn't support this extension and will remove
102 // it from the list of plugins.
103 // this is not called for web seeds
104 virtual bool on_handshake(char const* reserved_bits) { return true; }
106 // called when the extension handshake from the other end is received
107 // if this returns false, it means that this extension isn't
108 // supported by this peer. It will result in this peer_plugin
109 // being removed from the peer_connection and destructed.
110 // this is not called for web seeds
111 virtual bool on_extension_handshake(lazy_entry const& h) { return true; }
113 // returning true from any of the message handlers
114 // indicates that the plugin has handeled the message.
115 // it will break the plugin chain traversing and not let
116 // anyone else handle the message, including the default
117 // handler.
119 virtual bool on_choke()
120 { return false; }
122 virtual bool on_unchoke()
123 { return false; }
125 virtual bool on_interested()
126 { return false; }
128 virtual bool on_not_interested()
129 { return false; }
131 virtual bool on_have(int index)
132 { return false; }
134 virtual bool on_bitfield(bitfield const& bitfield)
135 { return false; }
137 virtual bool on_have_all()
138 { return false; }
140 virtual bool on_have_none()
141 { return false; }
143 virtual bool on_allowed_fast(int index)
144 { return false; }
146 virtual bool on_request(peer_request const& req)
147 { return false; }
149 virtual bool on_piece(peer_request const& piece, disk_buffer_holder& data)
150 { return false; }
152 virtual bool on_cancel(peer_request const& req)
153 { return false; }
155 virtual bool on_reject(peer_request const& req)
156 { return false; }
158 virtual bool on_suggest(int index)
159 { return false; }
161 // called when an extended message is received. If returning true,
162 // the message is not processed by any other plugin and if false
163 // is returned the next plugin in the chain will receive it to
164 // be able to handle it
165 // this is not called for web seeds
166 virtual bool on_extended(int length
167 , int msg, buffer::const_interval body)
168 { return false; }
170 // this is not called for web seeds
171 virtual bool on_unknown_message(int length, int msg
172 , buffer::const_interval body)
173 { return false; }
175 // called when a piece that this peer participated in either
176 // fails or passes the hash_check
177 virtual void on_piece_pass(int index) {}
178 virtual void on_piece_failed(int index) {}
180 // called aproximately once every second
181 virtual void tick() {}
183 // called each time a request message is to be sent. If true
184 // is returned, the original request message won't be sent and
185 // no other plugin will have this function called.
186 virtual bool write_request(peer_request const& r) { return false; }
191 #endif
193 #endif // TORRENT_EXTENSIONS_HPP_INCLUDED