| | 205 | } |
| | 206 | |
| | 207 | bool |
| | 208 | DownloadMain::start_initial_seeding() { |
| | 209 | if (!file_list()->is_done()) |
| | 210 | return false; |
| | 211 | |
| | 212 | m_initialSeeding = new InitialSeeding(this); |
| | 213 | return true; |
| | 214 | } |
| | 215 | |
| | 216 | void |
| | 217 | DownloadMain::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(); |