broadcast socket and piece_picker fix

This commit is contained in:
Arvid Norberg 2007-09-15 20:20:07 +00:00
parent 73bb0c05ad
commit 3a11c3bfad
5 changed files with 21 additions and 7 deletions

View File

@ -52,6 +52,7 @@ namespace libtorrent
public:
broadcast_socket(asio::io_service& ios, udp::endpoint const& multicast_endpoint
, receive_handler_t const& handler);
~broadcast_socket() { close(); }
void send(char const* buffer, int size, asio::error_code& ec);
void close();

View File

@ -233,7 +233,7 @@ namespace libtorrent
bool is_finished(piece_block block) const;
// marks this piece-block as queued for downloading
void mark_as_downloading(piece_block block, void* peer
bool mark_as_downloading(piece_block block, void* peer
, piece_state_t s);
void mark_as_writing(piece_block block, void* peer);
void mark_as_finished(piece_block block, void* peer);

View File

@ -60,8 +60,6 @@ namespace libtorrent
{
// ignore the loopback
if (i->endpoint().address() == address_v4((127 << 24) + 1)) continue;
// ignore addresses that are not on a local network
if (!is_local(i->endpoint().address())) continue;
// ignore non-IPv4 addresses
if (i->endpoint().address().is_v4()) break;
}
@ -96,17 +94,24 @@ namespace libtorrent
if (ec) continue;
s->set_option(datagram_socket::reuse_address(true), ec);
if (ec) continue;
s->bind(udp::endpoint(*i, 0), ec);
s->bind(udp::endpoint(*i, multicast_endpoint.port()), ec);
if (ec) continue;
s->set_option(join_group(multicast_endpoint.address()), ec);
if (ec) continue;
s->set_option(outbound_interface(i->to_v4()), ec);
if (ec) continue;
s->set_option(hops(255));
s->set_option(hops(255), ec);
if (ec) continue;
s->set_option(enable_loopback(true), ec);
if (ec) continue;
m_sockets.push_back(socket_entry(s));
socket_entry& se = m_sockets.back();
s->async_receive_from(asio::buffer(se.buffer, sizeof(se.buffer))
, se.remote, bind(&broadcast_socket::on_receive, this, &se, _1, _2));
#ifndef NDEBUG
// std::cerr << "broadcast socket [ if: " << i->to_v4().to_string()
// << " group: " << multicast_endpoint.address() << " ]" << std::endl;
#endif
}
}
@ -117,7 +122,9 @@ namespace libtorrent
{
asio::error_code e;
i->socket->send_to(asio::buffer(buffer, size), m_multicast_endpoint, 0, e);
#ifndef NDEBUG
// std::cerr << " sending on " << i->socket->local_endpoint().address().to_string() << std::endl;
#endif
if (e) ec = e;
}
}

View File

@ -1663,7 +1663,9 @@ namespace libtorrent
state = piece_picker::slow;
}
t->picker().mark_as_downloading(block, peer_info_struct(), state);
if (!t->picker().mark_as_downloading(block, peer_info_struct(), state))
return;
if (t->alerts().should_post(alert::info))
{
t->alerts().post_alert(block_downloading_alert(t->get_handle(),

View File

@ -1555,7 +1555,7 @@ namespace libtorrent
}
void piece_picker::mark_as_downloading(piece_block block
bool piece_picker::mark_as_downloading(piece_block block
, void* peer, piece_state_t state)
{
TORRENT_PIECE_PICKER_INVARIANT_CHECK;
@ -1590,6 +1590,9 @@ namespace libtorrent
= std::find_if(m_downloads.begin(), m_downloads.end(), has_index(block.piece_index));
assert(i != m_downloads.end());
block_info& info = i->info[block.block_index];
if (info.state == block_info::state_writing
|| info.state == block_info::state_finished)
return false;
assert(info.state == block_info::state_none
|| (info.state == block_info::state_requested
&& (info.num_peers > 0)));
@ -1602,6 +1605,7 @@ namespace libtorrent
++info.num_peers;
if (i->state == none) i->state = state;
}
return true;
}
int piece_picker::num_peers(piece_block block) const