2 // This file is part of aMule Project
4 // Copyright (c) 2004-2008 Angel Vidal (Kry) ( kry@amule.org )
5 // Copyright (c) 2004-2008 aMule Project ( http://www.amule-project.net )
6 // Copyright (C)2003 Barry Dunne (http://www.emule-project.net)
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License
10 // as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 // This work is based on the java implementation of the Kademlia protocol.
23 // Kademlia: Peer-to-peer routing based on the XOR metric
24 // Copyright (C) 2002 Petar Maymounkov [petar@post.harvard.edu]
25 // http://kademlia.scs.cs.nyu.edu
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..
41 #include <common/Macros.h>
43 #include "../../Statistics.h"
45 ////////////////////////////////////////
46 using namespace Kademlia
;
47 ////////////////////////////////////////
51 theStats::RemoveKadNode();
54 CContact::CContact(const CUInt128
&clientID
, uint32_t ip
, uint16_t udpPort
, uint16_t tcpPort
, uint8_t version
, const CKadUDPKey
& key
, bool ipVerified
, const CUInt128
&target
)
55 : m_clientID(clientID
),
56 m_distance(target
^ clientID
),
61 m_lastTypeSet(time(NULL
)),
63 m_created(m_lastTypeSet
),
67 m_ipVerified(ipVerified
),
71 theStats::AddKadNode();
74 void CContact::Copy(const CContact
& from
) throw()
76 m_clientID
= from
.m_clientID
;
77 m_distance
= from
.m_distance
;
79 m_tcpPort
= from
.m_tcpPort
;
80 m_udpPort
= from
.m_udpPort
;
81 m_inUse
= from
.m_inUse
;
82 m_lastTypeSet
= from
.m_lastTypeSet
;
83 m_expires
= from
.m_expires
;
84 m_created
= from
.m_created
;
86 m_version
= from
.m_version
;
87 m_checkKad2
= from
.m_checkKad2
;
88 m_ipVerified
= from
.m_ipVerified
;
89 m_udpKey
= from
.m_udpKey
;
92 void CContact::CheckingType() throw()
94 time_t now
= time(NULL
);
96 if(now
- m_lastTypeSet
< 10 || m_type
== 4) {
102 m_expires
= now
+ MIN2S(2);
106 void CContact::UpdateType() throw()
108 time_t now
= time(NULL
);
109 uint32_t hours
= (now
- m_created
) / HR2S(1);
113 m_expires
= now
+ HR2S(1);
117 m_expires
= now
+ MIN2S(90); //HR2S(1.5)
121 m_expires
= now
+ HR2S(2);
125 time_t CContact::GetLastSeen() const throw()
127 // calculating back from expire time, so we don't need an additional field.
128 // might result in wrong values if doing CheckingType() for example, so don't use for important timing stuff
129 if (m_expires
!= 0) {
131 case 2: return m_expires
- HR2S(1);
132 case 1: return m_expires
- MIN2S(90) /*(unsigned)HR2S(1.5)*/;
133 case 0: return m_expires
- HR2S(2);
138 // File_checked_for_headers