1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
10 //
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
24 //
25 
26 #ifndef UPLOADQUEUE_H
27 #define UPLOADQUEUE_H
28 
29 #include "ClientRef.h"		// Needed for CClientRefList
30 #include "MD4Hash.h"		// Needed for CMD4Hash
31 
32 // Experimental extended upload queue population
33 //
34 // When a client is set up from scratch (no shares, all downloads empty)
35 // it takes a while after completion of the first downloaded chunks until
36 // uploads start. Problem is, upload queue is empty, because clients that
37 // find nothing to download don't stay queued.
38 //
39 // Set this to 1 for faster finding of upload slots in this case.
40 // aMule will then try to contact its sources for uploading if the
41 // upload queue is empty.
42 #define EXTENDED_UPLOADQUEUE 0
43 
44 class CUpDownClient;
45 class CKnownFile;
46 
47 class CUploadQueue
48 {
49 public:
50 	CUploadQueue();
51 	~CUploadQueue();
52 	void	Process();
53 	void	AddClientToQueue(CUpDownClient* client);
54 	bool	RemoveFromUploadQueue(CUpDownClient* client);
55 	bool	RemoveFromWaitingQueue(CUpDownClient* client);
56 	bool	IsOnUploadQueue(const CUpDownClient* client) const;
57 	bool	IsDownloading(const CUpDownClient* client) const;
58 	bool	CheckForTimeOver(CUpDownClient* client);
ResortQueue()59 	void	ResortQueue() { SortGetBestClient(); }
60 
GetWaitingList()61 	const CClientRefList& GetWaitingList() const { return m_waitinglist; }
GetUploadingList()62 	const CClientRefList& GetUploadingList() const { return m_uploadinglist; }
63 
64 	CUpDownClient* GetWaitingClientByIP_UDP(uint32 dwIP, uint16 nUDPPort, bool bIgnorePortOnUniqueIP, bool* pbMultipleIPs = NULL);
65 
66 	uint16	SuspendUpload(const CMD4Hash &, bool terminate);
67 	void	ResumeUpload(const CMD4Hash &);
GetAllUploadingKnownFile()68 	CKnownFile* GetAllUploadingKnownFile() { return m_allUploadingKnownFile; }
69 
70 private:
71 	void	RemoveFromWaitingQueue(CClientRefList::iterator pos);
72 	uint16	GetMaxSlots() const;
73 	void	AddUpNextClient(CUpDownClient* directadd = 0);
IsSuspended(const CMD4Hash & hash)74 	bool	IsSuspended(const CMD4Hash& hash) { return suspendedUploadsSet.find(hash) != suspendedUploadsSet.end(); }
75 	void	SortGetBestClient(CClientRef * bestClient = NULL);
76 
77 	CClientRefList m_waitinglist;
78 	CClientRefList m_uploadinglist;
79 
80 #if EXTENDED_UPLOADQUEUE
81 	CClientRefList m_possiblyWaitingList;
82 	int		PopulatePossiblyWaitingList();
83 #endif
84 
85 	std::set<CMD4Hash> suspendedUploadsSet;  // set for suspended uploads
86 	uint32	m_nLastStartUpload;
87 	uint32	m_lastSort;
88 	bool	lastupslotHighID; // VQB lowID alternation
89 	bool	m_allowKicking;
90 	// This KnownFile collects all currently uploading clients for display in the upload list control
91 	CKnownFile * m_allUploadingKnownFile;
92 };
93 
94 #endif // UPLOADQUEUE_H
95 // File_checked_for_headers
96