broadcast sockets now join every network interface
This commit is contained in:
parent
66882b149c
commit
a65659f52f
|
@ -105,6 +105,8 @@ release 0.14.7
|
||||||
* fixed move_storage when source doesn't exist
|
* fixed move_storage when source doesn't exist
|
||||||
* fixed DHT state save bug for node-id
|
* fixed DHT state save bug for node-id
|
||||||
* fixed typo in python binding session_status struct
|
* fixed typo in python binding session_status struct
|
||||||
|
* broadcast sockets now join every network interface (used for UPnP and
|
||||||
|
local peer discovery)
|
||||||
|
|
||||||
release 0.14.6
|
release 0.14.6
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ namespace libtorrent
|
||||||
, std::size_t bytes_transferred);
|
, std::size_t bytes_transferred);
|
||||||
void open_unicast_socket(io_service& ios, address const& addr);
|
void open_unicast_socket(io_service& ios, address const& addr);
|
||||||
void open_multicast_socket(io_service& ios, address const& addr
|
void open_multicast_socket(io_service& ios, address const& addr
|
||||||
, bool loopback);
|
, bool loopback, error_code& ec);
|
||||||
|
|
||||||
// these sockets are used to
|
// these sockets are used to
|
||||||
// join the multicast group (on each interface)
|
// join the multicast group (on each interface)
|
||||||
|
|
|
@ -191,15 +191,6 @@ namespace libtorrent
|
||||||
error_code ec;
|
error_code ec;
|
||||||
std::vector<ip_interface> interfaces = enum_net_interfaces(ios, ec);
|
std::vector<ip_interface> interfaces = enum_net_interfaces(ios, ec);
|
||||||
|
|
||||||
#if TORRENT_USE_IPV6
|
|
||||||
if (multicast_endpoint.address().is_v4())
|
|
||||||
#endif
|
|
||||||
open_multicast_socket(ios, address_v4::any(), loopback);
|
|
||||||
#if TORRENT_USE_IPV6
|
|
||||||
else
|
|
||||||
open_multicast_socket(ios, address_v6::any(), loopback);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (std::vector<ip_interface>::const_iterator i = interfaces.begin()
|
for (std::vector<ip_interface>::const_iterator i = interfaces.begin()
|
||||||
, end(interfaces.end()); i != end; ++i)
|
, end(interfaces.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
|
@ -208,20 +199,24 @@ namespace libtorrent
|
||||||
// ignore any loopback interface
|
// ignore any loopback interface
|
||||||
if (is_loopback(i->interface_address)) continue;
|
if (is_loopback(i->interface_address)) continue;
|
||||||
|
|
||||||
|
ec.clear();
|
||||||
|
open_multicast_socket(ios, i->interface_address, loopback, ec);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// std::cerr << "broadcast socket [ if: " << i->interface_address.to_v4().to_string()
|
// extern std::string print_address(address const& addr);
|
||||||
// << " group: " << multicast_endpoint.address() << " ]" << std::endl;
|
// fprintf(stderr, "broadcast socket [ if: %s group: %s ] %s\n"
|
||||||
|
// , i->interface_address.to_string().c_str()
|
||||||
|
// , print_address(multicast_endpoint.address()).c_str()
|
||||||
|
// , ec.message().c_str());
|
||||||
#endif
|
#endif
|
||||||
open_unicast_socket(ios, i->interface_address);
|
open_unicast_socket(ios, i->interface_address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void broadcast_socket::open_multicast_socket(io_service& ios
|
void broadcast_socket::open_multicast_socket(io_service& ios
|
||||||
, address const& addr, bool loopback)
|
, address const& addr, bool loopback, error_code& ec)
|
||||||
{
|
{
|
||||||
using namespace asio::ip::multicast;
|
using namespace asio::ip::multicast;
|
||||||
|
|
||||||
error_code ec;
|
|
||||||
boost::shared_ptr<datagram_socket> s(new datagram_socket(ios));
|
boost::shared_ptr<datagram_socket> s(new datagram_socket(ios));
|
||||||
s->open(addr.is_v4() ? udp::v4() : udp::v6(), ec);
|
s->open(addr.is_v4() ? udp::v4() : udp::v6(), ec);
|
||||||
if (ec) return;
|
if (ec) return;
|
||||||
|
@ -265,7 +260,10 @@ namespace libtorrent
|
||||||
error_code e;
|
error_code e;
|
||||||
i->socket->send_to(asio::buffer(buffer, size), m_multicast_endpoint, 0, e);
|
i->socket->send_to(asio::buffer(buffer, size), m_multicast_endpoint, 0, e);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// std::cerr << " sending on " << i->socket->local_endpoint().address().to_string() << " to: " << m_multicast_endpoint << std::endl;
|
// extern std::string print_address(address const& addr);
|
||||||
|
// extern std::string print_endpoint(udp::endpoint const& ep);
|
||||||
|
// fprintf(stderr, " sending on %s to: %s\n", print_address(i->socket->local_endpoint().address()).c_str()
|
||||||
|
// , print_endpoint(m_multicast_endpoint).c_str());
|
||||||
#endif
|
#endif
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue