NodeHandle.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00025 #include "NodeHandle.h"
00026
00027
00028 const NodeHandle NodeHandle::UNSPECIFIED_NODE;
00029
00030 std::ostream& operator<<(std::ostream& os, const NodeHandle& n)
00031 {
00032 if (n.ip.isUnspecified()) {
00033 os << "<addr unspec> ";
00034 } else {
00035 os << n.ip << ":" << n.port << " ";
00036 }
00037
00038 if (n.key.isUnspecified()) {
00039 os << "<key unspec>";
00040 } else {
00041 os << n.key;
00042 }
00043
00044 return os;
00045 };
00046
00047
00048
00049 NodeHandle::NodeHandle()
00050 {
00051 port = -1;
00052 key = OverlayKey();
00053 }
00054
00055
00056 NodeHandle::NodeHandle( const NodeHandle& handle )
00057 {
00058 key = handle.key;
00059 port = handle.port;
00060 ip = handle.ip;
00061 }
00062
00063 NodeHandle::NodeHandle( const TransportAddress& ta )
00064 {
00065 this->setAddress(ta.getAddress());
00066 this->setPort(ta.getPort());
00067 this->setKey(OverlayKey::UNSPECIFIED_KEY);
00068 }
00069
00070
00071 NodeHandle::NodeHandle( const OverlayKey& key,
00072 const IPvXAddress& ip, int port )
00073 {
00074 this->setAddress(ip);
00075 this->setPort(port);
00076 this->setKey(key);
00077 }
00078
00079 NodeHandle::NodeHandle( const OverlayKey& key, const TransportAddress& ta )
00080 {
00081 this->setAddress(ta.getAddress());
00082 this->setPort(ta.getPort());
00083 this->setKey(key);
00084 }
00085
00086
00087 bool NodeHandle::isUnspecified() const
00088 {
00089 return (ip.isUnspecified() || key.isUnspecified());
00090 }
00091
00092
00093 NodeHandle& NodeHandle::operator=(const NodeHandle& rhs)
00094 {
00095 this->key = rhs.key;
00096 this->ip = rhs.ip;
00097 this->port = rhs.port;
00098
00099 return *this;
00100 }
00101
00102
00103 bool NodeHandle::operator==(const NodeHandle& rhs) const
00104 {
00105 assertUnspecified( rhs );
00106 return ( this->key == rhs.key &&
00107 this->ip == rhs.ip && this->port == rhs.port );
00108 }
00109
00110
00111 bool NodeHandle::operator!=(const NodeHandle& rhs) const
00112 {
00113 assertUnspecified( rhs );
00114 return !( this->key == rhs.key &&
00115 this->ip == rhs.ip && this->port == rhs.port );
00116 }
00117
00118
00119 bool NodeHandle::operator<(const NodeHandle &rhs) const
00120 {
00121 assertUnspecified(rhs);
00122 return this->key < rhs.key;
00123 }
00124
00125
00126 bool NodeHandle::operator>(const NodeHandle &rhs) const
00127 {
00128 assertUnspecified(rhs);
00129 return this->key > rhs.key;
00130 }
00131
00132
00133 bool NodeHandle::operator<=(const NodeHandle &rhs) const
00134 {
00135 assertUnspecified(rhs);
00136 return this->key <= rhs.key;
00137 }
00138
00139
00140 bool NodeHandle::operator>=(const NodeHandle &rhs) const
00141 {
00142 assertUnspecified(rhs);
00143 return this->key >= rhs.key;
00144 }
00145
00146
00147 void NodeHandle::setKey( const OverlayKey& key )
00148 {
00149 this->key = key;
00150 }
00151
00152
00153 const OverlayKey& NodeHandle::getKey() const
00154 {
00155 return key;
00156 }
00157
00158
00159
00160 inline void NodeHandle::assertUnspecified( const NodeHandle& handle ) const
00161 {
00162 if ( this->isUnspecified() || handle.isUnspecified() )
00163 opp_error("NodeHandle: Trying to compare unspecified NodeHandle!");
00164 }
00165
00166
00167 void NodeHandle::netPack(cCommBuffer *b)
00168 {
00169
00170 doPacking(b,this->ip);
00171 doPacking(b,this->key);
00172 doPacking(b,this->port);
00173 }
00174
00175 void NodeHandle::netUnpack(cCommBuffer *b)
00176 {
00177
00178 doUnpacking(b,this->ip);
00179 doUnpacking(b,this->key);
00180 doUnpacking(b,this->port);
00181 }
00182
00183 TransportAddress* NodeHandle::dup() const
00184 {
00185 return new NodeHandle(*this);
00186 }