MCPcopy Create free account
hub / github.com/arvidn/libtorrent / write_request

Method write_request

src/web_peer_connection.cpp:331–533  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

329}
330
331void web_peer_connection::write_request(peer_request const& r)
332{
333 INVARIANT_CHECK;
334
335 std::shared_ptr<torrent> t = associated_torrent().lock();
336 TORRENT_ASSERT(t);
337
338 TORRENT_ASSERT(t->valid_metadata());
339
340 torrent_info const& info = t->torrent_file();
341 peer_request req = r;
342
343 std::string request;
344 request.reserve(400);
345
346 int size = r.length;
347 const int block_size = t->block_size();
348 const int piece_size = info.piece_length();
349 peer_request pr{};
350
351 piece_index_t cur_piece = r.piece;
352 int cur_start = r.start;
353
354 while (size > 0)
355 {
356 pr.piece = cur_piece;
357 pr.start = cur_start;
358 pr.length = std::min(std::min(block_size, size), info.piece_size_for_req(pr.piece) - pr.start);
359 TORRENT_ASSERT(validate_piece_request(pr));
360 m_requests.push_back(pr);
361
362 if (m_web->restart_request == m_requests.front())
363 {
364 TORRENT_ASSERT(int(m_piece.size()) == m_received_in_piece);
365 TORRENT_ASSERT(m_piece.empty());
366 m_piece = std::move(m_web->restart_piece);
367 peer_request const& front = m_requests.front();
368 TORRENT_ASSERT(front.length > int(m_piece.size()));
369
370#ifndef TORRENT_DISABLE_LOGGING
371 peer_log(peer_log_alert::info, "RESTART_DATA",
372 "data: %d req: (%d, %d) size: %d"
373 , int(m_piece.size()), static_cast<int>(front.piece), front.start
374 , front.start + front.length - 1);
375#else
376 TORRENT_UNUSED(front);
377#endif
378
379 req.start += int(m_piece.size());
380 req.length -= int(m_piece.size());
381
382 // just to keep the accounting straight for the upper layer.
383 // it doesn't know we just re-wrote the request
384 incoming_piece_fragment(int(m_piece.size()));
385 m_web->restart_request.piece = piece_index_t(-1);
386
387 TORRENT_ASSERT(int(m_piece.size()) == m_received_in_piece);
388 }

Callers

nothing calls this directly

Calls 15

associated_torrentFunction · 0.85
minFunction · 0.85
escape_file_pathFunction · 0.85
get_contextFunction · 0.85
bindFunction · 0.85
torrent_fileMethod · 0.80
push_backMethod · 0.80
frontMethod · 0.80
num_filesMethod · 0.80
get_intMethod · 0.80
v2Method · 0.80
map_blockMethod · 0.80

Tested by

no test coverage detected