1459
1461
file->WriteUInt16(m_nCompleteSourcesCount);
1465
// Per ripartitore di Tiger (credo)
1462
1467
uint32 CPartFile::Process(uint32 reducedownload/*in percent*/,uint8 m_icounter)
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)
1464
1473
uint16 old_trans;
1465
1474
uint32 dwCurTick = ::GetTickCount();
1478
1487
old_trans=transferingsrc;
1479
1488
transferingsrc = 0;
1480
1489
kBpsDown = 0.0;
1491
m_ADU_ext_kBpsDown = 0.0;
1492
m_ADU_kadu_kBpsDown = 0.0;
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
1498
// Per problema iteratore, incremento past-the-end
1488
1500
CClientPtrList::iterator it = m_downloadingSourcesList.begin();
1489
1501
for( ; it != m_downloadingSourcesList.end(); ) {
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() );
1495
CClientPtrList::iterator it = downloadingClientList.begin();
1496
for( ; it != downloadingClientList.end(); ) {
1499
1502
CUpDownClient *cur_src = *it++;
1504
CClientPtrList tmp_downloadingSourcesList;
1506
wxMutexLocker lock(m_mutex_downloadingSourcesList);
1507
tmp_downloadingSourcesList = m_downloadingSourcesList;
1510
for ( CClientPtrList::iterator it = tmp_downloadingSourcesList.begin(); it != tmp_downloadingSourcesList.end(); ++it) {
1511
CUpDownClient *cur_src = *it;
1512
if (!cur_src) continue;
1500
1515
if(cur_src->GetDownloadState() == DS_DOWNLOADING) {
1501
1516
++transferingsrc;
1502
1519
kBpsDown += cur_src->SetDownloadLimit(reducedownload);
1521
float clientRate = 0.0f;
1523
if ((ADU_kadu_reducedownload == 0) && (ADU_ext_reducedownload == 0)) {
1524
// caso probabilmente impossibile
1525
clientRate = cur_src->SetDownloadLimit(reducedownload);
1527
if (cur_src->IsAdunanzA()) {
1528
clientRate = cur_src->SetDownloadLimit(ADU_kadu_reducedownload);
1529
m_ADU_kadu_kBpsDown += clientRate;
1531
clientRate = cur_src->SetDownloadLimit(ADU_ext_reducedownload);
1532
m_ADU_ext_kBpsDown += clientRate;
1534
kBpsDown += clientRate;
1506
1540
// Update all sources (including downloading sources)
1507
1541
// ADUNANZA BEGIN
1508
// Ennesima patch Gnucco per Faster-end-game e limite banda download
1542
// Per problema iteratore, incremento past-the-end
1511
1544
for ( SourceSet::iterator it = m_SrcList.begin(); it != m_SrcList.end(); ) {
1545
CUpDownClient* cur_src = *it++;
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();
1550
if (it == m_SrcList.end()) break;
1551
CUpDownClient* cur_src = *it;
1554
if (!cur_src) continue;
1516
1556
// ADUNANZA END
1517
CUpDownClient* cur_src = *it++;
1559
// Distinguo il FILEREASKTIME tra Aduner e Esterni
1560
uint32 dwFileReaskTime = (cur_src->IsAdunanzA() ? ADU_FILEREASKTIME : FILEREASKTIME); // Mr Hyde ADUFLAGS 20080201
1518
1562
switch (cur_src->GetDownloadState()) {
1519
1563
case DS_DOWNLOADING: {
1520
1564
++transferingsrc;
1521
1567
kBpsDown += cur_src->SetDownloadLimit(reducedownload);
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;
1577
clientRate = cur_src->SetDownloadLimit(ADU_ext_reducedownload);
1578
m_ADU_ext_kBpsDown += clientRate;
1580
kBpsDown += clientRate;
1524
1585
case DS_BANNED: {
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 )) {
1623
// Per problema iteratore, incremento past-the-end
1624
// La RemoveSource rischia di invalidare gli iteratori di m_SrcList
1553
1626
RemoveSource(cur_src);
1628
clientsToRemove.insert(cur_src);
1554
1631
lastpurgetime = dwCurTick;
1555
1632
break; //Johnny-B - nothing more to do here (good eye!)
1574
1661
if( cur_src->IsRemoteQueueFull()) {
1575
1662
if( ((dwCurTick - lastpurgetime) > 60000) &&
1576
1663
(GetSourceCount() >= (thePrefs::GetMaxSourcePerFile()*.8 )) ) {
1665
// Per problema iteratore, incremento past-the-end
1666
// La RemoveSource rischia di invalidare gli iteratori di m_SrcList
1577
1668
RemoveSource( cur_src );
1670
clientsToRemove.insert(cur_src);
1578
1673
lastpurgetime = dwCurTick;
1579
1674
break; //Johnny-B - nothing more to do here (good eye!)
1584
1679
// If we are within on min on TCP, do not try..
1585
1680
if ( theApp->IsConnected() &&
1586
1681
( (!cur_src->GetLastAskedTime()) ||
1587
1684
(dwCurTick - cur_src->GetLastAskedTime()) > FILEREASKTIME-20000)) {
1686
# if !defined(ENABLE_ADUNSLU2)
1687
(dwCurTick - cur_src->GetLastAskedTime()) > (dwFileReaskTime-20000))) {
1689
(dwFileReaskTime && ((dwCurTick - cur_src->GetLastAskedTime()) > (dwFileReaskTime-20000))))) {
1588
1693
cur_src->UDPReaskForDownload();
1602
1707
* gli esterni riceveranno richieste regolarmente, ovvero secondo tempo FILEREASKTIME
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
1611
1715
(dwCurTick - cur_src->GetLastAskedTime()) > FILEREASKTIME)) {
1717
# if !defined(ENABLE_ADUNSLU2)
1613
1718
(dwCurTick - cur_src->GetLastAskedTime()) > dwFileReaskTime)) {
1720
(dwFileReaskTime && (dwCurTick - cur_src->GetLastAskedTime()) > dwFileReaskTime))) {
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*/)) {
1737
(dwFileReaskTime && (dwCurTick - cur_src->GetLastAskedTime()) > dwFileReaskTime/* test Mr Hyde: FILEREASKTIME*/))) {
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..
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();
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;
1763
// Per problema iteratori incremento past-the-end
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);
1776
std::set<CUpDownClient*> clientsToSwap;
1778
for ( SourceSet::iterator itA4 = m_A4AFsrclist.begin(); itA4 != m_A4AFsrclist.end(); ++itA4) {
1779
CUpDownClient *cur_source = *itA4;
1780
if (!cur_source) continue;
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))
1787
clientsToSwap.insert(cur_source);
1791
std::set<CUpDownClient*>::iterator toswapit = clientsToSwap.begin();
1792
for (; toswapit != clientsToSwap.end(); ++toswapit) {
1793
CUpDownClient *cur_source = *toswapit;
1795
cur_source->SwapToAnotherFile(false, false, false, this);
1798
clientsToSwap.clear();
1654
1802
/* eMule 0.30c implementation, i give it a try (Creteil) END ... */
1663
1811
// ADUNANZA BEGIN
1665
1813
if( GetMaxSourcePerFileUDP() > GetSourceCount()){
1667
1815
if( GetMaxSourcePerFileUDP() > GetAduSourceCount()){
1668
1817
// ADUNANZA END
1670
1819
//Once we can handle lowID users in Kad, we remove the second IsConnected
1671
1820
// ADUNANZA BEGIN
1673
1822
if (theApp->downloadqueue->DoKademliaFileRequest() && (Kademlia::CKademlia::GetTotalFile() < KADEMLIATOTALFILE) && (dwCurTick > m_LastSearchTimeKad) && Kademlia::CKademlia::IsConnected() && theApp->IsConnected() && !IsStopped()){
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()){
1681
1832
// ADUNANZA END
1683
1834
theApp->downloadqueue->SetLastKademliaFileRequest();
1696
1847
// ADUNANZA BEGIN
1698
1849
if(m_TotalSearchesKad < 7) {
1851
// if(m_TotalSearchesKad < theApp->rm->kadReaskIncs) {
1852
if (m_TotalSearchesKad < theApp->get_kadReaskIncs()) {
1700
if(m_TotalSearchesKad < theApp->rm->kadReaskIncs) {
1701
1854
// ADUNANZA END
1702
1855
m_TotalSearchesKad++;
1704
1857
// ADUNANZA BEGIN
1706
1859
m_LastSearchTimeKad = dwCurTick + (KADEMLIAREASKTIME*m_TotalSearchesKad);
1861
// m_LastSearchTimeKad = dwCurTick + (theApp->rm->kadReaskTime*m_TotalSearchesKad);
1862
m_LastSearchTimeKad = dwCurTick + (theApp->get_kadReaskTime()*m_TotalSearchesKad);
1708
m_LastSearchTimeKad = dwCurTick + (theApp->rm->kadReaskTime*m_TotalSearchesKad);
1709
1864
// ADUNANZA END
1710
1865
SetKadFileSearchID(pSearch->GetSearchID());
1910
2071
ArrayOfUInts16 count;
1912
2073
// ADUNANZA BEGIN
2074
// TEST_20090908 BEGIN
2075
// Provo a rimettere il count.reserve sempre tolto dalle patch AdunanzA
1914
2077
count.reserve(GetSourceCount());
2079
// TEST_20090908 END
1916
2080
// ADUNANZA END
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
1921
2087
if ( !(*it)->GetUpPartStatus().empty() && (*it)->GetUpPartCount() == partcount ) {
1923
2089
// Mr Hyde ADUFLAGS 20080201
1924
2090
if ((*it) && (*it)->IsAdunanzA() && !(*it)->GetUpPartStatus().empty() && (*it)->GetUpPartCount() == partcount ) {
1925
2092
// ADUNANZA END
1926
2093
count.push_back((*it)->GetUpCompleteSourcesCount());
2006
2173
UpdateDisplayedInfo();
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)
2014
2181
// The purpose of this function is to return a list of blocks (~180KB) to
3797
3987
bool CPartFile::AddSource( CUpDownClient* client )
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
3803
3993
if (m_SrcList.insert( client ).second) {
3804
3994
theStats::AddFoundSource();
3805
3995
theStats::AddSourceOrigin(client->GetSourceFrom());
3997
if (client->IsAdunanzA()) {
3998
m_AduSrcList.insert( client );
4444
4657
CUpDownClient* CPartFile::GetSlowerDownloadingClient(uint32 speed, CUpDownClient* caller) {
4445
4658
// printf("Start slower source calculation\n");
4660
// Per problema incremento past-the-end iterator
4446
4662
for( SourceSet::iterator it = m_SrcList.begin(); it != m_SrcList.end(); ) {
4447
4663
CUpDownClient* cur_src = *it++;
4665
for( SourceSet::iterator it = m_SrcList.begin(); it != m_SrcList.end(); ++it) {
4666
CUpDownClient* cur_src = *it;
4667
if (!cur_src) continue;
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;
4456
printf("Not selecting source %p to drop: %d > %d\n", cur_src, factored_bytes_per_second, speed);
4678
// printf("Not selecting source %p to drop: %d > %d\n", cur_src, factored_bytes_per_second, speed);
4460
4682
// printf("End slower source calculation\n");