Upstream tarball 20080630
[amule.git] / src / kademlia / routing / Contact.h
blob3b3326a22efb2cf7d783f653e9f2942381a2ff6a
1 // -*- C++ -*-
2 // This file is part of the aMule Project.
3 //
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)
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.
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.
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
27 // Note To Mods //
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 __CONTACT_H__
40 #define __CONTACT_H__
42 #include "../kademlia/Kademlia.h"
43 #include "../utils/KadUDPKey.h"
45 ////////////////////////////////////////
46 namespace Kademlia {
47 ////////////////////////////////////////
49 class CContact
51 public:
52 ~CContact();
53 CContact(const CUInt128 &clientID,
54 uint32_t ip, uint16_t udpPort, uint16_t tcpPort, uint8_t version,
55 const CKadUDPKey& kadKey, bool ipVerified,
56 const CUInt128 &target = CKademlia::GetPrefs()->GetKadID());
58 CContact(const CContact& k1);
60 const CUInt128& GetClientID() const throw() { return m_clientID; }
61 void SetClientID(const CUInt128& clientID) throw() { m_clientID = clientID; m_distance = CKademlia::GetPrefs()->GetKadID() ^ clientID; }
63 const wxString GetClientIDString() const { return m_clientID.ToHexString(); }
65 const CUInt128& GetDistance() const throw() { return m_distance; }
66 const wxString GetDistanceString() const { return m_distance.ToBinaryString(); }
68 uint32_t GetIPAddress() const throw() { return m_ip; }
69 void SetIPAddress(uint32_t ip) throw() { if (m_ip != ip) { SetIPVerified(false); m_ip = ip; } }
71 uint16_t GetTCPPort() const throw() { return m_tcpPort; }
72 void SetTCPPort(uint16_t port) throw() { m_tcpPort = port; }
74 uint16_t GetUDPPort() const throw() { return m_udpPort; }
75 void SetUDPPort(uint16_t port) throw() { m_udpPort = port; }
77 uint8_t GetType() const throw() { return m_type; }
79 void UpdateType() throw();
80 void CheckingType() throw();
82 bool InUse() const throw() { return m_inUse > 0; }
83 void IncUse() throw() { m_inUse++; }
84 void DecUse() throw() { if (m_inUse) m_inUse--; else wxFAIL; }
86 time_t GetCreatedTime() const throw() { return m_created; }
88 void SetExpireTime(time_t value) throw() { m_expires = value; };
89 time_t GetExpireTime() const throw() { return m_expires; }
91 time_t GetLastTypeSet() const throw() { return m_lastTypeSet; }
93 time_t GetLastSeen() const throw();
95 uint8_t GetVersion() const throw() { return m_version; }
96 void SetVersion(uint8_t value) throw() { m_version = value; }
98 bool CheckIfKad2() throw() { return m_checkKad2 ? m_checkKad2 = false, true : false; }
100 const CKadUDPKey& GetUDPKey() const throw() { return m_udpKey; }
101 void SetUDPKey(const CKadUDPKey& key) throw() { m_udpKey = key; }
103 bool IsIPVerified() const throw() { return m_ipVerified; }
104 void SetIPVerified(bool ipVerified) throw() { m_ipVerified = ipVerified; }
106 private:
107 CUInt128 m_clientID;
108 CUInt128 m_distance;
109 uint32_t m_ip;
110 uint16_t m_tcpPort;
111 uint16_t m_udpPort;
112 uint8_t m_type;
113 time_t m_lastTypeSet;
114 time_t m_expires;
115 time_t m_created;
116 uint32_t m_inUse;
117 uint8_t m_version;
118 bool m_checkKad2;
119 bool m_ipVerified;
120 CKadUDPKey m_udpKey;
123 } // End namespace
125 #endif // __CONTACT_H__
126 // File_checked_for_headers