OverSim
TransportAddress Class Reference

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

#include <TransportAddress.h>

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

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 setIp (const IPvXAddress &ip, int port=-1, NatType natType=UNKNOWN_NAT)
 Sets the ip address, port and NAT type.
void setAddress (const IPvXAddress &ip, int port=-1, NatType natType=UNKNOWN_NAT) __attribute((deprecated))
 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 & getIp () const
 returns ip address
const IPvXAddress & getAddress () const __attribute((deprecated))
 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

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.

Constructor & Destructor Documentation

TransportAddress::TransportAddress ( )

Constructs a unspecified TransportAddress.

Definition at line 55 of file TransportAddress.cc.

Referenced by appendSourceRoute(), and dup().

{
port = -1;
}
virtual TransportAddress::~TransportAddress ( )
inlinevirtual

Standard destructor.

Definition at line 98 of file TransportAddress.h.

{};
TransportAddress::TransportAddress ( const TransportAddress handle)

Copy constructor.

Parameters
handleThe TransportAddress to copy

Definition at line 62 of file TransportAddress.cc.

{
port = handle.port;
ip = handle.ip;
natType = handle.natType;
}
TransportAddress::TransportAddress ( const IPvXAddress &  ip,
int  port = -1,
NatType  natType = UNKNOWN_NAT 
)

Complete constructor.

Parameters
ipThe IPvXAddress
portThe UDP-Port
natTypethe type of NAT this node is behind

Definition at line 72 of file TransportAddress.cc.

{
this->ip = ip;
this->port = port;
this->natType = natType;
}

Member Function Documentation

void TransportAddress::appendSourceRoute ( const TransportAddress sourceRoute)

Appends a source route to this TransportAddress.

Parameters
sourceRoutethe source route to append

Definition at line 197 of file TransportAddress.cc.

Referenced by doUnpacking(), and BaseOverlay::handleBaseOverlayMessage().

{
sourceRoute.push_back(TransportAddress(add.ip, add.port, add.natType));
for (size_t i = 0; i < sr.size(); i++) {
if (sr[i].getSourceRouteSize() > 0) {
throw cRuntimeError("TransportAddress::appendSourceRoute(): "
"Trying to add source route to source route!");
}
sourceRoute.push_back(TransportAddress(sr[i].ip, sr[i].port,
sr[i].natType));
}
}
void TransportAddress::assertUnspecified ( const TransportAddress handle) const
inlineprivate

throws an opp_error if this or handle is unspecified

Parameters
handlethe TransportAddress to check

Definition at line 232 of file TransportAddress.cc.

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

{
if ( this->isUnspecified() || handle.isUnspecified() )
opp_error("TransportAddress: Trying to compare unspecified TransportAddress!");
}
void TransportAddress::clearSourceRoute ( )
inline

Clears the source route of this TransportAddress.

Definition at line 216 of file TransportAddress.h.

