OverSim
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
KademliaNodeHandle.h
Go to the documentation of this file.
1
//
2
// Copyright (C) 2009 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3
//
4
// This program is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU General Public License
6
// as published by the Free Software Foundation; either version 2
7
// of the License, or (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18
#ifndef __KADEMLIA_NODE_HANDLE_H
19
#define __KADEMLIA_NODE_HANDLE_H
20
21
#include <
NodeHandle.h
>
22
#include <
NodeVector.h
>
23
28
class
KademliaBucketEntry
:
public
ProxNodeHandle
29
{
30
public
:
34
KademliaBucketEntry
()
35
:
ProxNodeHandle
()
36
{
37
staleCount
= 0;
38
pingSent
=
false
;
39
}
40
41
KademliaBucketEntry
(
const
NodeHandle
& handle, simtime_t
prox
= MAXTIME)
42
:
ProxNodeHandle
(handle)
43
{
44
staleCount
= 0;
45
this->
prox
.
proximity
= SIMTIME_DBL(
prox
);
46
this->
prox
.
accuracy
= 1.0;
47
pingSent
=
false
;
48
}
49
50
// TODO
51
inline
simtime_t
getRtt
()
const
{
return
getProx
(); }
//deprecated
52
inline
void
setRtt
(simtime_t rtt) { this->
prox
.
proximity
= SIMTIME_DBL(rtt); this->
prox
.
accuracy
= 1; }
//deprecated
53
54
inline
uint8_t
getStaleCount
()
const
{
return
staleCount
; }
55
56
inline
void
setStaleCount
(uint8_t
staleCount
) { this->staleCount =
staleCount
; }
57
58
inline
void
resetStaleCount
() { this->
setStaleCount
(0); }
59
60
inline
void
incStaleCount
() { this->
staleCount
++; }
61
62
inline
void
setLastSeen
(simtime_t
lastSeen
) { this->lastSeen =
lastSeen
; }
63
64
inline
simtime_t
getLastSeen
() {
return
this->
lastSeen
; }
65
66
inline
void
setPingSent
(
bool
pingSent
) { this->pingSent =
pingSent
; }
67
68
inline
bool
getPingSent
()
const
{
return
pingSent
; };
69
70
private
:
71
72
uint8_t
staleCount
;
73
simtime_t
lastSeen
;
74
bool
pingSent
;
/*< true, if there is a pending pong for this node */
75
76
friend
std::ostream&
operator<<
(std::ostream& os,
77
const
KademliaBucketEntry
& n)
78
{
79
os << (
NodeHandle
)n <<
" "
<< n.
prox
.
proximity
;
80
return
os;
81
};
82
};
83
91
template
<>
struct
KeyExtractor
<
KademliaBucketEntry
>
92
{
93
static
const
OverlayKey
&
key
(
const
KademliaBucketEntry
& entry)
94
{
95
return
entry.
getKey
();
96
};
97
};
98
99
template
<>
struct
ProxExtractor
<
KademliaBucketEntry
>
100
{
101
static
Prox
prox
(
const
KademliaBucketEntry
& entry)
102
{
103
return
entry.
getProx
();
104
};
105
};
106
107
108
class
MarkedNodeHandle
:
public
NodeHandle
109
{
110
public
:
114
MarkedNodeHandle
()
115
:
NodeHandle
()
116
{
117
isAlive
=
false
;
118
}
119
120
MarkedNodeHandle
(
const
NodeHandle
& handle,
bool
isAlive
=
false
)
121
:
NodeHandle
(handle)
122
{
123
this->
isAlive
=
isAlive
;
124
}
125
126
bool
getIsAlive
() {
return
isAlive
; };
127
void
setIsAlive
(
bool
isAlive
) { this->isAlive =
isAlive
; };
128
129
friend
std::ostream&
operator<<
(std::ostream& os,
const
MarkedNodeHandle
& n);
130
protected
:
131
132
bool
isAlive
;
133
};
134
135
typedef
BaseKeySortedVector< MarkedNodeHandle >
MarkedNodeVector
;
136
137
template
<>
138
struct
KeyExtractor
<
MarkedNodeHandle
> {
139
static
const
OverlayKey
&
key
(
const
MarkedNodeHandle
& node)
140
{
141
return
node.
getKey
();
142
};
143
};
144
145
#endif
src
overlay
kademlia
KademliaNodeHandle.h
Generated on Fri Dec 7 2012 13:37:52 for OverSim by
1.8.1.2