2 // This file is part of the aMule Project.
4 // Copyright (c) 2004-2008 Angel Vidal ( kry@amule.org )
5 // Copyright (c) 2004-2008 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Copyright (c) 2003 Barry Dunne (http://www.emule-project.net)
8 // Any parts of this program derived from the xMule, lMule or eMule project,
9 // or contributed by third-party developers are copyrighted by their
10 // respective authors.
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 Please do not change anything here and release it..
30 There is going to be a new forum created just for the Kademlia side of the client..
31 If you feel there is an error or a way to improve something, please
32 post it in the forum first and let us look at it.. If it is a real improvement,
33 it will be added to the offical client.. Changing something without knowing
34 what all it does can cause great harm to the network if released in mass form..
35 Any mod that changes anything within the Kademlia side will not be allowed to advertise
36 there client on the eMule forum..
39 #ifndef __SEARCHMANAGER_H__
40 #define __SEARCHMANAGER_H__
42 #include "../utils/UInt128.h"
43 #include "../routing/Maps.h"
44 #include "../../Tag.h"
48 ////////////////////////////////////////
50 ////////////////////////////////////////
54 class CKadClientSearcher
;
56 typedef std::list
<wxString
> WordList
;
57 typedef std::map
<CUInt128
, CSearch
*> SearchMap
;
61 friend class CRoutingZone
;
62 friend class CKademlia
;
66 static bool IsSearching(uint32_t searchID
) throw();
67 static void StopSearch(uint32_t searchID
, bool delayDelete
);
68 static void StopAllSearches();
70 // Search for a particular file
71 // Will return unique search id, returns zero if already searching for this file.
72 static CSearch
* PrepareLookup(uint32_t type
, bool start
, const CUInt128
& id
);
74 // Will return unique search id, returns zero if already searching for this keyword.
75 static CSearch
* PrepareFindKeywords(const wxString
& keyword
, uint32_t searchTermsDataSize
, const uint8_t *searchTermsData
, uint32_t searchid
);
77 static bool StartSearch(CSearch
* search
);
79 static void ProcessResponse(const CUInt128
& target
, uint32_t fromIP
, uint16_t fromPort
, ContactList
*results
);
80 static void ProcessResult(const CUInt128
& target
, const CUInt128
& answer
, TagPtrList
*info
);
81 static void ProcessPublishResult(const CUInt128
& target
, const uint8_t load
, const bool loadResponse
);
83 static void GetWords(const wxString
& str
, WordList
*words
);
85 static void UpdateStats() throw();
87 static bool AlreadySearchingFor(const CUInt128
& target
) throw() { return m_searches
.count(target
) > 0; }
89 static const wxChar
* GetInvalidKeywordChars() { return wxT(" ()[]{}<>,._-!?:;\\/"); }
91 static void CancelNodeFWCheckUDPSearch();
92 static bool FindNodeFWCheckUDP();
93 static bool IsFWCheckUDPSearch(const CUInt128
& target
);
94 static void SetNextSearchID(uint32_t nextID
) throw() { m_nextID
= nextID
; }
98 static void FindNode(const CUInt128
& id
, bool complete
);
99 static bool FindNodeSpecial(const CUInt128
& id
, CKadClientSearcher
*requester
);
100 static void CancelNodeSpecial(CKadClientSearcher
*requester
);
102 static void JumpStart();
104 static uint32_t m_nextID
;
105 static SearchMap m_searches
;
110 #endif // __SEARCHMANAGER_H__
111 // File_checked_for_headers