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 * transitioned exception types to system_error
* made alerts move-only * made alerts move-only
* move files one-by-one when moving storage for a torrent * move files one-by-one when moving storage for a torrent

View File

@ -534,10 +534,19 @@ void bind_alert()
#endif #endif
; ;
class_<peer_blocked_alert, bases<alert>, noncopyable>( class_<peer_blocked_alert, bases<peer_alert>, noncopyable>(
"peer_blocked_alert", no_init) "peer_blocked_alert", no_init)
.add_property("ip", make_getter(&peer_blocked_alert::ip .add_property("reason", &peer_blocked_alert::reason)
, return_value_policy<return_by_value>())) ;
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>( 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("num_peers", &dht_get_peers_reply_alert::num_peers)
.def("peers", peers) .def("peers", peers)
; ;
} }

View File

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

View File

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

View File

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

View File

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