IBR-DTN  1.0.0
DHTNameService.h
Go to the documentation of this file.
1 /*
2  * DHTNameService.h
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Till Lorentzen <lorenzte@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 DHTNAMESERVICE_H_
23 #define DHTNAMESERVICE_H_
24 
25 #define DHT_RESULTS_EXPIRE_TIMEOUT 600
26 #define DHT_PATH_EXPIRE_TIMEOUT 60
27 #define DHT_DISCOVERED_NODE_PRIORITY -10
28 
29 #include "Component.h"
30 #include "Configuration.h"
31 #include "core/Event.h"
32 #include "core/EventReceiver.h"
34 #include "core/NodeEvent.h"
36 
37 #include <ibrdtn/data/EID.h>
38 
39 #include <ibrcommon/thread/Mutex.h>
40 
41 #include <string>
42 #include <list>
43 
44 extern "C" {
45 #include <dtndht/dtndht.h>
46 }
47 
48 namespace dtn {
49 namespace dht {
60  public dtn::core::EventReceiver<dtn::routing::QueueBundleEvent>,
61  public dtn::core::EventReceiver<dtn::core::NodeEvent>,
63 private:
64  // All DHT configured sockets and needed setting are saved this structure
65  struct dtn_dht_context _context;
66  // Receiving buffer for DHT UDP packets
67  unsigned char _buf[4096];
68  // Helping pipe to interrupt the main loop select
69  int _interrupt_pipe[2];
70  // A little extra variable to signal main loop to exit on interrupt pipe
71  bool _exiting;
72  // true if the dht is correctly set up and ready for work
73  bool _initialized;
74  // true, if the dht was ready and I announced myself
75  bool _announced;
76  // A Mutex for the access to the dht lib
77  ibrcommon::Mutex _libmutex;
78  // Number of good and dubious DHT Nodes
79  int _foundNodes;
80  // A list of all lookups done before DHT is stable
81  std::list<dtn::data::EID> cachedLookups;
82  // Timestamp of the last bootstrapping call
83  time_t _bootstrapped;
84  // Configuration for the DHT
85  const daemon::Configuration::DHT& _config;
89  void lookup(const dtn::data::EID &eid);
93  void announce(const dtn::core::Node &n, enum dtn_dht_lookup_type type);
97  void deannounce(const dtn::core::Node &n);
98 
99  bool isNeighbourAnnouncable(const dtn::core::Node &n);
103  bool setNonBlockingInterruptPipe(void);
108  std::string getConvergenceLayerName(
113  void pingNode(const dtn::core::Node &n);
117  std::list<std::string> getAllIPAddresses(const dtn::core::Node &n);
118 
122  void bootstrapping();
123 
127  void bootstrappingFile();
128 
132  void bootstrappingDNS();
133 
137  void bootstrappingIPs();
138 
139 public:
140  DHTNameService();
141  virtual ~DHTNameService();
145  const std::string getName() const;
152  void raiseEvent(const dtn::routing::QueueBundleEvent &evt) throw ();
153  void raiseEvent(const dtn::core::NodeEvent &evt) throw ();
158  void onUpdateBeacon(const ibrcommon::vinterface &iface, DiscoveryBeacon &beacon)
160 
161 
162 protected:
166  void __cancellation() throw ();
171  void componentUp() throw ();
177  void componentRun() throw ();
182  void componentDown() throw ();
183 };
184 }
185 }
186 
187 #endif /* DHTNAMESERVICE_H_ */
void raiseEvent(const dtn::routing::QueueBundleEvent &evt)
const std::string getName() const
void onUpdateBeacon(const ibrcommon::vinterface &iface, DiscoveryBeacon &beacon)