OverSim
BaseTcpSupport Class Reference

#include <BaseTcpSupport.h>

Inheritance diagram for BaseTcpSupport:
BaseApp BaseOverlay ALMTest BootstrapList CBRDHT DHT DHTTestApp GIASearchApp I3 KBRTestApp Landmark MyApplication NeighborCache P2pns RealWorldTestApp Scribe SimMud SimpleGameClient TCPExampleApp TierDummy XmlRpcInterface BasePastry Broose Gia Kademlia MyOverlay NTree OverlayDummy oversim::Chord oversim::Nice PubSubLobby PubSubMMOG Quon Vast

Public Types

enum  EvCode {
  NO_EST_CONNECTION, PEER_CLOSED, PEER_TIMEDOUT, PEER_REFUSED,
  CONNECTION_RESET, CONNECTION_SUCC_ClOSED
}

Public Member Functions

virtual void socketDataArrived (int connId, void *yourPtr, cPacket *msg, bool urgent)
virtual void socketEstablished (int connId, void *yourPtr)
virtual void socketPeerClosed (int connId, void *yourPtr)
virtual void socketFailure (int connId, void *yourPtr, int code)
virtual void socketStatusArrived (int connId, void *yourPtr, TCPStatusInfo *status)

Protected Member Functions

void handleTCPMessage (cMessage *msg)
 Member function to handle incoming TCP messages.
void bindAndListenTcp (int port)
 Member function to bind service to the specified port and listen afterwards.
bool isAlreadyConnected (TransportAddress address)
 Member function to check if the service is already connected.
void establishTcpConnection (TransportAddress address)
 Member function to establish a connection to the specified node.
void sendTcpData (cPacket *msg, TransportAddress address)
 Member function to send TCP data to the specified node.
virtual void handleConnectionEvent (EvCode code, TransportAddress address)
 Member function to handle passive connection events.
virtual void handleDataReceived (TransportAddress address, cPacket *msg, bool urgent)
 Member function to handle incoming data.
virtual void handleIncomingConnection (TransportAddress address)
 Member function to handle newly opened connections.
void closeTcpConnection (TransportAddress address)
 Member function to close an established connection.
void setTcpOut (cGate *gate)
 Member function to set local gate towards the TCP module during init phase.
cGate * getTcpOut ()
 Member function to get local gate towards the TCP module.

Private Types

typedef std::vector< cMessage * > msgQueue
typedef std::map
< TransportAddress, msgQueue * > 
transQueue

Private Attributes

ExtTCPSocketMap sockets
 Socket map with extended functionality to find sockets.
transQueue queuedTx
 msg queue partitioned by destination
cGate * tcpOut
 local gate towards the TCP module

Detailed Description

Definition at line 33 of file BaseTcpSupport.h.

Member Typedef Documentation

typedef std::vector<cMessage*> BaseTcpSupport::msgQueue
private

Definition at line 132 of file BaseTcpSupport.h.

Definition at line 133 of file BaseTcpSupport.h.

Member Enumeration Documentation

Enumerator:
NO_EST_CONNECTION 
PEER_CLOSED 
PEER_TIMEDOUT 
PEER_REFUSED 
CONNECTION_RESET 
CONNECTION_SUCC_ClOSED 

Definition at line 38 of file BaseTcpSupport.h.

Member Function Documentation

void BaseTcpSupport::bindAndListenTcp ( int  port)
protected

Member function to bind service to the specified port and listen afterwards.

Parameters
portlocal portnumber to bind on

Definition at line 50 of file BaseTcpSupport.cc.

{
if (sockets.size() != 0) {
return;
}
TCPSocket* newSocket = new TCPSocket();
newSocket->bind(port);
newSocket->setOutputGate(getTcpOut());
newSocket->setCallbackObject(this);
newSocket->listen();
sockets.addSocket(newSocket);
}
void BaseTcpSupport::closeTcpConnection ( TransportAddress  address)
protected

Member function to close an established connection.

Parameters
addresstransport address of the remote host

Definition at line 196 of file BaseTcpSupport.cc.

{
if (!isAlreadyConnected(address)) {
return;
}
TCPSocket* oldSocket = sockets.findSocketFor(address.getIp(),
address.getPort());
oldSocket->close();
}
void BaseTcpSupport::establishTcpConnection ( TransportAddress  address)
protected

Member function to establish a connection to the specified node.

Parameters
addresstransport address of the remote host

Definition at line 75 of file BaseTcpSupport.cc.

Referenced by handleConnectionEvent().

{
if (isAlreadyConnected(address)) {
return;
}
TCPSocket* newSocket = new TCPSocket();
newSocket->setOutputGate(getTcpOut());
newSocket->setCallbackObject(this);
newSocket->connect(address.getIp(), address.getPort());
sockets.addSocket(newSocket);
}
cGate* BaseTcpSupport::getTcpOut ( )
inlineprotected

Member function to get local gate towards the TCP module.

Returns
The local gate towards the TCP module

Definition at line 127 of file BaseTcpSupport.h.

Referenced by bindAndListenTcp(), establishTcpConnection(), and handleTCPMessage().

{return tcpOut;}
void BaseTcpSupport::handleConnectionEvent ( EvCode  code,
TransportAddress  address 
)
protectedvirtual

Member function to handle passive connection events.

Parameters
codeevent code of the current event
addresstransport address of the remote host

Definition at line 114 of file BaseTcpSupport.cc.

Referenced by TCPExampleApp::handleConnectionEvent(), sendTcpData(), socketFailure(), and socketPeerClosed().

{
if (code == NO_EST_CONNECTION) {
}
}
void BaseTcpSupport::handleDataReceived ( TransportAddress  address,
cPacket *  msg,
bool  urgent 
)
protectedvirtual

