OverSim
I3Identifier.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
25 #ifndef __I3IDENTIFIER_H__
26 #define __I3IDENTIFIER_H__
27 
28 #include <omnetpp.h>
29 #include <OverlayKey.h>
30 
37 #define DEFAULT_PREFIX_LENGTH 160
38 #define DEFAULT_KEY_LENGTH 256
39 
40 class I3Identifier {
41 public:
43  I3Identifier();
44 
48  I3Identifier(unsigned char b);
49 
54  I3Identifier(int prefixL, int keyL);
55 
59  I3Identifier(const I3Identifier& id);
60 
64  I3Identifier(std::string s);
65 
67  int getKeyLength() const;
68 
70  int getPrefixLength() const;
71 
73  void clear();
74 
76  int compareTo(const I3Identifier&) const;
77 
79  bool operator <(const I3Identifier&) const;
80 
82  bool operator >(const I3Identifier&) const;
83 
85  bool operator ==(const I3Identifier&) const;
86 
89 
91  bool isClear();
92 
96  bool isMatch(const I3Identifier& id) const;
97 
107  int distanceTo(const I3Identifier& id) const;
108 
113  void createFromHash(const std::string &s, const std::string &o = "");
114 
115  void createRandomKey();
116  void createRandomPrefix();
117  void createRandomSuffix();
118 
119  int length() const;
120 
125  OverlayKey asOverlayKey() const;
126 
127  void setName(std::string s);
128  std::string getName();
129 
135  friend std::ostream& operator<<(std::ostream& os, const I3Identifier& id);
136 
138  ~I3Identifier();
139 
140 protected:
142  unsigned char *key;
143 
145  unsigned short prefixLength;
146 
148  unsigned short keyLength;
149 
150  std::string name;
151 
156  void initKey(int prefixL, int keyL);
157 };
158 
159 #endif
160