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 __ROUTING_BIN__
40 #define __ROUTING_BIN__
43 #include "../../Types.h"
44 #include "../kademlia/Defines.h"
47 ////////////////////////////////////////
49 ////////////////////////////////////////
57 : m_dontDeleteContacts(false)
61 bool AddContact(CContact
*contact
);
62 void SetAlive(CContact
*contact
);
63 void SetTCPPort(uint32_t ip
, uint16_t port
, uint16_t tcpPort
);
64 void RemoveContact(CContact
*contact
, bool noTrackingAdjust
= false) { if (!noTrackingAdjust
) AdjustGlobalTracking(contact
->GetIPAddress(), false); m_entries
.remove(contact
); }
65 CContact
*GetContact(const CUInt128
&id
) const throw();
66 CContact
*GetContact(uint32_t ip
, uint16_t port
, bool tcpPort
) const throw();
67 CContact
*GetOldest() const throw() { return m_entries
.size() ? m_entries
.front() : NULL
; }
69 uint32_t GetSize() const throw() { return m_entries
.size(); }
70 uint32_t GetRemaining() const throw() { return K
- m_entries
.size(); }
71 void GetEntries(ContactList
*result
, bool emptyFirst
= true) const;
72 void GetClosestTo(uint32_t maxType
, const CUInt128
&target
, uint32_t maxRequired
, ContactMap
*result
, bool emptyFirst
= true, bool setInUse
= false) const;
73 bool ChangeContactIPAddress(CContact
*contact
, uint32_t newIP
);
74 void PushToBottom(CContact
*contact
); // puts an existing contact from X to the end of the list
75 CContact
*GetRandomContact(uint32_t maxType
, uint32_t minKadVersion
) const throw();
77 bool m_dontDeleteContacts
;
80 static void AdjustGlobalTracking(uint32_t ip
, bool increase
);
83 ContactList m_entries
;
85 typedef std::map
<uint32_t, uint32_t> GlobalTrackingMap
;
87 static GlobalTrackingMap s_globalContactIPs
;
88 static GlobalTrackingMap s_globalContactSubnets
;
93 #endif // __ROUTING_BIN__
94 // File_checked_for_headers