include reason in peer_blocked_alert

This commit is contained in:
Arvid Norberg 2014-02-07 17:35:56 +00:00
parent b3de578fe7
commit a71fbc4f68
6 changed files with 61 additions and 18 deletions

View File

@ -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)

View File

@ -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

View File

@ -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;

View File

@ -477,7 +477,8 @@ namespace libtorrent
}
if (ses.m_alerts.should_post<peer_blocked_alert>())
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<peer_blocked_alert>())
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<peer_blocked_alert>())
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<peer_blocked_alert>())
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<peer_blocked_alert>())
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

View File

@ -2750,7 +2750,8 @@ retry:
session_log(" rejected uTP connection");
#endif
if (m_alerts.should_post<peer_blocked_alert>())
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<peer_blocked_alert>())
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<peer_blocked_alert>())
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;
}

View File

@ -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<peer_blocked_alert>())
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<peer_blocked_alert>())
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<peer_blocked_alert>())
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<peer_blocked_alert>())
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;
}