mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-02 03:06:31 -04:00
moved some files to unfinished and deleted soem unused files
This commit is contained in:
parent
602bc36eec
commit
ddca91b0c9
16 changed files with 0 additions and 1206 deletions
254
libretroshare/src/unfinished/mail/directmailservice.cc
Normal file
254
libretroshare/src/unfinished/mail/directmailservice.cc
Normal file
|
@ -0,0 +1,254 @@
|
|||
/*
|
||||
* libretroshare/src/services directmailservice.cc
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2014 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "services/mail/directmailservice.h"
|
||||
|
||||
#include "util/rsdebug.h"
|
||||
|
||||
//#define MSG_DEBUG 1
|
||||
|
||||
const int directmailzone = 54319;
|
||||
|
||||
using namespace Rs::Mail;
|
||||
|
||||
|
||||
DirectMailService::DirectMailService(p3ServiceControl *sc)
|
||||
:MailTransport(DEFAULT_MAX_MESSAGE_SIZE, RS_SERVICE_TYPE_DIRECT_MAIL),
|
||||
p3Service(), mServiceCtrl(sc), mMsgMtx("DirectMailService")
|
||||
{
|
||||
mSerialiser = new RsMailTransportSerialiser(RS_SERVICE_TYPE_DIRECT_MAIL);
|
||||
addSerialType(mSerialiser);
|
||||
}
|
||||
|
||||
const std::string MSGDIRECT_APP_NAME = "msgdirect";
|
||||
const uint16_t MSGDIRECT_APP_MAJOR_VERSION = 1;
|
||||
const uint16_t MSGDIRECT_APP_MINOR_VERSION = 0;
|
||||
const uint16_t MSGDIRECT_MIN_MAJOR_VERSION = 1;
|
||||
const uint16_t MSGDIRECT_MIN_MINOR_VERSION = 0;
|
||||
|
||||
RsServiceInfo DirectMailService::getServiceInfo()
|
||||
{
|
||||
return RsServiceInfo(RS_SERVICE_TYPE_DIRECT_MAIL,
|
||||
MSGDIRECT_APP_NAME,
|
||||
MSGDIRECT_APP_MAJOR_VERSION,
|
||||
MSGDIRECT_APP_MINOR_VERSION,
|
||||
MSGDIRECT_MIN_MAJOR_VERSION,
|
||||
MSGDIRECT_MIN_MINOR_VERSION);
|
||||
}
|
||||
|
||||
|
||||
bool DirectMailService::CanSend(const RsTlvMailAddress &addr)
|
||||
{
|
||||
/* we can send if MessageAddress is a peerID,
|
||||
* and the peer ID is a friend.
|
||||
*/
|
||||
if (addr.mAddressType == ADDRESS_TYPE_PEER_ID)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DirectMailService::sendMail(RsMailChunkItem *item)
|
||||
{
|
||||
// set the right serviceId.
|
||||
item->setPacketService(RS_SERVICE_TYPE_DIRECT_MAIL);
|
||||
if (!attemptToSend(item))
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
mOutgoingMsgs.push_back(item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
RsMailChunkItem *DirectMailService::recvMail()
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
if (!mIncomingMsgs.empty())
|
||||
{
|
||||
RsMailChunkItem *item = mIncomingMsgs.front();
|
||||
mIncomingMsgs.pop_front();
|
||||
return item;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RsPeerId convertAddressToPeerId(RsMailAckItem *item)
|
||||
{
|
||||
RsPeerId id;
|
||||
return id;
|
||||
}
|
||||
|
||||
bool DirectMailService::sendMailAck(RsMailAckItem *item)
|
||||
{
|
||||
// set the right serviceId.
|
||||
item->setPacketService(RS_SERVICE_TYPE_DIRECT_MAIL);
|
||||
item->PeerId(convertAddressToPeerId(item));
|
||||
if (!attemptToSend(item))
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
mOutgoingMsgs.push_back(item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
RsMailAckItem *DirectMailService::recvMailAck()
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
if (!mIncomingAckMsgs.empty())
|
||||
{
|
||||
RsMailAckItem *item = mIncomingAckMsgs.front();
|
||||
mIncomingMsgs.pop_front();
|
||||
|
||||
return item;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int DirectMailService::tick()
|
||||
{
|
||||
rslog(RSL_DEBUG_BASIC, directmailzone,
|
||||
"DirectMailService::tick()");
|
||||
|
||||
incomingMsgs();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int DirectMailService::status()
|
||||
{
|
||||
rslog(RSL_DEBUG_BASIC, directmailzone,
|
||||
"DirectMailService::status()");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void DirectMailService::statusChange(const std::list<pqiServicePeer> &plist)
|
||||
{
|
||||
/* should do it properly! */
|
||||
/* only do this when a new peer is connected */
|
||||
bool newPeers = false;
|
||||
std::list<pqiServicePeer>::const_iterator it;
|
||||
for(it = plist.begin(); it != plist.end(); it++)
|
||||
{
|
||||
if (it->actions & RS_SERVICE_PEER_CONNECTED)
|
||||
{
|
||||
newPeers = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (newPeers)
|
||||
{
|
||||
checkOutgoingMessages();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int DirectMailService::incomingMsgs()
|
||||
{
|
||||
RsItem *item;
|
||||
int i = 0;
|
||||
|
||||
while((item = recvItem()) != NULL)
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
RsMailChunkItem *mi = dynamic_cast<RsMailChunkItem *>(item);
|
||||
RsMailAckItem *mai = dynamic_cast<RsMailAckItem *>(item);
|
||||
if (mi)
|
||||
{
|
||||
mIncomingMsgs.push_back(mi);
|
||||
}
|
||||
else if (mai)
|
||||
{
|
||||
mIncomingAckMsgs.push_back(mai);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "DirectMailService::incomingMsgs() Unknown incoming Msg";
|
||||
std::cerr << std::endl;
|
||||
delete item;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
// This is a Local copy of an Outgoing message - either SentBox or Draft.
|
||||
bool DirectMailService::attemptToSend(RsItem *mi)
|
||||
{
|
||||
RsPeerId pid = mi->PeerId();
|
||||
if (mServiceCtrl->isPeerConnected(getServiceInfo().mServiceType, pid))
|
||||
{
|
||||
sendItem(mi);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void DirectMailService::checkOutgoingMessages()
|
||||
{
|
||||
/* iterate through the outgoing queue and attempt to send.
|
||||
*/
|
||||
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::list<RsItem *>::iterator mit;
|
||||
for(mit = mOutgoingMsgs.begin(); mit != mOutgoingMsgs.end(); mit++)
|
||||
{
|
||||
if (attemptToSend(*mit))
|
||||
{
|
||||
/* actually sent the message */
|
||||
mit = mOutgoingMsgs.erase(mit);
|
||||
}
|
||||
else
|
||||
{
|
||||
mit++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DirectMailService::haveIncomingMail()
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
if (!mIncomingMsgs.empty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!mIncomingAckMsgs.empty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
92
libretroshare/src/unfinished/mail/directmailservice.h
Normal file
92
libretroshare/src/unfinished/mail/directmailservice.h
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* libretroshare/src/services/mail directmailservice.h
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2014 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DIRECT_MAIL_SERVICE_HEADER
|
||||
#define DIRECT_MAIL_SERVICE_HEADER
|
||||
|
||||
#include "services/mail/mailtransport.h"
|
||||
#include "services/p3service.h"
|
||||
|
||||
#include "pqi/pqiservicemonitor.h"
|
||||
|
||||
#include "util/rsthreads.h"
|
||||
|
||||
|
||||
namespace Rs
|
||||
{
|
||||
namespace Mail
|
||||
{
|
||||
|
||||
class DirectMailService: public MailTransport, public p3Service, public pqiServiceMonitor
|
||||
{
|
||||
|
||||
public:
|
||||
DirectMailService(p3ServiceControl *sc);
|
||||
virtual RsServiceInfo getServiceInfo();
|
||||
|
||||
/******* MailTransport Interface ********************************************************/
|
||||
|
||||
virtual bool CanSend(const RsTlvMailAddress &addr);
|
||||
virtual bool haveIncomingMail();
|
||||
|
||||
virtual bool sendMail(RsMailChunkItem *msg);
|
||||
virtual RsMailChunkItem *recvMail();
|
||||
virtual bool sendMailAck(RsMailAckItem *ack);
|
||||
virtual RsMailAckItem *recvMailAck();
|
||||
|
||||
/******* MsgTransport Interface ********************************************************/
|
||||
|
||||
int tick();
|
||||
int status();
|
||||
|
||||
/*** Overloaded from pqiMonitor ***/
|
||||
virtual void statusChange(const std::list<pqiServicePeer> &plist);
|
||||
/*** Overloaded from pqiMonitor ***/
|
||||
|
||||
private:
|
||||
|
||||
int incomingMsgs();
|
||||
void checkOutgoingMessages();
|
||||
bool attemptToSend(RsItem *item);
|
||||
|
||||
p3ServiceControl *mServiceCtrl;
|
||||
|
||||
/* Mutex Required for stuff below */
|
||||
RsMutex mMsgMtx;
|
||||
RsMailTransportSerialiser *mSerialiser ;
|
||||
|
||||
/* outgoing messages */
|
||||
std::list<RsItem *> mOutgoingMsgs;
|
||||
|
||||
/* incoming msgs */
|
||||
std::list<RsMailChunkItem *> mIncomingMsgs;
|
||||
std::list<RsMailAckItem *> mIncomingAckMsgs;
|
||||
};
|
||||
|
||||
} // namspace Msg
|
||||
} // namspace Rs
|
||||
|
||||
#endif // DIRECT_MESSAGE_SERVICE_HEADER
|
56
libretroshare/src/unfinished/mail/mailtransport.cc
Normal file
56
libretroshare/src/unfinished/mail/mailtransport.cc
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* libretroshare/src/services/mail mailtransport.cc
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2014 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "services/mail/mailtransport.h"
|
||||
|
||||
using namespace Rs::Mail;
|
||||
|
||||
MailTransport::MailTransport(uint32_t max_size, uint16_t transport_type)
|
||||
:mEnabled(true), mMaxSize(max_size), mTransportType(transport_type)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool MailTransport::isEnabled()
|
||||
{
|
||||
return mEnabled;
|
||||
}
|
||||
|
||||
void MailTransport::setEnabled(bool enabled)
|
||||
{
|
||||
mEnabled = enabled;
|
||||
}
|
||||
|
||||
uint32_t MailTransport::getMaxSize()
|
||||
{
|
||||
return mMaxSize;
|
||||
}
|
||||
|
||||
uint16_t MailTransport::getTransportType()
|
||||
{
|
||||
return mTransportType;
|
||||
}
|
||||
|
||||
|
77
libretroshare/src/unfinished/mail/mailtransport.h
Normal file
77
libretroshare/src/unfinished/mail/mailtransport.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
#pragma once
|
||||
#ifndef RS_MAIL_TRANSPORT_HEADER
|
||||
#define RS_MAIL_TRANSPORT_HEADER
|
||||
/*
|
||||
* libretroshare/src/services/mail mailtransport.h
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2014 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "serialiser/rsmailtransportitems.h"
|
||||
|
||||
|
||||
namespace Rs
|
||||
{
|
||||
namespace Mail
|
||||
{
|
||||
|
||||
const uint32_t DEFAULT_MAX_MESSAGE_SIZE = (64 * 1024);
|
||||
|
||||
// To decide how this will work!
|
||||
const uint32_t ADDRESS_TYPE_PEER_ID = 0x001;
|
||||
const uint32_t ADDRESS_TYPE_GXS_ID = 0x002;
|
||||
const uint32_t ADDRESS_TYPE_EMAIL_ID = 0x003;
|
||||
|
||||
|
||||
class MailTransport
|
||||
{
|
||||
public:
|
||||
MailTransport(uint32_t max_size, uint16_t transport_type);
|
||||
virtual ~MailTransport();
|
||||
|
||||
virtual bool CanSend(const RsTlvMailAddress &addr) = 0;
|
||||
virtual bool haveIncomingMail() = 0;
|
||||
|
||||
virtual bool sendMail(RsMailChunkItem *msg) = 0;
|
||||
virtual RsMailChunkItem *recvMail() = 0;
|
||||
virtual bool sendMailAck(RsMailAckItem *ack) = 0;
|
||||
virtual RsMailAckItem *recvMailAck() = 0;
|
||||
|
||||
virtual bool isEnabled();
|
||||
virtual void setEnabled(bool enabled);
|
||||
|
||||
uint32_t getMaxSize();
|
||||
uint16_t getTransportType();
|
||||
|
||||
private:
|
||||
|
||||
bool mEnabled;
|
||||
uint32_t mMaxSize;
|
||||
uint16_t mTransportType;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Mail
|
||||
} // namespace Rs
|
||||
|
||||
#endif
|
347
libretroshare/src/unfinished/p3tunnel.cc
Normal file
347
libretroshare/src/unfinished/p3tunnel.cc
Normal file
|
@ -0,0 +1,347 @@
|
|||
/*
|
||||
* libretroshare/src/services: p3tunnel.cc
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2004-2008 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
//#include "retroshare/rsiface.h"
|
||||
//#include "retroshare/rsinit.h" /* for PGPSSL flag */
|
||||
//#include "retroshare/rspeers.h"
|
||||
#include "services/p3tunnel.h"
|
||||
#include "pqi/pqissltunnel.h"
|
||||
|
||||
#include "pqi/authssl.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "util/rsdebug.h"
|
||||
#include "util/rsprint.h"
|
||||
#include "util/rsversion.h"
|
||||
|
||||
#define TUNNEL_HANDSHAKE_INIT 1
|
||||
#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)
|
||||
{
|
||||
RsStackMutex stack(mTunnelMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
ownId = mConnMgr->getOwnId();
|
||||
std::cerr << "ownId : " << mConnMgr->getOwnId() << std::endl;
|
||||
addSerialType(new RsTunnelSerialiser());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void p3tunnel::statusChange(const std::list<pqipeer> &plist) {
|
||||
}
|
||||
|
||||
int p3tunnel::tick()
|
||||
{
|
||||
return handleIncoming();
|
||||
}
|
||||
|
||||
int p3tunnel::handleIncoming()
|
||||
{
|
||||
RsItem *item = NULL;
|
||||
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
//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;
|
||||
}
|
||||
|
||||
RsTunnelDataItem *tdi = NULL;
|
||||
RsTunnelHandshakeItem *thi = NULL;
|
||||
|
||||
{
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::string out = "p3tunnel::handleIncoming() Received Message!\n";
|
||||
item -> print_string(out);
|
||||
std::cerr << out;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (NULL != (tdi = dynamic_cast<RsTunnelDataItem *> (item))) {
|
||||
recvTunnelData(tdi);
|
||||
nhandled++;
|
||||
} else if (NULL != (thi = dynamic_cast<RsTunnelHandshakeItem *> (item))) {
|
||||
recvTunnelHandshake(thi);
|
||||
nhandled++;
|
||||
}
|
||||
delete item;
|
||||
}
|
||||
return nhandled;
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
RsStackMutex stack(mTunnelMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
// Then send message.
|
||||
{
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::string out = "p3tunnel::sendTunnelDataPrivate() Constructing a RsTunnelItem Message!\n";
|
||||
out += "Sending to: " + to;
|
||||
std::cerr << out << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Construct a message
|
||||
RsTunnelDataItem *rdi = new RsTunnelDataItem();
|
||||
rdi->destPeerId = destPeerId;
|
||||
rdi->sourcePeerId = sourcePeerId;
|
||||
rdi->relayPeerId = relayPeerId;
|
||||
rdi->encoded_data_len = 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 */
|
||||
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;
|
||||
#endif
|
||||
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();
|
||||
|
||||
rhi->PeerId(relayPeerId);
|
||||
|
||||
/* send msg */
|
||||
sendItem(rhi);
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
/* Input Network Msgs */
|
||||
/*************************************************************************************/
|
||||
void p3tunnel::recvTunnelHandshake(RsTunnelHandshakeItem *item)
|
||||
{
|
||||
#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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//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
|
||||
|
||||
//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);
|
||||
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
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
pqissltunnel *pqicon = (pqissltunnel *)(((pqiconnect *) pers->getKid(PQI_CONNECT_TUNNEL))->ni);
|
||||
pqicon->addIncomingPacket(item->encoded_data, item->encoded_data_len);
|
||||
}
|
||||
return;
|
||||
}
|
82
libretroshare/src/unfinished/p3tunnel.h
Normal file
82
libretroshare/src/unfinished/p3tunnel.h
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* libretroshare/src/services: p3tunnel.h
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2004-2008 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MRK_PQI_TUNNEL_H
|
||||
#define MRK_PQI_TUNNEL_H
|
||||
|
||||
// The AutoDiscovery Class
|
||||
|
||||
#include "pqi/pqipersongrp.h"
|
||||
|
||||
// system specific network headers
|
||||
#include "pqi/pqi.h"
|
||||
|
||||
class p3ConnectMgr;
|
||||
|
||||
#include "pqi/pqimonitor.h"
|
||||
#include "services/p3service.h"
|
||||
#include "serialiser/rstunnelitems.h"
|
||||
#include "pqi/authssl.h"
|
||||
|
||||
class p3tunnel: public p3Service, public pqiMonitor
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void statusChange(const std::list<pqipeer> &plist);
|
||||
|
||||
p3tunnel(p3ConnectMgr *cm, pqipersongrp *persGrp);
|
||||
|
||||
int tick();
|
||||
|
||||
void sendTunnelData(std::string destPeerId, std::string relayPeerId, void *data, int data_length);
|
||||
|
||||
void pingTunnelConnection(std::string relayPeerId, std::string destPeerId);
|
||||
void initiateHandshake(std::string relayPeerId, std::string destPeerId);
|
||||
|
||||
private:
|
||||
|
||||
void sendTunnelDataPrivate(std::string to, std::string sourcePeerId, std::string relayPeerId, std::string destPeerId, void *data, int data_length);
|
||||
|
||||
void privateRecvTunnelDataRelaying(RsTunnelDataItem *item); //invoked when I am relaying
|
||||
void privateRecvTunnelDataDestination(RsTunnelDataItem *item); //invoked when I am the destination of the tunnel
|
||||
|
||||
/* Network Input */
|
||||
int handleIncoming();
|
||||
void recvTunnelData(RsTunnelDataItem *item);
|
||||
void recvTunnelHandshake(RsTunnelHandshakeItem *item);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
pqipersongrp *mPqiPersonGrp;
|
||||
std::string ownId;
|
||||
|
||||
|
||||
/* data */
|
||||
RsMutex mTunnelMtx;
|
||||
};
|
||||
|
||||
#endif // MRK_PQI_TUNNEL_H
|
419
libretroshare/src/unfinished/rstlvdsdv.cc
Normal file
419
libretroshare/src/unfinished/rstlvdsdv.cc
Normal file
|
@ -0,0 +1,419 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvtypes.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie, Chris Parker
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "rstlvdsdv.h"
|
||||
#include "rsbaseserial.h"
|
||||
|
||||
|
||||
/************************************* RsTlvDsdvEndPoint ************************************/
|
||||
|
||||
RsTlvDsdvEndPoint::RsTlvDsdvEndPoint()
|
||||
:RsTlvItem(), idType(0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void RsTlvDsdvEndPoint::TlvClear()
|
||||
{
|
||||
idType = 0;
|
||||
anonChunk.clear();
|
||||
serviceId.clear();
|
||||
}
|
||||
|
||||
uint32_t RsTlvDsdvEndPoint::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header + 4 + str + str */
|
||||
|
||||
s += 4; // idType;
|
||||
s += GetTlvStringSize(anonChunk);
|
||||
s += GetTlvStringSize(serviceId);
|
||||
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvDsdvEndPoint::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
/* add mandatory parts first */
|
||||
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_DSDV_ENDPOINT, tlvsize);
|
||||
|
||||
ok &= setRawUInt32(data, tlvend, offset, idType);
|
||||
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_GENID, anonChunk);
|
||||
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_HASH_SHA1, serviceId);
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvDsdvEndPoint::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != TLV_TYPE_DSDV_ENDPOINT) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
ok &= getRawUInt32(data, tlvend, offset, &(idType));
|
||||
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_GENID, anonChunk);
|
||||
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_HASH_SHA1, serviceId);
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvDsdvEndPoint::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::ostream &RsTlvDsdvEndPoint::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvDsdvEndPoint", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "idType:" << idType;
|
||||
out << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "AnonChunk:" << anonChunk;
|
||||
out << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "ServiceId:" << serviceId;
|
||||
out << std::endl;
|
||||
|
||||
printEnd(out, "RsTlvDsdvEndPoint", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
/************************************* RsTlvDsdvEntry ************************************/
|
||||
|
||||
RsTlvDsdvEntry::RsTlvDsdvEntry()
|
||||
:RsTlvItem(), sequence(0), distance(0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void RsTlvDsdvEntry::TlvClear()
|
||||
{
|
||||
endPoint.TlvClear();
|
||||
sequence = 0;
|
||||
distance = 0;
|
||||
}
|
||||
|
||||
uint32_t RsTlvDsdvEntry::TlvSize() const
|
||||
{
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header + EndPoint.Size + 4 + 4 */
|
||||
|
||||
s += endPoint.TlvSize();
|
||||
s += 4; // sequence;
|
||||
s += 4; // distance;
|
||||
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
bool RsTlvDsdvEntry::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
/* add mandatory parts first */
|
||||
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_DSDV_ENTRY, tlvsize);
|
||||
|
||||
ok &= endPoint.SetTlv(data, size, offset);
|
||||
ok &= setRawUInt32(data, tlvend, offset, sequence);
|
||||
ok &= setRawUInt32(data, tlvend, offset, distance);
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvDsdvEntry::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != TLV_TYPE_DSDV_ENTRY) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
ok &= endPoint.GetTlv(data, size, offset);
|
||||
ok &= getRawUInt32(data, tlvend, offset, &(sequence));
|
||||
ok &= getRawUInt32(data, tlvend, offset, &(distance));
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvDsdvEntry::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::ostream &RsTlvDsdvEntry::print(std::ostream &out, uint16_t indent) const
|
||||
{
|
||||
printBase(out, "RsTlvDsdvEntry", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
endPoint.print(out, int_Indent);
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Sequence:" << sequence;
|
||||
out << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Distance:" << distance;
|
||||
out << std::endl;
|
||||
|
||||
printEnd(out, "RsTlvDsdvEntry", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
/************************************* RsTlvDsdvEntrySet ************************************/
|
||||
|
||||
#if 0
|
||||
RsTlvDsdvEntrySet::RsTlvDsdvEntrySet()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RsTlvDsdvEntrySet::TlvClear()
|
||||
{
|
||||
entries.clear();
|
||||
}
|
||||
|
||||
uint32_t RsTlvDsdvEntrySet::TlvSize()
|
||||
{
|
||||
|
||||
uint32_t s = TLV_HEADER_SIZE; /* header */
|
||||
|
||||
std::list<RsTlvDsdvEntry>::iterator it;
|
||||
|
||||
|
||||
if(!entries.empty())
|
||||
{
|
||||
|
||||
for(it = entries.begin(); it != entries.end() ; ++it)
|
||||
s += it->TlvSize();
|
||||
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsTlvDsdvEntrySet::SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
/* must check sizes */
|
||||
uint32_t tlvsize = TlvSize();
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* start at data[offset] */
|
||||
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_DSDV_ENTRY_SET , tlvsize);
|
||||
|
||||
if(!entries.empty())
|
||||
{
|
||||
std::list<RsTlvDsdvEntry>::iterator it;
|
||||
|
||||
for(it = entries.begin(); it != entries.end() ; ++it)
|
||||
ok &= it->SetTlv(data, size, offset);
|
||||
}
|
||||
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool RsTlvDsdvEntrySet::GetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||
{
|
||||
if (size < *offset + TLV_HEADER_SIZE)
|
||||
return false;
|
||||
|
||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||
uint32_t tlvend = *offset + tlvsize;
|
||||
|
||||
if (size < tlvend) /* check size */
|
||||
return false; /* not enough space */
|
||||
|
||||
if (tlvtype != TLV_TYPE_DSDV_ENTRY_SET) /* check type */
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
TlvClear();
|
||||
|
||||
/* skip the header */
|
||||
(*offset) += TLV_HEADER_SIZE;
|
||||
|
||||
/* while there is TLV */
|
||||
while((*offset) + 2 < tlvend)
|
||||
{
|
||||
/* get the next type */
|
||||
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||
|
||||
switch(tlvsubtype)
|
||||
{
|
||||
case TLV_TYPE_DSDV_ENTRY:
|
||||
{
|
||||
RsTlvDsdvEntry entry;
|
||||
ok &= entry.GetTlv(data, size, offset);
|
||||
if (ok)
|
||||
{
|
||||
entries.push_back(entry);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ok &= SkipUnknownTlv(data, tlvend, offset);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
* or be present (if this code is reading an extended version).
|
||||
*
|
||||
* We must chew up the extra characters to conform with TLV specifications
|
||||
***************************************************************************/
|
||||
if (*offset != tlvend)
|
||||
{
|
||||
#ifdef TLV_DEBUG
|
||||
std::cerr << "RsTlvDsdvEntrySet::GetTlv() Warning extra bytes at end of item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
*offset = tlvend;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
// prints out contents of RsTlvDsdvEntrySet
|
||||
std::ostream &RsTlvDsdvEntrySet::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printBase(out, "RsTlvDsdvEntrySet", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
std::list<RsTlvDsdvEntry>::iterator it;
|
||||
for(it = entries.begin(); it != entries.end() ; ++it)
|
||||
it->print(out, int_Indent);
|
||||
|
||||
printEnd(out, "RsTlvDsdvEntrySet", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
88
libretroshare/src/unfinished/rstlvdsdv.h
Normal file
88
libretroshare/src/unfinished/rstlvdsdv.h
Normal file
|
@ -0,0 +1,88 @@
|
|||
#pragma once
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstlvdsdv.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2011 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
/*******************************************************************
|
||||
* These are the Compound TLV structures that must be (un)packed.
|
||||
******************************************************************/
|
||||
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvlist.h"
|
||||
|
||||
#define RSDSDV_MAX_ROUTE_TABLE 1000
|
||||
|
||||
class RsTlvDsdvEndPoint: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvDsdvEndPoint();
|
||||
virtual ~RsTlvDsdvEndPoint() { return; }
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
uint32_t idType;
|
||||
std::string anonChunk;
|
||||
std::string serviceId;
|
||||
};
|
||||
|
||||
class RsTlvDsdvEntry: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvDsdvEntry();
|
||||
virtual ~RsTlvDsdvEntry() { return; }
|
||||
virtual uint32_t TlvSize() const;
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
|
||||
RsTlvDsdvEndPoint endPoint;
|
||||
uint32_t sequence;
|
||||
uint32_t distance;
|
||||
};
|
||||
|
||||
typedef t_RsTlvList<RsTlvDsdvEntry,TLV_TYPE_DSDV_ENTRY_SET> RsTlvDsdvEntrySet;
|
||||
|
||||
#if 0
|
||||
class RsTlvDsdvEntrySet: public RsTlvItem
|
||||
{
|
||||
public:
|
||||
RsTlvDsdvEntrySet();
|
||||
virtual ~RsTlvDsdvEntrySet() { return; }
|
||||
virtual uint32_t TlvSize();
|
||||
virtual void TlvClear();
|
||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
|
||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||
|
||||
std::list<RsTlvDsdvEntry> entries;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue