void CEDClients::OnRun() { DWORD tNow = GetTickCount(); // Delay to limit the rate of ed2k packets being sent. // Keep ed2k transfers under 10 KB/s per source if ( tNow < m_tLastRun + Settings.eDonkey.PacketThrottle ) return; CSingleLock oCEDClientsLock( &m_pSection ); if ( ! oCEDClientsLock.Lock( 250 ) ) return; CSingleLock oCTransfersLock( &Transfers.m_pSection ); if ( ! oCTransfersLock.Lock( 250 ) ) return; tNow = GetTickCount(); // Update if ( Settings.eDonkey.ServerWalk && Network.IsConnected() && Settings.eDonkey.Enabled ) RunGlobalStatsRequests( tNow ); for ( CEDClient* pClient = m_pFirst ; pClient ; ) { CEDClient* pNext = pClient->m_pEdNext; pClient->OnRunEx( tNow ); pClient = pNext; } m_tLastRun = tNow; }
void CEDClients::OnRun() { DWORD tNow = GetTickCount(); // Delay to limit the rate of ed2k packets being sent. // keep ed2k transfers under 10 KB/s per source if ( tNow - m_tLastRun < Settings.eDonkey.PacketThrottle ) return; CSingleLock oCTranfersLock( &Transfers.m_pSection ); if ( ! oCTranfersLock.Lock( 250 ) ) return; CSingleLock oCEDClientsLock( &m_pSection ); if ( ! oCEDClientsLock.Lock( 250 ) ) return; for ( CEDClient* pClient = m_pFirst ; pClient ; ) { CEDClient* pNext = pClient->m_pEdNext; pClient->OnRunEx( tNow ); pClient = pNext; } m_tLastRun = tNow; }
bool CEDClients::PushTo(DWORD nClientID, WORD nClientPort) { // Lock this object until we are finished with it CQuickLock oCEDClientsLock( m_pSection ); // Set up connection object CEDClient* pClient = Connect( nClientID, nClientPort, NULL, 0, Hashes::Guid() ); // Set up failed if ( pClient == NULL ) return false; // Signal that this client has requested a callback pClient->m_bCallbackRequested = true; // Log request theApp.Message( MSG_DEBUG, _T("[ED2K] Push request received for %s"), CString( inet_ntoa( pClient->m_pHost.sin_addr ) ) ); // Set up succeeded return true; }
BOOL CHostBrowser::Browse() { CQuickLock oTransfersLock( Transfers.m_pSection ); m_sAddress = inet_ntoa( m_pAddress ); m_sServer = protocolAbbr[ ( ( m_nProtocol == PROTOCOL_ANY ) ? PROTOCOL_NULL : m_nProtocol ) ]; m_pVendor = VendorCache.Lookup( m_sServer ); switch ( m_nProtocol ) { case PROTOCOL_G2: Settings.Gnutella2.Enabled = true; break; case PROTOCOL_G1: Settings.Gnutella1.Enabled = true; break; case PROTOCOL_ED2K: Settings.eDonkey.Enabled = true; break; case PROTOCOL_DC: Settings.DC.Enabled = true; break; //default: } // ED2K Clients have their connection controlled by ED2KClient. // (One connection used for many things) if ( m_nProtocol == PROTOCOL_ED2K ) { // Lock this object until we are finished with it CQuickLock oCEDClientsLock( EDClients.m_pSection ); SOCKADDR_IN* pServer = NULL; // ToDo: Add push connections CEDClient* pClient = EDClients.Connect( m_pAddress.s_addr, m_nPort, ( pServer ? &pServer->sin_addr : NULL ), ( pServer ? pServer->sin_port : 0 ), m_oClientID ); if ( pClient && pClient->m_bConnected ) { // Send browse request if ( CEDPacket* pPacket = CEDPacket::New( ED2K_C2C_ASKSHAREDDIRS ) ) pClient->Send( pPacket ); } else if ( ! pClient || ! pClient->Connect() ) { theApp.Message( MSG_NOTICE, IDS_BROWSE_CANT_CONNECT_TO, (LPCTSTR)m_sAddress ); return FALSE; } } else if ( m_nProtocol == PROTOCOL_DC ) { CEnvyURL oURL; oURL.m_nProtocol = PROTOCOL_DC; oURL.m_nAction = CEnvyURL::uriDownload; oURL.m_pServerAddress = m_pAddress; oURL.m_nServerPort = m_nPort; oURL.m_sLogin = m_sNick; oURL.m_sName.Format( L"Files of %s.xml.bz2", (LPCTSTR)SafeFilename( m_sNick ) ); oURL.m_sURL.Format( L"dchub://%s@%s:%u/files.xml.bz2", (LPCTSTR)URLEncode( m_sNick ), (LPCTSTR)CString( inet_ntoa( m_pAddress ) ), m_nPort ); return ( Downloads.Add( oURL ) != NULL ); } else // G2/Gunetella { if ( IsValid() ) return FALSE; if ( m_bMustPush ) { if ( SendPush( FALSE ) ) { theApp.Message( MSG_INFO, IDS_BROWSE_PUSHED_TO, (LPCTSTR)m_sAddress ); } else { theApp.Message( MSG_NOTICE, IDS_BROWSE_CANT_PUSH_TO, (LPCTSTR)m_sAddress ); return FALSE; } } else { if ( ConnectTo( &m_pAddress, m_nPort ) ) { theApp.Message( MSG_INFO, IDS_BROWSE_CONNECTING_TO, (LPCTSTR)m_sAddress ); } else { theApp.Message( MSG_NOTICE, IDS_BROWSE_CANT_CONNECT_TO, (LPCTSTR)m_sAddress ); return FALSE; } } } m_nState = hbsConnecting; m_nHits = 0; delete m_pProfile; m_pProfile = NULL; // Ensure window text is updated after state has been set to "connecting" m_pNotify->UpdateMessages(); return TRUE; }