OverSim
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
P2pnsCache.h
Go to the documentation of this file.
1
//
2
// Copyright (C) 2007 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
24
#ifndef __P2PNSCACHE_H_
25
#define __P2PNSCACHE_H_
26
27
#include <set>
28
#include <vector>
29
#include <deque>
30
#include <sstream>
31
32
#include <omnetpp.h>
33
34
#include <
NodeHandle.h
>
35
#include <
InitStages.h
>
36
#include <
BinaryValue.h
>
37
38
struct
P2pnsCacheEntry
39
{
40
BinaryValue
value
;
41
cMessage*
ttlMessage
;
42
friend
std::ostream&
operator<<
(std::ostream& Stream,
43
const
P2pnsCacheEntry
entry);
44
};
45
46
enum
P2pnsConnectionStates
{
47
CONNECTION_PENDING
= 0,
48
CONNECTION_ACTIVE
= 1
49
};
50
51
class
P2pnsIdCacheEntry
52
{
53
public
:
54
P2pnsIdCacheEntry
(
const
OverlayKey
&
key
) :
55
key(key),
state
(
CONNECTION_PENDING
) {};
56
57
public
:
58
OverlayKey
key
;
59
TransportAddress
addr
;
60
P2pnsConnectionStates
state
;
61
simtime_t
lastUsage
;
62
std::deque<BinaryValue>
payloadQueue
;
63
};
64
65
typedef
std::map<OverlayKey, P2pnsIdCacheEntry>
P2pnsIdCache
;
66
75
class
P2pnsCache
:
public
cSimpleModule
76
{
77
public
:
78
virtual
int
numInitStages
()
const
79
{
80
return
MAX_STAGE_APP
;
81
}
82
83
virtual
void
initialize
(
int
stage);
84
virtual
void
handleMessage
(cMessage* msg);
85
91
virtual
uint32_t
getSize
();
92
96
virtual
void
clear
();
97
103
virtual
bool
isEmpty
();
104
105
106
virtual
P2pnsIdCacheEntry
*
getIdCacheEntry
(
const
OverlayKey
& key);
107
108
virtual
P2pnsIdCacheEntry
*
addIdCacheEntry
(
const
OverlayKey
& key,
109
const
BinaryValue
* payload = NULL);
110
111
virtual
void
removeIdCacheEntry
(
const
OverlayKey
& key);
112
119
virtual
const
BinaryValue
&
getData
(
const
BinaryValue
& name);
120
127
virtual
cMessage*
getTtlMessage
(
const
BinaryValue
& name);
128
135
virtual
const
BinaryValue
&
getDataAtPos
(uint32_t pos = 0);
136
144
virtual
void
addData
(
BinaryValue
name,
BinaryValue
value, cMessage* ttlMessage = NULL);
145
151
virtual
void
removeData
(
const
BinaryValue
& name);
152
void
display
();
153
154
protected
:
155
std::map<BinaryValue, P2pnsCacheEntry>
cache
;
156
P2pnsIdCache
idCache
;
161
void
updateDisplayString
();
162
166
void
updateTooltip
();
167
};
168
169
#endif
src
tier2
p2pns
P2pnsCache.h
Generated on Fri Dec 7 2012 13:37:53 for OverSim by
1.8.1.2