IBR-DTNSuite
0.8
|
00001 /* 00002 * DTNTPWorker.h 00003 * 00004 * Created on: 05.05.2011 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef DTNTPWORKER_H_ 00009 #define DTNTPWORKER_H_ 00010 00011 #include "core/AbstractWorker.h" 00012 #include "core/EventReceiver.h" 00013 #include "net/DiscoveryServiceProvider.h" 00014 #include "Configuration.h" 00015 00016 namespace dtn 00017 { 00018 namespace daemon 00019 { 00020 class DTNTPWorker : public dtn::core::AbstractWorker, public dtn::core::EventReceiver, public dtn::net::DiscoveryServiceProvider 00021 { 00022 public: 00023 DTNTPWorker(); 00024 virtual ~DTNTPWorker(); 00025 00026 void callbackBundleReceived(const Bundle &b); 00027 void raiseEvent(const dtn::core::Event *evt); 00028 00029 void update(const ibrcommon::vinterface &iface, std::string &name, std::string &data) throw(NoServiceHereException); 00030 00031 class TimeSyncMessage 00032 { 00033 public: 00034 enum MSG_TYPE 00035 { 00036 TIMESYNC_REQUEST = 1, 00037 TIMESYNC_RESPONSE = 2 00038 }; 00039 00040 TimeSyncMessage(); 00041 ~TimeSyncMessage(); 00042 00043 MSG_TYPE type; 00044 00045 timeval origin_timestamp; 00046 float origin_quality; 00047 00048 timeval peer_timestamp; 00049 float peer_quality; 00050 00051 friend std::ostream &operator<<(std::ostream &stream, const DTNTPWorker::TimeSyncMessage &obj); 00052 friend std::istream &operator>>(std::istream &stream, DTNTPWorker::TimeSyncMessage &obj); 00053 }; 00054 00055 private: 00056 static const unsigned int PROTO_VERSION; 00057 00058 void decode(const dtn::core::Node::Attribute &attr, unsigned int &version, size_t ×tamp, float &quality); 00059 00060 // void shared_sync(const TimeSyncMessage &msg); 00061 void sync(const TimeSyncMessage &msg, struct timeval &tv); 00062 00063 const dtn::daemon::Configuration::TimeSync &_conf; 00064 int _qot_current_tic; 00065 double _sigma; 00066 double _epsilon; 00067 float _quality_diff; 00068 00069 TimeSyncMessage _last_sync; 00070 00071 ibrcommon::Mutex _sync_lock; 00072 time_t _sync_age; 00073 00074 ibrcommon::Mutex _blacklist_lock; 00075 std::map<EID, size_t> _sync_blacklist; 00076 }; 00077 } 00078 } 00079 00080 #endif /* DTNTPWORKER_H_ */