⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 torrent.hpp

📁 LINUX下
💻 HPP
📖 第 1 页 / 共 2 页
字号:
/*Copyright (c) 2003, Arvid NorbergAll rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditionsare met:    * Redistributions of source code must retain the above copyright      notice, this list of conditions and the following disclaimer.    * Redistributions in binary form must reproduce the above copyright      notice, this list of conditions and the following disclaimer in      the documentation and/or other materials provided with the distribution.    * Neither the name of the author nor the names of its      contributors may be used to endorse or promote products derived      from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSEARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BELIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, ORCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OFSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESSINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER INCONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THEPOSSIBILITY OF SUCH DAMAGE.*/#ifndef TORRENT_TORRENT_HPP_INCLUDE#define TORRENT_TORRENT_HPP_INCLUDE#include <algorithm>#include <vector>#include <set>#include <list>#include <iostream>#ifdef _MSC_VER#pragma warning(push, 1)#endif#include <boost/limits.hpp>#include <boost/filesystem/path.hpp>#include <boost/tuple/tuple.hpp>#include <boost/enable_shared_from_this.hpp>#include <boost/scoped_ptr.hpp>#include <boost/intrusive_ptr.hpp>#ifdef _MSC_VER#pragma warning(pop)#endif#include "libtorrent/torrent_handle.hpp"#include "libtorrent/entry.hpp"#include "libtorrent/torrent_info.hpp"#include "libtorrent/socket.hpp"#include "libtorrent/policy.hpp"#include "libtorrent/tracker_manager.hpp"#include "libtorrent/stat.hpp"#include "libtorrent/alert.hpp"#include "libtorrent/piece_picker.hpp"#include "libtorrent/config.hpp"#include "libtorrent/escape_string.hpp"#include "libtorrent/bandwidth_limit.hpp"#include "libtorrent/bandwidth_queue_entry.hpp"#include "libtorrent/storage.hpp"#include "libtorrent/hasher.hpp"#include "libtorrent/assert.hpp"namespace libtorrent{#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)	struct logger;#endif	class piece_manager;	struct torrent_plugin;	namespace aux	{		struct session_impl;		struct piece_checker_data;	}	namespace fs = boost::filesystem;	// a torrent is a class that holds information	// for a specific download. It updates itself against	// the tracker	class TORRENT_EXPORT torrent: public request_callback		, public boost::enable_shared_from_this<torrent>	{	public:		torrent(			aux::session_impl& ses			, aux::checker_impl& checker			, boost::intrusive_ptr<torrent_info> tf			, fs::path const& save_path			, tcp::endpoint const& net_interface			, storage_mode_t m_storage_mode			, int block_size			, storage_constructor_type sc			, bool paused);		// used with metadata-less torrents		// (the metadata is downloaded from the peers)		torrent(			aux::session_impl& ses			, aux::checker_impl& checker			, char const* tracker_url			, sha1_hash const& info_hash			, char const* name			, fs::path const& save_path			, tcp::endpoint const& net_interface			, storage_mode_t m_storage_mode			, int block_size			, storage_constructor_type sc			, bool paused);		~torrent();		// starts the announce timer		void start();#ifndef TORRENT_DISABLE_EXTENSIONS		void add_extension(boost::shared_ptr<torrent_plugin>);		void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> const& ext			, void* userdata);#endif		// this is called when the torrent has metadata.		// it will initialize the storage and the piece-picker		void init();		// this will flag the torrent as aborted. The main		// loop in session_impl will check for this state		// on all torrents once every second, and take		// the necessary actions then.		void abort();		bool is_aborted() const { return m_abort; }		// returns true if this torrent is being allocated		// by the checker thread.		bool is_allocating() const;				session_settings const& settings() const;				aux::session_impl& session() { return m_ses; }				void set_sequenced_download_threshold(int threshold);			bool verify_resume_data(entry& rd, std::string& error)		{ TORRENT_ASSERT(m_storage); return m_storage->verify_resume_data(rd, error); }		void second_tick(stat& accumulator, float tick_interval);		// debug purpose only		void print(std::ostream& os) const;		std::string name() const;		bool check_fastresume(aux::piece_checker_data&);		std::pair<bool, float> check_files();		void files_checked(std::vector<piece_picker::downloading_piece> const&			unfinished_pieces);		stat statistics() const { return m_stat; }		size_type bytes_left() const;		boost::tuples::tuple<size_type, size_type> bytes_done() const;		size_type quantized_bytes_done() const;		void ip_filter_updated() { m_policy.ip_filter_updated(); }		void pause();		void resume();		bool is_paused() const { return m_paused; }		void delete_files();		// ============ start deprecation =============		void filter_piece(int index, bool filter);		void filter_pieces(std::vector<bool> const& bitmask);		bool is_piece_filtered(int index) const;		void filtered_pieces(std::vector<bool>& bitmask) const;		void filter_files(std::vector<bool> const& files);		// ============ end deprecation =============		void piece_availability(std::vector<int>& avail) const;				void set_piece_priority(int index, int priority);		int piece_priority(int index) const;		void prioritize_pieces(std::vector<int> const& pieces);		void piece_priorities(std::vector<int>&) const;		void prioritize_files(std::vector<int> const& files);		torrent_status status() const;		void file_progress(std::vector<float>& fp) const;		void use_interface(const char* net_interface);		tcp::endpoint const& get_interface() const { return m_net_interface; }				void connect_to_url_seed(std::string const& url);		bool connect_to_peer(policy::peer* peerinfo);		void set_ratio(float ratio)		{ TORRENT_ASSERT(ratio >= 0.0f); m_ratio = ratio; }		float ratio() const		{ return m_ratio; }#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES		void resolve_countries(bool r)		{ m_resolve_countries = r; }		bool resolving_countries() const { return m_resolve_countries; }#endif// --------------------------------------------		// BANDWIDTH MANAGEMENT		bandwidth_limit m_bandwidth_limit[2];		void request_bandwidth(int channel			, boost::intrusive_ptr<peer_connection> const& p			, int priority);		void perform_bandwidth_request(int channel			, boost::intrusive_ptr<peer_connection> const& p			, int block_size, int priority);		void expire_bandwidth(int channel, int amount);		void assign_bandwidth(int channel, int amount, int blk);				int bandwidth_throttle(int channel) const;		int max_assignable_bandwidth(int channel) const		{ return m_bandwidth_limit[channel].max_assignable(); }// --------------------------------------------		// PEER MANAGEMENT				// add or remove a url that will be attempted for		// finding the file(s) in this torrent.		void add_url_seed(std::string const& url)		{ m_web_seeds.insert(url); }			void remove_url_seed(std::string const& url)		{ m_web_seeds.erase(url); }		void retry_url_seed(std::string const& url);		std::set<std::string> url_seeds() const		{ return m_web_seeds; }		bool free_upload_slots() const		{ return m_num_uploads < m_max_uploads; }		void choke_peer(peer_connection& c);		bool unchoke_peer(peer_connection& c);		// used by peer_connection to attach itself to a torrent		// since incoming connections don't know what torrent		// they're a part of until they have received an info_hash.		void attach_peer(peer_connection* p);		// this will remove the peer and make sure all		// the pieces it had have their reference counter		// decreased in the piece_picker		void remove_peer(peer_connection* p);		void cancel_block(piece_block block);		bool want_more_peers() const;		bool try_connect_peer();		// the number of peers that belong to this torrent		int num_peers() const { return (int)m_connections.size(); }		int num_seeds() const;		typedef std::set<peer_connection*>::iterator peer_iterator;		typedef std::set<peer_connection*>::const_iterator const_peer_iterator;		const_peer_iterator begin() const { return m_connections.begin(); }		const_peer_iterator end() const { return m_connections.end(); }		peer_iterator begin() { return m_connections.begin(); }		peer_iterator end() { return m_connections.end(); }		void resolve_peer_country(boost::intrusive_ptr<peer_connection> const& p) const;		void get_peer_info(std::vector<peer_info>& v);		void get_download_queue(std::vector<partial_piece_info>& queue);// --------------------------------------------		// TRACKER MANAGEMENT		// these are callbacks called by the tracker_connection instance		// (either http_tracker_connection or udp_tracker_connection)		// when this torrent got a response from its tracker request		// or when a failure occured		virtual void tracker_response(			tracker_request const& r			, std::vector<peer_entry>& e, int interval			, int complete, int incomplete);		virtual void tracker_request_timed_out(			tracker_request const& r);		virtual void tracker_request_error(tracker_request const& r			, int response_code, const std::string& str);		virtual void tracker_warning(std::string const& msg);		virtual void tracker_scrape_response(tracker_request const& req			, int complete, int incomplete, int downloaded);		// generates a request string for sending		// to the tracker		tracker_request generate_tracker_request();		// if no password and username is set		// this will return an empty string, otherwise		// it will concatenate the login and password		// ready to be sent over http (but without		// base64 encoding).		std::string tracker_login() const;		// returns the absolute time when the next tracker		// announce will take place.		ptime next_announce() const;		// returns true if it is time for this torrent to make another		// tracker request		bool should_request();		// forcefully sets next_announce to the current time		void force_tracker_request();		void force_tracker_request(ptime);		void scrape_tracker();		// sets the username and password that will be sent to		// the tracker		void set_tracker_login(std::string const& name, std::string const& pw);		// the tcp::endpoint of the tracker that we managed to		// announce ourself at the last time we tried to announce		const tcp::endpoint& current_tracker() const;// --------------------------------------------		// PIECE MANAGEMENT		// returns true if we have downloaded the given piece		bool have_piece(int index) const		{			TORRENT_ASSERT(index >= 0 && index < (signed)m_have_pieces.size());			return m_have_pieces[index];		}		const std::vector<bool>& pieces() const		{ return m_have_pieces; }		int num_pieces() const { return m_num_pieces; }		// when we get a have- or bitfield- messages, this is called for every		// piece a peer has gained.		void peer_has(int index)		{			if (m_picker.get())			{				TORRENT_ASSERT(!is_seed());				TORRENT_ASSERT(index >= 0 && index < (signed)m_have_pieces.size());				m_picker->inc_refcount(index);			}#ifndef NDEBUG			else			{				TORRENT_ASSERT(is_seed());			}#endif		}				void peer_has_all()		{			if (m_picker.get())			{				TORRENT_ASSERT(!is_seed());				m_picker->inc_refcount_all();			}#ifndef NDEBUG			else			{				TORRENT_ASSERT(is_seed());			}#endif		}		// when peer disconnects, this is called for every piece it had		void peer_lost(int index)		{			if (m_picker.get())			{				TORRENT_ASSERT(!is_seed());				TORRENT_ASSERT(index >= 0 && index < (signed)m_have_pieces.size());				m_picker->dec_refcount(index);			}#ifndef NDEBUG			else			{				TORRENT_ASSERT(is_seed());			}#endif		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -