1//								-*- C++ -*-
2// This file is part of the aMule Project.
3//
4// Copyright (c) 2004-2011 Angel Vidal ( kry@amule.org )
5// Copyright (c) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org )
6// Copyright (c) 2003-2011 Barry Dunne (http://www.emule-project.net)
7//
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.
11//
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.
16//
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.
21//
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
25//
26
27// Note To Mods //
28/*
29Please do not change anything here and release it..
30There is going to be a new forum created just for the Kademlia side of the client..
31If you feel there is an error or a way to improve something, please
32post it in the forum first and let us look at it.. If it is a real improvement,
33it will be added to the offical client.. Changing something without knowing
34what all it does can cause great harm to the network if released in mass form..
35Any mod that changes anything within the Kademlia side will not be allowed to advertise
36there client on the eMule forum..
37*/
38
39#ifndef __INDEXED_H__
40#define __INDEXED_H__
41
42
43#include "SearchManager.h"
44#include "Entry.h"
45
46class wxArrayString;
47
48
49typedef std::list<Kademlia::CEntry*> CKadEntryPtrList;
50
51struct Source
52{
53	Kademlia::CUInt128 sourceID;
54	CKadEntryPtrList entryList;
55};
56
57typedef std::list<Source*> CKadSourcePtrList;
58typedef std::map<Kademlia::CUInt128,Source*> CSourceKeyMap;
59
60struct KeyHash
61{
62	Kademlia::CUInt128 keyID;
63	CSourceKeyMap m_Source_map;
64};
65
66
67struct SrcHash
68{
69	Kademlia::CUInt128 keyID;
70	CKadSourcePtrList m_Source_map;
71};
72
73struct Load
74{
75	Kademlia::CUInt128 keyID;
76	uint32_t time;
77};
78
79struct SSearchTerm
80{
81	SSearchTerm();
82	~SSearchTerm();
83
84	enum ESearchTermType {
85		AND,
86		OR,
87		NOT,
88		String,
89		MetaTag,
90		OpGreaterEqual,
91		OpLessEqual,
92		OpGreater,
93		OpLess,
94		OpEqual,
95		OpNotEqual
96	} type;
97
98	CTag* tag;
99	wxArrayString* astr;
100
101	SSearchTerm* left;
102	SSearchTerm* right;
103};
104
105typedef std::map<Kademlia::CUInt128,KeyHash*> KeyHashMap;
106typedef std::map<Kademlia::CUInt128,SrcHash*> SrcHashMap;
107typedef std::map<Kademlia::CUInt128,Load*> LoadMap;
108
109////////////////////////////////////////
110namespace Kademlia {
111////////////////////////////////////////
112
113class CKadUDPKey;
114
115class CIndexed
116{
117
118public:
119	CIndexed();
120	~CIndexed();
121
122	bool AddKeyword(const CUInt128& keyWordID, const CUInt128& sourceID, Kademlia::CKeyEntry* entry, uint8_t& load);
123	bool AddSources(const CUInt128& keyWordID, const CUInt128& sourceID, Kademlia::CEntry* entry, uint8_t& load);
124	bool AddNotes(const CUInt128& keyID, const CUInt128& sourceID, Kademlia::CEntry* entry, uint8_t& load);
125	bool AddLoad(const CUInt128& keyID, uint32_t time);
126	size_t GetFileKeyCount() const throw() { return m_Keyword_map.size(); }
127	void SendValidKeywordResult(const CUInt128& keyID, const SSearchTerm* pSearchTerms, uint32_t ip, uint16_t port, bool oldClient, uint16_t startPosition, const CKadUDPKey& senderKey);
128	void SendValidSourceResult(const CUInt128& keyID, uint32_t ip, uint16_t port, uint16_t startPosition, uint64_t fileSize, const CKadUDPKey& senderKey);
129	void SendValidNoteResult(const CUInt128& keyID, uint32_t ip, uint16_t port, uint64_t fileSize, const CKadUDPKey& senderKey);
130	bool SendStoreRequest(const CUInt128& keyID);
131	uint32_t m_totalIndexSource;
132	uint32_t m_totalIndexKeyword;
133	uint32_t m_totalIndexNotes;
134	uint32_t m_totalIndexLoad;
135
136private:
137	time_t m_lastClean;
138	KeyHashMap m_Keyword_map;
139	SrcHashMap m_Sources_map;
140	SrcHashMap m_Notes_map;
141	LoadMap m_Load_map;
142	static wxString m_sfilename;
143	static wxString m_kfilename;
144	static wxString m_loadfilename;
145	void ReadFile();
146	void Clean();
147};
148
149} // End namespace
150
151#endif //__INDEXED_H__
152// File_checked_for_headers
153