00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef TORRENT_SESSION_HPP_INCLUDED
00034 #define TORRENT_SESSION_HPP_INCLUDED
00035
00036 #include <ctime>
00037 #include <algorithm>
00038 #include <vector>
00039 #include <set>
00040 #include <list>
00041 #include <deque>
00042
00043 #ifdef _MSC_VER
00044 #pragma warning(push, 1)
00045 #endif
00046
00047 #include <boost/limits.hpp>
00048 #include <boost/tuple/tuple.hpp>
00049 #include <boost/filesystem/path.hpp>
00050 #include <boost/thread.hpp>
00051
00052 #ifdef _MSC_VER
00053 #pragma warning(pop)
00054 #endif
00055
00056 #include "libtorrent/torrent_handle.hpp"
00057 #include "libtorrent/entry.hpp"
00058 #include "libtorrent/alert.hpp"
00059 #include "libtorrent/session_status.hpp"
00060 #include "libtorrent/version.hpp"
00061 #include "libtorrent/fingerprint.hpp"
00062
00063 #include "libtorrent/resource_request.hpp"
00064
00065 #ifdef _MSC_VER
00066 # include <eh.h>
00067 #endif
00068
00069 namespace libtorrent
00070 {
00071 struct torrent_plugin;
00072 class torrent;
00073 class ip_filter;
00074
00075
00076 namespace aux
00077 {
00078
00079
00080
00081 #ifdef _MSC_VER
00082 struct eh_initializer
00083 {
00084 eh_initializer()
00085 {
00086 ::_set_se_translator(straight_to_debugger);
00087 }
00088
00089 static void straight_to_debugger(unsigned int, _EXCEPTION_POINTERS*)
00090 { throw; }
00091 };
00092 #else
00093 struct eh_initializer {};
00094 #endif
00095 struct session_impl;
00096
00097 struct filesystem_init
00098 {
00099 filesystem_init();
00100 };
00101
00102 }
00103
00104 class TORRENT_EXPORT session_proxy
00105 {
00106 friend class session;
00107 public:
00108 session_proxy() {}
00109 private:
00110 session_proxy(boost::shared_ptr<aux::session_impl> impl)
00111 : m_impl(impl) {}
00112 boost::shared_ptr<aux::session_impl> m_impl;
00113 };
00114
00115 class TORRENT_EXPORT session: public boost::noncopyable, aux::eh_initializer
00116 {
00117 public:
00118
00119 session(fingerprint const& print = fingerprint("LT"
00120 , LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0));
00121 session(
00122 fingerprint const& print
00123 , std::pair<int, int> listen_port_range
00124 , char const* listen_interface = "0.0.0.0");
00125
00126 ~session();
00127
00128
00129 std::vector<torrent_handle> get_torrents() const;
00130
00131
00132 torrent_handle find_torrent(sha1_hash const& info_hash) const;
00133
00134
00135 torrent_handle add_torrent(
00136 torrent_info const& ti
00137 , boost::filesystem::path const& save_path
00138 , entry const& resume_data = entry()
00139 , bool compact_mode = true
00140 , int block_size = 16 * 1024);
00141
00142
00143 torrent_handle add_torrent(
00144 entry const& e
00145 , boost::filesystem::path const& save_path
00146 , entry const& resume_data = entry()
00147 , bool compact_mode = true
00148 , int block_size = 16 * 1024)
00149 {
00150 return add_torrent(torrent_info(e), save_path, resume_data
00151 , compact_mode, block_size);
00152 }
00153
00154 torrent_handle add_torrent(
00155 char const* tracker_url
00156 , sha1_hash const& info_hash
00157 , char const* name
00158 , boost::filesystem::path const& save_path
00159 , entry const& resume_data = entry()
00160 , bool compact_mode = true
00161 , int block_size = 16 * 1024);
00162
00163 session_proxy abort() { return session_proxy(m_impl); }
00164
00165 session_status status() const;
00166
00167 #ifndef TORRENT_DISABLE_DHT
00168 void start_dht(entry const& startup_state = entry());
00169 void stop_dht();
00170 void set_dht_settings(dht_settings const& settings);
00171 entry dht_state() const;
00172 void add_dht_node(std::pair<std::string, int> const& node);
00173 void add_dht_router(std::pair<std::string, int> const& node);
00174 #endif
00175
00176 #ifndef TORRENT_DISABLE_EXTENSIONS
00177
00178 void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*)> ext);
00179
00180 #endif
00181
00182 void set_ip_filter(ip_filter const& f);
00183 void set_peer_id(peer_id const& pid);
00184 void set_key(int key);
00185
00186 bool is_listening() const;
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 bool listen_on(
00200 std::pair<int, int> const& port_range
00201 , const char* net_interface = 0);
00202
00203
00204 unsigned short listen_port() const;
00205
00206
00207 int num_uploads() const;
00208
00209
00210
00211 int num_connections() const;
00212
00213 void remove_torrent(const torrent_handle& h);
00214
00215 void set_settings(session_settings const& s);
00216 session_settings const& settings();
00217
00218 int upload_rate_limit() const;
00219 int download_rate_limit() const;
00220
00221 void set_upload_rate_limit(int bytes_per_second);
00222 void set_download_rate_limit(int bytes_per_second);
00223 void set_max_uploads(int limit);
00224 void set_max_connections(int limit);
00225 void set_max_half_open_connections(int limit);
00226
00227 std::auto_ptr<alert> pop_alert();
00228 void set_severity_level(alert::severity_t s);
00229
00230
00231 resource_request m_ul_bandwidth_quota;
00232 resource_request m_dl_bandwidth_quota;
00233 resource_request m_uploads_quota;
00234 resource_request m_connections_quota;
00235
00236 private:
00237
00238
00239
00240 aux::filesystem_init m_dummy;
00241
00242
00243
00244 boost::shared_ptr<aux::session_impl> m_impl;
00245 };
00246
00247 }
00248
00249 #endif // TORRENT_SESSION_HPP_INCLUDED
00250