Peer blocked alert (#747)

make peer_blocked_alert derive from peer_alert
This commit is contained in:
Arvid Norberg 2016-05-22 19:56:14 -04:00
parent 836cd98d43
commit cf3c95702b
6 changed files with 39 additions and 30 deletions

View File

@ -1,3 +1,4 @@
* peer_blocked_alert now derives from peer_alert
* transitioned exception types to system_error
* made alerts move-only
* move files one-by-one when moving storage for a torrent

View File

@ -534,10 +534,19 @@ void bind_alert()
#endif
;
class_<peer_blocked_alert, bases<alert>, noncopyable>(
class_<peer_blocked_alert, bases<peer_alert>, noncopyable>(
"peer_blocked_alert", no_init)
.add_property("ip", make_getter(&peer_blocked_alert::ip
, return_value_policy<return_by_value>()))
.add_property("reason", &peer_blocked_alert::reason)
;
enum_<peer_blocked_alert::reason_t>("reason_t")
.value("ip_filter", peer_blocked_alert::reason_t::ip_filter)
.value("port_filter", peer_blocked_alert::reason_t::port_filter)
.value("i2p_mixed", peer_blocked_alert::reason_t::i2p_mixed)
.value("privileged_ports", peer_blocked_alert::reason_t::privileged_ports)
.value("utp_disabled", peer_blocked_alert::reason_t::utp_disabled)
.value("tcp_disabled", peer_blocked_alert::reason_t::tcp_disabled)
.value("invalid_local_interface", peer_blocked_alert::reason_t::invalid_local_interface)
;
class_<scrape_reply_alert, bases<tracker_alert>, noncopyable>(
@ -830,4 +839,5 @@ void bind_alert()
.def("num_peers", &dht_get_peers_reply_alert::num_peers)
.def("peers", peers)
;
}

View File

@ -1467,20 +1467,17 @@ namespace libtorrent
// * the port filter
// * the peer has a low port and ``no_connect_privileged_ports`` is enabled
// * the protocol of the peer is blocked (uTP/TCP blocking)
struct TORRENT_EXPORT peer_blocked_alert final : torrent_alert
struct TORRENT_EXPORT peer_blocked_alert final : peer_alert
{
// internal
peer_blocked_alert(aux::stack_allocator& alloc, torrent_handle const& h
, address const& i, int r);
, tcp::endpoint const& ep, int r);
TORRENT_DEFINE_ALERT(peer_blocked_alert, 54)
static const int static_category = alert::ip_block_notification;
virtual std::string message() const override;
// the address that was blocked.
address ip;
enum reason_t
{
ip_filter,
@ -1492,6 +1489,8 @@ namespace libtorrent
invalid_local_interface
};
// the reason for the peer being blocked. Is one of the values from the
// reason_t enum.
int reason;
};

View File

@ -1023,10 +1023,8 @@ namespace libtorrent {
}
peer_blocked_alert::peer_blocked_alert(aux::stack_allocator& alloc
, torrent_handle const& h, address const& i
, int r)
: torrent_alert(alloc, h)
, ip(i)
, torrent_handle const& h, tcp::endpoint const& ep, int r)
: peer_alert(alloc, h, ep, peer_id(0))
, reason(r)
{}
@ -1034,7 +1032,7 @@ namespace libtorrent {
{
error_code ec;
char ret[600];
char const* reason_str[] =
static char const* reason_str[] =
{
"ip_filter",
"port_filter",
@ -1045,9 +1043,8 @@ namespace libtorrent {
"invalid_local_interface"
};
std::snprintf(ret, sizeof(ret), "%s: blocked peer: %s [%s]"
, torrent_alert::message().c_str(), ip.to_string(ec).c_str()
, reason_str[reason]);
std::snprintf(ret, sizeof(ret), "%s: blocked peer [%s]"
, peer_alert::message().c_str(), reason_str[reason]);
return ret;
}

View File

@ -2666,7 +2666,7 @@ namespace aux {
#endif
if (m_alerts.should_post<peer_blocked_alert>())
m_alerts.emplace_alert<peer_blocked_alert>(torrent_handle()
, endp.address(), peer_blocked_alert::utp_disabled);
, endp, peer_blocked_alert::utp_disabled);
return;
}
@ -2678,7 +2678,7 @@ namespace aux {
#endif
if (m_alerts.should_post<peer_blocked_alert>())
m_alerts.emplace_alert<peer_blocked_alert>(torrent_handle()
, endp.address(), peer_blocked_alert::tcp_disabled);
, endp, peer_blocked_alert::tcp_disabled);
return;
}
@ -2714,7 +2714,7 @@ namespace aux {
#endif
if (m_alerts.should_post<peer_blocked_alert>())
m_alerts.emplace_alert<peer_blocked_alert>(torrent_handle()
, endp.address(), peer_blocked_alert::invalid_local_interface);
, endp, peer_blocked_alert::invalid_local_interface);
return;
}
}
@ -2738,7 +2738,7 @@ namespace aux {
#endif
if (m_alerts.should_post<peer_blocked_alert>())
m_alerts.emplace_alert<peer_blocked_alert>(torrent_handle()
, endp.address(), peer_blocked_alert::ip_filter);
, endp, peer_blocked_alert::ip_filter);
return;
}

