diff --git a/ChangeLog b/ChangeLog index 8b30820fa..50b5c499d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * include reason in peer_blocked_alert * support magnet links wrapped in .torrent files * rate limiter optimization * rate limiter overflow fix (for very high limits) diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 6be76993f..6d1c99d14 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -1492,22 +1492,32 @@ namespace libtorrent struct TORRENT_EXPORT peer_blocked_alert: torrent_alert { // internal - peer_blocked_alert(torrent_handle const& h, address const& i) + peer_blocked_alert(torrent_handle const& h, address const& i + , int r) : torrent_alert(h) , ip(i) + , reason(r) {} TORRENT_DEFINE_ALERT(peer_blocked_alert); const static int static_category = alert::ip_block_notification; - virtual std::string message() const - { - error_code ec; - return torrent_alert::message() + ": blocked peer: " + ip.to_string(ec); - } + virtual std::string message() const; // the address that was blocked. address ip; + + enum reason_t + { + ip_filter, + port_filter, + i2p_mixed, + privileged_ports, + utp_disabled, + tcp_disabled + }; + + int reason; }; // This alert is generated when a DHT node announces to an info-hash on our DHT node. It belongs diff --git a/src/alert.cpp b/src/alert.cpp index 1f0709a71..0b5611e3d 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -344,6 +344,26 @@ namespace libtorrent { return ret; } + std::string peer_blocked_alert::message() const + { + error_code ec; + char ret[600]; + char const* reason_str[] = + { + "ip_filter", + "port_filter", + "i2p_mixed", + "privileged_ports", + "utp_disabled", + "tcp_disabled" + }; + + snprintf(ret, sizeof(ret), "%s: blocked peer: %s [%s]" + , torrent_alert::message().c_str(), ip.to_string(ec).c_str() + , reason_str[reason]); + return ret; + } + std::string dht_announce_alert::message() const { error_code ec; diff --git a/src/policy.cpp b/src/policy.cpp index 2a3e4d2c1..f7aa25557 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -477,7 +477,8 @@ namespace libtorrent } if (ses.m_alerts.should_post()) - ses.m_alerts.post_alert(peer_blocked_alert(m_torrent->get_handle(), (*i)->address())); + ses.m_alerts.post_alert(peer_blocked_alert(m_torrent->get_handle() + , (*i)->address(), peer_blocked_alert::ip_filter)); int current = i - m_peers.begin(); TORRENT_ASSERT(current >= 0); @@ -1458,7 +1459,8 @@ namespace libtorrent if (!ses.m_settings.allow_i2p_mixed && m_torrent->torrent_file().is_i2p()) { if (ses.m_alerts.should_post()) - ses.m_alerts.post_alert(peer_blocked_alert(m_torrent->get_handle(), remote.address())); + ses.m_alerts.post_alert(peer_blocked_alert(m_torrent->get_handle() + , remote.address(), peer_blocked_alert::ip_filter)); return 0; } @@ -1466,7 +1468,8 @@ namespace libtorrent if (pf.access(remote.port()) & port_filter::blocked) { if (ses.m_alerts.should_post()) - ses.m_alerts.post_alert(peer_blocked_alert(m_torrent->get_handle(), remote.address())); + ses.m_alerts.post_alert(peer_blocked_alert(m_torrent->get_handle() + , remote.address(), peer_blocked_alert::port_filter)); #ifndef TORRENT_DISABLE_EXTENSIONS m_torrent->notify_extension_add_peer(remote, src, torrent_plugin::filtered); #endif @@ -1476,7 +1479,8 @@ namespace libtorrent if (ses.m_settings.no_connect_privileged_ports && remote.port() < 1024) { if (ses.m_alerts.should_post()) - ses.m_alerts.post_alert(peer_blocked_alert(m_torrent->get_handle(), remote.address())); + ses.m_alerts.post_alert(peer_blocked_alert(m_torrent->get_handle() + , remote.address(), peer_blocked_alert::privileged_ports)); #ifndef TORRENT_DISABLE_EXTENSIONS m_torrent->notify_extension_add_peer(remote, src, torrent_plugin::filtered); #endif @@ -1488,7 +1492,8 @@ namespace libtorrent && (ses.m_ip_filter.access(remote.address()) & ip_filter::blocked)) { if (ses.m_alerts.should_post()) - ses.m_alerts.post_alert(peer_blocked_alert(m_torrent->get_handle(), remote.address())); + ses.m_alerts.post_alert(peer_blocked_alert(m_torrent->get_handle() + , remote.address(), peer_blocked_alert::ip_filter)); #ifndef TORRENT_DISABLE_EXTENSIONS m_torrent->notify_extension_add_peer(remote, src, torrent_plugin::filtered); #endif diff --git a/src/session_impl.cpp b/src/session_impl.cpp index ad7c07d66..a5a6149fa 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2750,7 +2750,8 @@ retry: session_log(" rejected uTP connection"); #endif if (m_alerts.should_post()) - m_alerts.post_alert(peer_blocked_alert(torrent_handle(), endp.address())); + m_alerts.post_alert(peer_blocked_alert(torrent_handle() + , endp.address(), peer_blocked_alert::utp_disabled)); return; } @@ -2761,7 +2762,8 @@ retry: session_log(" rejected TCP connection"); #endif if (m_alerts.should_post()) - m_alerts.post_alert(peer_blocked_alert(torrent_handle(), endp.address())); + m_alerts.post_alert(peer_blocked_alert(torrent_handle() + , endp.address(), peer_blocked_alert::tcp_disabled)); return; } @@ -2782,7 +2784,8 @@ retry: session_log("filtered blocked ip"); #endif if (m_alerts.should_post()) - m_alerts.post_alert(peer_blocked_alert(torrent_handle(), endp.address())); + m_alerts.post_alert(peer_blocked_alert(torrent_handle() + , endp.address(), peer_blocked_alert::ip_filter)); return; } diff --git a/src/torrent.cpp b/src/torrent.cpp index 09b6a8f27..a6a33f10b 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2759,7 +2759,8 @@ namespace libtorrent debug_log("blocked ip from tracker: %s", host->endpoint().address().to_string(ec).c_str()); #endif if (m_ses.m_alerts.should_post()) - m_ses.m_alerts.post_alert(peer_blocked_alert(get_handle(), host->endpoint().address())); + m_ses.m_alerts.post_alert(peer_blocked_alert(get_handle() + , host->endpoint().address(), peer_blocked_alert::ip_filter)); return; } @@ -4698,7 +4699,8 @@ namespace libtorrent && m_ses.m_ip_filter.access(a.address()) & ip_filter::blocked) { if (m_ses.m_alerts.should_post()) - m_ses.m_alerts.post_alert(peer_blocked_alert(get_handle(), a.address())); + m_ses.m_alerts.post_alert(peer_blocked_alert(get_handle() + , a.address(), peer_blocked_alert::ip_filter)); return; } @@ -4760,7 +4762,8 @@ namespace libtorrent && m_ses.m_ip_filter.access(a.address()) & ip_filter::blocked) { if (m_ses.m_alerts.should_post()) - m_ses.m_alerts.post_alert(peer_blocked_alert(get_handle(), a.address())); + m_ses.m_alerts.post_alert(peer_blocked_alert(get_handle() + , a.address(), peer_blocked_alert::ip_filter)); return; } @@ -5977,7 +5980,8 @@ namespace libtorrent && m_ses.m_ip_filter.access(p->remote().address()) & ip_filter::blocked) { if (m_ses.m_alerts.should_post()) - m_ses.m_alerts.post_alert(peer_blocked_alert(get_handle(), p->remote().address())); + m_ses.m_alerts.post_alert(peer_blocked_alert(get_handle() + , p->remote().address(), peer_blocked_alert::ip_filter)); p->disconnect(errors::banned_by_ip_filter); return false; }