IBR-DTNSuite  0.10
DTNTPWorker.h
Go to the documentation of this file.
1 /*
2  * DTNTPWorker.h
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 #ifndef DTNTPWORKER_H_
23 #define DTNTPWORKER_H_
24 
25 #include "core/AbstractWorker.h"
26 #include "core/EventReceiver.h"
28 #include "Configuration.h"
29 
30 namespace dtn
31 {
32  namespace daemon
33  {
35  {
36  public:
40  DTNTPWorker();
41 
45  virtual ~DTNTPWorker();
46 
51  void callbackBundleReceived(const Bundle &b);
52 
57  void raiseEvent(const dtn::core::Event *evt) throw ();
58 
65  void update(const ibrcommon::vinterface &iface, DiscoveryAnnouncement &announcement)
67 
68 // /**
69 // * Determine the current local clock rating
70 // * @return The rating as double value.
71 // */
72 // double getClockRating() const;
73 
81  {
82  public:
83  enum MSG_TYPE
84  {
87  };
88 
91 
93 
95  double origin_rating;
96 
97  timeval peer_timestamp;
98  double peer_rating;
99 
100  friend std::ostream &operator<<(std::ostream &stream, const DTNTPWorker::TimeSyncMessage &obj);
101  friend std::istream &operator>>(std::istream &stream, DTNTPWorker::TimeSyncMessage &obj);
102  };
103 
104  private:
105  static const unsigned int PROTO_VERSION;
106  static const std::string TAG;
107 
112  bool shouldSyncWith(const dtn::core::Node &node) const;
113 
118  void syncWith(const dtn::core::Node &node);
119 
124  bool hasReference() const;
125 
133  void decode(const dtn::core::Node::Attribute &attr, unsigned int &version, dtn::data::Timestamp &timestamp, float &quality) const;
134 
140  void sync(const TimeSyncMessage &msg, const struct timeval &tv, const struct timeval &local, const struct timeval &remote);
141 
142  // sync threshold
143  float _sync_threshold;
144 
145  // send discovery announcements with the local clock rating
146  bool _announce_rating;
147 
148  // the base rating used to determine the current clock rating
149  double _base_rating;
150 
151  // the local rating is at least decremented by this value between each synchronization
152  double _psi;
153 
154  // current value for sigma
155  double _sigma;
156 
157  // synchronize with other nodes
158  bool _sync;
159 
160  // timestamp of the last synchronization with another (better) clock
161  timeval _last_sync_time;
162 
163  // Mutex to lock the synchronization process
164  ibrcommon::Mutex _sync_lock;
165 
166  // manage a list of recently sync'd nodes
167  ibrcommon::Mutex _blacklist_lock;
168  typedef std::map<EID, dtn::data::Timestamp> blacklist_map;
169  blacklist_map _sync_blacklist;
170  };
171  }
172 }
173 
174 #endif /* DTNTPWORKER_H_ */