IBR-DTN  1.0.0
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,
62  };
63 
70  enum Type
71  {
79  };
80 
81  class URI
82  {
83  public:
84  URI(const Type t, const Protocol proto, const std::string &uri, const dtn::data::Number &timeout = 0, const int priority = 0);
85  ~URI();
86 
89  std::string value;
91  int priority;
92 
93  void decode(std::string &address, unsigned int &port) const;
94 
95  bool operator<(const URI &other) const;
96  bool operator==(const URI &other) const;
97 
98  bool operator==(const Node::Protocol &p) const;
99  bool operator==(const Node::Type &t) const;
100 
101  friend std::ostream& operator<<(std::ostream&, const Node::URI&);
102  };
103 
104  class Attribute
105  {
106  public:
107  Attribute(const Type t, const std::string &name, const std::string &value, const dtn::data::Number &timeout = 0, const int priority = 0);
108  ~Attribute();
109 
111  std::string name;
112  std::string value;
114  int priority;
115 
116  bool operator<(const Attribute &other) const;
117  bool operator==(const Attribute &other) const;
118 
119  bool operator==(const std::string &name) const;
120 
121  friend std::ostream& operator<<(std::ostream&, const Node::Attribute&);
122  };
123 
124  static std::string toString(const Node::Type type);
125  static std::string toString(const Node::Protocol proto);
126  static Node::Protocol fromProtocolString(const std::string &protocol);
127 
133  Node(const dtn::data::EID &id);
134  Node();
135 
139  virtual ~Node();
140 
146  bool has(Node::Protocol proto) const;
147  bool has(const std::string &name) const;
148 
153  void add(const URI &u);
154  void add(const Attribute &attr);
155 
160  void remove(const URI &u);
161  void remove(const Attribute &attr);
162 
166  void clear();
167 
171  dtn::data::Size size() const throw ();
172 
178  std::list<URI> get(Node::Protocol proto) const;
179  std::list<URI> get(Node::Type type) const;
180  std::list<URI> get(Node::Type type, Node::Protocol proto) const;
181 
185  std::list<Node::URI> getAll() const;
186 
190  std::set<Node::Type> getTypes() const;
191 
197  std::list<Attribute> get(const std::string &name) const;
198 
203  const dtn::data::EID& getEID() const throw ();
204 
208  bool expire();
209 
216  bool operator==(const Node &other) const;
217  bool operator<(const Node &other) const;
218 
219  bool operator==(const dtn::data::EID &other) const;
220 
221  const Node& operator+=(const Node &other);
222  const Node& operator-=(const Node &other);
223 
224  std::string toString() const;
225 
226  bool doConnectImmediately() const;
227  void setConnectImmediately(bool val);
228 
232  bool isAvailable() const throw ();
233 
237  bool isAnnounced() const throw ();
238 
242  void setAnnounced(bool val) throw ();
243 
244  friend std::ostream& operator<<(std::ostream&, const Node&);
245 
246  private:
247  bool isAvailable(const Node::URI &uri) const throw ();
248 
249  bool _connect_immediately;
250  dtn::data::EID _id;
251 
252  std::set<URI> _uri_list;
253  std::set<Attribute> _attr_list;
254 
255  bool _announced_mark;
256  };
257  }
258 }
259 
260 #endif /*IBRDTN_DAEMON_NODE_H_*/
void decode(std::string &address, unsigned int &port) const
Definition: Node.cpp:47
std::string name
Definition: Node.h:111
virtual ~Node()
Definition: Node.cpp:148
dtn::data::Timestamp expire
Definition: Node.h:113
friend std::ostream & operator<<(std::ostream &, const Node::Attribute &)
Definition: Node.cpp:132
dtn::data::Size size() const
Definition: Node.cpp:308
bool operator==(const Attribute &other) const
Definition: Node.cpp:122
bool isAvailable() const
Definition: Node.cpp:526
Protocol protocol
Definition: Node.h:88
Attribute(const Type t, const std::string &name, const std::string &value, const dtn::data::Number &timeout=0, const int priority=0)
Definition: Node.cpp:105
void setAnnounced(bool val)
Definition: Node.cpp:574
dtn::data::Timestamp expire
Definition: Node.h:90
static Node::Protocol fromProtocolString(const std::string &protocol)
Definition: Node.cpp:231
bool expire()
Definition: Node.cpp:415
bool has(Node::Protocol proto) const
Definition: Node.cpp:262
bool isAnnounced() const
Definition: Node.cpp:579
friend std::ostream & operator<<(std::ostream &, const Node::URI &)
Definition: Node.cpp:99
URI(const Type t, const Protocol proto, const std::string &uri, const dtn::data::Number &timeout=0, const int priority=0)
Definition: Node.cpp:38
std::string value
Definition: Node.h:89
std::string value
Definition: Node.h:112
bool doConnectImmediately() const
Definition: Node.cpp:516
bool operator==(const URI &other) const
Definition: Node.cpp:84
void add(const URI &u)
Definition: Node.cpp:280
std::list< URI > get(Node::Protocol proto) const
Definition: Node.cpp:325
void clear()
Definition: Node.cpp:302
size_t Size
Definition: Number.h:34
std::string toString() const
Definition: Node.cpp:510
bool operator<(const URI &other) const
Definition: Node.cpp:73
const dtn::data::EID & getEID() const
Definition: Node.cpp:406
void setConnectImmediately(bool val)
Definition: Node.cpp:521
std::list< Node::URI > getAll() const
Definition: Node.cpp:372
bool operator<(const Attribute &other) const
Definition: Node.cpp:114
std::set< Node::Type > getTypes() const
Definition: Node.cpp:385