MCPcopy Create free account
hub / github.com/amule-project/amule / SendNextUDPPacket

Method SendNextUDPPacket

src/DownloadQueue.cpp:881–969  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

879
880
881bool CDownloadQueue::SendNextUDPPacket()
882{
883 if ( m_filelist.empty() || !theApp->serverconnect->IsUDPSocketAvailable() || !theApp->IsConnectedED2K()) {
884 return false;
885 }
886
887 // Start monitoring the server and the files list
888 if ( !m_queueServers.IsActive() ) {
889 AddObserver( &m_queueFiles );
890
891 theApp->serverlist->AddObserver( &m_queueServers );
892 }
893
894
895 bool packetSent = false;
896 while ( !packetSent ) {
897 // Get max files ids per packet for current server
898 int filesAllowed = GetMaxFilesPerUDPServerPacket();
899
900 if (filesAllowed < 1 || !m_udpserver || IsConnectedServer(m_udpserver)) {
901 // Select the next server to ask, must not be the connected server
902 do {
903 m_udpserver = m_queueServers.GetNext();
904 } while (IsConnectedServer(m_udpserver));
905
906 m_cRequestsSentToServer = 0;
907 filesAllowed = GetMaxFilesPerUDPServerPacket();
908 }
909
910
911 // Check if we have asked all servers, in which case we are done
912 if (m_udpserver == NULL) {
913 DoStopUDPRequests();
914
915 return false;
916 }
917
918 // Memoryfile containing the hash of every file to request
919 // 28bytes allocation because 16b + 4b + 8b is the worse case scenario.
920 CMemFile hashlist( 28 );
921
922 CPartFile* file = m_queueFiles.GetNext();
923
924 while ( file && filesAllowed ) {
925 uint8 status = file->GetStatus();
926
927 if ( ( status == PS_READY || status == PS_EMPTY ) && file->GetSourceCount() < thePrefs::GetMaxSourcePerFileUDP() ) {
928 if (file->IsLargeFile() && !m_udpserver->SupportsLargeFilesUDP()) {
929 AddDebugLogLineN(logDownloadQueue, "UDP Request for sources on a large file ignored: server doesn't support it");
930 } else {
931 ++m_cRequestsSentToServer;
932 hashlist.WriteHash( file->GetFileHash() );
933 // See the notes on TCP packet
934 if ( m_udpserver->GetUDPFlags() & SRV_UDPFLG_EXT_GETSOURCES2 ) {
935 if (file->IsLargeFile()) {
936 wxASSERT(m_udpserver->SupportsLargeFilesUDP());
937 hashlist.WriteUInt32( 0 );
938 hashlist.WriteUInt64( file->GetFileSize() );

Callers

nothing calls this directly

Calls 15

IsConnectedServerFunction · 0.85
IsUDPSocketAvailableMethod · 0.80
IsActiveMethod · 0.80
AddObserverMethod · 0.80
IsLargeFileMethod · 0.80
SupportsLargeFilesUDPMethod · 0.80
GetUDPFlagsMethod · 0.80
WriteUInt32Method · 0.80
WriteUInt64Method · 0.80
emptyMethod · 0.45
IsConnectedED2KMethod · 0.45
GetNextMethod · 0.45

Tested by

no test coverage detected