Show
Ignore:
Timestamp:
05/05/08 15:16:26 (4 years ago)
Author:
rakshasa
Message:

* Initial seeding support added. Patch by Josef Drexler.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/libtorrent/src/download/download_main.cc

    r1032 r1058  
    4343#include "protocol/extensions.h" 
    4444#include "protocol/handshake_manager.h" 
     45#include "protocol/initial_seed.h" 
    4546#include "protocol/peer_connection_base.h" 
     47#include "protocol/peer_factory.h" 
    4648#include "tracker/tracker_manager.h" 
     49#include "torrent/download.h" 
    4750#include "torrent/exceptions.h" 
    4851#include "torrent/data/file_list.h" 
     
    5760#include "download_info.h" 
    5861#include "download_main.h" 
     62#include "download_manager.h" 
     63#include "download_wrapper.h" 
    5964 
    6065namespace torrent { 
     
    6873  m_chunkStatistics(new ChunkStatistics), 
    6974 
     75  m_initialSeeding(NULL), 
    7076  m_uploadThrottle(NULL), 
    7177  m_downloadThrottle(NULL) { 
     
    192198 
    193199  m_slotStopHandshakes(this); 
    194  
    195200  connection_list()->erase_remaining(connection_list()->begin(), ConnectionList::disconnect_available); 
    196201 
     202  delete m_initialSeeding; 
     203 
    197204  priority_queue_erase(&taskScheduler, &m_taskTrackerRequest); 
     205} 
     206 
     207bool 
     208DownloadMain::start_initial_seeding() { 
     209  if (!file_list()->is_done()) 
     210    return false; 
     211 
     212  m_initialSeeding = new InitialSeeding(this); 
     213  return true; 
     214} 
     215 
     216void 
     217DownloadMain::initial_seeding_done(PeerConnectionBase* pcb) { 
     218  if (m_initialSeeding == NULL) 
     219    throw internal_error("DownloadMain::initial_seeding_done called when not initial seeding."); 
     220 
     221  // Close all connections but the currently active one (pcb). 
     222  // That one will be closed by throw close_connection() later. 
     223  if (m_connectionList->size() > 1) { 
     224    ConnectionList::iterator itr = std::find(m_connectionList->begin(), m_connectionList->end(), pcb); 
     225    if (itr == m_connectionList->end()) 
     226      throw internal_error("DownloadMain::initial_seeding_done could not find current connection."); 
     227 
     228    std::iter_swap(m_connectionList->begin(), itr); 
     229    m_connectionList->erase_remaining(m_connectionList->begin() + 1, ConnectionList::disconnect_available); 
     230  } 
     231 
     232  // Switch to normal seeding. 
     233  DownloadManager::iterator itr = manager->download_manager()->find(m_info); 
     234  (*itr)->set_connection_type(Download::CONNECTION_SEED); 
     235  m_connectionList->slot_new_connection(&createPeerConnectionSeed); 
     236  delete m_initialSeeding; 
     237  m_initialSeeding = NULL; 
     238 
     239  // And close the current connection. 
     240  throw close_connection(); 
    198241} 
    199242