add incoming_connection_alert for logging all successful incoming connections

This commit is contained in:
Arvid Norberg 2011-09-17 01:44:05 +00:00
parent 3e91b45904
commit f5b5160169
8 changed files with 101 additions and 0 deletions

View File

@ -1,3 +1,4 @@
* add incoming_connection_alert for logging all successful incoming connections
* feature to encrypt peer connections with a secret AES-256 key stored in .torrent file
* deprecated compact storage allocation
* close files in separate thread on systems where close() may block (Mac OS X for instance)

View File

@ -7319,6 +7319,56 @@ having to call ``get_settings()``.
``error`` is an error code used for when an error occurs on the feed.
incoming_connection_alert
-------------------------
The incoming connection alert is posted every time we successfully accept
an incoming connection, through any mean. The most straigh-forward ways
of accepting incoming connections are through the TCP listen socket and
the UDP listen socket for uTP sockets. However, connections may also be
accepted ofer a Socks5 or i2p listen socket, or via a torrent specific
listen socket for SSL torrents.
::
struct incoming_connection_alert: alert
{
// ...
virtual std::string message() const;
int socket_type;
tcp::endpoint ip;
};
``socket_type`` tells you what kind of socket the connection was accepted
as:
+==========+=====================================+
| value | type |
+==========+=====================================+
| 0 | none (no socket instantiated) |
+----------+-------------------------------------+
| 1 | TCP |
+----------+-------------------------------------+
| 2 | Socks5 |
+----------+-------------------------------------+
| 3 | HTTP |
+----------+-------------------------------------+
| 4 | uTP |
+----------+-------------------------------------+
| 5 | i2p |
+----------+-------------------------------------+
| 6 | SSL/TCP |
+----------+-------------------------------------+
| 7 | SSL/Socks5 |
+----------+-------------------------------------+
| 8 | HTTPS (SSL/HTTP) |
+----------+-------------------------------------+
| 9 | SSL/uTP |
+----------+-------------------------------------+
``ip`` is the IP address and port the connection came from.
alert dispatcher
================

View File

@ -1278,6 +1278,22 @@ namespace libtorrent
error_code error;
};
struct TORRENT_EXPORT incoming_connection_alert: alert
{
incoming_connection_alert(int type_, tcp::endpoint const& ip_)
: socket_type(type_)
, ip(ip_)
{}
TORRENT_DEFINE_ALERT(incoming_connection_alert);
const static int static_category = alert::peer_notification;
virtual std::string message() const;
int socket_type;
tcp::endpoint ip;
};
}

View File

@ -196,6 +196,7 @@ namespace libtorrent
endpoint_type remote_endpoint(error_code& ec) const;
void bind(endpoint_type const& endpoint, error_code& ec);
std::size_t available(error_code& ec) const;
int type();
template <class Mutable_Buffers>

View File

@ -566,5 +566,26 @@ namespace libtorrent {
return torrent_alert::message() + " needs SSL certificate";
}
std::string incoming_connection_alert::message() const
{
char msg[600];
char const* type_str[] = {
"null",
"TCP",
"Socks5/TCP",
"HTTP",
"uTP",
"i2p",
"SSL/TCP",
"SSL/Socks5",
"HTTPS",
"SSL/uTP"
};
error_code ec;
snprintf(msg, sizeof(msg), "incoming connection from %s (%s)"
, print_endpoint(ip).c_str(), type_str[socket_type]);
return msg;
}
} // namespace libtorrent

View File

@ -2243,6 +2243,11 @@ namespace aux {
(*m_logger) << time_now_string() << " <== INCOMING CONNECTION " << endp << "\n";
#endif
if (m_alerts.should_post<incoming_connection_alert>())
{
m_alerts.post_alert(incoming_connection_alert(s->type(), endp));
}
if (!m_settings.enable_incoming_utp
&& s->get<utp_stream>())
{

View File

@ -164,6 +164,8 @@ namespace libtorrent
std::size_t socket_type::available(error_code& ec) const
{ TORRENT_SOCKTYPE_FORWARD_RET(available(ec), 0) }
int socket_type::type() { return m_type; }
#ifndef BOOST_NO_EXCEPTIONS
void socket_type::open(protocol_type const& p)
{ TORRENT_SOCKTYPE_FORWARD(open(p)) }

View File

@ -1462,6 +1462,11 @@ ctx->set_verify_callback(verify_function, ec);
return;
}
if (alerts().should_post<incoming_connection_alert>())
{
alerts().post_alert(incoming_connection_alert(s->type(), endp));
}
if (!settings().enable_incoming_tcp)
{
if (alerts().should_post<peer_blocked_alert>())