IBR-DTNSuite  0.8
daemon/src/net/DHTNameService.h
Go to the documentation of this file.
00001 /*
00002  * DHTNameService.h
00003  *
00004  *  Created on: 21.11.2011
00005  *      Author: Till Lorentzen
00006  */
00007 
00008 #ifndef DHTNAMESERVICE_H_
00009 #define DHTNAMESERVICE_H_
00010 
00011 #define DHT_RESULTS_EXPIRE_TIMEOUT 600
00012 #define DHT_PATH_EXPIRE_TIMEOUT 60
00013 #define DHT_DISCOVERED_NODE_PRIORITY 3
00014 
00015 #include "Component.h"
00016 #include "Configuration.h"
00017 #include "core/Event.h"
00018 #include "net/DiscoveryServiceProvider.h"
00019 
00020 #include <ibrdtn/data/EID.h>
00021 
00022 #include <ibrcommon/thread/Mutex.h>
00023 
00024 #include <string>
00025 #include <list>
00026 
00027 extern "C" {
00028 #include <dtndht/dtndht.h>
00029 }
00030 
00031 namespace dtn {
00032 namespace dht {
00042 class DHTNameService: public dtn::daemon::IndependentComponent,
00043                 public dtn::core::EventReceiver,
00044                 public dtn::net::DiscoveryServiceProvider {
00045 private:
00046         // All DHT configured sockets and needed setting are saved this structure
00047         struct dtn_dht_context _context;
00048         // Receiving buffer for DHT UDP packets
00049         unsigned char _buf[4096];
00050         // Helping pipe to interrupt the main loop select
00051         int _interrupt_pipe[2];
00052         // A little extra variable to signal main loop to exit on interrupt pipe
00053         bool _exiting;
00054         // true if the dht is correctly set up and ready for work
00055         bool _initialized;
00056         // true, if the dht was ready and I announced myself
00057         bool _announced;
00058         // A Mutex for the access to the dht lib
00059         ibrcommon::Mutex _libmutex;
00060         // Number of good and dubious DHT Nodes
00061         int _foundNodes;
00062         // A list of all lookups done before DHT is stable
00063         std::list<dtn::data::EID> cachedLookups;
00064         // Timestamp of the last bootstrapping call
00065         time_t _bootstrapped;
00066         // Configuration for the DHT
00067         const daemon::Configuration::DHT& _config;
00071         void lookup(const dtn::data::EID &eid);
00075         void announce(const dtn::core::Node &n, enum dtn_dht_lookup_type type);
00079         void deannounce(const dtn::core::Node &n);
00080 
00081         bool isNeighbourAnnouncable(const dtn::core::Node &n);
00085         bool setNonBlockingInterruptPipe(void);
00090         std::string getConvergenceLayerName(
00091                         const dtn::daemon::Configuration::NetConfig &net);
00095         void pingNode(const dtn::core::Node &n);
00099         std::list<std::string> getAllIPAddresses(const dtn::core::Node &n);
00100 
00104         void bootstrapping();
00105 
00109         void bootstrappingFile();
00110 
00114         void bootstrappingDNS();
00115 
00119         void bootstrappingIPs();
00120 
00121 public:
00122         DHTNameService();
00123         virtual ~DHTNameService();
00127         const std::string getName() const;
00134         void raiseEvent(const dtn::core::Event *evt);
00139         void update(const ibrcommon::vinterface &iface, std::string &name,
00140                         std::string &data)
00141                         throw (dtn::net::DiscoveryServiceProvider::NoServiceHereException);
00142 
00143 
00144 protected:
00148         void __cancellation();
00153         void componentUp();
00159         void componentRun();
00164         void componentDown();
00165 };
00166 }
00167 }
00168 
00169 #endif /* DHTNAMESERVICE_H_ */