BOOL CUploadTransferED2K::ServeRequests() { if ( m_nState != upsUploading && m_nState != upsRequest ) return TRUE; ASSERT( m_pBaseFile != NULL ); if ( m_pClient == NULL || m_pClient->m_pOutput == NULL ) return TRUE; if ( m_pClient->m_pOutput->m_nLength > Settings.eDonkey.FrameSize ) return TRUE; if ( m_nLength == SIZE_UNKNOWN ) { // Check has just finished if ( m_bStopTransfer ) { m_tRotateTime = 0; m_bStopTransfer = FALSE; CUploadQueue* pQueue = m_pQueue; if ( pQueue ) pQueue->Dequeue( this ); pQueue->Enqueue( this, TRUE, FALSE ); int nQpos = UploadQueues.GetPosition( this, TRUE ); if ( nQpos != 0 ) { if ( m_pBaseFile != NULL && m_pClient->IsOnline() ) { Send( CEDPacket::New( ED2K_C2C_FINISHUPLOAD ) ); } if ( nQpos > 0 ) // If we aren't uploading any more (the queue wasn't empty) { // Set state to queued, and reset ranking to send a queue ranking packet. m_tRequest = GetTickCount(); m_nState = upsQueued; m_nRanking = -1; } return TRUE; } } if ( ! OpenFile() ) return FALSE; if ( ! StartNextRequest() ) return FALSE; } if ( m_nLength != SIZE_UNKNOWN ) { if ( DispatchNextChunk() ) { CheckFinishedRequest(); } else { Cleanup(); Close(); return FALSE; } } return TRUE; }
void CUploadsCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) { CSingleLock pLock( &Transfers.m_pSection, TRUE ); CUploadFile* pFile; CUploadQueue* pQueue; CRect rcItem; SetFocus(); if ( HitTest( point, &pQueue, &pFile, NULL, &rcItem ) ) { int nTitleStarts = GetExpandableColumnX(); if ( pQueue != NULL && point.x > nTitleStarts && point.x <= nTitleStarts + rcItem.left + 16 ) { pQueue->m_bExpanded = ! pQueue->m_bExpanded; if ( ! pQueue->m_bExpanded ) { for ( POSITION posActive = pQueue->GetActiveIterator() ; posActive ; ) { CUploadTransfer* pTransfer = pQueue->GetNextActive( posActive ); if ( pTransfer->m_pBaseFile != NULL ) pTransfer->m_pBaseFile->m_bSelected = FALSE; } for ( DWORD nPos = 0 ; nPos < pQueue->GetQueuedCount() ; nPos ++ ) { CUploadTransfer* pTransfer = (CUploadTransfer*)pQueue->GetQueuedAt( nPos ); if ( pTransfer->m_pBaseFile != NULL ) pTransfer->m_pBaseFile->m_bSelected = FALSE; } } Update(); } else if ( pQueue != NULL ) { GetOwner()->PostMessage( WM_TIMER, 5 ); GetOwner()->PostMessage( WM_COMMAND, ID_UPLOADS_EDIT_QUEUE ); } else if ( pFile != NULL ) { GetOwner()->PostMessage( WM_TIMER, 5 ); GetOwner()->PostMessage( WM_COMMAND, ID_UPLOADS_LAUNCH ); } } CWnd::OnLButtonDblClk( nFlags, point ); }
void CLocalSearch::AddHitDC(CDCPacket* pPacket, CSchemaMap& /*pSchemas*/, CLibraryFile* pFile, int /*nIndex*/) { // Active user: // $SR Nick FileName<0x05>FileSize FreeSlots/TotalSlots<0x05>HubName (HubIP:HubPort)| // Passive user: // $SR Nick FileName<0x05>FileSize FreeSlots/TotalSlots<0x05>HubName (HubIP:HubPort)<0x05>User| if ( ! m_pSearch ) return; CUploadQueue* pQueue = UploadQueues.SelectQueue( PROTOCOL_DC, NULL, 0, CUploadQueue::ulqBoth, NULL ); int nTotalSlots = pQueue ? pQueue->m_nMaxTransfers : 0; int nActiveSlots = pQueue ? pQueue->GetActiveCount() : 0; int nFreeSlots = nTotalSlots > nActiveSlots ? ( nTotalSlots - nActiveSlots ) : 0; CString sHubName; if ( pFile->m_oTiger ) // It's TTH search sHubName = _T("TTH:") + pFile->m_oTiger.toString(); else sHubName = m_pSearch->m_sMyHub; CBuffer pAnswer; pAnswer.Add( _P("$SR ") ); pAnswer.Print( m_pSearch->m_sMyNick ); pAnswer.Add( _P(" ") ); pAnswer.Print( pFile->m_sName ); pAnswer.Add( _P("\x05") ); CString strSize; strSize.Format( _T("%I64u %d/%d"), pFile->m_nSize, nFreeSlots, nTotalSlots ); pAnswer.Print( strSize ); pAnswer.Add( _P("\x05") ); pAnswer.Print( sHubName ); pAnswer.Add( _P(" (") ); pAnswer.Print( HostToString( &m_pSearch->m_pMyHub ) ); pAnswer.Add( _P(")") ); if ( ! m_pSearch->m_bUDP ) { pAnswer.Add( _P("\x05") ); pAnswer.Print( m_pSearch->m_sUserNick ); } pAnswer.Add( _P("|") ); pPacket->Write( pAnswer.m_pBuffer, pAnswer.m_nLength ); }
void CUploadsCtrl::OnLButtonDown(UINT nFlags, CPoint point) { CSingleLock pLock( &Transfers.m_pSection, TRUE ); CUploadFile* pFile; CUploadQueue* pQueue; CRect rcItem; int nIndex; SetFocus(); m_wndTip.Hide(); if ( HitTest( point, &pQueue, &pFile, &nIndex, &rcItem ) ) { int nTitleStarts = GetExpandableColumnX(); if ( point.x > nTitleStarts && point.x <= nTitleStarts + rcItem.left + 16 ) { if ( pQueue != NULL ) { pQueue->m_bExpanded = ! pQueue->m_bExpanded; if ( ! pQueue->m_bExpanded ) { for ( POSITION posActive = pQueue->GetActiveIterator() ; posActive ; ) { CUploadTransfer* pTransfer = pQueue->GetNextActive( posActive ); if ( pTransfer->m_pBaseFile != NULL ) pTransfer->m_pBaseFile->m_bSelected = FALSE; } for ( DWORD nPos = 0 ; nPos < pQueue->GetQueuedCount() ; nPos ++ ) { CUploadTransfer* pTransfer = (CUploadTransfer*)pQueue->GetQueuedAt( nPos ); if ( pTransfer->m_pBaseFile != NULL ) pTransfer->m_pBaseFile->m_bSelected = FALSE; } } Update(); } } else { if ( pFile != NULL && pFile->m_bSelected ) { if ( ( nFlags & ( MK_SHIFT | MK_CONTROL | MK_RBUTTON ) ) == 0 ) { m_pDeselect = pFile; } } else if ( nFlags & MK_RBUTTON ) { DeselectAll(); } SelectTo( nIndex ); } } else if ( ( nFlags & ( MK_SHIFT | MK_CONTROL ) ) == 0 ) { DeselectAll(); Update(); } }
void CLocalSearch::CreatePacketG2() { CG2Packet* pPacket = CG2Packet::New( G2_PACKET_HIT, TRUE ); m_pPacket = pPacket; pPacket->WritePacket( "GU", 16 ); GGUID tmp( MyProfile.GUID ); pPacket->Write( &tmp, sizeof(GGUID) ); if ( TRUE /* Network.IsListening() */ ) { pPacket->WritePacket( "NA", 6 ); pPacket->WriteLongLE( Network.m_pHost.sin_addr.S_un.S_addr ); pPacket->WriteShortBE( htons( Network.m_pHost.sin_port ) ); } pPacket->WritePacket( "V", 4 ); pPacket->WriteString( SHAREAZA_VENDOR_A, FALSE ); if ( ! Network.IsStable() || ! Datagrams.IsStable() ) { pPacket->WritePacket( "FW", 0 ); } { CSingleLock pNetLock( &Network.m_pSection ); if ( pNetLock.Lock( 50 ) ) { for ( POSITION pos = Neighbours.GetIterator() ; pos ; ) { CNeighbour* pNeighbour = Neighbours.GetNext( pos ); if ( pNeighbour->m_nNodeType != ntLeaf && pNeighbour->m_nProtocol == PROTOCOL_G2 ) { pPacket->WritePacket( "NH", 6 ); pPacket->WriteLongLE( pNeighbour->m_pHost.sin_addr.S_un.S_addr ); pPacket->WriteShortBE( htons( pNeighbour->m_pHost.sin_port ) ); } } } } if ( ! Uploads.m_bStable ) pPacket->WritePacket( "UNSTA", 0 ); CSingleLock pQueueLock( &UploadQueues.m_pSection ); int nQueue = 1; if ( pQueueLock.Lock() ) { for ( POSITION pos = UploadQueues.GetIterator() ; pos ; nQueue++ ) { CUploadQueue* pQueue = UploadQueues.GetNext( pos ); pPacket->WritePacket( "HG", ( 4 + 7 ) + 2, TRUE ); pPacket->WritePacket( "SS", 7 ); pPacket->WriteShortBE( pQueue->GetQueuedCount() + pQueue->GetTransferCount() ); pPacket->WriteByte( pQueue->GetTransferCount( TRUE ) ); pPacket->WriteLongBE( pQueue->GetPredictedBandwidth() * 8 / 1024 ); pPacket->WriteByte( 0 ); pPacket->WriteByte( nQueue ); } pQueueLock.Unlock(); } CString strNick = MyProfile.GetNick(); if ( strNick.GetLength() > 32 ) strNick = strNick.Left( 32 ); if ( strNick.GetLength() ) { int nNick = pPacket->GetStringLen( strNick ); pPacket->WritePacket( "UPRO", nNick + 6, TRUE ); pPacket->WritePacket( "NICK", nNick ); pPacket->WriteString( strNick, FALSE ); } if ( Settings.Community.ServeProfile ) pPacket->WritePacket( "BUP", 0 ); if ( Settings.Community.ServeFiles ) pPacket->WritePacket( "BH", 0 ); if ( Settings.Community.ChatEnable ) pPacket->WritePacket( "PCH", 0 ); }
void CRemote::PageUploads() { if ( CheckCookie() ) return; m_nTab = tabUploads; CSingleLock pLock( &UploadQueues.m_pSection, FALSE ); if ( ! SafeLock( pLock ) ) return; Prepare(); // Header CString strRandom; strRandom.Format( L"%i", GetRandomNum( 0i32, _I32_MAX ) ); Add( L"random", strRandom ); Output( L"uploadsHeader" ); for ( POSITION posQueue = CUploadsCtrl::GetQueueIterator(); posQueue != NULL; ) { CUploadQueue* pQueue = CUploadsCtrl::GetNextQueue( posQueue ); CString strQueueID; strQueueID.Format( L"%p", pQueue ); if ( GetKey( L"queue_expand" ) == strQueueID ) pQueue->m_bExpanded = TRUE; else if ( GetKey( L"queue_collapse" ) == strQueueID ) pQueue->m_bExpanded = FALSE; POSITION posFile = CUploadsCtrl::GetFileIterator( pQueue ); if ( posFile == NULL ) continue; Prepare(); Add( L"queue_id", strQueueID ); Add( L"queue_caption", pQueue->m_sName ); if ( pQueue->m_bExpanded ) Add( L"queue_expanded", L"true" ); if ( pQueue != UploadQueues.m_pTorrentQueue && pQueue != UploadQueues.m_pHistoryQueue ) { CString str; str.Format( L"%u", pQueue->GetTransferCount() ); Add( L"queue_transfers", str ); str.Format( L"%u", pQueue->GetQueuedCount() ); Add( L"queue_queued", str ); Add( L"queue_bandwidth", Settings.SmartSpeed( pQueue->GetMeasuredSpeed() ) ); } Output( L"uploadsQueueStart" ); if ( pQueue->m_bExpanded ) { while ( posFile != NULL ) { int nPosition; CUploadFile* pFile = CUploadsCtrl::GetNextFile( pQueue, posFile, &nPosition ); if ( pFile == NULL ) continue; CUploadTransfer* pTransfer = pFile->GetActive(); CString strFileID; strFileID.Format( L"%p", pFile ); if ( GetKey( L"drop" ) == strFileID ) { pFile->Remove(); continue; } Add( L"file_id", strFileID ); Add( L"file_filename", pFile->m_sName ); Add( L"file_size", Settings.SmartVolume( pFile->m_nSize ) ); if ( pTransfer != NULL ) { Add( L"file_address", pTransfer->m_sAddress ); Add( L"file_nick", pTransfer->m_sRemoteNick ); Add( L"file_user", pTransfer->m_sAddress + L" - " + pTransfer->m_sRemoteNick ); Add( L"file_agent", pTransfer->m_sUserAgent ); } CString str; if ( pTransfer == NULL || pTransfer->m_nState == upsNull ) { LoadString( str, IDS_STATUS_COMPLETED ); } else if ( pTransfer->m_nProtocol == PROTOCOL_BT ) { CUploadTransferBT* pBT = (CUploadTransferBT*)pTransfer; if ( ! pBT->m_bInterested ) LoadString( str, IDS_STATUS_UNINTERESTED ); else if ( pBT->m_bChoked ) LoadString( str, IDS_STATUS_CHOKED ); else if ( DWORD nSpeed = pTransfer->GetMeasuredSpeed() ) str = Settings.SmartSpeed( nSpeed ); } else if ( nPosition > 0 ) { LoadString( str, IDS_STATUS_Q ); str.Format( L"%s %i", (LPCTSTR)str, nPosition ); } else { if ( DWORD nSpeed = pTransfer->GetMeasuredSpeed() ) str = Settings.SmartSpeed( nSpeed ); else LoadString( str, IDS_STATUS_NEXT ); } Add( L"file_speed", str ); Add( L"file_status", str ); Output( L"uploadsFile" ); Prepare( L"file_" ); } } Output( L"uploadsQueueEnd" ); Prepare( L"queue_" ); } Prepare(); Output( L"uploadsFooter" ); }
BOOL CUploadTransferDC::RequestFile(CLibraryFile* pFile, QWORD nOffset, QWORD nLength) { m_pXML.Clear(); if ( ! RequestComplete( pFile ) ) { ASSERT( FALSE ); return FALSE; } if ( ! UploadQueues.CanUpload( PROTOCOL_DC, pFile, FALSE ) ) { theApp.Message( MSG_ERROR, IDS_UPLOAD_FILENOTFOUND, (LPCTSTR)m_sAddress, (LPCTSTR)m_sName ); m_pClient->SendCommand( FILE_NOT_AVAILABLE ); return TRUE; } m_nOffset = nOffset; if ( m_nOffset >= m_nSize ) m_nLength = SIZE_UNKNOWN; else m_nLength = min( ( ( nLength == SIZE_UNKNOWN ) ? m_nSize : nLength ), m_nSize - m_nOffset ); m_nPosition = 0; if ( m_nLength > m_nSize || m_nOffset + m_nLength > m_nSize ) { theApp.Message( MSG_ERROR, IDS_UPLOAD_BAD_RANGE, (LPCTSTR)m_sAddress, (LPCTSTR)m_sName ); m_pClient->SendCommand( FILE_NOT_AVAILABLE ); return TRUE; } AllocateBaseFile(); if ( m_bStopTransfer ) { m_tRotateTime = 0; m_bStopTransfer = FALSE; CUploadQueue* pQueue = m_pQueue; if ( pQueue ) pQueue->Dequeue( this ); } int nPosition = UploadQueues.GetPosition( this, TRUE ); if ( nPosition < 0 && UploadQueues.Enqueue( this ) ) { nPosition = UploadQueues.GetPosition( this, TRUE ); } if ( nPosition == 0 ) { // Ready to send if ( m_bGet ) return TRUE; // Wait for $Send return SendFile(); } else if ( nPosition > 0 ) { // Queued theApp.Message( MSG_INFO, IDS_UPLOAD_QUEUED, (LPCTSTR)m_sName, (LPCTSTR)m_sAddress, nPosition, m_pQueue->GetQueuedCount(), (LPCTSTR)m_pQueue->m_sName ); CString strQueued; strQueued.Format( UPLOAD_QUEUE, nPosition ); m_pClient->SendCommand( strQueued ); StartSending( upsPreQueue ); m_tRankingCheck = GetTickCount(); return TRUE; } else { // Unable to queue anywhere UploadQueues.Dequeue( this ); ASSERT( m_pQueue == NULL ); theApp.Message( MSG_ERROR, IDS_UPLOAD_BUSY_QUEUE, (LPCTSTR)m_sName, (LPCTSTR)m_sAddress, (LPCTSTR)m_sUserAgent ); m_pClient->SendCommand( UPLOAD_BUSY ); return TRUE; } }
CG2Packet* CLocalSearch::CreatePacketG2() { CG2Packet* pPacket = CG2Packet::New( G2_PACKET_HIT, TRUE ); pPacket->WritePacket( G2_PACKET_NODE_GUID, Hashes::Guid::byteCount ); pPacket->Write( Hashes::Guid( MyProfile.oGUID ) ); pPacket->WritePacket( G2_PACKET_NODE_ADDRESS, 6 ); pPacket->WriteLongLE( Network.m_pHost.sin_addr.s_addr ); pPacket->WriteShortBE( htons( Network.m_pHost.sin_port ) ); pPacket->WritePacket( G2_PACKET_VENDOR, 4 ); pPacket->WriteString( VENDOR_CODE, FALSE ); if ( Network.IsFirewalled() ) { pPacket->WritePacket( G2_PACKET_PEER_FIREWALLED, 0 ); } { CSingleLock pNetLock( &Network.m_pSection ); if ( pNetLock.Lock( 50 ) ) { for ( POSITION pos = Neighbours.GetIterator() ; pos ; ) { CNeighbour* pNeighbour = Neighbours.GetNext( pos ); if ( pNeighbour->m_nNodeType != ntLeaf && pNeighbour->m_nProtocol == PROTOCOL_G2 ) { pPacket->WritePacket( G2_PACKET_NEIGHBOUR_HUB, 6 ); pPacket->WriteLongLE( pNeighbour->m_pHost.sin_addr.s_addr ); pPacket->WriteShortBE( htons( pNeighbour->m_pHost.sin_port ) ); } } } } if ( ! Uploads.m_bStable ) pPacket->WritePacket( G2_PACKET_PEER_UNSTABLE, 0 ); CSingleLock pQueueLock( &UploadQueues.m_pSection ); int nQueue = 1; if ( pQueueLock.Lock() ) { for ( POSITION pos = UploadQueues.GetIterator() ; pos ; nQueue++ ) { CUploadQueue* pQueue = UploadQueues.GetNext( pos ); pPacket->WritePacket( G2_PACKET_HIT_GROUP, ( 4 + 7 ) + 2, TRUE ); pPacket->WritePacket( G2_PACKET_PEER_STATUS, 7 ); pPacket->WriteShortBE( WORD( pQueue->GetQueuedCount() + pQueue->GetTransferCount() ) ); pPacket->WriteByte( BYTE( pQueue->GetTransferCount( TRUE ) ) ); pPacket->WriteLongBE( pQueue->GetPredictedBandwidth() * 8 / 1024 ); pPacket->WriteByte( 0 ); pPacket->WriteByte( BYTE( nQueue ) ); } pQueueLock.Unlock(); } CString strNick = MyProfile.GetNick(); if ( strNick.GetLength() > 32 ) strNick = strNick.Left( 32 ); if ( strNick.GetLength() ) { int nNick = pPacket->GetStringLen( strNick ); pPacket->WritePacket( G2_PACKET_PROFILE, nNick + 6, TRUE ); pPacket->WritePacket( G2_PACKET_NICK, nNick ); pPacket->WriteString( strNick, FALSE ); } if ( Settings.Community.ServeProfile ) pPacket->WritePacket( G2_PACKET_BROWSE_PROFILE, 0 ); if ( Settings.Community.ServeFiles ) pPacket->WritePacket( G2_PACKET_BROWSE_HOST, 0 ); if ( Settings.Community.ChatEnable ) pPacket->WritePacket( G2_PACKET_PEER_CHAT, 0 ); return pPacket; }