IBR-DTNSuite  0.10
BundleStream.cpp
Go to the documentation of this file.
1 /*
2  * BundleStream.cpp
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #include <streaming/BundleStream.h>
24 
25 BundleStream::BundleStream(ibrcommon::socketstream &stream, size_t min_chunk_size, size_t max_chunk_size, const std::string &app, const dtn::data::EID &group, bool wait_seq_zero)
26  : dtn::api::Client(app, group, stream), _stream(stream), _buf(*this, _chunk, min_chunk_size, max_chunk_size, wait_seq_zero), _auto_flush(false)
27 {}
28 
30 
32 {
33  return _buf;
34 }
35 
37 {
38  return _chunk;
39 }
40 
42 {
43  _auto_flush = val;
44  _buf.setRequestAck(val);
45 }
46 
47 void BundleStream::setReceiveTimeout(unsigned int timeout)
48 {
49  _buf.setReceiveTimeout(timeout);
50 }
51 
53 {
54  // check if the received bundle contains an administrative record
56  {
57  // get the payload block of the bundle
59 
60  try {
61  // try to decode as status report
63  report.read(payload);
64 
65  // check if the received report matches a newer bundle
66  if ((_last_delivery_ack.source == dtn::data::EID()) || (report.bundleid > _last_delivery_ack))
67  {
68  // store the received ack
69  _last_delivery_ack = report.bundleid;
70 
71  // flush the buffer
72  _buf.flush();
73  }
74 
75  return;
77  // this is not a status report
78  }
79  return;
80  }
81 
82  // forward received bundles to the BundleStreamBuf
83  _buf.received(b);
84 }