View File

@ -3599,7 +3599,7 @@ namespace libtorrent
#endif
if (m_ses.alerts().should_post<peer_blocked_alert>())
m_ses.alerts().emplace_alert<peer_blocked_alert>(get_handle()
, host.address(), peer_blocked_alert::ip_filter);
, host, peer_blocked_alert::ip_filter);
return;
}
@ -6197,7 +6197,7 @@ namespace libtorrent
{
if (m_ses.alerts().should_post<peer_blocked_alert>())
m_ses.alerts().emplace_alert<peer_blocked_alert>(get_handle()
, a.address(), peer_blocked_alert::ip_filter);
, a, peer_blocked_alert::ip_filter);
return;
}
@ -6275,7 +6275,7 @@ namespace libtorrent
{
if (m_ses.alerts().should_post<peer_blocked_alert>())
m_ses.alerts().emplace_alert<peer_blocked_alert>(get_handle()
, a.address(), peer_blocked_alert::ip_filter);
, a, peer_blocked_alert::ip_filter);
return;
}
@ -7313,7 +7313,7 @@ namespace libtorrent
{
if (m_ses.alerts().should_post<peer_blocked_alert>())
m_ses.alerts().emplace_alert<peer_blocked_alert>(get_handle()
, p->remote().address(), peer_blocked_alert::ip_filter);
, p->remote(), peer_blocked_alert::ip_filter);
p->disconnect(errors::banned_by_ip_filter, op_bittorrent);
return false;
}
@ -10576,7 +10576,7 @@ namespace libtorrent
{
if (alerts().should_post<peer_blocked_alert>())
alerts().emplace_alert<peer_blocked_alert>(get_handle()
, adr.address(), peer_blocked_alert::ip_filter);
, adr, peer_blocked_alert::ip_filter);
#ifndef TORRENT_DISABLE_EXTENSIONS
notify_extension_add_peer(adr, source, torrent_plugin::filtered);
@ -10588,7 +10588,7 @@ namespace libtorrent
{
if (alerts().should_post<peer_blocked_alert>())
alerts().emplace_alert<peer_blocked_alert>(get_handle()
, adr.address(), peer_blocked_alert::port_filter);
, adr, peer_blocked_alert::port_filter);
#ifndef TORRENT_DISABLE_EXTENSIONS
notify_extension_add_peer(adr, source, torrent_plugin::filtered);
#endif
@ -10602,7 +10602,7 @@ namespace libtorrent
{
if (alerts().should_post<peer_blocked_alert>())
alerts().emplace_alert<peer_blocked_alert>(get_handle()
, adr.address(), peer_blocked_alert::i2p_mixed);
, adr, peer_blocked_alert::i2p_mixed);
return NULL;
}
#endif
@ -10611,7 +10611,7 @@ namespace libtorrent
{
if (alerts().should_post<peer_blocked_alert>())
alerts().emplace_alert<peer_blocked_alert>(get_handle()
, adr.address(), peer_blocked_alert::privileged_ports);
, adr, peer_blocked_alert::privileged_ports);
#ifndef TORRENT_DISABLE_EXTENSIONS
notify_extension_add_peer(adr, source, torrent_plugin::filtered);
#endif
@ -10739,7 +10739,8 @@ namespace libtorrent
{
for (std::vector<address>::iterator i = banned.begin()
, end(banned.end()); i != end; ++i)
alerts().emplace_alert<peer_blocked_alert>(get_handle(), *i
alerts().emplace_alert<peer_blocked_alert>(get_handle()
, tcp::endpoint(*i, 0)
, peer_blocked_alert::ip_filter);
}
@ -10759,7 +10760,8 @@ namespace libtorrent
{
for (std::vector<address>::iterator i = banned.begin()
, end(banned.end()); i != end; ++i)
alerts().emplace_alert<peer_blocked_alert>(get_handle(), *i
alerts().emplace_alert<peer_blocked_alert>(get_handle()
, tcp::endpoint(*i, 0)
, peer_blocked_alert::port_filter);
}