Member function to handle incoming data.

Parameters
addresstransport address of the remote host
msgincoming data message
urgentmessage urgency

Definition at line 121 of file BaseTcpSupport.cc.

Referenced by socketDataArrived().

{
}
void BaseTcpSupport::handleIncomingConnection ( TransportAddress  address)
protectedvirtual

Member function to handle newly opened connections.

Parameters
addresstransport address of the remote host

Definition at line 126 of file BaseTcpSupport.cc.

Referenced by handleTCPMessage().

{
}
void BaseTcpSupport::handleTCPMessage ( cMessage *  msg)
protected

Member function to handle incoming TCP messages.

Definition at line 30 of file BaseTcpSupport.cc.

{
TCPSocket* socket = sockets.findSocketFor(msg);
if (socket == NULL) {
socket = new TCPSocket(msg);
socket->setCallbackObject(this);
socket->setOutputGate(getTcpOut());
sockets.addSocket(socket);
TransportAddress newAddress =
TransportAddress(socket->getRemoteAddress(),
socket->getRemotePort());
socket->processMessage(msg);
} else {
socket->processMessage(msg);
}
}
bool BaseTcpSupport::isAlreadyConnected ( TransportAddress  address)
protected

Member function to check if the service is already connected.

Parameters
addresstransport address of the remote host

Definition at line 64 of file BaseTcpSupport.cc.

Referenced by closeTcpConnection(), establishTcpConnection(), and sendTcpData().

{
TCPSocket* newSocket = sockets.findSocketFor(address.getIp(),
address.getPort());
if (newSocket == NULL) {
return false;
} else if (newSocket->getState() >= TCPSocket::PEER_CLOSED) {
return false;
} else return true;
}
void BaseTcpSupport::sendTcpData ( cPacket *  msg,
TransportAddress  address 
)
protected

Member function to send TCP data to the specified node.

Parameters
msgdata message
addresstransport address of the remote host

Definition at line 89 of file BaseTcpSupport.cc.

{
if (!isAlreadyConnected(address)) {
return;
}
TCPSocket* socket = sockets.findSocketFor(address.getIp(),
address.getPort());
if (socket->getState() == TCPSocket::CONNECTED) {
socket->send(msg);
}
transQueue::iterator tx = queuedTx.find(address);
if (tx != queuedTx.end()) {
tx->second->push_back(msg);
} else {
msgQueue* newQueue = new msgQueue();
newQueue->push_back(msg);
queuedTx[address] = newQueue;
}
}
void BaseTcpSupport::setTcpOut ( cGate *  gate)
inlineprotected

Member function to set local gate towards the TCP module during init phase.

Parameters
gatelocal gate towards the TCP module

Definition at line 120 of file BaseTcpSupport.h.

{tcpOut = gate;}
void BaseTcpSupport::socketDataArrived ( int  connId,
void *  yourPtr,
cPacket *  msg,
bool  urgent 
)
virtual

Definition at line 130 of file BaseTcpSupport.cc.

{
TCPSocket* socket = sockets.findSocketFor(connId);
TransportAddress remoteAddress(socket->getRemoteAddress(),
socket->getRemotePort());
handleDataReceived(remoteAddress, msg, urgent);
}
void BaseTcpSupport::socketEstablished ( int  connId,
void *  yourPtr 
)
virtual

Definition at line 140 of file BaseTcpSupport.cc.

{
TCPSocket* socket = sockets.findSocketFor(connId);
if (socket == NULL) {
return;
}
TransportAddress remoteAddress(socket->getRemoteAddress(),
socket->getRemotePort());
transQueue::iterator tx = queuedTx.find(remoteAddress);
if (tx != queuedTx.end()) {
for (uint32 i = 0 ; i < tx->second->size(); i++) {
socket->send(tx->second->at(i));
}
tx->second->clear();
delete tx->second;
queuedTx.erase(remoteAddress);
}
}
void BaseTcpSupport::socketFailure ( int  connId,
void *  yourPtr,
int  code 
)
virtual

Definition at line 179 of file BaseTcpSupport.cc.

{
TCPSocket* socket = sockets.findSocketFor(connId);
TransportAddress remoteAddress(socket->getRemoteAddress(),
socket->getRemotePort());
if (code == TCP_I_CONNECTION_REFUSED) {
} else if (code == TCP_I_TIMED_OUT) {
} else if (code == TCP_I_CONNECTION_RESET) {
} else {
throw new cRuntimeError("Invalid error code on socketFailure.");
}
}
void BaseTcpSupport::socketPeerClosed ( int  connId,
void *  yourPtr 
)
virtual

Definition at line 164 of file BaseTcpSupport.cc.

{
TCPSocket* socket = sockets.findSocketFor(connId);
TransportAddress remoteAddress(socket->getRemoteAddress(),
socket->getRemotePort());
if (socket->getState() == TCPSocket::PEER_CLOSED) {
socket->close();
} else if (socket->getState() == TCPSocket::CLOSED) {
sockets.removeSocket(socket);
}
}
virtual void BaseTcpSupport::socketStatusArrived ( int  connId,
void *  yourPtr,
TCPStatusInfo *  status 
)
inlinevirtual

Definition at line 46 of file BaseTcpSupport.h.

{delete status;}

Member Data Documentation

transQueue BaseTcpSupport::queuedTx
private

msg queue partitioned by destination

Definition at line 134 of file BaseTcpSupport.h.

Referenced by sendTcpData(), and socketEstablished().

ExtTCPSocketMap BaseTcpSupport::sockets
private
cGate* BaseTcpSupport::tcpOut
private

local gate towards the TCP module

Definition at line 136 of file BaseTcpSupport.h.

Referenced by getTcpOut(), and setTcpOut().


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