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

📄 refresh.cpp

📁 LINUX下
💻 CPP
字号:
/*Copyright (c) 2006, Arvid Norberg & Daniel WallinAll 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.*/#include "libtorrent/pch.hpp"#include <libtorrent/kademlia/refresh.hpp>#include <libtorrent/kademlia/routing_table.hpp>#include <libtorrent/kademlia/rpc_manager.hpp>#include <libtorrent/kademlia/logging.hpp>#include <libtorrent/kademlia/msg.hpp>#include <libtorrent/io.hpp>#include <boost/bind.hpp>using boost::bind;namespace libtorrent { namespace dht{using asio::ip::udp;#ifdef TORRENT_DHT_VERBOSE_LOGGINGTORRENT_DEFINE_LOG(refresh)#endifrefresh_observer::~refresh_observer(){	if (m_algorithm) m_algorithm->failed(m_self, true);}void refresh_observer::reply(msg const& in){	if (!m_algorithm) return;	if (!in.nodes.empty())	{		for (msg::nodes_t::const_iterator i = in.nodes.begin()			, end(in.nodes.end()); i != end; ++i)		{			m_algorithm->traverse(i->id, i->addr);		}	}	m_algorithm->finished(m_self);	m_algorithm = 0;}void refresh_observer::timeout(){	if (!m_algorithm) return;	m_algorithm->failed(m_self);	m_algorithm = 0;}ping_observer::~ping_observer(){	if (m_algorithm) m_algorithm->ping_timeout(m_self, true);}void ping_observer::reply(msg const& m){	if (!m_algorithm) return;		m_algorithm->ping_reply(m_self);	m_algorithm = 0;}void ping_observer::timeout(){	if (!m_algorithm) return;	m_algorithm->ping_timeout(m_self);	m_algorithm = 0;}void refresh::invoke(node_id const& nid, udp::endpoint addr){	observer_ptr o(new (m_rpc.allocator().malloc()) refresh_observer(		this, nid, m_target));#ifndef NDEBUG	o->m_in_constructor = false;#endif	m_rpc.invoke(messages::find_node, addr, o);}void refresh::done(){	m_leftover_nodes_iterator = (int)m_results.size() > m_max_results ?		m_results.begin() + m_max_results : m_results.end();	invoke_pings_or_finish();}void refresh::ping_reply(node_id nid){	m_active_pings--;	invoke_pings_or_finish();}void refresh::ping_timeout(node_id nid, bool prevent_request){	m_active_pings--;	invoke_pings_or_finish(prevent_request);}void refresh::invoke_pings_or_finish(bool prevent_request){	if (prevent_request)	{		--m_max_active_pings;		if (m_max_active_pings <= 0)			m_max_active_pings = 1;	}	else	{		while (m_active_pings < m_max_active_pings)		{			if (m_leftover_nodes_iterator == m_results.end()) break;			result const& node = *m_leftover_nodes_iterator;			// Skip initial nodes			if (node.flags & result::initial)			{				++m_leftover_nodes_iterator;				continue;			}			try			{				observer_ptr o(new (m_rpc.allocator().malloc()) ping_observer(					this, node.id));#ifndef NDEBUG				o->m_in_constructor = false;#endif				m_rpc.invoke(messages::ping, node.addr, o);				++m_active_pings;				++m_leftover_nodes_iterator;			}			catch (std::exception& e) {}		}	}	if (m_active_pings == 0)	{		m_done_callback();	}}} } // namespace libtorrent::dht

⌨️ 快捷键说明

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