Corrected two harmful bugs in tunnel connexion code:

- added a destructor to RsTunnelDataItem, to remove a memory leak on all data packets.
- apparently the code would allow data items of zero size, hence calling malloc(0), which
  has undetermined behavior.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3191 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-06-22 21:05:56 +00:00
parent 13671d03ea
commit 5045e720b2
3 changed files with 229 additions and 204 deletions

View File

@ -82,6 +82,12 @@ RsItem *RsTunnelSerialiser::deserialise(void *data, uint32_t *size)
}
}
RsTunnelDataItem::~RsTunnelDataItem()
{
if(encoded_data != NULL)
free(encoded_data) ;
}
bool RsTunnelDataItem::serialize(void *data,uint32_t& pktsize)
{
#ifdef P3TUNNEL_DEBUG
@ -109,25 +115,27 @@ bool RsTunnelDataItem::serialize(void *data,uint32_t& pktsize)
/* add mandatory parts first */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, sourcePeerId);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, relayPeerId);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, destPeerId);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, destPeerId);
ok &= setRawUInt32(data, tlvsize, &offset, encoded_data_len) ;
memcpy((void*)((unsigned char*)data+offset),encoded_data,encoded_data_len) ;
if(encoded_data != NULL)
memcpy((void*)((unsigned char*)data+offset),encoded_data,encoded_data_len) ;
#ifdef P3TUNNEL_DEBUG
std::cerr << "RsTunnelDataItem::serialise() (offset + encoded_data_len) " << (offset + encoded_data_len) << std::endl;
std::cerr << "RsTunnelDataItem::serialise() tlvsize " << tlvsize << std::endl;
std::cerr << "RsTunnelDataItem::serialise() (offset + encoded_data_len) " << (offset + encoded_data_len) << std::endl;
std::cerr << "RsTunnelDataItem::serialise() tlvsize " << tlvsize << std::endl;
#endif
if ((offset + encoded_data_len) != tlvsize )
if ((offset + encoded_data_len) != tlvsize )
{
ok = false;
std::cerr << "RsTunnelDataItem::serialiseTransfer() Size Error! " << std::endl;
std::cerr << "RsTunnelDataItem::serialiseTransfer() Size Error! " << std::endl;
}
#ifdef P3TUNNEL_DEBUG
std::cerr << "RsTunnelDataItem::serialize() packet size inside serialised data : " << getRsItemSize(data) << std::endl ;
#endif
#ifdef P3TUNNEL_DEBUG
std::cerr << "RsTunnelDataItem::serialize() packet size inside serialised data : " << getRsItemSize(data) << std::endl ;
#endif
return ok;
}
@ -215,11 +223,16 @@ RsTunnelDataItem *RsTunnelDataItem::deserialise(void *data,uint32_t pktsize)
ok &= getRawUInt32(data, pktsize, &offset, &item->encoded_data_len) ;
if(!ok) // return early to avoid calling malloc with 0 size
if(!ok) // return early to avoid calling malloc with invalid size
return NULL ;
item->encoded_data = (void*)malloc(item->encoded_data_len) ;
memcpy(item->encoded_data, (void*)((unsigned char*)data+offset), item->encoded_data_len);
if(item->encoded_data_len > 0)
{
item->encoded_data = (void*)malloc(item->encoded_data_len) ;
memcpy(item->encoded_data, (void*)((unsigned char*)data+offset), item->encoded_data_len);
}
else
item->encoded_data = NULL ;
if ((offset + item->encoded_data_len) != rssize)
{

View File

@ -47,6 +47,8 @@ class RsTunnelItem: public RsItem
public:
RsTunnelItem(uint8_t tunnel_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TUNNEL,tunnel_subtype) {}
virtual ~RsTunnelItem() {}
virtual bool serialize(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialize themselves ?
virtual uint32_t serial_size() { return 0;}
@ -56,8 +58,13 @@ class RsTunnelItem: public RsItem
class RsTunnelDataItem: public RsTunnelItem
{
public:
RsTunnelDataItem() : RsTunnelItem(RS_TUNNEL_SUBTYPE_DATA) {}
RsTunnelDataItem(void *data,uint32_t size) ; // deserialization
RsTunnelDataItem() : RsTunnelItem(RS_TUNNEL_SUBTYPE_DATA)
{
encoded_data = NULL ; // To comply with the destructor below.
}
virtual ~RsTunnelDataItem() ;
static RsTunnelDataItem *deserialise(void *data,uint32_t size) ; // deserialization
uint32_t encoded_data_len;
void *encoded_data;
@ -76,7 +83,9 @@ class RsTunnelHandshakeItem: public RsTunnelItem
{
public:
RsTunnelHandshakeItem() : RsTunnelItem(RS_TUNNEL_SUBTYPE_HANDSHAKE) {}
RsTunnelHandshakeItem(void *data,uint32_t size) ; // deserialization
virtual ~RsTunnelHandshakeItem() {}
static RsTunnelHandshakeItem *deserialise(void *data,uint32_t size) ; // deserialization
std::string sourcePeerId ;
std::string relayPeerId ;

View File

@ -44,13 +44,13 @@
#define TUNNEL_HANDSHAKE_ACK 2
#define TUNNEL_HANDSHAKE_REFUSE 0
p3tunnel::p3tunnel(p3ConnectMgr *cm, pqipersongrp *perGrp)
:p3Service(RS_SERVICE_TYPE_TUNNEL), mConnMgr(cm), mPqiPersonGrp(perGrp)
p3tunnel::p3tunnel(p3ConnectMgr *cm, pqipersongrp *perGrp)
:p3Service(RS_SERVICE_TYPE_TUNNEL), mConnMgr(cm), mPqiPersonGrp(perGrp)
{
RsStackMutex stack(mTunnelMtx); /********** STACK LOCKED MTX ******/
ownId = mConnMgr->getOwnId();
std::cerr << "ownId : " << mConnMgr->getOwnId() << std::endl;
std::cerr << "ownId : " << mConnMgr->getOwnId() << std::endl;
addSerialType(new RsTunnelSerialiser());
return;
@ -69,39 +69,39 @@ int p3tunnel::handleIncoming()
RsItem *item = NULL;
#ifdef P3TUNNEL_DEBUG
//std::cerr << "p3tunnel::handleIncoming() called." << std::endl;
//std::cerr << "p3tunnel::handleIncoming() called." << std::endl;
#endif
int nhandled = 0;
// While messages read
while(NULL != (item = recvItem()))
{
if (!mConnMgr->getTunnelConnection()) {
//no tunnel allowed, just drop the packet
continue;
}
{
if (!mConnMgr->getTunnelConnection()) {
//no tunnel allowed, just drop the packet
continue;
}
RsTunnelDataItem *tdi = NULL;
RsTunnelHandshakeItem *thi = NULL;
RsTunnelHandshakeItem *thi = NULL;
{
#ifdef P3TUNNEL_DEBUG
#ifdef P3TUNNEL_DEBUG
std::ostringstream out;
out << "p3tunnel::handleIncoming()";
out << " Received Message!" << std::endl;
item -> print(out);
std::cerr << out.str();
#endif
item -> print(out);
std::cerr << out.str();
#endif
}
if (NULL != (tdi = dynamic_cast<RsTunnelDataItem *> (item))) {
recvTunnelData(tdi);
if (NULL != (tdi = dynamic_cast<RsTunnelDataItem *> (item))) {
recvTunnelData(tdi);
nhandled++;
} else if (NULL != (thi = dynamic_cast<RsTunnelHandshakeItem *> (item))) {
recvTunnelHandshake(thi);
nhandled++;
}
delete item;
} else if (NULL != (thi = dynamic_cast<RsTunnelHandshakeItem *> (item))) {
recvTunnelHandshake(thi);
nhandled++;
}
delete item;
}
return nhandled;
}
@ -110,74 +110,77 @@ int p3tunnel::handleIncoming()
/* Output Network Msgs */
/*************************************************************************************/
void p3tunnel::sendTunnelData(std::string destPeerId, std::string relayPeerId, void *data, int data_length) {
sendTunnelDataPrivate(relayPeerId, ownId,relayPeerId, destPeerId, data, data_length);
sendTunnelDataPrivate(relayPeerId, ownId,relayPeerId, destPeerId, data, data_length);
}
void p3tunnel::sendTunnelDataPrivate(std::string to, std::string sourcePeerId, std::string relayPeerId, std::string destPeerId, void *data, int data_length) {
if (!mConnMgr->getTunnelConnection()) {
//no tunnel allowed, just drop the request
return;
}
if (!mConnMgr->getTunnelConnection()) {
//no tunnel allowed, just drop the request
return;
}
RsStackMutex stack(mTunnelMtx); /********** STACK LOCKED MTX ******/
RsStackMutex stack(mTunnelMtx); /********** STACK LOCKED MTX ******/
// Then send message.
{
#ifdef P3TUNNEL_DEBUG
std::ostringstream out;
out << "p3tunnel::sendTunnelDataPrivate() Constructing a RsTunnelItem Message!" << std::endl;
out << "Sending to: " << to;
std::cerr << out.str() << std::endl;
#endif
#ifdef P3TUNNEL_DEBUG
std::ostringstream out;
out << "p3tunnel::sendTunnelDataPrivate() Constructing a RsTunnelItem Message!" << std::endl;
out << "Sending to: " << to;
std::cerr << out.str() << std::endl;
#endif
}
// Construct a message
RsTunnelDataItem *rdi = new RsTunnelDataItem();
rdi->destPeerId = destPeerId;
rdi->sourcePeerId = sourcePeerId;
rdi->relayPeerId = relayPeerId;
rdi->relayPeerId = relayPeerId;
rdi->encoded_data_len = data_length;
rdi->encoded_data = (void*)malloc(data_length);
memcpy(rdi->encoded_data, data, data_length);
if(data_length > 0)
{
rdi->encoded_data = (void*)malloc(data_length);
memcpy(rdi->encoded_data, data, data_length);
}
rdi->PeerId(to);
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::sendTunnelDataPrivate() data_length : "<< data_length << std::endl;
#endif
/* send msg */
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::sendTunnelDataPrivate() data_length : "<< data_length << std::endl;
#endif
/* send msg */
sendItem(rdi);
}
void p3tunnel::pingTunnelConnection(std::string relayPeerId, std::string destPeerId) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::pingTunnelConnection() sending ping with relay id : " << relayPeerId << std::endl;
std::cerr << "ownId : " << ownId << std::endl;
std::cerr << "destPeerId : " << destPeerId << std::endl;
std::cerr << "p3tunnel::pingTunnelConnection() sending ping with relay id : " << relayPeerId << std::endl;
std::cerr << "ownId : " << ownId << std::endl;
std::cerr << "destPeerId : " << destPeerId << std::endl;
#endif
this->sendTunnelDataPrivate(relayPeerId, ownId, relayPeerId, destPeerId, NULL, 0);
this->sendTunnelDataPrivate(relayPeerId, ownId, relayPeerId, destPeerId, NULL, 0);
}
void p3tunnel::initiateHandshake(std::string relayPeerId, std::string destPeerId) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::initiateHandshake() initiating handshake with relay id : " << relayPeerId << std::endl;
std::cerr << "ownId : " << ownId << std::endl;
std::cerr << "destPeerId : " << destPeerId << std::endl;
#endif
// Construct a message
RsTunnelHandshakeItem *rhi = new RsTunnelHandshakeItem();
rhi->destPeerId = destPeerId;
rhi->sourcePeerId = ownId;
rhi->relayPeerId = relayPeerId;
rhi->connection_accepted = TUNNEL_HANDSHAKE_INIT;
rhi->sslCertPEM = AuthSSL::getAuthSSL()->SaveOwnCertificateToString();
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::initiateHandshake() initiating handshake with relay id : " << relayPeerId << std::endl;
std::cerr << "ownId : " << ownId << std::endl;
std::cerr << "destPeerId : " << destPeerId << std::endl;
#endif
// Construct a message
RsTunnelHandshakeItem *rhi = new RsTunnelHandshakeItem();
rhi->destPeerId = destPeerId;
rhi->sourcePeerId = ownId;
rhi->relayPeerId = relayPeerId;
rhi->connection_accepted = TUNNEL_HANDSHAKE_INIT;
rhi->sslCertPEM = AuthSSL::getAuthSSL()->SaveOwnCertificateToString();
rhi->PeerId(relayPeerId);
rhi->PeerId(relayPeerId);
/* send msg */
sendItem(rhi);
/* send msg */
sendItem(rhi);
}
/*************************************************************************************/
@ -185,164 +188,164 @@ void p3tunnel::initiateHandshake(std::string relayPeerId, std::string destPeerId
/*************************************************************************************/
void p3tunnel::recvTunnelHandshake(RsTunnelHandshakeItem *item)
{
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvTunnelHandshake() From: " << item->PeerId() << std::endl;
#endif
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvTunnelHandshake() From: " << item->PeerId() << std::endl;
#endif
RsPeerDetails pd;
if (!AuthSSL::getAuthSSL()->LoadDetailsFromStringCert(item->sslCertPEM, pd)) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvTunnelHandshake() cert is not valid. This might be a intrusion attempt." << std::endl;
#endif
return;
}
RsPeerDetails pd;
if (!AuthSSL::getAuthSSL()->LoadDetailsFromStringCert(item->sslCertPEM, pd)) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvTunnelHandshake() cert is not valid. This might be a intrusion attempt." << std::endl;
#endif
return;
}
if (item->sourcePeerId != pd.id) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvTunnelHandshake() cert is not issued from the source id of the tunnel. This might be a intrusion attempt." << std::endl;
#endif
return;
}
if (item->sourcePeerId != pd.id) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvTunnelHandshake() cert is not issued from the source id of the tunnel. This might be a intrusion attempt." << std::endl;
#endif
return;
}
//compare the peer id from the item sender to the ids in the item.
if (item->PeerId() == item->sourcePeerId && ownId == item->relayPeerId) {
if (mConnMgr->isOnline(item->destPeerId)) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvTunnelHandshake() relaying packet." << std::endl;
#endif
//relaying the handshake
RsTunnelHandshakeItem* forwardItem = new RsTunnelHandshakeItem();
forwardItem->sourcePeerId = item->sourcePeerId;
forwardItem->relayPeerId = item->relayPeerId;
forwardItem->destPeerId = item->destPeerId;
forwardItem->connection_accepted = item->connection_accepted;
forwardItem->sslCertPEM = item->sslCertPEM;
forwardItem->PeerId(item->destPeerId);
sendItem(forwardItem);
} else {
//sending back refuse
//not implemented
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvTunnelHandshake() not relaying packet because destination is offline." << std::endl;
#endif
}
} else if (item->PeerId() == item->relayPeerId && ownId == item->destPeerId) {
if (item->connection_accepted == TUNNEL_HANDSHAKE_INIT || item->connection_accepted == TUNNEL_HANDSHAKE_ACK) {
//check if we accept connection
if (!mConnMgr->isFriend(pd.id)) {
//send back a refuse
// not implemented
} else {
if (item->connection_accepted == TUNNEL_HANDSHAKE_INIT) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvTunnelHandshake() sending back acknowledgement to " << item->sourcePeerId << std::endl;
#endif
//send back acknowledgement
RsTunnelHandshakeItem* ack = new RsTunnelHandshakeItem();
ack->sourcePeerId = ownId;
ack->relayPeerId = item->relayPeerId;
ack->destPeerId = item->sourcePeerId;
ack->connection_accepted = TUNNEL_HANDSHAKE_ACK;
ack->sslCertPEM = AuthSSL::getAuthSSL()->SaveOwnCertificateToString();
ack->PeerId(item->relayPeerId);
sendItem(ack);
}
//compare the peer id from the item sender to the ids in the item.
if (item->PeerId() == item->sourcePeerId && ownId == item->relayPeerId) {
if (mConnMgr->isOnline(item->destPeerId)) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvTunnelHandshake() relaying packet." << std::endl;
#endif
//relaying the handshake
RsTunnelHandshakeItem* forwardItem = new RsTunnelHandshakeItem();
forwardItem->sourcePeerId = item->sourcePeerId;
forwardItem->relayPeerId = item->relayPeerId;
forwardItem->destPeerId = item->destPeerId;
forwardItem->connection_accepted = item->connection_accepted;
forwardItem->sslCertPEM = item->sslCertPEM;
forwardItem->PeerId(item->destPeerId);
sendItem(forwardItem);
} else {
//sending back refuse
//not implemented
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvTunnelHandshake() not relaying packet because destination is offline." << std::endl;
#endif
}
} else if (item->PeerId() == item->relayPeerId && ownId == item->destPeerId) {
if (item->connection_accepted == TUNNEL_HANDSHAKE_INIT || item->connection_accepted == TUNNEL_HANDSHAKE_ACK) {
//check if we accept connection
if (!mConnMgr->isFriend(pd.id)) {
//send back a refuse
// not implemented
} else {
if (item->connection_accepted == TUNNEL_HANDSHAKE_INIT) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvTunnelHandshake() sending back acknowledgement to " << item->sourcePeerId << std::endl;
#endif
//send back acknowledgement
RsTunnelHandshakeItem* ack = new RsTunnelHandshakeItem();
ack->sourcePeerId = ownId;
ack->relayPeerId = item->relayPeerId;
ack->destPeerId = item->sourcePeerId;
ack->connection_accepted = TUNNEL_HANDSHAKE_ACK;
ack->sslCertPEM = AuthSSL::getAuthSSL()->SaveOwnCertificateToString();
ack->PeerId(item->relayPeerId);
sendItem(ack);
}
//open the local tunnel connection
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvTunnelHandshake() opening localy the tunnel connection emulation." << std::endl;
#endif
pqiperson *pers = mPqiPersonGrp->getPeer(item->sourcePeerId);
pqissltunnel *pqicon = (pqissltunnel *)(((pqiconnect *) pers->getKid(PQI_CONNECT_TUNNEL))->ni);
pqicon->IncommingHanshakePacket(item->relayPeerId);
}
}
}
//open the local tunnel connection
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvTunnelHandshake() opening localy the tunnel connection emulation." << std::endl;
#endif
pqiperson *pers = mPqiPersonGrp->getPeer(item->sourcePeerId);
pqissltunnel *pqicon = (pqissltunnel *)(((pqiconnect *) pers->getKid(PQI_CONNECT_TUNNEL))->ni);
pqicon->IncommingHanshakePacket(item->relayPeerId);
}
}
}
}
void p3tunnel::recvTunnelData(RsTunnelDataItem *item)
{
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvPeerConnectRequest() From: " << item->PeerId() << std::endl;
#endif
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::recvPeerConnectRequest() From: " << item->PeerId() << std::endl;
#endif
//compare the peer id from the item sender to the ids in the item.
if (item->PeerId() == item->sourcePeerId && ownId == item->relayPeerId) {
privateRecvTunnelDataRelaying(item);
} else if (item->PeerId() == item->relayPeerId && ownId == item->destPeerId) {
privateRecvTunnelDataDestination(item);
}
}
}
void p3tunnel::privateRecvTunnelDataRelaying(RsTunnelDataItem *item) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataRelaying() I am relaying, let's see if it's possible to send the packet to destination." << std::endl;
#endif
if (!mConnMgr->isFriend(item->sourcePeerId) || !mConnMgr->isFriend(item->destPeerId)) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() not trusting relay or dest peer. Aborting." << std::endl;
#endif
return;
}
if (mConnMgr->isOnline(item->destPeerId)) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataRelaying() I am relaying, relay the packet to destination." << std::endl;
#endif
sendTunnelDataPrivate(item->destPeerId, item->sourcePeerId, ownId, item->destPeerId, item->encoded_data, item->encoded_data_len);
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataRelaying() I am relaying, let's see if it's possible to send the packet to destination." << std::endl;
#endif
if (!mConnMgr->isFriend(item->sourcePeerId) || !mConnMgr->isFriend(item->destPeerId)) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() not trusting relay or dest peer. Aborting." << std::endl;
#endif
return;
}
}
if (mConnMgr->isOnline(item->destPeerId)) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataRelaying() I am relaying, relay the packet to destination." << std::endl;
#endif
sendTunnelDataPrivate(item->destPeerId, item->sourcePeerId, ownId, item->destPeerId, item->encoded_data, item->encoded_data_len);
return;
}
}
void p3tunnel::privateRecvTunnelDataDestination(RsTunnelDataItem *item) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() I am the destination Id, let's make some checks and read the packet." << std::endl;
#endif
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() I am the destination Id, let's make some checks and read the packet." << std::endl;
#endif
if (!mConnMgr->isFriend(item->sourcePeerId) || !mConnMgr->isFriend(item->relayPeerId)) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() not trusting relay or source peer. Aborting." << std::endl;
#endif
return;
}
if (!mConnMgr->isOnline(item->relayPeerId)) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() relay peer is not connected, connection impossible. Aborting." << std::endl;
#endif
if (!mConnMgr->isFriend(item->sourcePeerId) || !mConnMgr->isFriend(item->relayPeerId)) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() not trusting relay or source peer. Aborting." << std::endl;
#endif
return;
}
}
pqiperson *pers = mPqiPersonGrp->getPeer(item->sourcePeerId);
if (pers == NULL) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() tunnel connection not found. Aborting." << std::endl;
#endif
return;
}
pqissltunnel *pqicon = (pqissltunnel *)(((pqiconnect *) pers->getKid(PQI_CONNECT_TUNNEL))->ni);
if (pqicon == NULL || !pqicon->isactive()) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() tunnel connection not found. Aborting." << std::endl;
#endif
if (!mConnMgr->isOnline(item->relayPeerId)) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() relay peer is not connected, connection impossible. Aborting." << std::endl;
#endif
return;
}
}
//send the packet to the net emulation layer
if (item->encoded_data_len == 0) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() receiving a ping packet, activating connection and sending back acknowlegment." << std::endl;
#endif
pqiperson *pers = mPqiPersonGrp->getPeer(item->sourcePeerId);
if (pers == NULL) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() tunnel connection not found. Aborting." << std::endl;
#endif
return;
}
pqissltunnel *pqicon = (pqissltunnel *)(((pqiconnect *) pers->getKid(PQI_CONNECT_TUNNEL))->ni);
if (pqicon == NULL || !pqicon->isactive()) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() tunnel connection not found. Aborting." << std::endl;
#endif
return;
}
//send the packet to the net emulation layer
if (item->encoded_data_len == 0) {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() receiving a ping packet, activating connection and sending back acknowlegment." << std::endl;
#endif
pqissltunnel *pqicon = (pqissltunnel *)(((pqiconnect *) pers->getKid(PQI_CONNECT_TUNNEL))->ni);
pqicon->IncommingPingPacket();
} else {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() receiving a data packet, transfer it to the pqissltunnel connection." << std::endl;
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() getRsItemSize(item->encoded_data) : " << getRsItemSize(item->encoded_data) << std::endl;
#endif
pqicon->IncommingPingPacket();
} else {
#ifdef P3TUNNEL_DEBUG
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() receiving a data packet, transfer it to the pqissltunnel connection." << std::endl;
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() getRsItemSize(item->encoded_data) : " << getRsItemSize(item->encoded_data) << std::endl;
#endif
pqissltunnel *pqicon = (pqissltunnel *)(((pqiconnect *) pers->getKid(PQI_CONNECT_TUNNEL))->ni);
pqicon->addIncomingPacket(item->encoded_data, item->encoded_data_len);
}
return;
}
return;
}