TransportAddress Class Reference

This class implements a common transport address. More...

#include <TransportAddress.h>

Inheritance diagram for TransportAddress:
I3IPAddress NodeHandle BootstrapNodeHandle BrooseHandle GiaNode ProxNodeHandle KademliaBucketEntry

List of all members.

Classes

class  hashFcn
 defines a hash function for TransportAddress More...

Public Types

enum  NatType {
  UNKNOWN_NAT = 0, NO_NAT = 1, FULL_CONE_NAT = 2, PORT_RESTRICTED_NAT = 3,
  SYMMETRIC_NAT = 4
}
typedef UNORDERED_SET
< TransportAddress, hashFcn
Set
 a hashed set of TransportAddresses

Public Member Functions

 TransportAddress ()
 Constructs a unspecified TransportAddress.
virtual ~TransportAddress ()
 Standard destructor.
 TransportAddress (const TransportAddress &handle)
 Copy constructor.
 TransportAddress (const IPvXAddress &ip, int port=-1, NatType natType=UNKNOWN_NAT)
 Complete constructor.
bool operator== (const TransportAddress &rhs) const
 compares this to a given TransportAddress
bool operator!= (const TransportAddress &rhs) const
 compares this to a given TransportAddress
bool operator< (const TransportAddress &rhs) const
 compares this to a given TransportAddress
bool operator> (const TransportAddress &rhs) const
 compares this to a given TransportAddress
bool operator<= (const TransportAddress &rhs) const
 compares this to a given TransportAddress
bool operator>= (const TransportAddress &rhs) const
 compares this to a given TransportAddress
TransportAddressoperator= (const TransportAddress &rhs)
 assigns ip and port of rhs to this->ip and this->port
void setAddress (const IPvXAddress &ip, int port=-1, NatType natType=UNKNOWN_NAT)
 Sets the ip address, port and NAT type.
void appendSourceRoute (const TransportAddress &sourceRoute)
 Appends a source route to this TransportAddress.
void clearSourceRoute ()
 Clears the source route of this TransportAddress.
void setPort (int port)
 sets this->port to the given port
const IPvXAddress & getAddress () const
 returns ip address
int getPort () const
 returns port
NatType getNatType () const
 returns the type of NAT this node is behind
size_t getSourceRouteSize () const
 Returns the length of the source route to reach this node.
const TransportAddressVectorgetSourceRoute () const
 Returns source route used to reach this node.
bool isUnspecified () const
 indicates if TransportAddress is specified
size_t hash () const
 creates a hash value of ip and port
virtual TransportAddressdup () const
 returns a copy of the TransportAddress

Static Public Attributes

static const TransportAddress UNSPECIFIED_NODE
 TransportAddress without specified ip and port.
static const TransportAddressVector UNSPECIFIED_NODES

Protected Attributes

IPvXAddress ip
 the ip of this TransportAddress object
int port
 the port of this TransportAddress object

Private Member Functions

void assertUnspecified (const TransportAddress &handle) const
 throws an opp_error if this or handle is unspecified

Private Attributes

