include reason in peer_blocked_alert
This commit is contained in:
parent
b3de578fe7
commit
a71fbc4f68
|
@ -1,3 +1,4 @@
|
||||||
|
* include reason in peer_blocked_alert
|
||||||
* support magnet links wrapped in .torrent files
|
* support magnet links wrapped in .torrent files
|
||||||
* rate limiter optimization
|
* rate limiter optimization
|
||||||
* rate limiter overflow fix (for very high limits)
|
* rate limiter overflow fix (for very high limits)
|
||||||
|
|
|
@ -1492,22 +1492,32 @@ namespace libtorrent
|
||||||
struct TORRENT_EXPORT peer_blocked_alert: torrent_alert
|
struct TORRENT_EXPORT peer_blocked_alert: torrent_alert
|
||||||
{
|
{
|
||||||
// internal
|
// 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)
|
: torrent_alert(h)
|
||||||
, ip(i)
|
, ip(i)
|
||||||
|
, reason(r)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
TORRENT_DEFINE_ALERT(peer_blocked_alert);
|
TORRENT_DEFINE_ALERT(peer_blocked_alert);
|
||||||
|
|
||||||
const static int static_category = alert::ip_block_notification;
|
const static int static_category = alert::ip_block_notification;
|
||||||
virtual std::string message() const
|
virtual std::string message() const;
|
||||||
{
|
|
||||||
error_code ec;
|
|
||||||
return torrent_alert::message() + ": blocked peer: " + ip.to_string(ec);
|
|
||||||
}
|
|
||||||
|
|
||||||
// the address that was blocked.
|
// the address that was blocked.
|
||||||
address ip;
|
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
|
// This alert is generated when a DHT node announces to an info-hash on our DHT node. It belongs
|
||||||
|
|
|
@ -344,6 +344,26 @@ namespace libtorrent {
|
||||||
return ret;
|
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
|
std::string dht_announce_alert::message() const
|
||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
|
|
@ -477,7 +477,8 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ses.m_alerts.should_post<peer_blocked_alert>())
|
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();
|
int current = i - m_peers.begin();
|
||||||
TORRENT_ASSERT(current >= 0);
|
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_settings.allow_i2p_mixed && m_torrent->torrent_file().is_i2p())
|
||||||
{
|
{
|
||||||
if (ses.m_alerts.should_post<peer_blocked_alert>())
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1466,7 +1468,8 @@ namespace libtorrent
|
||||||
if (pf.access(remote.port()) & port_filter::blocked)
|
if (pf.access(remote.port()) & port_filter::blocked)
|
||||||
{
|
{
|
||||||
if (ses.m_alerts.should_post<peer_blocked_alert>())
|
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
|
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||||
m_torrent->notify_extension_add_peer(remote, src, torrent_plugin::filtered);
|
m_torrent->notify_extension_add_peer(remote, src, torrent_plugin::filtered);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1476,7 +1479,8 @@ namespace libtorrent
|
||||||
if (ses.m_settings.no_connect_privileged_ports && remote.port() < 1024)
|
if (ses.m_settings.no_connect_privileged_ports && remote.port() < 1024)
|
||||||
{
|
{
|
||||||
if (ses.m_alerts.should_post<peer_blocked_alert>())
|
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
|
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||||
m_torrent->notify_extension_add_peer(remote, src, torrent_plugin::filtered);
|
m_torrent->notify_extension_add_peer(remote, src, torrent_plugin::filtered);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1488,7 +1492,8 @@ namespace libtorrent
|
||||||
&& (ses.m_ip_filter.access(remote.address()) & ip_filter::blocked))
|
&& (ses.m_ip_filter.access(remote.address()) & ip_filter::blocked))
|
||||||
{
|
{
|
||||||
if (ses.m_alerts.should_post<peer_blocked_alert>())
|
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
|
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||||
m_torrent->notify_extension_add_peer(remote, src, torrent_plugin::filtered);
|
m_torrent->notify_extension_add_peer(remote, src, torrent_plugin::filtered);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2750,7 +2750,8 @@ retry:
|
||||||
session_log(" rejected uTP connection");
|
session_log(" rejected uTP connection");
|
||||||
#endif
|
#endif
|
||||||
if (m_alerts.should_post<peer_blocked_alert>())
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2761,7 +2762,8 @@ retry:
|
||||||
session_log(" rejected TCP connection");
|
session_log(" rejected TCP connection");
|
||||||
#endif
|
#endif
|
||||||
if (m_alerts.should_post<peer_blocked_alert>())
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2782,7 +2784,8 @@ retry:
|
||||||
session_log("filtered blocked ip");
|
session_log("filtered blocked ip");
|
||||||
#endif
|
#endif
|
||||||
if (m_alerts.should_post<peer_blocked_alert>())
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2759,7 +2759,8 @@ namespace libtorrent
|
||||||
debug_log("blocked ip from tracker: %s", host->endpoint().address().to_string(ec).c_str());
|
debug_log("blocked ip from tracker: %s", host->endpoint().address().to_string(ec).c_str());
|
||||||
#endif
|
#endif
|
||||||
if (m_ses.m_alerts.should_post<peer_blocked_alert>())
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4698,7 +4699,8 @@ namespace libtorrent
|
||||||
&& m_ses.m_ip_filter.access(a.address()) & ip_filter::blocked)
|
&& m_ses.m_ip_filter.access(a.address()) & ip_filter::blocked)
|
||||||
{
|
{
|
||||||
if (m_ses.m_alerts.should_post<peer_blocked_alert>())
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4760,7 +4762,8 @@ namespace libtorrent
|
||||||
&& m_ses.m_ip_filter.access(a.address()) & ip_filter::blocked)
|
&& m_ses.m_ip_filter.access(a.address()) & ip_filter::blocked)
|
||||||
{
|
{
|
||||||
if (m_ses.m_alerts.should_post<peer_blocked_alert>())
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5977,7 +5980,8 @@ namespace libtorrent
|
||||||
&& m_ses.m_ip_filter.access(p->remote().address()) & ip_filter::blocked)
|
&& m_ses.m_ip_filter.access(p->remote().address()) & ip_filter::blocked)
|
||||||
{
|
{
|
||||||
if (m_ses.m_alerts.should_post<peer_blocked_alert>())
|
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);
|
p->disconnect(errors::banned_by_ip_filter);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue