move where socket buffers are set up, to happen after the socket is opened. log errors in the peer's log instead of session and torrent

This commit is contained in:
arvidn 2018-11-28 10:18:56 +01:00 committed by Arvid Norberg
parent 7a51813d32
commit 507fffe872
5 changed files with 43 additions and 46 deletions

View File

@ -145,8 +145,8 @@ namespace libtorrent {
std::string peer_alert::message() const
{
return torrent_alert::message() + " peer (" + print_endpoint(endpoint)
+ ", " + aux::identify_client_impl(pid) + ")";
return torrent_alert::message() + " peer [ " + print_endpoint(endpoint)
+ " client: " + aux::identify_client_impl(pid) + " ]";
}
tracker_alert::tracker_alert(aux::stack_allocator& alloc

View File

@ -65,6 +65,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/time.hpp"
#include "libtorrent/buffer.hpp"
#include "libtorrent/aux_/array.hpp"
#include "libtorrent/aux_/set_socket_buffer.hpp"
#if TORRENT_USE_ASSERTS
#include <set>
@ -387,7 +388,22 @@ namespace libtorrent {
}
// if this is an incoming connection, we're done here
if (!m_connecting) return;
if (!m_connecting)
{
error_code err;
aux::set_socket_buffer_size(*m_socket, m_settings, err);
#ifndef TORRENT_DISABLE_LOGGING
if (err && should_log(peer_log_alert::incoming))
{
error_code ignore;
peer_log(peer_log_alert::incoming, "SOCKET_BUFFER", "%s %s"
, print_endpoint(m_remote).c_str()
, print_error(err).c_str());
}
#endif
return;
}
#ifndef TORRENT_DISABLE_LOGGING
if (should_log(peer_log_alert::outgoing))
@ -422,6 +438,20 @@ namespace libtorrent {
return;
}
{
error_code err;
aux::set_socket_buffer_size(*m_socket, m_settings, err);
#ifndef TORRENT_DISABLE_LOGGING
if (err && should_log(peer_log_alert::outgoing))
{
error_code ignore;
peer_log(peer_log_alert::outgoing, "SOCKET_BUFFER", "%s %s"
, print_endpoint(m_remote).c_str()
, print_error(err).c_str());
}
#endif
}
#ifndef TORRENT_DISABLE_LOGGING
if (should_log(peer_log_alert::outgoing))
{

View File

@ -2920,20 +2920,6 @@ namespace aux {
if (m_alerts.should_post<incoming_connection_alert>())
m_alerts.emplace_alert<incoming_connection_alert>(s->type(), endp);
{
error_code err;
set_socket_buffer_size(*s, m_settings, err);
#ifndef TORRENT_DISABLE_LOGGING
if (err && should_log())
{
error_code ignore;
session_log("socket buffer size [ %s %d ]: %s"
, s->local_endpoint().address().to_string(ignore).c_str()
, s->local_endpoint().port(), print_error(err).c_str());
}
#endif
}
peer_connection_args pack{
this
, &m_settings
@ -6419,9 +6405,9 @@ namespace aux {
if (ec && should_log())
{
error_code err;
session_log("socket buffer size [ udp %s %d]: (%d) %s"
session_log("listen socket buffer size [ udp %s:%d ] %s"
, l->udp_sock->sock.local_endpoint().address().to_string(err).c_str()
, l->udp_sock->sock.local_port(), ec.value(), ec.message().c_str());
, l->udp_sock->sock.local_port(), print_error(ec).c_str());
}
#endif
ec.clear();
@ -6430,9 +6416,9 @@ namespace aux {
if (ec && should_log())
{
error_code err;
session_log("socket buffer size [ udp %s %d]: (%d) %s"
session_log("listen socket buffer size [ tcp %s:%d] %s"
, l->sock->local_endpoint().address().to_string(err).c_str()
, l->sock->local_endpoint().port(), ec.value(), ec.message().c_str());
, l->sock->local_endpoint().port(), print_error(ec).c_str());
}
#endif
}

View File

@ -57,13 +57,14 @@ namespace aux {
allocation_slot stack_allocator::format_string(char const* fmt, va_list v)
{
int const ret = int(m_storage.size());
m_storage.resize(ret + 512);
int const max_size = 1024;
m_storage.resize(ret + max_size);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
int const len = std::vsnprintf(m_storage.data() + ret, 512, fmt, v);
int const len = std::vsnprintf(m_storage.data() + ret, max_size, fmt, v);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
@ -75,7 +76,7 @@ namespace aux {
}
// +1 is to include the 0-terminator
m_storage.resize(ret + (len > 512 ? 512 : len) + 1);
m_storage.resize(ret + std::min(len, max_size) + 1);
return allocation_slot(ret);
}

View File

@ -99,7 +99,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/disk_io_thread.hpp" // for cache_status
#include "libtorrent/aux_/numeric_cast.hpp"
#include "libtorrent/aux_/path.hpp"
#include "libtorrent/aux_/set_socket_buffer.hpp"
#include "libtorrent/aux_/generate_peer_id.hpp"
#ifndef TORRENT_DISABLE_LOGGING
@ -3204,12 +3203,8 @@ bool is_downloading_state(int const st)
resolved_to += i.to_string();
resolved_to += ", ";
}
debug_log("TRACKER RESPONSE\n"
"interval: %d\n"
"min-interval: %d\n"
"external ip: %s\n"
"resolved to: %s\n"
"we connected to: %s\n"
debug_log("TRACKER RESPONSE [ interval: %d | min-interval: %d | "
"external ip: %s | resolved to: %s | we connected to: %s ]"
, interval.count()
, resp.min_interval.count()
, print_address(resp.external_ip).c_str()
@ -6562,21 +6557,6 @@ bool is_downloading_state(int const st)
#endif
}
{
error_code err;
aux::set_socket_buffer_size(*s, settings(), err);
#ifndef TORRENT_DISABLE_LOGGING
if (err && should_log())
{
error_code ignore;
auto const lep = s->local_endpoint(ignore);
debug_log("socket buffer size [ %s %d]: (%d) %s"
, lep.address().to_string(ignore).c_str()
, lep.port(), err.value(), err.message().c_str());
}
#endif
}
peer_id const our_pid = aux::generate_peer_id(settings());
peer_connection_args pack{
&m_ses