NatType natType
 the assumed type of a NAT this node is behind (work in progress and currently not used
TransportAddressVector sourceRoute
 source route for NAT traversal

Friends

std::ostream & operator<< (std::ostream &os, const TransportAddress &n)
 standard output stream for TransportAddress, gives out ip and port

Detailed Description

This class implements a common transport address.


It covers the complete node information, like IP-Address, and port. The information can be sparse, so parts can be omited by setting the property to an unspecified value.

Author:
Markus Mauch
Sebastian Mies
Ingmar Baumgart

Definition at line 49 of file TransportAddress.h.


Member Typedef Documentation

a hashed set of TransportAddresses

Reimplemented in NodeHandle.

Definition at line 76 of file TransportAddress.h.


Member Enumeration Documentation

Enumerator:
UNKNOWN_NAT 
NO_NAT 
FULL_CONE_NAT 
PORT_RESTRICTED_NAT 
SYMMETRIC_NAT 

Definition at line 66 of file TransportAddress.h.

00066                  {
00067         UNKNOWN_NAT = 0,
00068         NO_NAT = 1,
00069         FULL_CONE_NAT = 2,
00070         PORT_RESTRICTED_NAT = 3,
00071         SYMMETRIC_NAT = 4
00072     };


Constructor & Destructor Documentation

TransportAddress::TransportAddress (  ) 

Constructs a unspecified TransportAddress.

Definition at line 55 of file TransportAddress.cc.

Referenced by appendSourceRoute(), and dup().

00056 {
00057     port = -1;
00058     natType = UNKNOWN_NAT;
00059 }

virtual TransportAddress::~TransportAddress (  )  [inline, virtual]

Standard destructor.

Definition at line 98 of file TransportAddress.h.

00098 {};

TransportAddress::TransportAddress ( const TransportAddress handle  ) 

Copy constructor.

Parameters:
handle The TransportAddress to copy

Definition at line 62 of file TransportAddress.cc.

00063 {
00064     port = handle.port;
00065     ip = handle.ip;
00066     natType = handle.natType;
00067     sourceRoute = handle.sourceRoute;
00068 }

TransportAddress::TransportAddress ( const IPvXAddress &  ip,
int  port = -1,
NatType  natType = UNKNOWN_NAT 
)

Complete constructor.

Parameters:
ip The IPvXAddress
port The UDP-Port
natType the type of NAT this node is behind

Definition at line 72 of file TransportAddress.cc.

00074 {
00075     this->ip = ip;
00076     this->port = port;
00077     this->natType = natType;
00078 }


Member Function Documentation

void TransportAddress::appendSourceRoute ( const TransportAddress sourceRoute  ) 

Appends a source route to this TransportAddress.

Parameters:
sourceRoute the source route to append

Definition at line 197 of file TransportAddress.cc.

Referenced by doUnpacking().

00198 {
00199     sourceRoute.push_back(TransportAddress(add.ip, add.port, add.natType));
00200     const TransportAddressVector& sr = add.getSourceRoute();
00201     for (size_t i = 0; i < sr.size(); i++) {
00202         if (sr[i].getSourceRouteSize() > 0) {
00203             throw cRuntimeError("TransportAddress::appendSourceRoute(): "
00204                                 "Trying to add source route to source route!");
00205         }
00206         sourceRoute.push_back(TransportAddress(sr[i].ip, sr[i].port,
00207                                                sr[i].natType));
00208     }
00209 }

void TransportAddress::assertUnspecified ( const TransportAddress handle  )  const [inline, private]

throws an opp_error if this or handle is unspecified

Parameters:
handle the TransportAddress to check

Definition at line 232 of file TransportAddress.cc.

Referenced by operator!=(), operator<(), operator==(), and operator>().

00233 {
00234     if ( this->isUnspecified() || handle.isUnspecified() )
00235         opp_error("TransportAddress: Trying to compare unspecified TransportAddress!");
00236 }

void TransportAddress::clearSourceRoute (  )  [inline]

Clears the source route of this TransportAddress.

Definition at line 205 of file TransportAddress.h.

00205 { sourceRoute.clear(); };

TransportAddress * TransportAddress::dup (  )  const [virtual]

returns a copy of the TransportAddress

Returns:
a copy of the TransportAddress

Reimplemented in NodeHandle.

Definition at line 226 of file TransportAddress.cc.

Referenced by BaseRpc::sendRpcCall().

00227 {
00228     return new TransportAddress(*this);
00229 }

const IPvXAddress & TransportAddress::getAddress (  )  const

returns ip address

Returns:
this->ip

Definition at line 167 of file TransportAddress.cc.

Referenced by GlobalNodeList::addPeer(), IterativeLookup::addSibling(), Quon::addSite(), BasePastry::baseInit(), BaseOverlay::bindToPort(), BaseApp::bindToPort(), I3BaseApp::bootstrapI3(), BootstrapNodeHandle::BootstrapNodeHandle(), BrooseHandle::BrooseHandle(), MyOverlay::callbackNeighbors(), BaseApp::callRoute(), BaseOverlay::callUpdate(), Vast::changeState(), Quon::changeState(), Gia::changeState(), oversim::Chord::changeState(), Pastry::checkProxCache(), oversim::Chord::closestPreceedingNode(), I3SubIdentifier::compareTo(), Nps::coordsReqRpcResponse(), Quon::deleteSite(), RealWorldTestApp::deliver(), MyApplication::deliver(), KBRTestApp::deliver(), Scribe::deliverALMDataToGroup(), Broose::displayBucketState(), Bamboo::doLocalTuning(), doPacking(), Pastry::doRoutingTableMaintenance(), Pastry::doSecondStage(), PastryRoutingTable::failedNode(), PastryNeighborhoodSet::failedNode(), PastryLeafSet::failedNode(), BaseOverlay::findNodeRpc(), KBRTestApp::forward(), GlobalNodeList::getBootstrapNode(), BrooseBucket::getFailedResponses(), Nps::getLandmarks(), BrooseBucket::getLastSeen(), GlobalNodeList::getPeerInfo(), BrooseBucket::getPos(), Gia::getRoute(), BrooseBucket::getRTT(), PubSubMMOG::handleAdoptChildCall(), PubSubMMOG::handleAdoptChildResponse(), Vast::handleAppMessage(), Quon::handleAppMessage(), BaseOverlay::handleBaseOverlayMessage(), BaseApp::handleCommonAPIMessage(), Pastry::handleFailedNode(), CBRDHT::handleGetResponse(), PubSubMMOG::handleHelpResponse(), PubSubMMOG::handleIntermediateResponse(), Scribe::handleJoinMessage(), Scribe::handleJoinResponse(), KBRTestApp::handleLookupResponse(), BootstrapList::handleLookupResponse(), GIASearchApp::handleLowerMessage(), XmlRpcInterface::handleMessage(), BaseOverlay::handleMessage(), BaseApp::handleMessage(), PubSubMMOG::handleMoveMessage(), Vast::handleNodeLeaveNotification(), PubSubMMOG::handlePingCall(), Scribe::handlePublishCall(), Scribe::handlePublishResponse(), SimpleGameClient::handleRealworldPacket(), BasePastry::handleRequestMessage(), oversim::Koorde::handleRpcCall(), oversim::Chord::handleRpcCall(), oversim::Chord::handleRpcNotifyResponse(), Scribe::handleRpcResponse(), PubSubMMOG::handleRpcResponse(), oversim::Koorde::handleRpcResponse(), KBRTestApp::handleRpcResponse(), oversim::Chord::handleRpcResponse(), Broose::handleRpcResponse(), BootstrapList::handleRpcResponse(), PubSubMMOG::handleRpcTimeout(), PubSubLobby::handleRpcTimeout(), oversim::Koorde::handleRpcTimeout(), Kademlia::handleRpcTimeout(), oversim::Chord::handleRpcTimeout(), Broose::handleRpcTimeout(), Pastry::handleStateMessage(), Bamboo::handleStateMessage(), SimpleGameClient::handleTimerEvent(), Scribe::handleTimerEvent(), Pastry::handleTimerEvent(), MyApplication::handleTimerEvent(), GIASearchApp::handleTimerEvent(), DHTTestApp::handleTimerEvent(), Bamboo::handleTimerEvent(), Vast::handleUDPMessage(), Quon::handleUDPMessage(), Pastry::handleUDPMessage(), MyApplication::handleUDPMessage(), Bamboo::handleUDPMessage(), Scribe::handleUpperMessage(), BrooseBucket::increaseFailedResponses(), SimpleGameClient::initializeApp(), Landmark::initializeApp(), BootstrapList::initializeApp(), MyOverlay::initializeOverlay(), I3::insertTrigger(), BaseRpc::internalHandleRpcMessage(), Kademlia::isSiblingFor(), IterativeLookup::lookup(), SendToKeyListener::lookupFinished(), BaseOverlay::lookupRpc(), Pastry::mergeState(), BasePastry::newLeafs(), NodeHandle::NodeHandle(), BrooseHandle::operator!=(), __gnu_cxx::hash< TransportAddress >::operator()(), operator<<(), GiaNode::operator=(), BrooseHandle::operator=(), BrooseHandle::operator==(), BrooseBucket::output(), BasePastry::pingNodes(), Pastry::pingResponse(), oversim::Chord::pingResponse(), BootstrapList::pingResponse(), BasePastry::pingResponse(), oversim::Chord::pingTimeout(), BootstrapList::pingTimeout(), BasePastry::pingTimeout(), BasePastry::proxCallback(), Quon::purgeSites(), oversim::Nice::Query(), GlobalNodeList::refreshEntry(), I3BaseApp::refreshTriggers(), GlobalNodeList::registerPeer(), BrooseBucket::remove(), GlobalNodeList::removePeer(), BrooseBucket::resetFailedResponses(), BaseOverlay::route(), Kademlia::routingAdd(), Vast::sendDiscardNode(), Vast::sendMessage(), Quon::sendMessage(), BaseOverlay::sendMessageToUDP(), BaseApp::sendMessageToUDP(), I3::sendPacket(), I3::sendQueryReply(), BaseOverlay::sendRouteMessage(), IterativePathLookup::sendRpc(), BasePastry::sendStateTables(), I3BaseApp::sendThroughUDP(), Vast::sendToApp(), Quon::sendToApp(), BaseOverlay::sendToKey(), BrooseBucket::setLastSeen(), BrooseBucket::setRTT(), PubSubMMOG::startTimer(), IterativeLookup::stop(), Scribe::subscribeToGroup(), DHT::update(), NeighborCache::updateNcsInfo(), SimpleGameClient::updateNeighbors(), NeighborCache::updateNode(), Quon::updateThisSite(), oversim::Koorde::updateTooltip(), and Broose::updateTooltip().

00168 {
00169     return ip;
00170 }

TransportAddress::NatType TransportAddress::getNatType (  )  const

returns the type of NAT this node is behind

Returns:
The type of NAT this node is behind

Definition at line 179 of file TransportAddress.cc.

Referenced by doPacking().

00180 {
00181     return natType;
00182 }

int TransportAddress::getPort (  )  const
const TransportAddressVector & TransportAddress::getSourceRoute (  )  const

Returns source route used to reach this node.

Returns:
The source route

Definition at line 191 of file TransportAddress.cc.

Referenced by appendSourceRoute(), doPacking(), BaseRpc::internalHandleRpcMessage(), operator<<(), and BaseRpc::sendRpcCall().

00192 {
00193     return sourceRoute;
00194 }

size_t TransportAddress::getSourceRouteSize (  )  const

Returns the length of the source route to reach this node.

Returns:
The length of the source route

Definition at line 185 of file TransportAddress.cc.

Referenced by appendSourceRoute(), doPacking(), BaseRpc::internalHandleRpcMessage(), operator<<(), and BaseRpc::sendRpcCall().

00186 {
00187     return sourceRoute.size();
00188 }

size_t TransportAddress::hash (  )  const

creates a hash value of ip and port

Returns:
the hash value

Definition at line 213 of file TransportAddress.cc.

Referenced by TransportAddress::hashFcn::operator()().

00214 {
00215     size_t iphash;
00216     if (ip.isIPv6()) {
00217         uint32_t* addr = (uint32_t*) ip.get6().words();
00218         iphash = (size_t)(addr[0]^addr[1]^addr[2]^addr[3]);
00219     } else {
00220         iphash = (size_t)ip.get4().getInt();
00221     }
00222 
00223     return (size_t)(iphash^port);
00224 }

bool TransportAddress::isUnspecified (  )  const
bool TransportAddress::operator!= ( const TransportAddress rhs  )  const

compares this to a given TransportAddress

Parameters:
rhs the TransportAddress this is compared to
Returns:
true if both IPvXAddress and port are not equal, false otherwise

Definition at line 103 of file TransportAddress.cc.

00104 {
00105     assertUnspecified(rhs);
00106     return !operator==(rhs);
00107 }

bool TransportAddress::operator< ( const TransportAddress rhs  )  const

compares this to a given TransportAddress

Parameters:
rhs the TransportAddress this is compared to
Returns:
true if this->ip is smaller than rhs->ip, false otherwise

Definition at line 110 of file TransportAddress.cc.

Referenced by operator>=().

00111 {
00112     assertUnspecified(rhs);
00113     if (ip < rhs.ip) {
00114         return true;
00115     } else if (rhs.ip < ip) {
00116         return false;
00117     } else if (port < rhs.port) {
00118         return true;
00119     }
00120     return false;
00121 }

bool TransportAddress::operator<= ( const TransportAddress rhs  )  const

compares this to a given TransportAddress

Parameters:
rhs the TransportAddress this is compared to
Returns:
true if this->ip is smaller than or equal to rhs->ip, false otherwise

Definition at line 138 of file TransportAddress.cc.

00139 {
00140     return !operator>(rhs);
00141 }

TransportAddress & TransportAddress::operator= ( const TransportAddress rhs  ) 

assigns ip and port of rhs to this->ip and this->port

Parameters:
rhs the TransportAddress with the defined ip and port
Returns:
this TransportAddress object

Definition at line 87 of file TransportAddress.cc.

00088 {
00089     this->ip = rhs.ip;
00090     this->port = rhs.port;
00091 
00092     return *this;
00093 }

bool TransportAddress::operator== ( const TransportAddress rhs  )  const

compares this to a given TransportAddress

Parameters:
rhs the TransportAddress this is compared to
Returns:
true if both IPvXAddress and port are equal, false otherwise

Definition at line 96 of file TransportAddress.cc.

Referenced by operator!=().

00097 {
00098     assertUnspecified(rhs);
00099     return (this->ip == rhs.ip && this->port == rhs.port);
00100 }

bool TransportAddress::operator> ( const TransportAddress rhs  )  const

compares this to a given TransportAddress

Parameters:
rhs the TransportAddress this is compared to
Returns:
true if this->ip is greater than rhs->ip, false otherwise

Definition at line 124 of file TransportAddress.cc.

Referenced by operator<=().

00125 {
00126     assertUnspecified(rhs);
00127     if (rhs.ip < ip) {
00128         return true;
00129     } else if (ip < rhs.ip) {
00130         return false;
00131     } else if (port > rhs.port) {
00132         return true;
00133     }
00134     return false;
00135 }

bool TransportAddress::operator>= ( const TransportAddress rhs  )  const

compares this to a given TransportAddress

Parameters:
rhs the TransportAddress this is compared to
Returns:
true if this->ip is greater than or equal to rhs->ip, false otherwise

Definition at line 144 of file TransportAddress.cc.

00145 {
00146     return !operator<(rhs);
00147 }

void TransportAddress::setAddress ( const IPvXAddress &  ip,
int  port = -1,
NatType  natType = UNKNOWN_NAT 
)

Sets the ip address, port and NAT type.

Parameters:
ip the new IPvXAddress
port the new port
natType the type of NAT this node is behind

Definition at line 150 of file TransportAddress.cc.

Referenced by doUnpacking(), NeighborCache::getNearestNode(), BaseOverlay::handleTransportAddressChangedNotification(), BaseOverlay::initialize(), BaseApp::initialize(), BaseOverlay::join(), MyOverlay::joinOverlay(), NodeHandle::NodeHandle(), I3IdentifierStack::push(), Vast::sendDiscardNode(), and Nps::setLandmarkSet().

00152 {
00153     this->ip = ip;
00154     if (port!=-1)
00155         this->port = port;
00156     if (natType != UNKNOWN_NAT)
00157         this->natType = natType;
00158 }

void TransportAddress::setPort ( int  port  ) 

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const TransportAddress n 
) [friend]

