make operation_t public and document it. include peer disconnects in client_test log

This commit is contained in:
Arvid Norberg 2015-02-15 05:17:09 +00:00
parent 84fd07e226
commit 91270a0c2b
23 changed files with 252 additions and 151 deletions

View File

@ -100,6 +100,7 @@ category_mapping = {
'ip_filter.hpp': 'Filter',
'session_settings.hpp': 'Settings',
'settings_pack.hpp': 'Settings',
'operations.hpp': 'Alerts',
}
category_fun_mapping = {

View File

@ -972,6 +972,19 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a
}
#endif
// don't log every peer we try to connect to
if (alert_cast<peer_connect_alert>(a)) return true;
if (peer_disconnected_alert* pd = alert_cast<peer_disconnected_alert>(a))
{
// ignore failures to connect and peers not responding with a
// handshake. The peers that we successfully connect to and then
// disconnect is more interesting.
if (pd->operation == op_connect
|| pd->error == error_code(errors::timed_out_no_handshake
, get_libtorrent_category()))
return true;
}
if (metadata_received_alert* p = alert_cast<metadata_received_alert>(a))
{
@ -1299,7 +1312,6 @@ int main(int argc, char* argv[])
, alert::all_categories
& ~(alert::dht_notification
+ alert::progress_notification
+ alert::debug_notification
+ alert::stats_notification
+ alert::session_log_notification
+ alert::torrent_log_notification

View File

@ -276,7 +276,7 @@ void torrent_view::print_headers()
// print title bar for torrent list
pos = snprintf(str, sizeof(str)
, " %-3s %-50s %-35s %-17s %-17s %-11s %-6s %-6s %-4s\x1bK"
, " %-3s %-50s %-35s %-17s %-17s %-11s %-6s %-6s %-4s\x1b[K"
, "#", "Name", "Progress", "Download", "Upload", "Peers (D:S)"
, "Down", "Up", "Flags");

View File

@ -77,6 +77,7 @@ nobase_include_HEADERS = \
max.hpp \
natpmp.hpp \
network_thread_pool.hpp \
operations.hpp \
packet_buffer.hpp \
parse_url.hpp \
part_file.hpp \

View File

@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/address.hpp"
#include "libtorrent/stat.hpp"
#include "libtorrent/rss.hpp" // for feed_handle
#include "libtorrent/operations.hpp" // for operation_t enum
namespace libtorrent
{
@ -702,8 +703,9 @@ namespace libtorrent
{
// internal
peer_disconnected_alert(torrent_handle const& h, tcp::endpoint const& ep
, peer_id const& peer_id, int op, error_code const& e)
, peer_id const& peer_id, operation_t op, int type, error_code const& e)
: peer_alert(h, ep, peer_id)
, socket_type(type)
, operation(op)
, error(e)
{
@ -717,9 +719,12 @@ namespace libtorrent
const static int static_category = alert::debug_notification;
virtual std::string message() const;
// a NULL-terminated string of the low-level operation that failed, or NULL if
// there was no low level disk operation.
int operation;
// the kind of socket this peer was connected over
int socket_type;
// the operation or level where the error occurred. Specified as an
// value from the operation_t enum. Defined in operations.hpp.
operation_t operation;
// tells you what error caused peer to disconnect.
error_code error;

View File

@ -94,7 +94,7 @@ namespace libtorrent
std::string const& url() const { return m_url; }
virtual void get_specific_peer_info(peer_info& p) const;
virtual void disconnect(error_code const& ec, peer_connection_interface::operation_t op, int error = 0);
virtual void disconnect(error_code const& ec, operation_t op, int error = 0);
void write_request(peer_request const& r);

View File

@ -0,0 +1,105 @@
/*
Copyright (c) 2015, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are 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, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TORRENT_OPERATIONS_HPP_INCLUDED
#define TORRENT_OPERATIONS_HPP_INCLUDED
namespace libtorrent
{
// these constants are used to identify the operation that failed, causing a
// peer to disconnect
enum operation_t
{
// this is used when the bittorrent logic
// determines to disconnect
op_bittorrent = 0,
// a call to iocontrol failed
op_iocontrol,
// a call to getpeername failed (querying the remote IP of a
// connection)
op_getpeername,
// a call to getname failed (querying the local IP of a
// connection)
op_getname,
// an attempt to allocate a receive buffer failed
op_alloc_recvbuf,
// an attempt to allocate a send buffer failed
op_alloc_sndbuf,
// writing to a file failed
op_file_write,
// reading from a file failed
op_file_read,
// a non-read and non-write file operation failed
op_file,
// a socket write operation failed
op_sock_write,
// a socket read operation failed
op_sock_read,
// a call to open(), to create a socket socket failed
op_sock_open,
// a call to bind() on a socket failed
op_sock_bind,
// an attempt to query the number of bytes available to read from a socket
// failed
op_available,
// a call related to bittorrent protocol encryption failed
op_encryption,
// an attempt to connect a socket failed
op_connect,
// establishing an SSL connection failed
op_ssl_handshake,
// a connection failed to satisfy the bind interface setting
op_get_interface,
};
}
#endif // TORRENT_OPERATIONS_HPP_INCLUDED

View File

@ -484,7 +484,7 @@ namespace libtorrent
// this will cause this peer_connection to be disconnected.
virtual void disconnect(error_code const& ec
, peer_connection_interface::operation_t op, int error = 0);
, operation_t op, int error = 0);
// called when a connect attempt fails (not when an
// established connection fails)

View File

@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/alert_types.hpp"
#include "libtorrent/operations.hpp" // for operation_t enum
namespace libtorrent
{
@ -45,35 +47,10 @@ namespace libtorrent
// TODO: make this interface smaller!
struct peer_connection_interface
{
// these constants are used to identify the operation
// that failed, causing a peer to disconnect
enum operation_t
{
// this is used when the bittorrent logic
// determines to disconnect
op_bittorrent = 0,
op_iocontrol,
op_getpeername,
op_getname,
op_alloc_recvbuf,
op_alloc_sndbuf,
op_file_write,
op_file_read,
op_file,
op_sock_write,
op_sock_read,
op_sock_open,
op_sock_bind,
op_available,
op_encryption,
op_connect,
op_ssl_handshake,
op_get_interface,
};
virtual tcp::endpoint const& remote() const = 0;
virtual tcp::endpoint local_endpoint() const = 0;
virtual void disconnect(error_code const& ec, operation_t op, int error = 0) = 0;
virtual void disconnect(error_code const& ec
, operation_t op, int error = 0) = 0;
virtual peer_id const& pid() const = 0;
virtual void set_holepunch_mode() = 0;
virtual torrent_peer* peer_info_struct() const = 0;

View File

@ -616,7 +616,7 @@ namespace libtorrent
void retry_web_seed(peer_connection* p, int retry = 0);
void remove_web_seed(peer_connection* p, error_code const& ec
, peer_connection_interface::operation_t op, int error = 0);
, operation_t op, int error = 0);
std::set<std::string> web_seeds(web_seed_entry::type_t type) const;
@ -843,7 +843,7 @@ namespace libtorrent
int block_size() const { TORRENT_ASSERT(m_block_size_shift > 0); return 1 << m_block_size_shift; }
peer_request to_req(piece_block const& p) const;
void disconnect_all(error_code const& ec, peer_connection_interface::operation_t op);
void disconnect_all(error_code const& ec, operation_t op);
int disconnect_peers(int num, error_code const& ec);
// called every time a block is marked as finished in the

View File

@ -60,6 +60,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/torrent.hpp"
#include "libtorrent/piece_block_progress.hpp"
#include "libtorrent/http_parser.hpp"
#include "libtorrent/operations.hpp" // for operation_t enum
namespace libtorrent
{
@ -90,7 +91,7 @@ namespace libtorrent
virtual void get_specific_peer_info(peer_info& p) const;
virtual void disconnect(error_code const& ec
, peer_connection_interface::operation_t op, int error = 0);
, operation_t op, int error = 0);
virtual void write_request(peer_request const& r);

View File

@ -288,6 +288,29 @@ namespace libtorrent {
return ret;
}
namespace
{
static char const* const sock_type_str[] =
{
"TCP", "TCP/SSL", "UDP", "I2P", "Socks5", "uTP/SSL"
};
static char const* const nat_type_str[] = {"NAT-PMP", "UPnP"};
static char const* const socket_type_str[] = {
"null",
"TCP",
"Socks5/TCP",
"HTTP",
"uTP",
"i2p",
"SSL/TCP",
"SSL/Socks5",
"HTTPS",
"SSL/uTP"
};
}
std::string listen_failed_alert::message() const
{
static char const* op_str[] =
@ -299,52 +322,41 @@ namespace libtorrent {
"get_peer_name",
"accept"
};
static char const* type_str[] =
{
"TCP", "TCP/SSL", "UDP", "I2P", "Socks5", "uTP/SSL"
};
char ret[300];
snprintf(ret, sizeof(ret), "listening on %s failed: [%s] [%s] %s"
, interface.c_str()
, op_str[operation]
, type_str[sock_type]
, sock_type_str[sock_type]
, convert_from_native(error.message()).c_str());
return ret;
}
std::string listen_succeeded_alert::message() const
{
static char const* type_str[] =
{
"TCP", "TCP/SSL", "UDP", "uTP/SSL"
};
char ret[200];
snprintf(ret, sizeof(ret), "successfully listening on [%s] %s"
, type_str[sock_type], print_endpoint(endpoint).c_str());
, sock_type_str[sock_type], print_endpoint(endpoint).c_str());
return ret;
}
std::string portmap_error_alert::message() const
{
static char const* type_str[] = {"NAT-PMP", "UPnP"};
return std::string("could not map port using ") + type_str[map_type]
return std::string("could not map port using ") + nat_type_str[map_type]
+ ": " + convert_from_native(error.message());
}
std::string portmap_alert::message() const
{
static char const* type_str[] = {"NAT-PMP", "UPnP"};
char ret[200];
snprintf(ret, sizeof(ret), "successfully mapped port using %s. external port: %u"
, type_str[map_type], external_port);
, nat_type_str[map_type], external_port);
return ret;
}
std::string portmap_log_alert::message() const
{
static char const* type_str[] = {"NAT-PMP", "UPnP"};
char ret[600];
snprintf(ret, sizeof(ret), "%s: %s", type_str[map_type], msg.c_str());
snprintf(ret, sizeof(ret), "%s: %s", nat_type_str[map_type], msg.c_str());
return ret;
}
@ -501,25 +513,12 @@ namespace libtorrent {
return torrent_alert::message() + " needs SSL certificate";
}
static char const* type_str[] = {
"null",
"TCP",
"Socks5/TCP",
"HTTP",
"uTP",
"i2p",
"SSL/TCP",
"SSL/Socks5",
"HTTPS",
"SSL/uTP"
};
std::string incoming_connection_alert::message() const
{
char msg[600];
error_code ec;
snprintf(msg, sizeof(msg), "incoming connection from %s (%s)"
, print_endpoint(ip).c_str(), type_str[socket_type]);
, print_endpoint(ip).c_str(), socket_type_str[socket_type]);
return msg;
}
@ -528,7 +527,7 @@ namespace libtorrent {
char msg[600];
error_code ec;
snprintf(msg, sizeof(msg), "%s connecting to peer (%s)"
, peer_alert::message().c_str(), type_str[socket_type]);
, peer_alert::message().c_str(), socket_type_str[socket_type]);
return msg;
}
@ -634,8 +633,11 @@ namespace libtorrent {
std::string peer_disconnected_alert::message() const
{
char msg[600];
snprintf(msg, sizeof(msg), "%s disconnecting [%s] [%s]: %s", peer_alert::message().c_str()
, operation_name(operation), error.category().name(), convert_from_native(error.message()).c_str());
snprintf(msg, sizeof(msg), "%s disconnecting (%s) [%s] [%s]: %s"
, peer_alert::message().c_str()
, socket_type_str[socket_type]
, operation_name(operation), error.category().name()
, convert_from_native(error.message()).c_str());
return msg;
}

View File

@ -83,13 +83,11 @@ namespace libtorrent
}
void http_seed_connection::disconnect(error_code const& ec
, peer_connection_interface::operation_t op, int error)
, operation_t op, int error)
{
if (is_disconnecting()) return;
if (op == peer_connection_interface::op_connect
&& m_web
&& !m_web->endpoints.empty())
if (op == op_connect && m_web && !m_web->endpoints.empty())
{
// we failed to connect to this IP. remove it so that the next attempt
// uses the next IP in the list.

View File

@ -201,7 +201,7 @@ namespace libtorrent { namespace
int ret = lazy_bdecode(body.begin, body.end, msg, ec);
if (ret != 0 || msg.type() != lazy_entry::dict_t)
{
m_pc.disconnect(errors::invalid_lt_tracker_message, peer_connection_interface::op_bittorrent, 2);
m_pc.disconnect(errors::invalid_lt_tracker_message, op_bittorrent, 2);
return true;
}

View File

@ -389,7 +389,7 @@ namespace libtorrent { namespace
if (length > 500 * 1024)
{
m_pc.disconnect(errors::metadata_too_large, peer_connection_interface::op_bittorrent, 2);
m_pc.disconnect(errors::metadata_too_large, op_bittorrent, 2);
return true;
}
@ -412,7 +412,7 @@ namespace libtorrent { namespace
if (length != 3)
{
// invalid metadata request
m_pc.disconnect(errors::invalid_metadata_request, peer_connection_interface::op_bittorrent, 2);
m_pc.disconnect(errors::invalid_metadata_request, op_bittorrent, 2);
return true;
}
@ -434,22 +434,22 @@ namespace libtorrent { namespace
if (total_size > m_torrent.session().settings().get_int(settings_pack::max_metadata_size))
{
m_pc.disconnect(errors::metadata_too_large, peer_connection_interface::op_bittorrent, 2);
m_pc.disconnect(errors::metadata_too_large, op_bittorrent, 2);
return true;
}
if (total_size <= 0)
{
m_pc.disconnect(errors::invalid_metadata_size, peer_connection_interface::op_bittorrent, 2);
m_pc.disconnect(errors::invalid_metadata_size, op_bittorrent, 2);
return true;
}
if (offset > total_size || offset < 0)
{
m_pc.disconnect(errors::invalid_metadata_offset, peer_connection_interface::op_bittorrent, 2);
m_pc.disconnect(errors::invalid_metadata_offset, op_bittorrent, 2);
return true;
}
if (offset + data_size > total_size)
{
m_pc.disconnect(errors::invalid_metadata_message, peer_connection_interface::op_bittorrent, 2);
m_pc.disconnect(errors::invalid_metadata_message, op_bittorrent, 2);
return true;
}
@ -476,7 +476,7 @@ namespace libtorrent { namespace
break;
default:
{
m_pc.disconnect(errors::invalid_metadata_message, peer_connection_interface::op_bittorrent, 2);
m_pc.disconnect(errors::invalid_metadata_message, op_bittorrent, 2);
}
}
return true;

View File

@ -3898,7 +3898,8 @@ namespace libtorrent
// the error argument defaults to 0, which means deliberate disconnect
// 1 means unexpected disconnect/error
// 2 protocol error (client sent something invalid)
void peer_connection::disconnect(error_code const& ec, operation_t op, int error)
void peer_connection::disconnect(error_code const& ec
, operation_t op, int error)
{
TORRENT_ASSERT(is_single_thread());
#if TORRENT_USE_ASSERTS
@ -4080,7 +4081,8 @@ namespace libtorrent
else if (error <= 1 && t->alerts().should_post<peer_disconnected_alert>())
{
t->alerts().post_alert(
peer_disconnected_alert(handle, remote(), pid(), op, ec));
peer_disconnected_alert(handle, remote(), pid(), op
, m_socket->type(), ec));
}
}

View File

@ -179,7 +179,7 @@ namespace libtorrent
banned.push_back(p->remote().address());
p->disconnect(errors::banned_by_ip_filter
, peer_connection_interface::op_bittorrent);
, op_bittorrent);
// what *i refers to has changed, i.e. cur was deleted
if (m_peers.size() < count)
@ -240,7 +240,7 @@ namespace libtorrent
banned.push_back(p->remote().address());
p->disconnect(errors::banned_by_port_filter, peer_connection_interface::op_bittorrent);
p->disconnect(errors::banned_by_port_filter, op_bittorrent);
// what *i refers to has changed, i.e. cur was deleted
if (int(m_peers.size()) < count)
{
@ -623,7 +623,7 @@ namespace libtorrent
#endif
if (i->banned)
{
c.disconnect(errors::peer_banned, peer_connection_interface::op_bittorrent);
c.disconnect(errors::peer_banned, op_bittorrent);
return false;
}
@ -635,8 +635,8 @@ namespace libtorrent
if (self_connection)
{
c.disconnect(errors::self_connection, peer_connection_interface::op_bittorrent, 1);
i->connection->disconnect(errors::self_connection, peer_connection_interface::op_bittorrent, 1);
c.disconnect(errors::self_connection, op_bittorrent, 1);
i->connection->disconnect(errors::self_connection, op_bittorrent, 1);
TORRENT_ASSERT(i->connection == 0);
return false;
}
@ -648,7 +648,7 @@ namespace libtorrent
{
// if the other end connected to us both times, just drop
// the second one. Or if we made both connections.
c.disconnect(errors::duplicate_peer_id, peer_connection_interface::op_bittorrent);
c.disconnect(errors::duplicate_peer_id, op_bittorrent);
return false;
}
else
@ -681,12 +681,12 @@ namespace libtorrent
// we should keep our outgoing connection
if (!outgoing1)
{
c.disconnect(errors::duplicate_peer_id, peer_connection_interface::op_bittorrent);
c.disconnect(errors::duplicate_peer_id, op_bittorrent);
return false;
}
TORRENT_ASSERT(m_locked_peer == NULL);
m_locked_peer = i;
i->connection->disconnect(errors::duplicate_peer_id, peer_connection_interface::op_bittorrent);
i->connection->disconnect(errors::duplicate_peer_id, op_bittorrent);
m_locked_peer = NULL;
}
else
@ -698,12 +698,12 @@ namespace libtorrent
// they should keep their outgoing connection
if (outgoing1)
{
c.disconnect(errors::duplicate_peer_id, peer_connection_interface::op_bittorrent);
c.disconnect(errors::duplicate_peer_id, op_bittorrent);
return false;
}
TORRENT_ASSERT(m_locked_peer == NULL);
m_locked_peer = i;
i->connection->disconnect(errors::duplicate_peer_id, peer_connection_interface::op_bittorrent);
i->connection->disconnect(errors::duplicate_peer_id, op_bittorrent);
m_locked_peer = NULL;
}
}
@ -724,7 +724,7 @@ namespace libtorrent
erase_peers(state, force_erase);
if (int(m_peers.size()) >= state->max_peerlist_size)
{
c.disconnect(errors::too_many_connections, peer_connection_interface::op_bittorrent);
c.disconnect(errors::too_many_connections, op_bittorrent);
return false;
}
// restore it
@ -820,7 +820,7 @@ namespace libtorrent
// we need to make sure we don't let it do that, locking i
TORRENT_ASSERT(m_locked_peer == NULL);
m_locked_peer = p;
p->connection->disconnect(errors::duplicate_peer_id, peer_connection_interface::op_bittorrent);
p->connection->disconnect(errors::duplicate_peer_id, op_bittorrent);
m_locked_peer = NULL;
erase_peer(p, state);
return false;

View File

@ -1051,7 +1051,7 @@ namespace aux {
#if TORRENT_USE_ASSERTS
int conn = m_connections.size();
#endif
(*m_connections.begin())->disconnect(errors::stopping_torrent, peer_connection::op_bittorrent);
(*m_connections.begin())->disconnect(errors::stopping_torrent, op_bittorrent);
TORRENT_ASSERT_VAL(conn == int(m_connections.size()) + 1, conn);
}
@ -2344,7 +2344,7 @@ retry:
if (m_alerts.should_post<peer_error_alert>())
{
m_alerts.post_alert(peer_error_alert(torrent_handle(), endp
, peer_id(), peer_connection::op_ssl_handshake, ec));
, peer_id(), op_ssl_handshake, ec));
}
return;
}
@ -2512,7 +2512,7 @@ retry:
{
m_alerts.post_alert(
peer_disconnected_alert(torrent_handle(), endp, peer_id()
, peer_connection::op_bittorrent
, op_bittorrent, s->type()
, error_code(errors::too_many_connections, get_libtorrent_category())));
}
#if defined TORRENT_LOGGING
@ -2985,7 +2985,7 @@ retry:
// TODO: have a separate list for these connections, instead of having to loop through all of them
if (m_last_tick - p->connected_time()
> seconds(m_settings.get_int(settings_pack::handshake_timeout)))
p->disconnect(errors::timed_out, peer_connection::op_bittorrent);
p->disconnect(errors::timed_out, op_bittorrent);
}
// --------------------------------------------------------------

View File

@ -58,6 +58,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_connection.hpp"
#include "libtorrent/peer_info.hpp"
#include "libtorrent/random.hpp"
#include "libtorrent/operations.hpp" // for operation_t enum
//#define TORRENT_LOG_HASH_FAILURES
@ -291,7 +292,7 @@ namespace
#endif
m_torrent.ban_peer(p);
if (p->connection) p->connection->disconnect(
errors::peer_banned, peer_connection_interface::op_bittorrent);
errors::peer_banned, op_bittorrent);
}
// we already have this exact entry in the map
// we don't have to insert it
@ -366,7 +367,7 @@ namespace
#endif
m_torrent.ban_peer(p);
if (p->connection) p->connection->disconnect(
errors::peer_banned, peer_connection_interface::op_bittorrent);
errors::peer_banned, op_bittorrent);
}
torrent& m_torrent;

View File

@ -902,7 +902,7 @@ namespace libtorrent
TORRENT_ASSERT(m_abort);
TORRENT_ASSERT(m_connections.empty());
if (!m_connections.empty())
disconnect_all(errors::torrent_aborted, peer_connection_interface::op_bittorrent);
disconnect_all(errors::torrent_aborted, op_bittorrent);
}
void torrent::read_piece(int piece)
@ -1126,7 +1126,7 @@ namespace libtorrent
if (alerts().should_post<file_error_alert>())
alerts().post_alert(file_error_alert(j->error.ec
, resolve_filename(j->error.file), j->error.operation_str(), get_handle()));
if (c) c->disconnect(errors::no_memory, peer_connection_interface::op_file);
if (c) c->disconnect(errors::no_memory, op_file);
return;
}
@ -2400,7 +2400,7 @@ namespace libtorrent
if (!need_loaded()) return;
disconnect_all(errors::stopping_torrent, peer_connection_interface::op_bittorrent);
disconnect_all(errors::stopping_torrent, op_bittorrent);
stop_announcing();
m_ses.disk_thread().async_release_files(m_storage.get()
@ -4346,7 +4346,7 @@ namespace libtorrent
#if defined TORRENT_LOGGING
peer->peer_log("*** BANNING PEER: Too many corrupt pieces");
#endif
peer->disconnect(errors::too_many_corrupt_pieces, peer_connection_interface::op_bittorrent);
peer->disconnect(errors::too_many_corrupt_pieces, op_bittorrent);
}
}
}
@ -4707,7 +4707,7 @@ namespace libtorrent
// disconnect all peers and close all
// files belonging to the torrents
disconnect_all(errors::torrent_aborted, peer_connection_interface::op_bittorrent);
disconnect_all(errors::torrent_aborted, op_bittorrent);
// post a message to the main thread to destruct
// the torrent object from there
@ -5898,8 +5898,7 @@ namespace libtorrent
// disconnect it and clear its reference to the peer_info object
// that's part of the web_seed_t we're about to remove
TORRENT_ASSERT(peer->m_in_use == 1337);
peer->disconnect(boost::asio::error::operation_aborted
, peer_connection_interface::op_bittorrent);
peer->disconnect(boost::asio::error::operation_aborted, op_bittorrent);
peer->set_peer_info(0);
}
if (has_picker()) picker().clear_peer(&web->peer_info);
@ -6374,7 +6373,7 @@ namespace libtorrent
#if defined TORRENT_LOGGING
debug_log("*** PEER_ERROR: %s", e.what());
#endif
c->disconnect(errors::no_error, peer_connection_interface::op_bittorrent, 1);
c->disconnect(errors::no_error, op_bittorrent, 1);
}
}
@ -7395,7 +7394,7 @@ namespace libtorrent
update_want_peers();
update_want_tick();
}
c->disconnect(errors::no_error, peer_connection_interface::op_bittorrent, 1);
c->disconnect(errors::no_error, op_bittorrent, 1);
return false;
}
@ -7532,14 +7531,14 @@ namespace libtorrent
if (ssl_conn == 0)
{
// don't allow non SSL peers on SSL torrents
p->disconnect(errors::requires_ssl_connection, peer_connection_interface::op_bittorrent);
p->disconnect(errors::requires_ssl_connection, op_bittorrent);
return false;
}
if (!m_ssl_ctx)
{
// we don't have a valid cert, don't accept any connection!
p->disconnect(errors::invalid_ssl_cert, peer_connection_interface::op_ssl_handshake);
p->disconnect(errors::invalid_ssl_cert, op_ssl_handshake);
return false;
}
@ -7550,14 +7549,14 @@ namespace libtorrent
// connected to one torrent, and the BitTorrent protocol
// to a different one. This is probably an attempt to circumvent
// access control. Don't allow it.
p->disconnect(errors::invalid_ssl_cert, peer_connection_interface::op_bittorrent);
p->disconnect(errors::invalid_ssl_cert, op_bittorrent);
return false;
}
}
#else // BOOST_VERSION
if (is_ssl_torrent())
{
p->disconnect(asio::error::operation_not_supported, peer_connection_interface::op_bittorrent);
p->disconnect(asio::error::operation_not_supported, op_bittorrent);
return false;
}
#endif
@ -7566,7 +7565,7 @@ namespace libtorrent
{
// Don't accidentally allow seeding of SSL torrents, just
// because libtorrent wasn't built with SSL support
p->disconnect(errors::requires_ssl_connection, peer_connection_interface::op_ssl_handshake);
p->disconnect(errors::requires_ssl_connection, op_ssl_handshake);
return false;
}
#endif // TORRENT_USE_OPENSSL
@ -7582,7 +7581,7 @@ namespace libtorrent
if (m_ses.alerts().should_post<peer_blocked_alert>())
m_ses.alerts().post_alert(peer_blocked_alert(get_handle()
, p->remote().address(), peer_blocked_alert::ip_filter));
p->disconnect(errors::banned_by_ip_filter, peer_connection_interface::op_bittorrent);
p->disconnect(errors::banned_by_ip_filter, op_bittorrent);
return false;
}
@ -7590,19 +7589,19 @@ namespace libtorrent
|| m_state == torrent_status::checking_resume_data)
&& valid_metadata())
{
p->disconnect(errors::torrent_not_ready, peer_connection_interface::op_bittorrent);
p->disconnect(errors::torrent_not_ready, op_bittorrent);
return false;
}
if (!m_ses.has_connection(p))
{
p->disconnect(errors::peer_not_constructed, peer_connection_interface::op_bittorrent);
p->disconnect(errors::peer_not_constructed, op_bittorrent);
return false;
}
if (m_ses.is_aborted())
{
p->disconnect(errors::session_closing, peer_connection_interface::op_bittorrent);
p->disconnect(errors::session_closing, op_bittorrent);
return false;
}
@ -7639,10 +7638,10 @@ namespace libtorrent
if (i == end() || !(*i)->is_connecting() || (*i)->is_disconnecting())
{
// this seems odd, but we might as well handle it
p->disconnect(errors::too_many_connections, peer_connection_interface::op_bittorrent);
p->disconnect(errors::too_many_connections, op_bittorrent);
return false;
}
(*i)->disconnect(errors::too_many_connections, peer_connection_interface::op_bittorrent);
(*i)->disconnect(errors::too_many_connections, op_bittorrent);
// if this peer was let in via connections slack,
// it has done its duty of causing the disconnection
@ -7674,7 +7673,7 @@ namespace libtorrent
debug_log("CLOSING CONNECTION \"%s\" peer list full"
, print_endpoint(p->remote()).c_str());
#endif
p->disconnect(errors::too_many_connections, peer_connection_interface::op_bittorrent);
p->disconnect(errors::too_many_connections, op_bittorrent);
return false;
}
peers_erased(st.erased);
@ -7688,7 +7687,7 @@ namespace libtorrent
debug_log("CLOSING CONNECTION \"%s\" caught exception: %s"
, print_endpoint(p->remote()).c_str(), e.what());
#endif
p->disconnect(errors::no_error, peer_connection_interface::op_bittorrent);
p->disconnect(errors::no_error, op_bittorrent);
return false;
}
TORRENT_ASSERT(sorted_find(m_connections, p) == m_connections.end());
@ -7725,12 +7724,12 @@ namespace libtorrent
// TODO: 2 if peer is a really good peer, maybe we shouldn't disconnect it
if (peer && peer->peer_rank() < p->peer_rank())
{
peer->disconnect(errors::too_many_connections, peer_connection_interface::op_bittorrent);
peer->disconnect(errors::too_many_connections, op_bittorrent);
p->peer_disconnected_other();
}
else
{
p->disconnect(errors::too_many_connections, peer_connection_interface::op_bittorrent);
p->disconnect(errors::too_many_connections, op_bittorrent);
// we have to do this here because from the peer's point of
// it wasn't really attached to the torrent, but we do need
// to let peer_list know we're removing it
@ -7845,7 +7844,7 @@ namespace libtorrent
}
}
void torrent::disconnect_all(error_code const& ec, peer_connection_interface::operation_t op)
void torrent::disconnect_all(error_code const& ec, operation_t op)
{
// doesn't work with the !m_allow_peers -> m_num_peers == 0 condition
// INVARIANT_CHECK;
@ -7861,7 +7860,7 @@ namespace libtorrent
if (p->is_disconnecting())
m_connections.erase(m_connections.begin());
else
p->disconnect(ec, (peer_connection::operation_t)op);
p->disconnect(ec, op);
TORRENT_ASSERT(m_connections.size() <= size);
}
@ -7932,7 +7931,7 @@ namespace libtorrent
#if TORRENT_USE_ASSERTS
int num_conns = m_connections.size();
#endif
p->disconnect(ec, peer_connection_interface::op_bittorrent);
p->disconnect(ec, op_bittorrent);
TORRENT_ASSERT(int(m_connections.size()) == num_conns - 1);
}
@ -7986,7 +7985,7 @@ namespace libtorrent
}
std::for_each(seeds.begin(), seeds.end()
, boost::bind(&peer_connection::disconnect, _1, errors::torrent_finished
, peer_connection_interface::op_bittorrent, 0));
, op_bittorrent, 0));
}
if (m_abort) return;
@ -8709,7 +8708,7 @@ namespace libtorrent
log_to_all_peers("DELETING FILES IN TORRENT");
#endif
disconnect_all(errors::torrent_removed, peer_connection_interface::op_bittorrent);
disconnect_all(errors::torrent_removed, op_bittorrent);
stop_announcing();
// storage may be NULL during shutdown
@ -9130,7 +9129,7 @@ namespace libtorrent
if (alerts().should_post<torrent_paused_alert>())
alerts().post_alert(torrent_paused_alert(get_handle()));
}
disconnect_all(errors::torrent_paused, peer_connection_interface::op_bittorrent);
disconnect_all(errors::torrent_paused, op_bittorrent);
return;
}
@ -9150,7 +9149,7 @@ namespace libtorrent
alerts().post_alert(torrent_paused_alert(get_handle()));
}
disconnect_all(errors::torrent_paused, peer_connection_interface::op_bittorrent);
disconnect_all(errors::torrent_paused, op_bittorrent);
}
else
{
@ -9187,7 +9186,7 @@ namespace libtorrent
#if defined TORRENT_LOGGING
p->peer_log("*** CLOSING CONNECTION: torrent_paused");
#endif
p->disconnect(errors::torrent_paused, peer_connection_interface::op_bittorrent);
p->disconnect(errors::torrent_paused, op_bittorrent);
i = j;
}
if (update_ticks)
@ -9669,7 +9668,7 @@ namespace libtorrent
#if defined TORRENT_LOGGING
p->peer_log("*** ERROR %s", e.what());
#endif
p->disconnect(errors::no_error, peer_connection_interface::op_bittorrent, 1);
p->disconnect(errors::no_error, op_bittorrent, 1);
}
if (p->is_disconnecting())
@ -9820,7 +9819,7 @@ namespace libtorrent
TORRENT_ASSERT(to_disconnect <= int(seeds.size()));
for (int i = 0; i < to_disconnect; ++i)
seeds[i]->disconnect(errors::upload_upload_connection
, peer_connection_interface::op_bittorrent);
, op_bittorrent);
}
if (num_downloaders == 0) return;
@ -10609,7 +10608,7 @@ namespace libtorrent
}
void torrent::remove_web_seed(peer_connection* p, error_code const& ec
, peer_connection_interface::operation_t op, int error)
, operation_t op, int error)
{
std::list<web_seed_t>::iterator i = std::find_if(m_web_seeds.begin()
, m_web_seeds.end()

View File

@ -284,7 +284,7 @@ namespace libtorrent { namespace
m_pc.peer_log("*** UT_METADATA [ invalid piece %d metadata size: %d ]"
, piece, int(m_tp.get_metadata_size()));
#endif
m_pc.disconnect(errors::invalid_metadata_message, peer_connection_interface::op_bittorrent, 2);
m_pc.disconnect(errors::invalid_metadata_message, op_bittorrent, 2);
return;
}
@ -333,7 +333,7 @@ namespace libtorrent { namespace
#ifdef TORRENT_LOGGING
m_pc.peer_log("<== UT_METADATA [ packet too big %d ]", length);
#endif
m_pc.disconnect(errors::invalid_metadata_message, peer_connection_interface::op_bittorrent, 2);
m_pc.disconnect(errors::invalid_metadata_message, op_bittorrent, 2);
return true;
}
@ -346,7 +346,7 @@ namespace libtorrent { namespace
#ifdef TORRENT_LOGGING
m_pc.peer_log("<== UT_METADATA [ not a dictionary ]");
#endif
m_pc.disconnect(errors::invalid_metadata_message, peer_connection_interface::op_bittorrent, 2);
m_pc.disconnect(errors::invalid_metadata_message, op_bittorrent, 2);
return true;
}
@ -358,7 +358,7 @@ namespace libtorrent { namespace
#ifdef TORRENT_LOGGING
m_pc.peer_log("<== UT_METADATA [ missing or invalid keys ]");
#endif
m_pc.disconnect(errors::invalid_metadata_message, peer_connection_interface::op_bittorrent, 2);
m_pc.disconnect(errors::invalid_metadata_message, op_bittorrent, 2);
return true;
}
int type = type_ent->integer();

View File

@ -280,7 +280,7 @@ namespace libtorrent { namespace
if (length > 500 * 1024)
{
m_pc.disconnect(errors::pex_message_too_large, peer_connection_interface::op_bittorrent, 2);
m_pc.disconnect(errors::pex_message_too_large, op_bittorrent, 2);
return true;
}
@ -291,7 +291,7 @@ namespace libtorrent { namespace
{
// this client appears to be trying to flood us
// with pex messages. Don't allow that.
m_pc.disconnect(errors::too_frequent_pex, peer_connection_interface::op_bittorrent);
m_pc.disconnect(errors::too_frequent_pex, op_bittorrent);
return true;
}
@ -305,7 +305,7 @@ namespace libtorrent { namespace
int ret = lazy_bdecode(body.begin, body.end, pex_msg, ec);
if (ret != 0 || pex_msg.type() != lazy_entry::dict_t)
{
m_pc.disconnect(errors::invalid_pex_message, peer_connection_interface::op_bittorrent, 2);
m_pc.disconnect(errors::invalid_pex_message, op_bittorrent, 2);
return true;
}

View File

@ -115,12 +115,11 @@ void web_peer_connection::on_connected()
}
void web_peer_connection::disconnect(error_code const& ec
, peer_connection_interface::operation_t op, int error)
, operation_t op, int error)
{
if (is_disconnecting()) return;
if (op == peer_connection_interface::op_sock_write
&& ec == boost::system::errc::broken_pipe)
if (op == op_sock_write && ec == boost::system::errc::broken_pipe)
{
#ifdef TORRENT_LOGGING
// a write operation failed with broken-pipe. This typically happens
@ -144,9 +143,7 @@ void web_peer_connection::disconnect(error_code const& ec
return;
}
if (op == peer_connection_interface::op_connect
&& m_web
&& !m_web->endpoints.empty())
if (op == op_connect && m_web && !m_web->endpoints.empty())
{
// we failed to connect to this IP. remove it so that the next attempt
// uses the next IP in the list.