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

📄 peer_connection.hpp

📁 LINUX下
💻 HPP
📖 第 1 页 / 共 2 页
字号:
		{			m_send_buffer.append_buffer(buffer, size, size, destructor);#ifdef TORRENT_STATS			m_ses.m_buffer_usage_logger << log_time() << " append_send_buffer: " << size << std::endl;			m_ses.log_buffer_usage();#endif		}#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES			void set_country(char const* c)		{			TORRENT_ASSERT(strlen(c) == 2);			m_country[0] = c[0];			m_country[1] = c[1];		}		bool has_country() const { return m_country[0] != 0; }#endif		int send_buffer_size() const		{ return m_send_buffer.size(); }		int send_buffer_capacity() const		{ return m_send_buffer.capacity(); }	protected:		virtual void get_specific_peer_info(peer_info& p) const = 0;		virtual void write_choke() = 0;		virtual void write_unchoke() = 0;		virtual void write_interested() = 0;		virtual void write_not_interested() = 0;		virtual void write_request(peer_request const& r) = 0;		virtual void write_cancel(peer_request const& r) = 0;		virtual void write_have(int index) = 0;		virtual void write_keepalive() = 0;		virtual void write_piece(peer_request const& r, char* buffer) = 0;				virtual void write_reject_request(peer_request const& r) = 0;		virtual void write_allow_fast(int piece) = 0;		virtual void on_connected() = 0;		virtual void on_tick() {}			virtual void on_receive(asio::error_code const& error			, std::size_t bytes_transferred) = 0;		virtual void on_sent(asio::error_code const& error			, std::size_t bytes_transferred) = 0;#ifndef TORRENT_DISABLE_ENCRYPTION		buffer::interval wr_recv_buffer()		{			if (m_recv_buffer.empty()) return buffer::interval(0,0);			return buffer::interval(&m_recv_buffer[0]				, &m_recv_buffer[0] + m_recv_pos);		}#endif				buffer::const_interval receive_buffer() const		{			if (m_recv_buffer.empty()) return buffer::const_interval(0,0);			return buffer::const_interval(&m_recv_buffer[0]				, &m_recv_buffer[0] + m_recv_pos);		}		void cut_receive_buffer(int size, int packet_size);		void reset_recv_buffer(int packet_size);		int packet_size() const { return m_packet_size; }		bool packet_finished() const		{			return m_packet_size <= m_recv_pos;		}		void setup_receive();		void attach_to_torrent(sha1_hash const& ih);		bool verify_piece(peer_request const& p) const;		// the bandwidth channels, upload and download		// keeps track of the current quotas		bandwidth_limit m_bandwidth_limit[num_channels];		// statistics about upload and download speeds		// and total amount of uploads and downloads for		// this peer		stat m_statistics;		// a back reference to the session		// the peer belongs to.		aux::session_impl& m_ses;		// called from the main loop when this connection has any		// work to do.		void on_send_data(asio::error_code const& error			, std::size_t bytes_transferred);		void on_receive_data(asio::error_code const& error			, std::size_t bytes_transferred);		// this is the limit on the number of outstanding requests		// we have to this peer. This is initialized to the settings		// in the session_settings structure. But it may be lowered		// if the peer is known to require a smaller limit (like BitComet).		// or if the extended handshake sets a limit.		// web seeds also has a limit on the queue size.		int m_max_out_request_queue;		void set_timeout(int s) { m_timeout = s; }#ifndef TORRENT_DISABLE_EXTENSIONS		typedef std::list<boost::shared_ptr<peer_plugin> > extension_list_t;		extension_list_t m_extensions;#endif#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES			// in case the session settings is set		// to resolve countries, this is set to		// the two character country code this		// peer resides in.		char m_country[2];#endif	private:		void fill_send_buffer();		void on_disk_read_complete(int ret, disk_io_job const& j, peer_request r);		void on_disk_write_complete(int ret, disk_io_job const& j			, peer_request r, boost::shared_ptr<torrent> t);		// the timeout in seconds		int m_timeout;		// the time when we last got a part of a		// piece packet from this peer		ptime m_last_piece;		// the time we sent a request to		// this peer the last time		ptime m_last_request;		// the time we received the last		// piece request from the peer		ptime m_last_incoming_request;		// the time when we unchoked this peer		ptime m_last_unchoke;		int m_packet_size;		int m_recv_pos;		buffer m_recv_buffer;		chained_buffer m_send_buffer;		// the number of bytes we are currently reading		// from disk, that will be added to the send		// buffer as soon as they complete		int m_reading_bytes;				// timeouts		ptime m_last_receive;		ptime m_last_sent;		boost::shared_ptr<socket_type> m_socket;		// this is the peer we're actually talking to		// it may not necessarily be the peer we're		// connected to, in case we use a proxy		tcp::endpoint m_remote;				// this is the torrent this connection is		// associated with. If the connection is an		// incoming conncetion, this is set to zero		// until the info_hash is received. Then it's		// set to the torrent it belongs to.		boost::weak_ptr<torrent> m_torrent;		// is true if it was we that connected to the peer		// and false if we got an incoming connection		// could be considered: true = local, false = remote		bool m_active;		// remote peer's id		peer_id m_peer_id;		// other side says that it's interested in downloading		// from us.		bool m_peer_interested;		// the other side has told us that it won't send anymore		// data to us for a while		bool m_peer_choked;		// the peer has pieces we are interested in		bool m_interesting;		// we have choked the upload to the peer		bool m_choked;		// this is set to true if the connection timed		// out or closed the connection. In that		// case we will not try to reconnect to		// this peer		bool m_failed;		// if this is set to true, the peer will not		// request bandwidth from the limiter, but instead		// just send and receive as much as possible.		bool m_ignore_bandwidth_limits;		// the pieces the other end have		std::vector<bool> m_have_piece;		// this is set to true when a have_all		// message is received. This information		// is used to fill the bitmask in init()		bool m_have_all;		// the number of pieces this peer		// has. Must be the same as		// std::count(m_have_piece.begin(),		// m_have_piece.end(), true)		int m_num_pieces;		// the queue of requests we have got		// from this peer		std::deque<peer_request> m_requests;		// the blocks we have reserved in the piece		// picker and will request from this peer.		std::deque<piece_block> m_request_queue;				// the queue of blocks we have requested		// from this peer		std::deque<piece_block> m_download_queue;				// the number of request we should queue up		// at the remote end.		int m_desired_queue_size;		// the amount of data this peer has been given		// as free upload. This is distributed from		// peers from which we get free download		// this will be negative on a peer from which		// we get free download, and positive on peers		// that we give the free upload, to keep the balance.		size_type m_free_upload;		// if this is true, this peer is assumed to handle all piece		// requests in fifo order. All skipped blocks are re-requested		// immediately instead of having a looser requirement		// where blocks can be sent out of order. The default is to		// allow non-fifo order.		bool m_assume_fifo;		// the number of invalid piece-requests		// we have got from this peer. If the request		// queue gets empty, and there have been		// invalid requests, we can assume the		// peer is waiting for those pieces.		// we can then clear its download queue		// by sending choke, unchoke.		int m_num_invalid_requests;		// this is true if this connection has been added		// to the list of connections that will be closed.		bool m_disconnecting;		// the time when this peer sent us a not_interested message		// the last time.		ptime m_became_uninterested;		// the time when we sent a not_interested message to		// this peer the last time.		ptime m_became_uninteresting;		// this is true until this socket has become		// writable for the first time (i.e. the		// connection completed). While connecting		// the timeout will not be triggered. This is		// because windows XP SP2 may delay connection		// attempts, which means that the connection		// may not even have been attempted when the		// time out is reached.		bool m_connecting;		// This is true until connect is called on the		// peer_connection's socket. It is false on incoming		// connections.		bool m_queued;		// these are true when there's a asynchronous write		// or read operation in progress. Or an asyncronous bandwidth		// request is in progress.		bool m_writing;		bool m_reading;		// if set to non-zero, this peer will always prefer		// to request entire n pieces, rather than blocks.		// where n is the value of this variable.		// if it is 0, the download rate limit setting		// will be used to determine if whole pieces		// are preferred.		int m_prefer_whole_pieces;				// if this is true, the blocks picked by the piece		// picker will be merged before passed to the		// request function. i.e. subsequent blocks are		// merged into larger blocks. This is used by		// the http-downloader, to request whole pieces		// at a time.		bool m_request_large_blocks;				// this is the priority with which this peer gets		// download bandwidth quota assigned to it.		int m_priority;		int m_upload_limit;		int m_download_limit;		// this peer's peer info struct. This may		// be 0, in case the connection is incoming		// and hasn't been added to a torrent yet.		policy::peer* m_peer_info;		// this is a measurement of how fast the peer		// it allows some variance without changing		// back and forth between states		peer_speed_t m_speed;		// the ticket id from the connection queue.		// This is used to identify the connection		// so that it can be removed from the queue		// once the connection completes		int m_connection_ticket;				// bytes downloaded since last second		// timer timeout; used for determining 		// approx download rate		int m_remote_bytes_dled;		// approximate peer download rate		int m_remote_dl_rate;		// a timestamp when the remote download rate		// was last updated		ptime m_remote_dl_update;		// the pieces we will send to the peer		// if requested (regardless of choke state)		std::set<int> m_accept_fast;		// the pieces the peer will send us if		// requested (regardless of choke state)		std::vector<int> m_allowed_fast;		// pieces that has been suggested to be		// downloaded from this peer		std::vector<int> m_suggested_pieces;		// the number of bytes send to the disk-io		// thread that hasn't yet been completely written.		int m_outstanding_writing_bytes;		// if this is true, the disconnection		// timestamp is not updated when the connection		// is closed. This means the time until we can		// reconnect to this peer is shorter, and likely		// immediate.		bool m_fast_reconnect;		#ifndef NDEBUG	public:		bool m_in_constructor;#endif	};}#endif // TORRENT_PEER_CONNECTION_HPP_INCLUDED

⌨️ 快捷键说明

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