IBR-DTNSuite  0.10
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 3
28 
29 #include "Component.h"
30 #include "Configuration.h"
31 #include "core/Event.h"
32 #include "core/EventReceiver.h"
34 
35 #include <ibrdtn/data/EID.h>
36 
37 #include <ibrcommon/thread/Mutex.h>
38 
39 #include <string>
40 #include <list>
41 
42 extern "C" {
43 #include <dtndht/dtndht.h>
44 }
45 
46 namespace dtn {
47 namespace dht {
60 private:
61  // All DHT configured sockets and needed setting are saved this structure
62  struct dtn_dht_context _context;
63  // Receiving buffer for DHT UDP packets
64  unsigned char _buf[4096];
65  // Helping pipe to interrupt the main loop select
66  int _interrupt_pipe[2];
67  // A little extra variable to signal main loop to exit on interrupt pipe
68  bool _exiting;
69  // true if the dht is correctly set up and ready for work
70  bool _initialized;
71  // true, if the dht was ready and I announced myself
72  bool _announced;
73  // A Mutex for the access to the dht lib
74  ibrcommon::Mutex _libmutex;
75  // Number of good and dubious DHT Nodes
76  int _foundNodes;
77  // A list of all lookups done before DHT is stable
78  std::list<dtn::data::EID> cachedLookups;
79  // Timestamp of the last bootstrapping call
80  time_t _bootstrapped;
81  // Configuration for the DHT
82  const daemon::Configuration::DHT& _config;
86  void lookup(const dtn::data::EID &eid);
90  void announce(const dtn::core::Node &n, enum dtn_dht_lookup_type type);
94  void deannounce(const dtn::core::Node &n);
95 
96  bool isNeighbourAnnouncable(const dtn::core::Node &n);
100  bool setNonBlockingInterruptPipe(void);
105  std::string getConvergenceLayerName(
110  void pingNode(const dtn::core::Node &n);
114  std::list<std::string> getAllIPAddresses(const dtn::core::Node &n);
115 
119  void bootstrapping();
120 
124  void bootstrappingFile();
125 
129  void bootstrappingDNS();
130 
134  void bootstrappingIPs();
135 
136 public:
137  DHTNameService();
138  virtual ~DHTNameService();
142  const std::string getName() const;
149  void raiseEvent(const dtn::core::Event *evt) throw ();
154  void update(const ibrcommon::vinterface &iface, DiscoveryAnnouncement &announcement)
156 
157 
158 protected:
162  void __cancellation() throw ();
167  void componentUp() throw ();
173  void componentRun() throw ();;
178  void componentDown() throw ();
179 };
180 }
181 }
182 
183 #endif /* DHTNAMESERVICE_H_ */