IBR-DTNSuite  0.8
daemon/src/core/Node.h
Go to the documentation of this file.
00001 
00002 #ifndef IBRDTN_DAEMON_NODE_H_
00003 #define IBRDTN_DAEMON_NODE_H_
00004 
00005 #include <string>
00006 #include <ibrdtn/data/EID.h>
00007 #include <set>
00008 #include <list>
00009 #include <iostream>
00010 
00011 namespace dtn
00012 {
00013         namespace net
00014         {
00015                 class ConvergenceLayer;
00016         }
00017 
00018         namespace core
00019         {
00023                 class Node
00024                 {
00025                 public:
00026                         enum Protocol
00027                         {
00028                                 CONN_UNSUPPORTED = -1,
00029                                 CONN_UNDEFINED = 0,
00030                                 CONN_TCPIP = 1,
00031                                 CONN_UDPIP = 2,
00032                                 CONN_LOWPAN = 3,
00033                                 CONN_BLUETOOTH = 4,
00034                                 CONN_HTTP = 5,
00035                                 CONN_FILE = 6,
00036                                 CONN_DGRAM_UDP = 7,
00037                                 CONN_DGRAM_LOWPAN = 8,
00038                                 CONN_DGRAM_ETHERNET = 9
00039                         };
00040 
00047                         enum Type
00048                         {
00049                                 NODE_UNAVAILABLE = 0,
00050                                 NODE_CONNECTED = 1,
00051                                 NODE_DISCOVERED = 2,
00052                                 NODE_STATIC = 3,
00053                                 NODE_DHT_DISCOVERED = 4
00054                         };
00055 
00056                         class URI
00057                         {
00058                         public:
00059                                 URI(const Type t, const Protocol proto, const std::string &uri, const size_t timeout = 0, const int priority = 0);
00060                                 ~URI();
00061 
00062                                 const Type type;
00063                                 const Protocol protocol;
00064                                 const std::string value;
00065                                 const size_t expire;
00066                                 const int priority;
00067 
00068                                 void decode(std::string &address, unsigned int &port) const;
00069 
00070                                 bool operator<(const URI &other) const;
00071                                 bool operator==(const URI &other) const;
00072 
00073                                 bool operator==(const Node::Protocol &p) const;
00074                                 bool operator==(const Node::Type &t) const;
00075 
00076                                 friend std::ostream& operator<<(std::ostream&, const Node::URI&);
00077                         };
00078 
00079                         class Attribute
00080                         {
00081                         public:
00082                                 Attribute(const Type t, const std::string &name, const std::string &value, const size_t timeout = 0, const int priority = 0);
00083                                 ~Attribute();
00084 
00085                                 const Type type;
00086                                 const std::string name;
00087                                 const std::string value;
00088                                 const size_t expire;
00089                                 const int priority;
00090 
00091                                 bool operator<(const Attribute &other) const;
00092                                 bool operator==(const Attribute &other) const;
00093 
00094                                 bool operator==(const std::string &name) const;
00095 
00096                                 friend std::ostream& operator<<(std::ostream&, const Node::Attribute&);
00097                         };
00098 
00099                         static std::string toString(Node::Type type);
00100                         static std::string toString(Node::Protocol proto);
00101 
00107                         Node(const dtn::data::EID &id);
00108                         Node();
00109 
00113                         virtual ~Node();
00114 
00120                         bool has(Node::Protocol proto) const;
00121                         bool has(const std::string &name) const;
00122 
00127                         void add(const URI &u);
00128                         void add(const Attribute &attr);
00129 
00134                         void remove(const URI &u);
00135                         void remove(const Attribute &attr);
00136 
00140                         void clear();
00141 
00147                         std::list<URI> get(Node::Protocol proto) const;
00148                         std::list<URI> get(Node::Type type, Node::Protocol proto) const;
00149 
00153                         std::set<Node::Type> getTypes() const;
00154 
00160                         std::list<Attribute> get(const std::string &name) const;
00161 
00166                         const dtn::data::EID& getEID() const;
00167 
00171                         bool expire();
00172 
00179                         bool operator==(const Node &other) const;
00180                         bool operator<(const Node &other) const;
00181 
00182                         bool operator==(const dtn::data::EID &other) const;
00183 
00184                         const Node& operator+=(const Node &other);
00185                         const Node& operator-=(const Node &other);
00186 
00187                         std::string toString() const;
00188 
00189                         bool doConnectImmediately() const;
00190                         void setConnectImmediately(bool val);
00191 
00195                         bool isAvailable() const;
00196 
00197                         friend std::ostream& operator<<(std::ostream&, const Node&);
00198 
00199                 private:
00200                         bool _connect_immediately;
00201                         dtn::data::EID _id;
00202 
00203                         std::set<URI> _uri_list;
00204                         std::set<Attribute> _attr_list;
00205                 };
00206         }
00207 }
00208 
00209 #endif /*IBRDTN_DAEMON_NODE_H_*/