IBR-DTNSuite  0.10
Node.h
Go to the documentation of this file.
1 /*
2  * Node.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 IBRDTN_DAEMON_NODE_H_
23 #define IBRDTN_DAEMON_NODE_H_
24 
25 #include <string>
26 #include <ibrdtn/data/EID.h>
27 #include <set>
28 #include <list>
29 #include <iostream>
30 
31 namespace dtn
32 {
33  namespace net
34  {
35  class ConvergenceLayer;
36  }
37 
38  namespace core
39  {
43  class Node
44  {
45  public:
46  enum Protocol
47  {
54  CONN_HTTP = 5,
55  CONN_FILE = 6,
61  };
62 
69  enum Type
70  {
78  };
79 
80  class URI
81  {
82  public:
83  URI(const Type t, const Protocol proto, const std::string &uri, const dtn::data::Number &timeout = 0, const int priority = 0);
84  ~URI();
85 
86  const Type type;
88  const std::string value;
90  const int priority;
91 
92  void decode(std::string &address, unsigned int &port) const;
93 
94  bool operator<(const URI &other) const;
95  bool operator==(const URI &other) const;
96 
97  bool operator==(const Node::Protocol &p) const;
98  bool operator==(const Node::Type &t) const;
99 
100  friend std::ostream& operator<<(std::ostream&, const Node::URI&);
101  };
102 
103  class Attribute
104  {
105  public:
106  Attribute(const Type t, const std::string &name, const std::string &value, const dtn::data::Number &timeout = 0, const int priority = 0);
107  ~Attribute();
108 
109  const Type type;
110  const std::string name;
111  const std::string value;
113  const int priority;
114 
115  bool operator<(const Attribute &other) const;
116  bool operator==(const Attribute &other) const;
117 
118  bool operator==(const std::string &name) const;
119 
120  friend std::ostream& operator<<(std::ostream&, const Node::Attribute&);
121  };
122 
123  static std::string toString(const Node::Type type);
124  static std::string toString(const Node::Protocol proto);
125  static Node::Protocol fromProtocolString(const std::string &protocol);
126 
132  Node(const dtn::data::EID &id);
133  Node();
134 
138  virtual ~Node();
139 
145  bool has(Node::Protocol proto) const;
146  bool has(const std::string &name) const;
147 
152  void add(const URI &u);
153  void add(const Attribute &attr);
154 
159  void remove(const URI &u);
160  void remove(const Attribute &attr);
161 
165  void clear();
166 
170  dtn::data::Size size() const;
171 
177  std::list<URI> get(Node::Protocol proto) const;
178  std::list<URI> get(Node::Type type) const;
179  std::list<URI> get(Node::Type type, Node::Protocol proto) const;
180 
184  std::list<Node::URI> getAll() const;
185 
189  std::set<Node::Type> getTypes() const;
190 
196  std::list<Attribute> get(const std::string &name) const;
197 
202  const dtn::data::EID& getEID() const;
203 
207  bool expire();
208 
215  bool operator==(const Node &other) const;
216  bool operator<(const Node &other) const;
217 
218  bool operator==(const dtn::data::EID &other) const;
219 
220  const Node& operator+=(const Node &other);
221  const Node& operator-=(const Node &other);
222 
223  std::string toString() const;
224 
225  bool doConnectImmediately() const;
226  void setConnectImmediately(bool val);
227 
231  bool hasDialup() const;
232 
236  bool isAvailable() const;
237 
241  bool isAnnounced() const;
242 
246  void setAnnounced(bool val);
247 
248  friend std::ostream& operator<<(std::ostream&, const Node&);
249 
250  private:
251  bool isAvailable(const Node::URI &uri) const;
252 
253  bool _connect_immediately;
254  dtn::data::EID _id;
255 
256  std::set<URI> _uri_list;
257  std::set<Attribute> _attr_list;
258 
259  bool _announced_mark;
260  };
261  }
262 }
263 
264 #endif /*IBRDTN_DAEMON_NODE_H_*/