~ubuntu-branches/ubuntu/precise/amule-adunanza/precise

« back to all changes in this revision

Viewing changes to src/PartFile.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-02-18 21:16:23 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100218211623-gptwe60zx1knfkmu
Tags: 2010.1+2.2.6-0ubuntu1
* New upstream release (LP: #524697)
  - Drop manpages_spelling_fixes.diff fixed by upstream
  - Drop cryptopp-reference.diff fixed by upstream
  - Bump Standards-Version no changes required
  - Update install files (amule -> amuleadunanza)
  - debian/rules: amule.xpm -> amuleadunanza.xpm
  - Add README.Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
2
// This file is part of the aMule Project.
3
3
//
4
 
// Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
 
4
// Copyright (c) 2003-2009 aMule Team ( admin@amule.org / http://www.amule.org )
5
5
// Copyright (c) 2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6
6
//
7
7
// Any parts of this program derived from the xMule, lMule or eMule project,
472
472
// ADUNANZA BEGIN
473
473
#if 0                                           
474
474
                                                if(GetLastPublishTimeKadSrc() > (uint32)time(NULL)+KADEMLIAREPUBLISHTIMES) {
 
475
#else
 
476
                                                // if(GetLastPublishTimeKadSrc() > (uint32)time(NULL)+theApp->rm->kadRepublishTimeS) {
 
477
                                                if (GetLastPublishTimeKadSrc() > (uint32)time(NULL)+theApp->get_kadRepublishTimeS()) {
475
478
#endif
476
 
                                                if(GetLastPublishTimeKadSrc() > (uint32)time(NULL)+theApp->rm->kadRepublishTimeS) {
477
479
// ADUNANZA END                                                 
478
480
                                                        //There may be a posibility of an older client that saved a random number here.. This will check for that..
479
481
                                                        SetLastPublishTimeKadSrc(0,0);
1459
1461
        file->WriteUInt16(m_nCompleteSourcesCount);
1460
1462
}
1461
1463
 
 
1464
// ADUNANZA BEGIN
 
1465
// Per ripartitore di Tiger (credo)
 
1466
#if 0
1462
1467
uint32 CPartFile::Process(uint32 reducedownload/*in percent*/,uint8 m_icounter)
 
1468
#else
 
1469
uint32 CPartFile::Process(uint32 reducedownload/*in percent*/, uint32 ADU_ext_reducedownload, uint32 ADU_kadu_reducedownload, uint8 m_icounter, uint32& ADU_ext_datarate, uint32& ADU_kadu_datarate)
 
1470
#endif
 
1471
// ADUNANZA END
1463
1472
{
1464
1473
        uint16 old_trans;
1465
1474
        uint32 dwCurTick = ::GetTickCount();
1478
1487
        old_trans=transferingsrc;
1479
1488
        transferingsrc = 0;
1480
1489
        kBpsDown = 0.0;
 
1490
// ADUNANZA BEGIN
 
1491
        m_ADU_ext_kBpsDown  = 0.0;
 
1492
        m_ADU_kadu_kBpsDown = 0.0;
 
1493
// ADUNANZA END
1481
1494
 
1482
1495
        if (m_icounter < 10) {
1483
1496
                // Update only downloading sources.
1484
1497
// ADUNANZA BEGIN
1485
 
// Ennesima patch Gnucco per Faster-end-game e limite banda download
1486
 
// (parte 1)
 
1498
// Per problema iteratore, incremento past-the-end
1487
1499
#if 0
1488
1500
                CClientPtrList::iterator it = m_downloadingSourcesList.begin();
1489
1501
                for( ; it != m_downloadingSourcesList.end(); ) {
1490
 
#else
1491
 
                // Perform a copy of the list!!!
1492
 
                // This is required to avoid triggering iterator it invalidation
1493
 
                CClientPtrList downloadingClientList( m_downloadingSourcesList.begin(), m_downloadingSourcesList.end() );
1494
 
 
1495
 
                CClientPtrList::iterator it = downloadingClientList.begin();
1496
 
                for( ; it != downloadingClientList.end(); ) {
1497
 
#endif
1498
 
// ADUNANZA END
1499
1502
                        CUpDownClient *cur_src = *it++;
 
1503
#else
 
1504
                CClientPtrList tmp_downloadingSourcesList;
 
1505
                {
 
1506
                        wxMutexLocker lock(m_mutex_downloadingSourcesList);
 
1507
                        tmp_downloadingSourcesList = m_downloadingSourcesList;
 
1508
                }
 
1509
 
 
1510
                for ( CClientPtrList::iterator it = tmp_downloadingSourcesList.begin(); it != tmp_downloadingSourcesList.end(); ++it) {
 
1511
                        CUpDownClient *cur_src = *it;
 
1512
                        if (!cur_src) continue;
 
1513
#endif
 
1514
// ADUNANZA END
1500
1515
                        if(cur_src->GetDownloadState() == DS_DOWNLOADING) {
1501
1516
                                ++transferingsrc;
 
1517
// ADUNANZA BEGIN
 
1518
#if 0
1502
1519
                                kBpsDown += cur_src->SetDownloadLimit(reducedownload);
 
1520
#else
 
1521
                                float clientRate = 0.0f;
 
1522
                                /*
 
1523
                                if ((ADU_kadu_reducedownload == 0) && (ADU_ext_reducedownload == 0)) {
 
1524
                                        // caso probabilmente impossibile
 
1525
                                        clientRate = cur_src->SetDownloadLimit(reducedownload);
 
1526
                                } else*/ 
 
1527
                                if (cur_src->IsAdunanzA()) {
 
1528
                                        clientRate = cur_src->SetDownloadLimit(ADU_kadu_reducedownload);
 
1529
                                        m_ADU_kadu_kBpsDown += clientRate;
 
1530
                                } else {
 
1531
                                        clientRate = cur_src->SetDownloadLimit(ADU_ext_reducedownload);
 
1532
                                        m_ADU_ext_kBpsDown += clientRate;
 
1533
                                }
 
1534
                                kBpsDown += clientRate;
 
1535
#endif
 
1536
// ADUNANZA END
1503
1537
                        }
1504
1538
                }
1505
1539
        } else {
1506
1540
                // Update all sources (including downloading sources)
1507
1541
// ADUNANZA BEGIN
1508
 
// Ennesima patch Gnucco per Faster-end-game e limite banda download
1509
 
// (parte 2)
 
1542
// Per problema iteratore, incremento past-the-end
1510
1543
#if 0
1511
1544
                for ( SourceSet::iterator it = m_SrcList.begin(); it != m_SrcList.end(); ) {
 
1545
                        CUpDownClient* cur_src = *it++;
1512
1546
#else
1513
 
                SourceSet copyOfSrcList( m_SrcList.begin(), m_SrcList.end() );
1514
 
                for ( SourceSet::iterator it = copyOfSrcList.begin(); it != copyOfSrcList.end(); ) {
 
1547
                std::set<CUpDownClient*> clientsToRemove;
 
1548
                SourceSet::iterator it = m_SrcList.begin();
 
1549
                while (1) {
 
1550
                        if (it == m_SrcList.end()) break;
 
1551
                        CUpDownClient* cur_src = *it;
 
1552
                        ++it;
 
1553
 
 
1554
                        if (!cur_src) continue;
1515
1555
#endif
1516
1556
// ADUNANZA END
1517
 
                        CUpDownClient* cur_src = *it++;
 
1557
 
 
1558
// ADUNANZA BEGIN
 
1559
// Distinguo il FILEREASKTIME tra Aduner e Esterni
 
1560
                        uint32 dwFileReaskTime = (cur_src->IsAdunanzA() ? ADU_FILEREASKTIME : FILEREASKTIME); // Mr Hyde ADUFLAGS 20080201
 
1561
// ADUNANZA END
1518
1562
                        switch (cur_src->GetDownloadState()) {
1519
1563
                                case DS_DOWNLOADING: {
1520
1564
                                        ++transferingsrc;
 
1565
// ADUNANZA BEGIN
 
1566
#if 0
1521
1567
                                        kBpsDown += cur_src->SetDownloadLimit(reducedownload);                  
 
1568
#else
 
1569
                                        float clientRate = 0.0f;
 
1570
                                        /*if ((ADU_kadu_reducedownload == 0) && (ADU_ext_reducedownload == 0)) {
 
1571
                                                // caso probabilmente impossibile
 
1572
                                                clientRate = cur_src->SetDownloadLimit(reducedownload);
 
1573
                                        } else*/ if (cur_src->IsAdunanzA()) {
 
1574
                                                clientRate = cur_src->SetDownloadLimit(ADU_kadu_reducedownload);
 
1575
                                                m_ADU_kadu_kBpsDown += clientRate;
 
1576
                                        } else {
 
1577
                                                clientRate = cur_src->SetDownloadLimit(ADU_ext_reducedownload);
 
1578
                                                m_ADU_ext_kBpsDown += clientRate;
 
1579
                                        }
 
1580
                                        kBpsDown += clientRate;
 
1581
#endif
 
1582
// ADUNANZA END
1522
1583
                                        break;
1523
1584
                                }
1524
1585
                                case DS_BANNED: {
1534
1595
                                                // if we can find a better source.
1535
1596
                                                if(     ((dwCurTick - lastpurgetime) > 30000) &&
1536
1597
                                                        (GetSourceCount() >= (thePrefs::GetMaxSourcePerFile()*.8))) {
 
1598
// ADUNANZA BEGIN
 
1599
// Per problema iteratore, incremento past-the-end
 
1600
// La RemoveSource rischia di invalidare gli iteratori di m_SrcList
 
1601
#if 0
1537
1602
                                                        RemoveSource( cur_src );
 
1603
#else
 
1604
                                                        clientsToRemove.insert(cur_src);
 
1605
#endif
 
1606
// ADUNANZA END
1538
1607
                                                        lastpurgetime = dwCurTick;
1539
1608
                                                        break;
1540
1609
                                                }
1550
1619
                                                if(!cur_src->SwapToAnotherFile(false , false, false , NULL)) {
1551
1620
                                                        //however we only delete them if reaching the limit
1552
1621
                                                        if (GetSourceCount() >= (thePrefs::GetMaxSourcePerFile()*.8 )) {
 
1622
// ADUNANZA BEGIN
 
1623
// Per problema iteratore, incremento past-the-end
 
1624
// La RemoveSource rischia di invalidare gli iteratori di m_SrcList
 
1625
#if 0
1553
1626
                                                                RemoveSource(cur_src);
 
1627
#else
 
1628
                                                                clientsToRemove.insert(cur_src);
 
1629
#endif
 
1630
// ADUNANZA END
1554
1631
                                                                lastpurgetime = dwCurTick;
1555
1632
                                                                break; //Johnny-B - nothing more to do here (good eye!)
1556
1633
                                                        }
1561
1638
                                        }
1562
1639
                                        // doubled reasktime for no needed parts - save connections and traffic
1563
1640
                                        if (    !((!cur_src->GetLastAskedTime()) ||
 
1641
// ADUNANZA BEGIN
 
1642
#if 0
1564
1643
                                                 (dwCurTick - cur_src->GetLastAskedTime()) > FILEREASKTIME*2)) {
 
1644
#else
 
1645
#    if !defined(ENABLE_ADUNSLU2)
 
1646
                                                 (dwCurTick - cur_src->GetLastAskedTime()) > dwFileReaskTime *2)) {
 
1647
#    else
 
1648
                                                 (dwFileReaskTime && (dwCurTick - cur_src->GetLastAskedTime()) > dwFileReaskTime *2))) {
 
1649
#    endif
 
1650
#endif
 
1651
// ADUNANZA END
1565
1652
                                                break;
1566
1653
                                        }
1567
1654
                                        // Recheck this client to see if still NNP..
1574
1661
                                        if( cur_src->IsRemoteQueueFull()) {
1575
1662
                                                if(     ((dwCurTick - lastpurgetime) > 60000) &&
1576
1663
                                                        (GetSourceCount() >= (thePrefs::GetMaxSourcePerFile()*.8 )) ) {
 
1664
// ADUNANZA BEGIN
 
1665
// Per problema iteratore, incremento past-the-end
 
1666
// La RemoveSource rischia di invalidare gli iteratori di m_SrcList
 
1667
#if 0
1577
1668
                                                        RemoveSource( cur_src );
 
1669
#else
 
1670
                                                        clientsToRemove.insert(cur_src);
 
1671
#endif
 
1672
// ADUNANZA END
1578
1673
                                                        lastpurgetime = dwCurTick;
1579
1674
                                                        break; //Johnny-B - nothing more to do here (good eye!)
1580
1675
                                                }
1584
1679
                                        // If we are within on min on TCP, do not try..
1585
1680
                                        if (    theApp->IsConnected() &&
1586
1681
                                                (       (!cur_src->GetLastAskedTime()) ||
 
1682
// ADUNANZA BEGIN
 
1683
#if 0
1587
1684
                                                        (dwCurTick - cur_src->GetLastAskedTime()) > FILEREASKTIME-20000)) {
 
1685
#else
 
1686
#    if !defined(ENABLE_ADUNSLU2)
 
1687
                                                        (dwCurTick - cur_src->GetLastAskedTime()) > (dwFileReaskTime-20000))) {
 
1688
#    else
 
1689
                                                        (dwFileReaskTime && ((dwCurTick - cur_src->GetLastAskedTime()) > (dwFileReaskTime-20000))))) {
 
1690
#    endif
 
1691
#endif
 
1692
// ADUNANZA END
1588
1693
                                                cur_src->UDPReaskForDownload();
1589
1694
                                        }
1590
1695
                                        
1602
1707
                                         * gli esterni riceveranno richieste regolarmente, ovvero secondo tempo FILEREASKTIME
1603
1708
                                         */
1604
1709
 
1605
 
                                        uint32 dwFileReaskTime = (cur_src->IsAdunanzA() ? ADU_FILEREASKTIME : FILEREASKTIME); // Mr Hyde ADUFLAGS 20080201
1606
1710
// ADUNANZA END
1607
1711
                                        if (    theApp->IsConnected() &&
1608
1712
                                                (       (!cur_src->GetLastAskedTime()) ||
1609
1713
// ADUNANZA BEGIN
1610
1714
#if 0
1611
1715
                                                        (dwCurTick - cur_src->GetLastAskedTime()) > FILEREASKTIME)) {
1612
 
#endif
 
1716
#else
 
1717
#    if !defined(ENABLE_ADUNSLU2)
1613
1718
                                                        (dwCurTick - cur_src->GetLastAskedTime()) > dwFileReaskTime)) {
 
1719
#    else
 
1720
                                                        (dwFileReaskTime && (dwCurTick - cur_src->GetLastAskedTime()) > dwFileReaskTime))) {
 
1721
#    endif
 
1722
#endif
1614
1723
// ADUNANZA END
1615
1724
                                                if (!cur_src->AskForDownload()) {
1616
1725
                                                        // I left this break here just as a reminder
1622
1731
                                        // Gestisco il client NON ADU
1623
1732
                                                if (    theApp->serverconnect->IsConnected() &&
1624
1733
                                                        (       (!cur_src->GetLastAskedTime()) ||
 
1734
#if !defined(ENABLE_ADUNSLU2)
1625
1735
                                                                (dwCurTick - cur_src->GetLastAskedTime()) > dwFileReaskTime/* test Mr Hyde: FILEREASKTIME*/)) {
 
1736
#else
 
1737
                                                                (dwFileReaskTime && (dwCurTick - cur_src->GetLastAskedTime()) > dwFileReaskTime/* test Mr Hyde: FILEREASKTIME*/))) {
 
1738
#endif
1626
1739
                                                                if (!cur_src->AskForDownload()) {
1627
1740
                                                                        // I left this break here just as a reminder
1628
1741
                                                                        // just in case re rearange things..
1637
1750
                        }
1638
1751
                }
1639
1752
 
 
1753
// ADUNANZA BEGIN
 
1754
// E ora posso eliminare i client in clientsToRemove
 
1755
        std::set<CUpDownClient*>::iterator toremit = clientsToRemove.begin();
 
1756
        for (; toremit != clientsToRemove.end(); ++toremit) RemoveSource(*toremit);
 
1757
        clientsToRemove.clear();
 
1758
// ADUNANZA END
1640
1759
                /* eMule 0.30c implementation, i give it a try (Creteil) BEGIN ... */
1641
1760
                if (IsA4AFAuto() && ((!m_LastNoNeededCheck) || (dwCurTick - m_LastNoNeededCheck > 900000))) {
1642
1761
                        m_LastNoNeededCheck = dwCurTick;
 
1762
// ADUNANZA BEGIN
 
1763
// Per problema iteratori incremento past-the-end
 
1764
#if 0
1643
1765
                        for ( SourceSet::iterator it = m_A4AFsrclist.begin(); it != m_A4AFsrclist.end(); ) {
1644
1766
                                CUpDownClient *cur_source = *it++;
1645
1767
                                uint8 download_state=cur_source->GetDownloadState();
1650
1772
                                        cur_source->SwapToAnotherFile(false, false, false, this);
1651
1773
                                }
1652
1774
                        }
 
1775
#else
 
1776
                        std::set<CUpDownClient*> clientsToSwap;
 
1777
 
 
1778
                        for ( SourceSet::iterator itA4 = m_A4AFsrclist.begin(); itA4 != m_A4AFsrclist.end(); ++itA4) {
 
1779
                                CUpDownClient *cur_source = *itA4;
 
1780
                                if (!cur_source) continue;
 
1781
 
 
1782
                                uint8 download_state=cur_source->GetDownloadState();
 
1783
                                if( download_state != DS_DOWNLOADING
 
1784
                                && cur_source->GetRequestFile() 
 
1785
                                && ((!cur_source->GetRequestFile()->IsA4AFAuto()) || download_state == DS_NONEEDEDPARTS))
 
1786
                                {
 
1787
                                        clientsToSwap.insert(cur_source);
 
1788
                                }
 
1789
                        }
 
1790
                        
 
1791
                        std::set<CUpDownClient*>::iterator toswapit = clientsToSwap.begin();
 
1792
                        for (; toswapit != clientsToSwap.end(); ++toswapit) {
 
1793
                                CUpDownClient *cur_source = *toswapit;
 
1794
                                if (cur_source) {
 
1795
                                        cur_source->SwapToAnotherFile(false, false, false, this);
 
1796
                                } 
 
1797
                        }
 
1798
                        clientsToSwap.clear();
 
1799
#endif
 
1800
// ADUNANZA END
1653
1801
                }
1654
1802
                /* eMule 0.30c implementation, i give it a try (Creteil) END ... */
1655
1803
                
1663
1811
// ADUNANZA BEGIN
1664
1812
#if 0
1665
1813
                if( GetMaxSourcePerFileUDP() > GetSourceCount()){
1666
 
#endif
 
1814
#else
1667
1815
                if( GetMaxSourcePerFileUDP() > GetAduSourceCount()){
 
1816
#endif
1668
1817
// ADUNANZA END
1669
1818
 
1670
1819
                        //Once we can handle lowID users in Kad, we remove the second IsConnected
1671
1820
// ADUNANZA BEGIN
1672
1821
#if 0
1673
1822
                        if (theApp->downloadqueue->DoKademliaFileRequest() && (Kademlia::CKademlia::GetTotalFile() < KADEMLIATOTALFILE) && (dwCurTick > m_LastSearchTimeKad) &&  Kademlia::CKademlia::IsConnected() && theApp->IsConnected() && !IsStopped()){ 
1674
 
#endif
 
1823
#else
1675
1824
                        if (theApp->downloadqueue->DoKademliaFileRequest()
1676
 
                                        && (Kademlia::CKademlia::GetTotalFile() < (uint32) theApp->rm->kadTotalSearchFile)
 
1825
                                        // && (Kademlia::CKademlia::GetTotalFile() < (uint32) theApp->rm->kadTotalSearchFile)
 
1826
                                        && (Kademlia::CKademlia::GetTotalFile() < (uint32) theApp->get_kadTotalSearchFile())
1677
1827
                                        && (dwCurTick > m_LastSearchTimeKad)
1678
1828
                                        &&  Kademlia::CKademlia::IsConnected()
1679
1829
                                        && theApp->IsConnected()
1680
1830
                                        && !IsStopped()){ 
 
1831
#endif
1681
1832
// ADUNANZA END
1682
1833
                                //Kademlia
1683
1834
                                theApp->downloadqueue->SetLastKademliaFileRequest();
1696
1847
// ADUNANZA BEGIN
1697
1848
#if 0
1698
1849
                                        if(m_TotalSearchesKad < 7) {
 
1850
#else
 
1851
                                        // if(m_TotalSearchesKad < theApp->rm->kadReaskIncs) {
 
1852
                                        if (m_TotalSearchesKad < theApp->get_kadReaskIncs()) {
1699
1853
#endif
1700
 
                                        if(m_TotalSearchesKad < theApp->rm->kadReaskIncs) {
1701
1854
// ADUNANZA END
1702
1855
                                                m_TotalSearchesKad++;
1703
1856
                                        }
1704
1857
// ADUNANZA BEGIN
1705
1858
#if 0
1706
1859
                                        m_LastSearchTimeKad = dwCurTick + (KADEMLIAREASKTIME*m_TotalSearchesKad);
 
1860
#else
 
1861
                                        // m_LastSearchTimeKad = dwCurTick + (theApp->rm->kadReaskTime*m_TotalSearchesKad);
 
1862
                                        m_LastSearchTimeKad = dwCurTick + (theApp->get_kadReaskTime()*m_TotalSearchesKad);
1707
1863
#endif
1708
 
                                        m_LastSearchTimeKad = dwCurTick + (theApp->rm->kadReaskTime*m_TotalSearchesKad);
1709
1864
// ADUNANZA END
1710
1865
                                        SetKadFileSearchID(pSearch->GetSearchID());
1711
1866
                                }
1745
1900
                        Notify_ShowUpdateCatTabTitles();
1746
1901
                }                               
1747
1902
        }
1748
 
        
 
1903
 
 
1904
// ADUNANZA BEGIN
 
1905
// Per ripartitore di banda, credo
 
1906
// Riporto anche la parte di datarate per KADU e ESTERNI
 
1907
        ADU_kadu_datarate = (uint32)(m_ADU_kadu_kBpsDown*1024.0); 
 
1908
        ADU_ext_datarate  = (uint32)(m_ADU_ext_kBpsDown*1024.0); 
 
1909
// ADUNANZA END 
1749
1910
        return (uint32)(kBpsDown*1024.0);
1750
1911
}
1751
1912
 
1910
2071
                ArrayOfUInts16 count;   
1911
2072
        
1912
2073
// ADUNANZA BEGIN
1913
 
#if 0
 
2074
// TEST_20090908 BEGIN
 
2075
// Provo a rimettere il count.reserve sempre tolto dalle patch AdunanzA
 
2076
// #if 0
1914
2077
                count.reserve(GetSourceCount());        
1915
 
#endif
 
2078
// #endif
 
2079
// TEST_20090908 END
1916
2080
// ADUNANZA END
1917
2081
        
1918
2082
                for ( SourceSet::iterator it = m_SrcList.begin(); it != m_SrcList.end(); ++it ) {
1919
2083
// ADUNANZA BEGIN
 
2084
// Mod Adu Lupz (SECONDO STIMATORE)
 
2085
// Consideriamo solo i client AdunanzA per effettuare la stima
1920
2086
#if 0
1921
2087
                        if ( !(*it)->GetUpPartStatus().empty() && (*it)->GetUpPartCount() == partcount ) {
1922
 
#endif
 
2088
#else
1923
2089
                        // Mr Hyde ADUFLAGS 20080201
1924
2090
                        if ((*it) && (*it)->IsAdunanzA() && !(*it)->GetUpPartStatus().empty() && (*it)->GetUpPartCount() == partcount ) {
 
2091
#endif
1925
2092
// ADUNANZA END
1926
2093
                                count.push_back((*it)->GetUpCompleteSourcesCount());
1927
2094
                        }
2006
2173
        UpdateDisplayedInfo();
2007
2174
}       
2008
2175
 
2009
 
// Kry - Updated to 0.42e + bugfix
2010
2176
// [Maella -Enhanced Chunk Selection- (based on jicxicmic)]
2011
 
bool CPartFile::GetNextRequestedBlock(CUpDownClient* sender, Requested_Block_Struct** newblocks, uint16* count)
 
2177
bool CPartFile::GetNextRequestedBlock(CUpDownClient* sender, 
 
2178
                                                        std::vector<Requested_Block_Struct*>& toadd, uint16& count)
2012
2179
{
2013
2180
 
2014
2181
        // The purpose of this function is to return a list of blocks (~180KB) to
2059
2226
        //
2060
2227
 
2061
2228
        // Check input parameters
2062
 
        if(count == NULL) {
2063
 
                return false;
2064
 
        }
2065
2229
        if ( sender->GetPartStatus().empty() ) {
2066
2230
                return false;
2067
2231
        }
2071
2235
        
2072
2236
        // Main loop
2073
2237
        uint16 newBlockCount = 0;
2074
 
        while(newBlockCount != *count) {
 
2238
        while(newBlockCount != count) {
2075
2239
                // Create a request block stucture if a chunk has been previously selected
2076
2240
                if(sender->GetLastPartAsked() != 0xffff) {
2077
2241
                        Requested_Block_Struct* pBlock = new Requested_Block_Struct;
2079
2243
                                // Keep a track of all pending requested blocks
2080
2244
                                m_requestedblocks_list.push_back(pBlock);
2081
2245
                                // Update list of blocks to return
2082
 
                                newblocks[newBlockCount++] = pBlock;
 
2246
                                toadd.push_back(pBlock);
 
2247
                                newBlockCount++;
2083
2248
                                // Skip end of loop (=> CPU load)
2084
2249
                                continue;
2085
2250
                        } else {
2267
2432
                }
2268
2433
        }
2269
2434
        // Return the number of the blocks 
2270
 
        *count = newBlockCount;
 
2435
        count = newBlockCount;
2271
2436
        // Return
2272
2437
        return (newBlockCount > 0);
2273
2438
}
2274
2439
// Maella end
2275
 
// Kry EOI
2276
2440
 
2277
2441
 
2278
2442
void  CPartFile::RemoveBlockFromList(uint64 start,uint64 end)
2307
2471
        if (!bIsHashingDone) {
2308
2472
                SetPartFileStatus(PS_COMPLETING);
2309
2473
                kBpsDown = 0.0;
 
2474
// ADUNANZA BEGIN
 
2475
                m_ADU_ext_kBpsDown  = 0.0;
 
2476
                m_ADU_kadu_kBpsDown = 0.0;
 
2477
// ADUNANZA END
 
2478
 
2310
2479
 
2311
2480
                CPath partFile = m_partmetfilename.RemoveExt();
2312
2481
                CThreadScheduler::AddTask(new CHashingTask(GetFilePath(), partFile, this));
2342
2511
 
2343
2512
                SetFilePath(m_fullname.GetPath());
2344
2513
                SetFileName(m_fullname.GetFullName());
 
2514
                m_lastDateChanged = CPath::GetModificationTime(m_fullname);
2345
2515
                
2346
2516
                SetPartFileStatus(PS_COMPLETE);
2347
2517
                m_paused = false;
2566
2736
        
2567
2737
        RemoveAllSources(true);
2568
2738
        kBpsDown = 0.0;
 
2739
// ADUNANZA BEGIN
 
2740
        m_ADU_ext_kBpsDown  = 0.0;
 
2741
        m_ADU_kadu_kBpsDown = 0.0;
 
2742
// ADUNANZA END
 
2743
 
2569
2744
        transferingsrc = 0;
2570
2745
        memset(m_anStates,0,sizeof(m_anStates));
2571
2746
        
2632
2807
        
2633
2808
        
2634
2809
        kBpsDown = 0.0;
 
2810
// ADUNANZA BEGIN
 
2811
        m_ADU_ext_kBpsDown  = 0.0;
 
2812
        m_ADU_kadu_kBpsDown = 0.0;
 
2813
// ADUNANZA END
 
2814
 
2635
2815
        transferingsrc = 0;
2636
2816
        m_anStates[DS_DOWNLOADING] = 0;
2637
2817
 
3440
3620
 
3441
3621
void CPartFile::AddDownloadingSource(CUpDownClient* client)
3442
3622
{
 
3623
// ADUNANZA BEGIN
 
3624
// Per problemi past-the-end iterator
 
3625
        wxMutexLocker lock(m_mutex_downloadingSourcesList);
 
3626
// ADUNANZA END
 
3627
 
3443
3628
        CClientPtrList::iterator it = 
3444
3629
                std::find(m_downloadingSourcesList.begin(), m_downloadingSourcesList.end(), client);
3445
3630
        if (it == m_downloadingSourcesList.end()) {
3450
3635
 
3451
3636
void CPartFile::RemoveDownloadingSource(CUpDownClient* client)
3452
3637
{
 
3638
// ADUNANZA BEGIN
 
3639
// Per problemi past-the-end iterator
 
3640
        wxMutexLocker lock(m_mutex_downloadingSourcesList);
 
3641
// ADUNANZA END
 
3642
 
3453
3643
        CClientPtrList::iterator it = 
3454
3644
                std::find(m_downloadingSourcesList.begin(), m_downloadingSourcesList.end(), client);
3455
3645
        if (it != m_downloadingSourcesList.end()) {
3797
3987
bool CPartFile::AddSource( CUpDownClient* client )
3798
3988
{
3799
3989
// ADUNANZA BEGIN
3800
 
        if (client && client->IsAdunanzA()) // Mr Hyde ADUFLAGS 20080201
3801
 
                m_AduSrcList.insert( client );
 
3990
        if (!client) return false;
3802
3991
// ADUNANZA END
 
3992
 
3803
3993
        if (m_SrcList.insert( client ).second) {
3804
3994
                theStats::AddFoundSource();
3805
3995
                theStats::AddSourceOrigin(client->GetSourceFrom());
 
3996
// ADUNANZA BEGIN
 
3997
                if (client->IsAdunanzA()) {
 
3998
                        m_AduSrcList.insert( client );
 
3999
                }
 
4000
// ADUNANZA END
3806
4001
                return true;
3807
4002
        } else {
3808
4003
                return false;
3813
4008
bool CPartFile::DelSource( CUpDownClient* client )
3814
4009
{
3815
4010
// ADUNANZA BEGIN
3816
 
        m_AduSrcList.erase( client );
 
4011
        if (!client) return false;
3817
4012
// ADUNANZA END
 
4013
 
3818
4014
        if (m_SrcList.erase( client )) {
3819
4015
                theStats::RemoveSourceOrigin(client->GetSourceFrom());
3820
4016
                theStats::RemoveFoundSource();
 
4017
// ADUNANZA BEGIN
 
4018
                m_AduSrcList.erase( client );
 
4019
// ADUNANZA END
3821
4020
                return true;
3822
4021
        } else {
3823
4022
                return false;
3921
4120
3922
4121
        return m_FileRatingList; 
3923
4122
}
 
4123
 
 
4124
void CPartFile::SetCategory(uint8 cat)
 
4125
{
 
4126
        wxASSERT( cat < theApp->glob_prefs->GetCatCount() );
 
4127
        
 
4128
        m_category = cat; 
 
4129
}
3924
4130
#endif // !CLIENT_GUI
3925
4131
 
3926
4132
 
3965
4171
        transferingsrc = 0; // new
3966
4172
        
3967
4173
        kBpsDown = 0.0;
 
4174
// ADUNANZA BEGIN
 
4175
        m_ADU_ext_kBpsDown  = 0.0;
 
4176
        m_ADU_kadu_kBpsDown = 0.0;
 
4177
// ADUNANZA END
 
4178
 
3968
4179
        
3969
4180
        m_CommentUpdated = false;
3970
4181
        m_hashsetneeded = true;
4274
4485
#if 0
4275
4486
        if (temp > MAX_SOURCES_FILE_SOFT) {
4276
4487
                return MAX_SOURCES_FILE_SOFT;
 
4488
#else
 
4489
        if (theApp && (theApp->rm) && (temp > (unsigned int) theApp->rm->m_maxSrc)) {
 
4490
                return theApp->rm->m_maxSrc;
4277
4491
#endif
4278
 
        if (temp > (unsigned int) theApp->rm->maxSrc) {
4279
 
                return theApp->rm->maxSrc;
4280
4492
// ADUNANZA END
4281
4493
        }
4282
4494
        return temp;
4289
4501
#if 0
4290
4502
        if (temp > MAX_SOURCES_FILE_UDP) {
4291
4503
                return MAX_SOURCES_FILE_UDP;
 
4504
#else
 
4505
        if (theApp && (theApp->rm) && (temp > (unsigned int) theApp->rm->m_maxSrcUdp)) {
 
4506
                return theApp->rm->m_maxSrcUdp;
4292
4507
#endif
4293
 
        if (temp > (unsigned int) theApp->rm->maxSrcUdp) {
4294
 
                return theApp->rm->maxSrcUdp;
4295
4508
// ADUNANZA END
4296
4509
        }
4297
4510
        return temp;
4325
4538
        std::list<CUpDownClient*>::const_iterator it = m_downloadingSourcesList.begin();
4326
4539
        for( ; it != m_downloadingSourcesList.end(); ++it) {
4327
4540
*/
4328
 
        for( SourceSet::const_iterator it = m_SrcList.begin(); it != m_SrcList.end(); it++) {
 
4541
        for( SourceSet::const_iterator it = m_SrcList.begin(); it != m_SrcList.end(); ++it) {
4329
4542
                CUpDownClient* cur_src = *it;
4330
4543
 
4331
4544
                if (!cur_src) continue;
4443
4656
 
4444
4657
CUpDownClient* CPartFile::GetSlowerDownloadingClient(uint32 speed, CUpDownClient* caller) {
4445
4658
//      printf("Start slower source calculation\n");
 
4659
// ADUNANZA BEGIN
 
4660
// Per problema incremento past-the-end iterator
 
4661
#if 0
4446
4662
        for( SourceSet::iterator it = m_SrcList.begin(); it != m_SrcList.end(); ) {
4447
4663
                CUpDownClient* cur_src = *it++;
 
4664
#else
 
4665
        for( SourceSet::iterator it = m_SrcList.begin(); it != m_SrcList.end(); ++it) {
 
4666
                CUpDownClient* cur_src = *it;
 
4667
                if (!cur_src) continue;
 
4668
#endif
 
4669
// ADUNANZA END
4448
4670
                if ((cur_src->GetDownloadState() == DS_DOWNLOADING) && (cur_src != caller)) {
4449
4671
                        uint32 factored_bytes_per_second = static_cast<uint32>(
4450
4672
                                (cur_src->GetKBpsDown() * 1024) * DROP_FACTOR);
4452
4674
//                              printf("Selecting source %p to drop: %d < %d\n", cur_src, factored_bytes_per_second, speed);
4453
4675
//                              printf("End slower source calculation\n");
4454
4676
                                return cur_src;
4455
 
                        } /*else {
4456
 
                                printf("Not selecting source %p to drop: %d > %d\n", cur_src, factored_bytes_per_second, speed);
4457
 
                        }*/
 
4677
                        } else {
 
4678
//                              printf("Not selecting source %p to drop: %d > %d\n", cur_src, factored_bytes_per_second, speed);
 
4679
                        }
4458
4680
                }
4459
4681
        }       
4460
4682
//      printf("End slower source calculation\n");