IBR-DTNSuite
0.10
Main Page
Namespaces
Classes
Files
File List
File Members
AcknowledgementSet.cpp
Go to the documentation of this file.
1
/*
2
* AcknowledgementSet.cpp
3
*
4
* Created on: 11.01.2013
5
* Author: morgenro
6
*/
7
8
#include "
routing/prophet/AcknowledgementSet.h
"
9
#include "
core/BundleCore.h
"
10
#include <
ibrdtn/utils/Clock.h
>
11
12
namespace
dtn
13
{
14
namespace
routing
15
{
16
const
dtn::data::Number
AcknowledgementSet::identifier
=
NodeHandshakeItem::PROPHET_ACKNOWLEDGEMENT_SET
;
17
18
AcknowledgementSet::AcknowledgementSet
()
19
{
20
}
21
22
AcknowledgementSet::AcknowledgementSet
(
const
AcknowledgementSet
&other)
23
: ibrcommon::Mutex(), _bundles(other._bundles)
24
{
25
}
26
27
void
AcknowledgementSet::add
(
const
dtn::data::MetaBundle
&bundle)
throw
()
28
{
29
try
{
30
// check if the bundle is valid
31
dtn::core::BundleCore::getInstance
().
validate
(bundle);
32
33
// add the bundle to the set
34
_bundles.add(bundle);
35
}
catch
(
dtn::data::Validator::RejectedException
&ex) {
36
// bundle rejected
37
}
38
}
39
40
void
AcknowledgementSet::expire
(
const
dtn::data::Timestamp
×tamp)
throw
()
41
{
42
_bundles.expire(timestamp);
43
}
44
45
void
AcknowledgementSet::merge
(
const
AcknowledgementSet
&other)
throw
()
46
{
47
for
(
dtn::data::BundleList::const_iterator
it = other._bundles.begin(); it != other._bundles.end(); ++it)
48
{
49
const
dtn::data::MetaBundle
&ack = (*it);
50
this->add(ack);
51
}
52
}
53
54
bool
AcknowledgementSet::has
(
const
dtn::data::BundleID
&
id
)
const
throw
()
55
{
56
dtn::data::BundleList::const_iterator
iter = _bundles.find(
dtn::data::MetaBundle::mockUp
(
id
));
57
return
!(iter == _bundles.end());
58
}
59
60
const
dtn::data::Number
&
AcknowledgementSet::getIdentifier
()
const
61
{
62
return
identifier
;
63
}
64
65
dtn::data::Length
AcknowledgementSet::getLength
()
const
66
{
67
std::stringstream ss;
68
serialize
(ss);
69
return
ss.str().length();
70
}
71
72
std::ostream&
AcknowledgementSet::serialize
(std::ostream& stream)
const
73
{
74
stream << (*this);
75
return
stream;
76
}
77
78
std::istream&
AcknowledgementSet::deserialize
(std::istream& stream)
79
{
80
stream >> (*this);
81
return
stream;
82
}
83
84
std::ostream&
operator<<
(std::ostream& stream,
const
AcknowledgementSet
& ack_set)
85
{
86
dtn::data::Number
ackset_size(ack_set._bundles.
size
());
87
ackset_size.
encode
(stream);
88
for
(
dtn::data::BundleList::const_iterator
it = ack_set._bundles.
begin
(); it != ack_set._bundles.
end
(); ++it)
89
{
90
const
dtn::data::MetaBundle
&ack = (*it);
91
stream << (
const
dtn::data::BundleID
&)ack;
92
ack.
expiretime
.
encode
(stream);
93
}
94
95
return
stream;
96
}
97
98
std::istream&
operator>>
(std::istream &stream,
AcknowledgementSet
&ack_set)
99
{
100
// clear the ack set first
101
ack_set._bundles.
clear
();
102
103
dtn::data::Number
size;
104
size.
decode
(stream);
105
106
for
(
size_t
i = 0; size > i; ++i)
107
{
108
dtn::data::MetaBundle
ack;
109
stream >> (
dtn::data::BundleID
&)ack;
110
ack.
expiretime
.
decode
(stream);
111
ack.
lifetime
=
dtn::utils::Clock::getLifetime
(ack, ack.
expiretime
);
112
113
ack_set.
add
(ack);
114
}
115
return
stream;
116
}
117
}
/* namespace routing */
118
}
/* namespace dtn */
daemon
src
routing
prophet
AcknowledgementSet.cpp
Generated on Mon Jul 22 2013 15:16:00 for IBR-DTNSuite by
1.8.3.1