{ 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().

{
return new TransportAddress(*this);
}
const IPvXAddress& TransportAddress::getAddress ( ) const
inline

returns ip address.

DEPRECATED: Use getIp() instead!

Returns
this->ip

Definition at line 237 of file TransportAddress.h.

{ return getIp(); };
const IPvXAddress & TransportAddress::getIp ( ) const

returns ip address

Returns
this->ip

Definition at line 167 of file TransportAddress.cc.

Referenced by IterativeLookup::addSibling(), Quon::addSite(), BasePastry::baseInit(), I3BaseApp::bootstrapI3(), BootstrapNodeHandle::BootstrapNodeHandle(), BrooseHandle::BrooseHandle(), MyOverlay::callbackNeighbors(), BaseOverlay::callUpdate(), Gia::changeState(), Quon::changeState(), Vast::changeState(), oversim::Nice::checkLeaderHeartbeatsForCollisions(), TreeManagement::checkParentValid(), Pastry::checkProxCache(), oversim::Nice::cleanPeers(), BaseTcpSupport::closeTcpConnection(), oversim::Nice::ClusterMerge(), oversim::Nice::ClusterSplit(), I3SubIdentifier::compareTo(), TreeManagement::connectToParent(), Nps::coordsReqRpcResponse(), BasePastry::createStateMessage(), TreeManagement::debugChildren(), Quon::deleteSite(), RealWorldTestApp::deliver(), MyApplication::deliver(), KBRTestApp::deliver(), Bamboo::doLocalTuning(), doPacking(), Pastry::doRoutingTableMaintenance(), Pastry::doSecondStage(), BaseTcpSupport::establishTcpConnection(), PastryNeighborhoodSet::failedNode(), PastryLeafSet::failedNode(), PastryRoutingTable::failedNode(), KBRTestApp::forward(), getAddress(), GlobalNodeList::getBootstrapNode(), BrooseBucket::getFailedResponses(), Nps::getLandmarks(), BrooseBucket::getLastSeen(), GlobalNodeList::getPeerInfo(), BrooseBucket::getPos(), Gia::getRoute(), BrooseBucket::getRTT(), oversim::Nice::gracefulLeave(), Vast::handleAppMessage(), Quon::handleAppMessage(), oversim::Nice::handleAppMessage(), GlobalViewBuilder::handleCoordinateRpcCall(), TCPExampleApp::handleDataReceived(), Pastry::handleFailedNode(), CBRDHT::handleGetResponse(), KBRTestApp::handleLookupResponse(), SimpleGameClient::handleLowerMessage(), GIASearchApp::handleLowerMessage(), oversim::Nice::handleNiceClusterMergeRequest(), oversim::Nice::handleNiceHeartbeat(), oversim::Nice::handleNiceJoinCluster(), oversim::Nice::handleNiceLeaderHeartbeat(), oversim::Nice::handleNiceLeaderTransfer(), oversim::Nice::handleNiceQuery(), oversim::Nice::handleNiceRemove(), Vast::handleNodeLeaveNotification(), TreeManagement::handleParentRequestRpcCall(), TreeManagement::handleParentRequestRpcResponse(), Pastry::handlePastryJoinCall(), Pastry::handlePastryJoinResponse(), SimpleGameClient::handleRealworldPacket(), BasePastry::handleRequestLeafSetCall(), Bamboo::handleRequestLeafSetResponse(), Pastry::handleRequestLeafSetResponse(), BasePastry::handleRequestLeafSetResponse(), Pastry::handleRequestRepairCall(), Pastry::handleRequestRepairResponse(), BasePastry::handleRequestRoutingRowCall(), Pastry::handleRequestRoutingRowResponse(), BasePastry::handleRequestRoutingRowResponse(), Pastry::handleRequestStateCall(), Pastry::handleRequestStateResponse(), Pastry::handleRpcCall(), BasePastry::handleRpcCall(), DiscoveryMode::handleRpcResponse(), Bamboo::handleRpcResponse(), Pastry::handleRpcResponse(), KBRTestApp::handleRpcResponse(), BasePastry::handleRpcResponse(), TreeManagement::handleRpcTimeout(), Pastry::handleRpcTimeout(), KBRTestApp::handleRpcTimeout(), Kademlia::handleRpcTimeout(), BasePastry::handleRpcTimeout(), Pastry::handleStateMessage(), Bamboo::handleStateMessage(), MyApplication::handleTimerEvent(), TCPExampleApp::handleTimerEvent(), SimpleGameClient::handleTimerEvent(), Pastry::handleTimerEvent(), Bamboo::handleTimerEvent(), GIASearchApp::handleTimerEvent(), Vast::handleUDPMessage(), Quon::handleUDPMessage(), MyApplication::handleUDPMessage(), Pastry::handleUDPMessage(), BrooseBucket::increaseFailedResponses(), SimpleNcs::init(), Landmark::initializeApp(), SimpleGameClient::initializeApp(), MyOverlay::initializeOverlay(), PastryLeafSet::insertLeaf(), BaseRpc::internalHandleRpcMessage(), BaseOverlay::internalHandleRpcTimeout(), BaseTcpSupport::isAlreadyConnected(), Kademlia::isSiblingFor(), oversim::Nice::JoinCluster(), IterativeLookup::lookup(), Bamboo::lookupFinished(), oversim::Nice::maintenance(), 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(), BootstrapList::pingResponse(), oversim::Nice::pollRP(), Pastry::processState(), BasePastry::proxCallback(), Quon::purgeSites(), oversim::Nice::Query(), GlobalNodeList::refreshEntry(), I3BaseApp::refreshTriggers(), GlobalNodeList::registerPeer(), BrooseBucket::remove(), oversim::Nice::Remove(), TreeManagement::removeParentConnection(), GlobalNodeList::removePeer(), BrooseBucket::resetFailedResponses(), NTree::routeViaNTree(), Kademlia::routingAdd(), Vast::sendDiscardNode(), Quon::sendMessage(), Vast::sendMessage(), BaseApp::sendMessageToUDP(), BaseOverlay::sendMessageToUDP(), DiscoveryMode::sendNewRequest(), BaseOverlay::sendRouteMessage(), IterativePathLookup::sendRpc(), BaseTcpSupport::sendTcpData(), I3BaseApp::sendThroughUDP(), Quon::sendToApp(), Vast::sendToApp(), BaseOverlay::sendToKey(), NeighborCache::setCbrNodeId(), BrooseBucket::setLastSeen(), GlobalNodeList::setMalicious(), BrooseBucket::setRTT(), GlobalViewBuilder::spreadGlobalView(), DiscoveryMode::start(), DiscoveryMode::stop(), IterativeLookup::stop(), NeighborCache::updateNcsInfo(), SimpleGameClient::updateNeighbors(), NeighborCache::updateNode(), Quon::updateThisSite(), oversim::Koorde::updateTooltip(), and oversim::Nice::updateVisualization().

{
return ip;
}
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().

{
return natType;
}
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().

{
return sourceRoute;
}
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().

{
return sourceRoute.size();
}
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()().

{
size_t iphash;
if (ip.isIPv6()) {
uint32_t* addr = (uint32_t*) ip.get6().words();
iphash = (size_t)(addr[0]^addr[1]^addr[2]^addr[3]);
} else {
iphash = (size_t)ip.get4().getInt();
}
return (size_t)(iphash^port);
}
bool TransportAddress::isUnspecified ( ) const

indicates if TransportAddress is specified

Returns
true, if TransportAddress has no ip or port specified, false otherwise

Reimplemented in NodeHandle.

Definition at line 81 of file TransportAddress.cc.

Referenced by assertUnspecified(), BasePastry::baseChangeState(), oversim::Nice::changeState(), Pastry::checkProxCache(), oversim::Nice::ClusterMerge(), oversim::Nice::ClusterSplit(), NiceCluster::contains(), BasePastry::determineAliveTable(), Bamboo::doLeafsetMaintenance(), Bamboo::doLocalTuning(), Pastry::doRoutingTableMaintenance(), PubSubLobby::failedNode(), PastryLeafSet::failedNode(), PastryRoutingTable::failedNode(), oversim::Nice::findCenter(), PastryRoutingTable::findNextNodeToAsk(), BootstrapList::getBootstrapNode(), NeighborCache::getNodeRtt(), NeighborCache::getProx(), oversim::Nice::gracefulLeave(), NTree::handleAppMessage(), Bamboo::handleFailedNode(), Pastry::handleFailedNode(), Kademlia::handleFailedNode(), Quon::handleJoin(), Vast::handleJoin(), oversim::Nice::handleNiceLeaderHeartbeat(), oversim::Nice::handleNiceLeaderTransfer(), oversim::Nice::handleNicePollRpResponse(), oversim::Nice::handleNiceRemove(), DiscoveryMode::handleRpcResponse(), TreeManagement::handleRpcTimeout(), Kademlia::handleRpcTimeout(), BasePastry::handleRpcTimeout(), Pastry::handleStateMessage(), P2pns::handleTimerEvent(), KBRTestApp::handleTimerEvent(), oversim::Nice::handleTimerEvent(), BaseRpc::internalHandleRpcMessage(), BaseOverlay::internalHandleRpcTimeout(), TreeManagement::isParent(), Pastry::iterativeJoinHook(), Kademlia::joinOverlay(), Bamboo::joinOverlay(), Pastry::joinOverlay(), oversim::Nice::maintenance(), operator<<(), P2pns::pingTimeout(), NeighborCache::prepareOverlay(), NiceCluster::remove(), BootstrapList::removeBootstrapCandidate(), PastryLeafSet::repair(), oversim::Chord::rpcNotify(), GlobalViewBuilder::sendCapRequest(), NTree::sendMessage(), BaseRpc::sendRouteRpcCall(), BaseRpc::sendRpcResponse(), NiceCluster::setLeader(), oversim::Nice::splitNeeded(), DiscoveryMode::start(), and P2pns::updateIdCacheWithNewTransport().

{
return (ip.isUnspecified() || (port == -1));
}
bool TransportAddress::operator!= ( const TransportAddress rhs) const

compares this to a given TransportAddress

Parameters
rhsthe 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.

{
return !operator==(rhs);
}
bool TransportAddress::operator< ( const TransportAddress rhs) const

compares this to a given TransportAddress

Parameters
rhsthe 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>=().

{
if (ip < rhs.ip) {
return true;
} else if (rhs.ip < ip) {
return false;
} else if (port < rhs.port) {
return true;
}
return false;
}
bool TransportAddress::operator<= ( const TransportAddress rhs) const

compares this to a given TransportAddress

Parameters
rhsthe 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.

{
return !operator>(rhs);
}
TransportAddress & TransportAddress::operator= ( const TransportAddress rhs)

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

Parameters
rhsthe TransportAddress with the defined ip and port
Returns
this TransportAddress object

Definition at line 87 of file TransportAddress.cc.

{
this->ip = rhs.ip;
this->port = rhs.port;
return *this;
}
bool TransportAddress::operator== ( const TransportAddress rhs) const

compares this to a given TransportAddress

Parameters
rhsthe 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!=().

{
return (this->ip == rhs.ip && this->port == rhs.port);
}
bool TransportAddress::operator> ( const TransportAddress rhs) const

compares this to a given TransportAddress

Parameters
rhsthe 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<=().

{
if (rhs.ip < ip) {
return true;
} else if (ip < rhs.ip) {
return false;
} else if (port > rhs.port) {
return true;
}
return false;
}
bool TransportAddress::operator>= ( const TransportAddress rhs) const

compares this to a given TransportAddress

Parameters
rhsthe 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.

{
return !operator<(rhs);
}
void TransportAddress::setAddress ( const IPvXAddress &  ip,
int  port = -1,
NatType  natType = UNKNOWN_NAT 
)
inline

Sets the ip address, port and NAT type.

DEPRECATED: Use setIp() instead!

Parameters
ipthe new IPvXAddress
portthe new port
natTypethe type of NAT this node is behind

Definition at line 201 of file TransportAddress.h.

{ setIp(ip, port, natType); };
void TransportAddress::setIp ( const IPvXAddress &  ip,
int  port = -1,
NatType  natType = UNKNOWN_NAT 
)

Sets the ip address, port and NAT type.

Parameters
ipthe new IPvXAddress
portthe new port
natTypethe type of NAT this node is behind

Definition at line 150 of file TransportAddress.cc.

Referenced by doUnpacking(), NeighborCache::getNearestNode(), MyOverlay::joinOverlay(), SimpleUnderlayConfigurator::migrateNode(), NodeHandle::NodeHandle(), I3IdentifierStack::push(), Vast::sendDiscardNode(), setAddress(), and Nps::setLandmarkSet().

{
this->ip = ip;
if (port!=-1)
this->port = port;
this->natType = natType;
}
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
osthe ostream
nthe TransportAddress
Returns
the output stream

Definition at line 33 of file TransportAddress.cc.

{
if (n.isUnspecified()) {
os << "<addr unspec>";
} else {
os << n.ip << ":" << n.port;
}
if (n.getSourceRouteSize() > 0) {
os << "(SR:";
for (size_t i = 0; i < n.getSourceRouteSize(); i++) {
os << " " << n.getSourceRoute()[i].ip << ":"
<< n.getSourceRoute()[i].port;
}
os << ")";
}
return os;
};

Member Data Documentation

NatType TransportAddress::natType
private

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(), setAddress(), setIp(), and TransportAddress().

TransportAddressVector TransportAddress::sourceRoute
private

source route for NAT traversal

Definition at line 86 of file TransportAddress.h.

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

const std::vector< TransportAddress > TransportAddress::UNSPECIFIED_NODES
static

Definition at line 120 of file TransportAddress.h.


The documentation for this class was generated from the following files: