2 // This file is part of aMule Project
4 // Copyright (c) 2004-2008 Angel Vidal ( kry@amule.org )
5 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Copyright (c) 2003-2008 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
),
68 m_receivedHelloPacket(false),
72 theStats::AddKadNode();
75 CContact::CContact(const CContact
& k1
)
78 theStats::AddKadNode();
81 void CContact::CheckingType() throw()
83 time_t now
= time(NULL
);
85 if(now
- m_lastTypeSet
< 10 || m_type
== 4) {
91 m_expires
= now
+ MIN2S(2);
95 void CContact::UpdateType() throw()
97 time_t now
= time(NULL
);
98 uint32_t hours
= (now
- m_created
) / HR2S(1);
102 m_expires
= now
+ HR2S(1);
106 m_expires
= now
+ MIN2S(90); //HR2S(1.5)
110 m_expires
= now
+ HR2S(2);
114 time_t CContact::GetLastSeen() const throw()
116 // calculating back from expire time, so we don't need an additional field.
117 // might result in wrong values if doing CheckingType() for example, so don't use for important timing stuff
118 if (m_expires
!= 0) {
120 case 2: return m_expires
- HR2S(1);
121 case 1: return m_expires
- MIN2S(90) /*(unsigned)HR2S(1.5)*/;
122 case 0: return m_expires
- HR2S(2);
127 // File_checked_for_headers