libktorrent  2.2.0
delaywindow.h
1 /***************************************************************************
2  * Copyright (C) 2010 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 
22 #ifndef UTP_DELAYWINDOW_H
23 #define UTP_DELAYWINDOW_H
24 
25 #ifndef Q_MOC_RUN
26 #include <boost/circular_buffer.hpp>
27 #endif // Q_MOC_RUN
28 #include <utp/utpprotocol.h>
29 
30 namespace utp
31 {
32  const bt::Uint32 MAX_DELAY = 0xFFFFFFFF;
33 
34  class KTORRENT_EXPORT DelayWindow
35  {
36  public:
37  DelayWindow();
38  virtual ~DelayWindow();
39 
41  bt::Uint32 update(const Header* hdr, bt::TimeStamp receive_time);
42 
43  private:
44  struct DelayEntry
45  {
46  bt::Uint32 timestamp_difference_microseconds;
47  bt::TimeStamp receive_time;
48 
49  DelayEntry() : timestamp_difference_microseconds(0), receive_time(0)
50  {}
51 
52  DelayEntry(bt::Uint32 tdm, bt::TimeStamp rt) : timestamp_difference_microseconds(tdm), receive_time(rt)
53  {}
54 
55  bool operator < (const DelayEntry & e) const
56  {
57  return timestamp_difference_microseconds < e.timestamp_difference_microseconds;
58  }
59  };
60 
61  typedef boost::circular_buffer<DelayEntry>::iterator DelayEntryItr;
62 
63  private:
64  boost::circular_buffer<DelayEntry> delay_window;
65  };
66 
67 }
68 
69 #endif // UTP_DELAYWINDOW_H
utp::DelayWindow
Definition: delaywindow.h:35
utp::DelayWindow::update
bt::Uint32 update(const Header *hdr, bt::TimeStamp receive_time)
Update the window with a new packet, returns the base delay.
utp::Header
Definition: utpprotocol.h:50