standard output stream for TransportAddress, gives out ip and port

Parameters:
os the ostream
n the TransportAddress
Returns:
the output stream

Definition at line 33 of file TransportAddress.cc.

00034 {
00035     if (n.isUnspecified()) {
00036         os << "<addr unspec>";
00037     } else {
00038         os << n.ip << ":" << n.port;
00039     }
00040 
00041     if (n.getSourceRouteSize() > 0) {
00042         os << "(SR:";
00043         for (size_t i = 0; i < n.getSourceRouteSize(); i++) {
00044             os << " " << n.getSourceRoute()[i].ip << ":"
00045                << n.getSourceRoute()[i].port;
00046         }
00047         os << ")";
00048     }
00049 
00050     return os;
00051 };


Member Data Documentation

IPvXAddress TransportAddress::ip [protected]

the assumed type of a NAT this node is behind (work in progress and currently not used

Definition at line 84 of file TransportAddress.h.

Referenced by appendSourceRoute(), getNatType(), and TransportAddress().

int TransportAddress::port [protected]

source route for NAT traversal

Definition at line 86 of file TransportAddress.h.

Referenced by appendSourceRoute(), clearSourceRoute(), getSourceRoute(), getSourceRouteSize(), and TransportAddress().

Definition at line 120 of file TransportAddress.h.


The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:19 2010 for OverSim by  doxygen 1.6.3