uint32_t CKademlia::CalculateKadUsersNew(){ // the idea of calculating the user count with this method is simple: // whenever we do search for any NodeID (except in certain cases were the result is not usable), // we remember the distance of the closest node we found. Because we assume all NodeIDs are distributed // equally, we can calcualte based on this distance how "filled" the possible NodesID room is and by this // calculate how many users there are. Of course this only works if we have enough samples, because // each single sample will be wrong, but the average of them should produce a usable number. To avoid // drifts caused by a a single (or more) really close or really far away hits, we do use median-average instead through // doesnt works well if we have no files to index and nothing to download and the numbers seems to be a bit too low // compared to out other method. So lets stay with the old one for now, but keeps this here as alternative if (m_liStatsEstUsersProbes.GetCount() < 10) return 0; uint32_t nMedian = 0; CList<uint32_t, uint32_t> liMedian; for (POSITION pos1 = m_liStatsEstUsersProbes.GetHeadPosition(); pos1 != NULL; ) { uint32_t nProbe = m_liStatsEstUsersProbes.GetNext(pos1); bool bInserted = false; for (POSITION pos2 = liMedian.GetHeadPosition(); pos2 != NULL; liMedian.GetNext(pos2)){ if (liMedian.GetAt(pos2) > nProbe){ liMedian.InsertBefore(pos2, nProbe); bInserted = true; break; } } if (!bInserted) liMedian.AddTail(nProbe); } // cut away 1/3 of the values - 1/6 of the top and 1/6 of the bottom to avoid spikes having too much influence, build the average of the rest int32_t nCut = liMedian.GetCount() / 6; for (int i = 0; i != nCut; i++){ liMedian.RemoveHead(); liMedian.RemoveTail(); } uint64_t nAverage = 0; for (POSITION pos1 = liMedian.GetHeadPosition(); pos1 != NULL; ) nAverage += liMedian.GetNext(pos1); nMedian = (uint32_t)(nAverage / liMedian.GetCount()); // LowIDModififier // Modify count by assuming 20% of the users are firewalled and can't be a contact for < 0.49b nodes // Modify count by actual statistics of Firewalled ratio for >= 0.49b if we are not firewalled ourself // Modify count by 40% for >= 0.49b if we are firewalled outself (the actual Firewalled count at this date on kad is 35-55%) const float fFirewalledModifyOld = 1.20F; float fFirewalledModifyNew = 0; if (CUDPFirewallTester::IsFirewalledUDP(true)) fFirewalledModifyNew = 1.40F; // we are firewalled and get get the real statistic, assume 40% firewalled >=0.49b nodes else if (GetPrefs()->StatsGetFirewalledRatio(true) > 0) { fFirewalledModifyNew = 1.0F + (CKademlia::GetPrefs()->StatsGetFirewalledRatio(true)); // apply the firewalled ratio to the modify ASSERT( fFirewalledModifyNew > 1.0F && fFirewalledModifyNew < 1.90F ); } float fNewRatio = CKademlia::GetPrefs()->StatsGetKadV8Ratio(); float fFirewalledModifyTotal = 0; if (fNewRatio > 0 && fFirewalledModifyNew > 0) // weigth the old and the new modifier based on how many new contacts we have fFirewalledModifyTotal = (fNewRatio * fFirewalledModifyNew) + ((1 - fNewRatio) * fFirewalledModifyOld); else fFirewalledModifyTotal = fFirewalledModifyOld; ASSERT( fFirewalledModifyTotal > 1.0F && fFirewalledModifyTotal < 1.90F ); return (uint32_t)((float)nMedian*fFirewalledModifyTotal); }
//********************************************************************************* int CBCGPVisualManagerVS2005::CreateAutoHideButtonRegion (CRect rect, DWORD dwAlignment, LPPOINT& points) { switch (dwAlignment & CBRS_ALIGN_ANY) { case CBRS_ALIGN_LEFT: rect.right--; break; case CBRS_ALIGN_TOP: rect.bottom--; break; } CRect rectOrign = rect; DWORD dwAlignmentOrign = dwAlignment; if ((dwAlignment & CBRS_ALIGN_ANY) == CBRS_ALIGN_LEFT || (dwAlignment & CBRS_ALIGN_ANY) == CBRS_ALIGN_RIGHT) { rect = CRect (0, 0, rectOrign.Height (), rectOrign.Width ()); dwAlignment = (dwAlignment == CBRS_ALIGN_LEFT) ? CBRS_ALIGN_TOP : CBRS_ALIGN_BOTTOM; } CList<POINT, POINT> pts; if (!m_bRoundedAutohideButtons) { rect.right--; pts.AddHead (CPoint (rect.left, rect.top)); pts.AddHead (CPoint (rect.left, rect.bottom - 2)); pts.AddHead (CPoint (rect.left + 2, rect.bottom)); pts.AddHead (CPoint (rect.right - 2, rect.bottom)); pts.AddHead (CPoint (rect.right, rect.bottom - 2)); pts.AddHead (CPoint (rect.right, rect.top)); } else { POSITION posLeft = pts.AddHead (CPoint (rect.left, rect.top)); posLeft = pts.InsertAfter (posLeft, CPoint (rect.left, rect.top + 2)); POSITION posRight = pts.AddTail (CPoint (rect.right, rect.top)); posRight = pts.InsertBefore (posRight, CPoint (rect.right, rect.top + 2)); int xLeft = rect.left + 1; int xRight = rect.right - 1; int y = 0; BOOL bIsHorz = (dwAlignmentOrign & CBRS_ALIGN_ANY) == CBRS_ALIGN_LEFT || (dwAlignmentOrign & CBRS_ALIGN_ANY) == CBRS_ALIGN_RIGHT; for (y = rect.top + 2; y < rect.bottom - 4; y += 2) { posLeft = pts.InsertAfter (posLeft, CPoint (xLeft, y)); posLeft = pts.InsertAfter (posLeft, CPoint (xLeft, y + 2)); posRight = pts.InsertBefore (posRight, CPoint (xRight, y)); posRight = pts.InsertBefore (posRight, CPoint (xRight, y + 2)); xLeft++; xRight--; } if ((dwAlignmentOrign & CBRS_ALIGN_ANY) == CBRS_ALIGN_BOTTOM && !bIsHorz) { xLeft--; xRight++; } if (bIsHorz) { xRight++; } for (;y < rect.bottom - 1; y++) { posLeft = pts.InsertAfter (posLeft, CPoint (xLeft, y)); posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 1, y + 1)); posRight = pts.InsertBefore (posRight, CPoint (xRight, y)); posRight = pts.InsertBefore (posRight, CPoint (xRight - 1, y + 1)); if (y == rect.bottom - 2) { posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 1, y + 1)); posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 3, y + 1)); posRight = pts.InsertBefore (posRight, CPoint (xRight, y + 1)); posRight = pts.InsertBefore (posRight, CPoint (xRight - 2, y + 1)); } xLeft++; xRight--; } posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 2, rect.bottom)); posRight = pts.InsertBefore (posRight, CPoint (xRight - 2, rect.bottom)); } points = new POINT [pts.GetCount ()]; int i = 0; for (POSITION pos = pts.GetHeadPosition (); pos != NULL; i++) { points [i] = pts.GetNext (pos); switch (dwAlignmentOrign & CBRS_ALIGN_ANY) { case CBRS_ALIGN_BOTTOM: points [i].y = rect.bottom - (points [i].y - rect.top); break; case CBRS_ALIGN_RIGHT: { int x = rectOrign.right - points [i].y; int y = rectOrign.top + points [i].x; points [i] = CPoint (x, y); } break; case CBRS_ALIGN_LEFT: { int x = rectOrign.left + points [i].y; int y = rectOrign.top + points [i].x; points [i] = CPoint (x, y); } break; } } return (int) pts.GetCount (); }