Major changes to the networking core of retroshare to introduce the new serialiser.

- Added new serialiser (PQItem -> RsItem), removed old one.
- switched packet sorting from ChanId (array of ids) to PeerId (string)
- introduced cleaner service interface (pqiservice).
- moved p3disc to service interface.
- modified streamers to use the new serialiser.
- moved msg/chat to service interface.
- removed old source code. (supernode / p3loopback).

I've disabled UDP connections / Proxy and Channels for the moment.
The code it still here, but is not compiled. The Proxy and Channels 
will become services, and the UDP connections will be reworked 
in the near future.




git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@274 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2007-12-12 01:29:14 +00:00
parent 07d33009b9
commit 2c9c31eaf0
36 changed files with 866 additions and 8116 deletions

View File

@ -5,13 +5,11 @@ include ../make.opt
# All the executables that should be generated.
EXECS = # test_p3items
BASE_OBJ = pqi_base.o pqi.o pqipacket.o \
BASE_OBJ = pqi_base.o \
pqidebug.o pqisecurity.o pqinetwork.o \
pqistreamer.o pqibin.o pqimon.o
pqibin.o pqimon.o \
TUNN_OBJ = pqitunnel.o pqitunneltst.o
LOOP_OBJ = pqiloopback.o p3loopback.o
DISC_OBJ = discItem.o p3disc.o
LOOP_OBJ = pqiloopback.o
ifdef PQI_USE_XPGP
SSL_OBJ = xpgpcert.o
@ -20,39 +18,52 @@ else
SSL_OBJ = sslcert.o
endif
SSL_OBJ += pqissl.o pqiarchive.o pqissllistener.o
GRP_OBJ = pqiperson.o pqihandler.o pqipersongrp.o
SSL_OBJ += pqissl.o pqissllistener.o
GRP_OBJ = pqiperson.o pqihandler.o pqiservice.o pqipersongrp.o
STREAM_OBJ = pqistreamer.o pqiarchive.o
OLD_OBJ = pqipacket.o p3loopback.o pqi.o
TUNN_OBJ = pqitunnel.o pqitunneltst.o
DISC_OBJ = discItem.o p3disc.o
UDP_OBJ = pqistunner.o pqiudpproxy.o pqissludp.o pqitunnelproxyudp.o
PRXY_OBJ = pqiproxy.o pqitunnelproxy.o
CHAN_OBJ = p3channel.o pqichannel.o
SN_OBJ = pqisupernode.o
OBJ = $(BASE_OBJ) $(TUNN_OBJ) $(LOOP_OBJ) $(DISC_OBJ) \
$(GRP_OBJ) $(SSL_OBJ) $(CHAN_OBJ) $(PRXY_OBJ) $(UDP_OBJ)
OBJ = $(BASE_OBJ) $(LOOP_OBJ) \
$(GRP_OBJ) $(SSL_OBJ) $(STREAM_OBJ)
# Disabling this part of pqi core - until we have the basic
# items replaced by the new serialiser.....
# $(TUNN_OBJ) $(DISC_OBJ) \
# $(CHAN_OBJ) $(PRXY_OBJ) $(UDP_OBJ)
# Linux only parts.
ifeq ($(OS),Linux)
OBJ += $(SN_OBJ)
# OBJ += $(SN_OBJ)
endif
BASE_HDR = pqi_base.h pqi.h pqi_data.h pqipacket.h pqisecurity.h pqinetwork.h \
BASE_HDR = pqi_base.h pqisecurity.h pqinetwork.h \
pqidebug.h pqistreamer.h pqiarchive.h pqiindic.h pqibin.h
TUNN_HDR = pqitunnel.h pqitunneltst.h
LOOP_HDR = p3loopback.h pqiloopback.h
DISC_HDR = discItem.h p3disc.h
LOOP_HDR = pqiloopback.h
SSL_HDR = pqissl.h pqissllistener.h xpgpcert.h
GPR_HDR = pqihandler.h pqiperson.h pqipersongrp.h
GPR_HDR = pqihandler.h pqiperson.h pqiservice.h pqipersongrp.h
STREAM_HDR = pqistreamer.h pqiarchive.h
OLD_HDR = pqipacket.h pqi_data.h p3loopback.h pqi.h
TUNN_HDR = pqitunnel.h pqitunneltst.h
DISC_HDR = discItem.h p3disc.h
UDP_HDR = pqistunner.h pqiudpproxy.h pqissludp.h pqitunnelproxyudp.h
PRXY_HDR = pqitunnelproxy.h pqiproxy.h
CHAN_HDR = pqichannel.h p3channel.h
SN_HDR = pqisupernode.h
HDR = $(BASE_HDR) $(TUNN_HDR) $(LOOP_HDR) $(DISC_HDR) \
$(GRP_HDR) $(SSL_HDR) $(CHAN_HDR) $(PRXY_HDR) $(UDP_HDR)
HDR = $(BASE_HDR) $(LOOP_HDR) $(GRP_HDR) $(SSL_HDR) $(STREAM_HDR)
#$(DISC_HDR) $(TUNN_HDR)
#$(CHAN_HDR) $(PRXY_HDR) $(UDP_HDR)
LIBPQIA = $(LIBDIR)/libpqi.a
LIBPQISO = $(LIBDIR)/libpqi.so

View File

@ -1,353 +0,0 @@
/*
* "$Id: discItem.cc,v 1.8 2007-02-18 21:46:49 rmf24 Exp $"
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2004-2006 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 "pqi/discItem.h"
static const int pqidizone = 44863;
#include "pqi/pqidebug.h"
#include <sstream>
PQTunnel *createDiscItems(void *d, int n)
{
pqioutput(PQL_DEBUG_BASIC, pqidizone,
"createDiscItems()");
// check the discType of DiscItem;
if ( ((int *) d)[0] == 0)
{
return new DiscItem();
}
return new DiscReplyItem();
}
DiscItem::DiscItem()
:PQTunnel(PQI_TUNNEL_DISC_ITEM_TYPE), discType(0), discFlags(0)
{
pqioutput(PQL_DEBUG_BASIC, pqidizone,
"DiscItem::DiscItem()");
return;
}
DiscItem *DiscItem::clone()
{
pqioutput(PQL_DEBUG_BASIC, pqidizone,
"DiscItem::clone()");
DiscItem *di = new DiscItem();
di -> copy(this);
return di;
}
void DiscItem::copy(const DiscItem *di)
{
pqioutput(PQL_DEBUG_BASIC, pqidizone,
"DiscItem::copy()");
PQTunnel::copy(di);
discType = di -> discType;
saddr = di -> saddr;
laddr = di -> laddr;
receive_tr = di -> receive_tr;
connect_tr = di -> connect_tr;
discFlags = di -> discFlags;
}
// Overloaded from PQTunnel.
const int DiscItem::getSize() const
{
return 3 * 4 + 2 * sizeof(struct sockaddr_in);
}
int DiscItem::out(void *data, const int size) const
{
{
std::ostringstream out;
out << "DiscItem::out() Data: " << data;
out << " Size: " << size << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqidizone, out.str());
}
if (size < DiscItem::getSize())
{
pqioutput(PQL_DEBUG_BASIC, pqidizone,
"DiscItem::out() Packet Too Small!");
return -1;
}
char *dta = (char *) data;
((int *) dta)[0] = discType;
dta += 4;
((struct sockaddr_in *) dta)[0] = saddr;
dta += sizeof(sockaddr_in);
((struct sockaddr_in *) dta)[0] = laddr;
dta += sizeof(sockaddr_in);
// version 1....
// : 4 bytes for receive_tr
// : 4 bytes for connect_tr
//((int *) dta)[0] = receive_tr;
//dta += 4;
//((int *) dta)[0] = connect_tr;
//dta += 4;
// version 2....
// : 2 bytes for receive_tf
// : 2 bytes for connect_tf
// : 4 bytes for cert->flags.
((unsigned short *) dta)[0] = htons(receive_tr);
dta += 2;
((unsigned short *) dta)[0] = htons(connect_tr);
dta += 2;
((unsigned long *) dta)[0] = htonl(discFlags);
dta += 4;
return DiscItem::getSize();
}
int DiscItem::in(const void *data, const int size)
{
{
std::ostringstream out;
out << "DiscItem::in() Data: " << data;
out << " Size: " << size << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqidizone, out.str());
}
if (size < DiscItem::getSize())
{
std::ostringstream out;
out << "DiscItem::in() Pkt to small";
pqioutput(PQL_DEBUG_BASIC, pqidizone, out.str());
return -1;
}
char *dta = (char *) data;
discType = ((int *) dta)[0];
dta += 4;
saddr = ((struct sockaddr_in *) dta)[0];
dta += sizeof(sockaddr_in);
laddr = ((struct sockaddr_in *) dta)[0];
dta += sizeof(sockaddr_in);
// version 1....
// : 4 bytes for receive_tr
// : 4 bytes for connect_tr
//receive_tf = ((int *) dta)[0];
//dta += 4;
//connect_tf = ((int *) dta)[0];
//dta += 4;
// version 2....
// : 2 bytes for receive_tr
// : 2 bytes for connect_tr
// : 4 bytes for cert->flags.
receive_tr = ntohs(((unsigned short *) dta)[0]);
dta += 2;
connect_tr = ntohs(((unsigned short *) dta)[0]);
dta += 2;
discFlags = ntohl(((unsigned long *) dta)[0]);
dta += 4;
return getSize();
}
std::ostream &DiscItem::print(std::ostream &out)
{
out << "-------- DiscItem" << std::endl;
PQItem::print(out);
out << "Peer Details" << std::endl;
out << "Local Address: " << inet_ntoa(laddr.sin_addr);
out << " Port: " << ntohs(laddr.sin_port) << std::endl;
out << "Server Address: " << inet_ntoa(saddr.sin_addr);
out << " Port: " << ntohs(saddr.sin_port) << std::endl;
out << "[R/C]_TF: " << receive_tr;
out << "/" << connect_tr << std::endl;
out << "discFlags: " << discFlags << std::endl;
return out << "--------" << std::endl;
}
DiscReplyItem::DiscReplyItem()
:DiscItem(), certDER(NULL), certLen(0)
{
pqioutput(PQL_DEBUG_BASIC, pqidizone,
"DiscReplyItem::DiscReplyItem()");
discType = 1;
return;
}
DiscReplyItem::~DiscReplyItem()
{
pqioutput(PQL_DEBUG_BASIC, pqidizone,
"DiscReplyItem::~DiscReplyItem()");
if (certDER != NULL)
{
free(certDER);
certDER = NULL;
certLen = 0;
}
}
DiscReplyItem *DiscReplyItem::clone()
{
pqioutput(PQL_DEBUG_BASIC, pqidizone,
"DiscReplyItem::clone()");
DiscReplyItem *di = new DiscReplyItem();
di -> copy(this);
return di;
}
void DiscReplyItem::copy(const DiscReplyItem *di)
{
pqioutput(PQL_DEBUG_BASIC, pqidizone,
"DiscReplyItem::copy()");
DiscItem::copy(di);
if (di -> certDER != NULL)
{
certLen = di -> certLen;
certDER = (unsigned char *) malloc(certLen);
memcpy(certDER, di -> certDER, certLen);
}
else
{
certLen = 0;
certDER = NULL;
}
return;
}
// Overloaded from PQTunnel.
const int DiscReplyItem::getSize() const
{
return DiscItem::getSize() + 4 + certLen;
}
int DiscReplyItem::out(void *data, const int maxsize) const
{
{
std::ostringstream out;
out << "DiscReplyItem::out() Data: " << data;
out << " Size: " << maxsize << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqidizone, out.str());
}
if (maxsize < getSize())
{
std::ostringstream out;
out << "DiscReplyItem::out() Not Enough space";
pqioutput(PQL_DEBUG_BASIC, pqidizone, out.str());
return -1;
}
int basesize = DiscItem::getSize();
// put out the DiscItem Part.
DiscItem::out(data, basesize);
char *loc = ((char *) data) + basesize;
((int *) loc)[0] = certLen;
loc += 4;
memcpy(loc, certDER, certLen);
return getSize();
}
int DiscReplyItem::in(const void *data, const int size)
{
{
std::ostringstream out;
out << "DiscReplyItem::in() Data: " << data;
out << " Size: " << size << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqidizone, out.str());
}
// harder.
int basesize = DiscItem::getSize();
if (basesize + 4 > size)
{
pqioutput(PQL_DEBUG_BASIC, pqidizone,
"DiscReplyItem::in() Not enough space for Base Class!");
return -1; // cant be us.
}
// read in the DiscItem part.
DiscItem::in(data, DiscItem::getSize());
char *loc = ((char *) data) + basesize;
int certsize = ((int *) loc)[0];
// check the size again.
if (basesize + 4 + certsize != size)
{
pqioutput(PQL_DEBUG_BASIC, pqidizone,
"DiscReplyItem::in() Not enough space for Certificate");
return -1;
}
loc += 4;
// allocate memory for certDER....
if ((certLen != certsize) && (!certLen))
{
if (certDER)
free(certDER);
}
certLen = certsize;
if (!certDER)
{
certDER = (unsigned char *) malloc(certsize);
}
memcpy(certDER, loc, certLen);
return getSize();
}
std::ostream &DiscReplyItem::print(std::ostream &out)
{
out << "---------------- DiscReplyItem" << std::endl;
out << "A Friend of a Friend:" << std::endl;
DiscItem::print(out);
if (certDER != NULL)
{
out << "CertLen: " << certLen << std::endl;
}
else
{
out << "No Certificate" << std::endl;
}
return out << "----------------" << std::endl;
}

View File

@ -1,90 +0,0 @@
/*
* "$Id: discItem.h,v 1.6 2007-02-18 21:46:49 rmf24 Exp $"
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2004-2006 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_DISCITEM_H
#define MRK_PQI_DISCITEM_H
#include "pqi/pqitunnel.h"
#define PQI_TUNNEL_DISC_ITEM_TYPE 121
PQTunnel *createDiscItems(void *d, int n);
class DiscItem: public PQTunnel
{
protected:
DiscItem(int st);
public:
DiscItem();
virtual DiscItem *clone();
void copy(const DiscItem *di);
virtual std::ostream &print(std::ostream &out);
// Overloaded from PQTunnel.
virtual const int getSize() const;
virtual int out(void *data, const int size) const;
virtual int in(const void *data, const int size);
int discType; // specifies subtypes.
struct sockaddr_in laddr;
struct sockaddr_in saddr;
// time frame of recent connections.
unsigned short connect_tr;
unsigned short receive_tr;
// flags...
unsigned long discFlags;
};
class DiscReplyItem: public DiscItem
{
public:
DiscReplyItem();
virtual ~DiscReplyItem();
virtual DiscReplyItem *clone();
void copy(const DiscReplyItem *di);
virtual std::ostream &print(std::ostream &out);
// Overloaded from PQTunnel.
virtual const int getSize() const;
virtual int out(void *data, const int size) const;
virtual int in(const void *data, const int size);
unsigned char *certDER;
int certLen;
};
#define AUTODISC_RDI_SUBTYPE_PING 1
#define AUTODISC_RDI_SUBTYPE_RPLY 2
#define AUTODISC_LDI_SUBTYPE_PING 1
#define AUTODISC_LDI_SUBTYPE_RPLY 2
#endif // MRK_PQI_DISCITEM_H

File diff suppressed because it is too large Load Diff

View File

@ -1,186 +0,0 @@
/*
* "$Id: p3disc.h,v 1.11 2007-02-18 21:46:49 rmf24 Exp $"
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2004-2006 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_AUTODISC_H
#define MRK_PQI_AUTODISC_H
// The AutoDiscovery Class
#include <string>
#include <list>
// system specific network headers
#include "pqi/pqinetwork.h"
#include "pqi/pqi.h"
/**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP)
#include "pqi/xpgpcert.h"
#else /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
#include "pqi/sslcert.h"
#endif /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
#include "pqi/discItem.h"
#include "pqi/pqitunnel.h"
class autoserver
{
public:
autoserver()
:id(NULL), ca(NULL), connect(false), c_ts(0),
listen(false), l_ts(0), discFlags(0) { return;}
Person *id;
Person *ca;
bool connect;
unsigned int c_ts; // this is connect_tf converted to timestamp, 0 invalid.
bool listen;
unsigned int l_ts; // this is receive_tf converted to timestamp, 0 invalid.
struct sockaddr_in local_addr;
struct sockaddr_in server_addr;
unsigned long discFlags;
};
class autoneighbour: public autoserver
{
public:
autoneighbour()
:autoserver(), local(false), active(false) {}
bool local;
bool active; // meaning in ssl's list.
std::list<autoserver *> neighbour_of;
};
class p3disc: public PQTunnelService
{
public:
bool local_disc;
bool remote_disc;
//sslroot *sslbase;
p3disc(sslroot *r);
virtual ~p3disc();
// PQTunnelService functions.
virtual int receive(PQTunnel *);
virtual PQTunnel *send();
virtual PQTunnel *getObj();
virtual int tick();
// doesn't use the init functions.
virtual int receive(PQTunnelInit *i) { delete i; return 1; }
virtual PQTunnelInit *sendInit() { return NULL; }
virtual PQTunnelInit *getObjInit() { return NULL; }
// End of PQTunnelService functions.
//
// For Proxy Information.
std::list<sockaddr_in> requestStunServers();
std::list<cert *> potentialproxy(cert *target);
// load and save configuration to sslroot.
int save_configuration();
int load_configuration();
int ts_lastcheck;
int idServers();
// Handle Local Discovery.
int localListen();
int localSetup();
int lsock; // local discovery socket.
struct sockaddr_in laddr; // local addr
struct sockaddr_in baddr; // local broadcast addr.
struct sockaddr_in saddr; // pqi ssl server addr.
// bonus configuration flags.
bool local_firewalled;
bool local_forwarded;
// local message construction/destruction.
void *ldata;
int ldlen;
int ldlenmax;
bool std_port; // if we have bound to default.
int ts_nextlp; // -1 for never (if on default)
// helper functions.
int setLocalAddress(struct sockaddr_in srvaddr);
int determineLocalNetAddr();
int setupLocalPacket(int type, struct sockaddr_in *home,
struct sockaddr_in *server);
int localPing(struct sockaddr_in);
int localReply(struct sockaddr_in);
int addLocalNeighbour(struct sockaddr_in*, struct sockaddr_in*);
// remote discovery function.
int newRequests();
int handleReplies();
int handleDiscoveryData(DiscReplyItem *di);
int handleDiscoveryPing(DiscItem *di);
int sendDiscoveryReply(cert *);
int collectCerts();
int distillData();
//cert *checkDuplicateX509(X509 *x509);
std::list<cert *> &getDiscovered();
// Main Storage
std::list<autoneighbour *> neighbours;
std::list<cert *> ad_init;
std::list<cert *> discovered;
sslroot *sroot;
// Storage for incoming/outgoing.
std::list<PQItem *> inpkts;
std::list<PQItem *> outpkts;
};
#endif // MRK_PQI_AUTODISC_H

View File

@ -1,341 +0,0 @@
/*
* "$Id: p3loopback.cc,v 1.3 2007-02-18 21:46:49 rmf24 Exp $"
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2004-2006 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 "pqi/pqi.h"
#include "pqi/p3loopback.h"
// Test Interface (LoopBack)
p3loopback::~p3loopback()
{
// should clean up lists ...
// delete all random search items...
// fix later..
return;
}
int p3loopback::Search(SearchItem *si)
{
// no more copy - just use.
// tag as new.
si -> flags = 1;
// add to requested searches.
searches[si -> sid] = si;
return 1;
}
int p3loopback::CancelSearch(SearchItem *item)
{
std::map<int, SearchItem *>::iterator it;
std::list<PQFileItem *>::iterator it2;
unsigned int sid = item -> sid;
// Quick Sanity Check.
it = searches.find(sid);
if (it == searches.end())
{
std::cerr << "p3loopback::CancelSearch(" << sid;
std::cerr << ") Search Not Found!" << std::endl;
return -2;
}
// found search delete.
SearchItem *osi = it -> second;
searches.erase(it);
// find anything matching in the list.
for(it2 = searchResults.begin(); it2 != searchResults.end();)
{
if ((*it2) -> sid == sid) // erase
{
PQFileItem *osr = (*it2);
it2 = searchResults.erase(it2);
delete osr;
}
else
{
it2++;
}
}
cancelledSearches.push_back(osi);
// clean up input.
delete item;
return 1;
}
PQFileItem * p3loopback::GetSearchResult()
{
std::list<PQFileItem *>::iterator it;
it = searchResults.begin();
if (it == searchResults.end()) // empty list
{
return NULL;
}
PQFileItem *osr = (*it);
searchResults.erase(it);
// set as local...
osr -> flags |= PQI_ITEM_FLAG_LOCAL;
return osr;
}
int p3loopback::GetFile(PQFileItem *item, std::ostream &in)
{
// save a stream ....
// send on the request.
//fixme("p3loopback::GetFile()", 1);
return 1;
}
int p3loopback::CancelFile(PQFileItem *item)
{
// close down stream (if we created it)
// send on request.
//fixme("p3loopback::CancelFile()", 1);
return 1;
}
// Remote Requests.
SearchItem *p3loopback::RequestedSearch()
{
std::map<int, SearchItem *>::iterator it;
SearchItem *ns;
for(it = searches.begin(); it != searches.end(); it++)
{
// check if new...
if ((it -> second) -> flags == 1)
{
// generate new sid number.
int rsid = getPQIsearchId();
int sid = (it -> second) -> sid;
// setup translation stuff.
sid2rsid[sid] = rsid;
ns = new SearchItem();
ns -> copy(it -> second);
(it -> second) -> flags = 0;
ns -> sid = rsid;
return ns;
}
}
return NULL;
}
SearchItem *p3loopback::CancelledSearch()
{
std::list<SearchItem *>::iterator it;
std::map<int, int>::iterator mit;
it = cancelledSearches.begin();
if (it == cancelledSearches.end()) // empty list
{
return NULL;
}
// else copy into structure.
SearchItem *ncs = (*it);
cancelledSearches.erase(it);
// get from mapping.
mit = sid2rsid.find(ncs -> sid);
if (mit == sid2rsid.end()) // error
{
std::cerr << "Error No Mapping (Cancelling the Cancel)!";
std::cerr << "But Still deleting item";
std::cerr << std::endl;
delete ncs;
return NULL;
}
else
{
ncs -> sid = mit -> second;
sid2rsid.erase(mit);
}
return ncs;
}
int p3loopback::SendSearchResult(PQFileItem *item)
{
//std::list<SearchItem *> >::iterator it;
std::map<int, int>::iterator it;
int rsid = item -> sid;
int sid = 0;
// get from mapping.
for(it = sid2rsid.begin(); ((it != sid2rsid.end()) && (sid == 0)); it++)
{
if (rsid == (it -> second))
{
sid = it -> first;
}
}
// if no mapping.
if (sid == 0)
{
std::cerr << "SendSearchResult::Error No Mapping (Removing Item)!";
std::cerr << std::endl;
delete item;
return 0;
}
// have mapping.... translate.
item -> sid = sid;
// stick on the queue.
searchResults.push_back(item);
return 1;
}
PQFileItem *p3loopback::RequestedFile()
{
// check for searches with new tag...
// if none return 0;
// copy data from first.
// mark old.
//fixme("p3loopback::RequestedFile()", 1);
return NULL;
}
PQFileItem *p3loopback::CancelledFile()
{
// check for cancelled files.
// if none return 0;
// copy data from first.
// remove/cleanup
//fixme("p3loopback::CancelledFile()", 1);
return NULL;
}
int p3loopback::SendFile(PQFileItem *, std::istream &out)
{
// get data...
// attach streams.....
//
//fixme("p3loopback::SendFile()", 1);
return 1;
}
//
//// control interface.
//int p3loopback::RequestInfo(InfoItem *item)
//{
// switch(item -> querytype)
// {
// case PQI_II_QUERYTYPE_TAG:
// item -> answer = "<++Local++>";
// return 1;
// break;
//
// case PQI_II_QUERYTYPE_CLASS:
// item -> answer = "p3loopback";
// return 1;
// break;
//
// default:
// return 0;
// break;
// }
// return -1;
//
// return 0;
//}
//
//int p3loopback::doCommand(CommandItem *)
//{
// //fixme("p3loopback::doCommand()", 1);
// return 0;
//}
//
// // chat interface.
int p3loopback::SendMsg(ChatItem *item)
{
//fixme("p3loopback::SendMsg()", 1);
return 0;
}
ChatItem *p3loopback::GetMsg()
{
//fixme("p3loopback::GetMsg()", 1);
return NULL;
}
int p3loopback::SendOtherPQItem(PQItem *item)
{
other.push_back(item);
return 1;
}
PQItem *p3loopback::GetOtherPQItem()
{
if (other.size() != 0)
{
PQItem *i = other.front();
other.pop_front();
return i;
}
return NULL;
}
// // PQI interface.
int p3loopback::tick()
{
//fixme("p3loopback::tick()", 1);
return 0;
}
int p3loopback::status()
{
//fixme("p3loopback::status()", 1);
return 0;
}

View File

@ -1,91 +0,0 @@
/*
* "$Id: p3loopback.h,v 1.4 2007-02-18 21:46:49 rmf24 Exp $"
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2004-2006 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_P3_LOOPBACK_HEADER
#define MRK_P3_LOOPBACK_HEADER
// The standard data types and the search interface.
#include "pqi/pqi.h"
#include <map>
#include <list>
// Test Interface (LoopBack)
// public interface .... includes the whole p3interface.
class p3loopback: public P3Interface
{
public:
virtual ~p3loopback();
// search Interface.
virtual int Search(SearchItem *item);
virtual int CancelSearch(SearchItem *item);
virtual PQFileItem *GetSearchResult();
virtual int GetFile(PQFileItem *item, std::ostream &in);
virtual int CancelFile(PQFileItem *);
virtual SearchItem *RequestedSearch();
virtual SearchItem *CancelledSearch();
virtual int SendSearchResult(PQFileItem *item);
virtual PQFileItem *RequestedFile();
virtual PQFileItem *CancelledFile();
virtual int SendFile(PQFileItem *, std::istream &out);
// control interface.
//virtual int RequestInfo(InfoItem *);
//virtual int doCommand(CommandItem *);
// chat interface.
virtual int SendMsg(ChatItem *item);
virtual ChatItem *GetMsg();
// PQI interface.
virtual int tick();
virtual int status();
virtual int SendOtherPQItem(PQItem *);
virtual PQItem *GetOtherPQItem();
private:
std::list<PQFileItem *> searchResults;
std::map<int, SearchItem *> searches;
std::map<int, SearchItem *> files;
std::list<SearchItem *> cancelledSearches;
std::list<SearchItem *> cancelledFiles;
std::list<PQItem *> other;
// remote mapping
std::map<int, int> sid2rsid;
};
#endif //MRK_P3_LOOPBACK_HEADER

View File

@ -1,317 +0,0 @@
/*
* "$Id: p3supernode.cc,v 1.3 2007-02-18 21:46:49 rmf24 Exp $"
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2004-2006 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 "pqi/pqisupernode.h"
#include <list>
#include <string>
// Includes for directory creation.
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
// Conflicts with FLTK def - hope they are the same.
//#include <dirent.h>
// for blocking signals
#include <signal.h>
#include "pqi/pqidebug.h"
void load_check_basedir();
// Global Pointers for the callback functions.
// initial configuration bootstrapping...
static const std::string config_init_file = "default_cert.txt";
static const std::string config_file = "config.rs";
static const std::string cert_dir = "friends";
static const std::string key_dir = "keys";
static const std::string ca_file = "cacerts.pem";
static std::string config_basedir;
static std::string load_cert;
static std::string load_key;
static std::string load_cacert;
void load_check_basedir();
static const char dirSeperator = '/'; // For unix.
// standard start for unix.
int main(int argc, char **argv)
{
// setup debugging for desired zones.
setOutputLevel(PQL_ALERT); // to show the others.
setZoneLevel(PQL_ALERT, 38422); // pqipacket.
setZoneLevel(PQL_ALERT, 96184); // pqinetwork;
setZoneLevel(PQL_ALERT, 82371); // pqiperson.
setZoneLevel(PQL_ALERT, 60478); // pqitunnel.
setZoneLevel(PQL_ALERT, 34283); // pqihandler.
setZoneLevel(PQL_ALERT, 44863); // discItems.
setZoneLevel(PQL_DEBUG_BASIC, 2482); // p3disc
setZoneLevel(PQL_ALERT, 1728); // proxy
setZoneLevel(PQL_ALERT, 1211); // sslroot.
setZoneLevel(PQL_ALERT, 37714); // pqissl.
setZoneLevel(PQL_ALERT, 8221); // pqistreamer.
setZoneLevel(PQL_ALERT, 354); // pqipersongrp.
std::list<std::string> dirs;
short port = 7812; // default port.
bool forceLocalAddr = false;
char inet[256] = "127.0.0.1";
char passwd[256] = "";
char logfname[1024] = "";
int c;
bool havePasswd = false;
bool haveLogFile = false;
while((c = getopt(argc, argv,"i:p:c:s:w:l:")) != -1)
{
switch (c)
{
case 'l':
strncpy(logfname, optarg, 1024);
std::cerr << "LogFile (" << logfname;
std::cerr << ") Selected" << std::endl;
haveLogFile = true;
break;
case 'w':
strncpy(passwd, optarg, 256);
std::cerr << "Password Specified(" << passwd;
std::cerr << ") Selected" << std::endl;
havePasswd = true;
break;
case 'i':
strncpy(inet, optarg, 256);
std::cerr << "New Inet Addr(" << inet;
std::cerr << ") Selected" << std::endl;
forceLocalAddr = true;
break;
case 'p':
port = atoi(optarg);
std::cerr << "New Listening Port(" << port;
std::cerr << ") Selected" << std::endl;
break;
case 'c':
config_basedir = optarg;
std::cerr << "New Base Config Dir(";
std::cerr << config_basedir;
std::cerr << ") Selected" << std::endl;
break;
case 's':
dirs.push_back(std::string(optarg));
std::cerr << "Adding Search Directory (" << optarg;
std::cerr << ")" << std::endl;
break;
default:
std::cerr << "Unknown Option!";
exit(1);
}
}
// Can only log under linux.
// set the debug file.
if (haveLogFile)
{
setDebugFile(logfname);
}
// first check config directories, and set bootstrap values.
load_check_basedir();
// SWITCH off the SIGPIPE - kills process on Linux.
struct sigaction sigact;
sigact.sa_handler = SIG_IGN;
sigact.sa_flags = 0;
if (0 == sigaction(SIGPIPE, &sigact, NULL))
{
std::cerr << "RetroShare:: Successfully Installed";
std::cerr << "the SIGPIPE Block" << std::endl;
}
else
{
std::cerr << "RetroShare:: Failed to Install";
std::cerr << "the SIGPIPE Block" << std::endl;
}
if (!havePasswd)
{
std::cerr << "main() - Fatal Error....." << std::endl;
std::cerr << "Missing Passwd!" << std::endl;
std::cerr << std::endl;
exit(1);
}
/* determine the cert/key parameters....
*/
load_check_basedir();
bool sslroot_ok = false;
sslroot *sr = getSSLRoot();
/**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP)
if (0 < sr -> initssl(load_cert.c_str(), load_key.c_str(), passwd))
{
sslroot_ok = true;
}
#else /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
if (0 < sr -> initssl(load_cert.c_str(), load_key.c_str(),
load_cacert.c_str(), passwd))
{
sslroot_ok = true;
}
#endif /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
if (!sslroot_ok)
{
std::cerr << "main() - Fatal Error....." << std::endl;
std::cerr << "Invalid Certificate configuration!" << std::endl;
std::cerr << std::endl;
exit(1);
}
// wait for this window to be finished....
if(!(sr -> active()))
{
std::cerr << "main() - Fatal Error....." << std::endl;
std::cerr << "SSLRoot Failed to start" << std::endl;
std::cerr << std::endl;
exit(1);
}
// set the directories for full configuration load.
sr -> setConfigDirs(config_basedir.c_str(), cert_dir.c_str());
sr -> loadCertificates(config_file.c_str());
sr -> checkNetAddress();
SecurityPolicy *none = secpolicy_create();
if (forceLocalAddr)
{
struct sockaddr_in laddr;
laddr.sin_family = AF_INET;
laddr.sin_port = htons(port);
// universal
laddr.sin_addr.s_addr = inet_addr(inet);
// unix specific
//inet_aton(inet, &(laddr.sin_addr));
cert *own = sr -> getOwnCert();
if (own != NULL)
{
own -> localaddr = laddr;
}
}
/**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP)
/* can only do this in XPGP */
sr -> superNodeMode();
#endif /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
pqisupernode psn(none, sr);
psn.load_config();
psn.run();
return 1;
}
void load_check_basedir()
{
// get the default configuration location.
if (config_basedir == "")
{
std::cerr << "load_check_basedir() - Fatal Error....." << std::endl;
std::cerr << "Missing config_basedir" << std::endl;
std::cerr << std::endl;
exit(1);
}
std::string key_subdir = config_basedir + dirSeperator;
key_subdir += key_dir;
// will catch bad files later.
// Check for config file.
std::string initfile = config_basedir + dirSeperator;
initfile += config_init_file;
/* setup the ca cert file */
load_cacert = key_dir + dirSeperator;
load_cacert += ca_file;
// open and read in the lines.
FILE *ifd = fopen(initfile.c_str(), "r");
char path[1024];
int i;
if (ifd != NULL)
{
if (NULL != fgets(path, 1024, ifd))
{
for(i = 0; (path[i] != '\0') && (path[i] != '\n'); i++);
path[i] = '\0';
load_cert = path;
}
if (NULL != fgets(path, 1024, ifd))
{
for(i = 0; (path[i] != '\0') && (path[i] != '\n'); i++);
path[i] = '\0';
load_key = path;
}
fclose(ifd);
}
else
{
std::cerr << "load_check_basedir() - Fatal Error....." << std::endl;
std::cerr << "Cannot open initfile." << std::endl;
std::cerr << std::endl;
exit(1);
}
return;
}

View File

@ -1,440 +0,0 @@
/*
* "$Id: pqi.cc,v 1.8 2007-03-21 18:45:41 rmf24 Exp $"
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2004-2006 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 "pqi/pqi.h"
#include "pqi/pqi_data.h"
#include <ctype.h>
// local functions.
//int pqiroute_setshift(PQItem *item, int chan);
//int pqiroute_getshift(PQItem *item);
//int pqicid_clear(ChanId *cid);
//int pqicid_copy(const ChanId *cid, ChanId *newcid);
// Helper functions for the PQInterface.
int fixme(char *str, int n)
{
for(int i = 0; i < n; i++)
{
std::cerr << "FIXME:: " << str << std::endl;
}
return 1;
}
SearchItem::SearchItem()
:PQItem(PQI_ITEM_TYPE_SEARCHITEM, PQI_SI_SUBTYPE_SEARCH),
datatype(PQI_SI_DATATYPE_TERMS)
{
//std::cerr << "Creating SearchItem()" << std::endl;
return;
}
SearchItem::SearchItem(int st)
:PQItem(PQI_ITEM_TYPE_SEARCHITEM, st), datatype(PQI_SI_DATATYPE_TERMS)
{
//std::cerr << "Creating SearchItem()" << std::endl;
return;
}
SearchItem::~SearchItem()
{
//std::cerr << "Deleting SearchItem()" << std::endl;
return;
}
// These need to be recursive.
SearchItem *SearchItem::clone()
{
SearchItem *nsi = new SearchItem();
nsi -> copy(this);
return nsi;
}
void SearchItem::copy(const SearchItem *si)
{
// copy below.
PQItem::copy(si);
// do elements of searchItem.
datatype = si -> datatype;
data = si -> data;
}
std::ostream &SearchItem::print(std::ostream &out)
{
out << "---- SearchItem" << std::endl;
PQItem::print(out);
out << "Search Type: " << datatype << std::endl;
out << "Search: " << data << std::endl;
return out << "----" << std::endl;
}
ChatItem::ChatItem()
:PQItem(PQI_ITEM_TYPE_CHATITEM, PQI_MI_SUBTYPE_CHAT)
{
//std::cerr << "Creating ChatItem()" << std::endl;
return;
}
ChatItem::ChatItem(int st)
:PQItem(PQI_ITEM_TYPE_CHATITEM, st)
{
//std::cerr << "Creating ChatItem()" << std::endl;
return;
}
ChatItem::~ChatItem()
{
//std::cerr << "Deleting ChatItem()" << std::endl;
return;
}
MsgItem::MsgItem()
:ChatItem(PQI_MI_SUBTYPE_MSG), msgflags(0), sendTime(0)
{
//std::cerr << "Creating MsgItem()" << std::endl;
return;
}
MsgItem::~MsgItem()
{
//std::cerr << "Deleting MsgItem()" << std::endl;
return;
}
ChatItem *ChatItem::clone()
{
ChatItem *nsi = new ChatItem();
nsi -> copy(this);
return nsi;
}
void ChatItem::copy(const ChatItem *si)
{
// copy below.
PQItem::copy(si);
msg = si -> msg;
return;
}
std::ostream &ChatItem::print(std::ostream &out)
{
out << "---- ChatItem" << std::endl;
PQItem::print(out);
out << "Msg: " << msg;
out << std::endl << "----";
return out << std::endl;
}
MsgItem *MsgItem::clone()
{
MsgItem *nsi = new MsgItem();
nsi -> copy(this);
return nsi;
}
void MsgItem::copy(const MsgItem *mi)
{
// copy below.
ChatItem::copy(mi);
msgflags = mi -> msgflags;
sendTime = mi -> sendTime;
title = mi -> title;
header = mi -> header;
files = mi -> files;
}
std::ostream &MsgItem::print(std::ostream &out)
{
out << "-------- MsgItem" << std::endl;
ChatItem::print(out);
out << "MsgFlags: " << msgflags;
out << std::endl;
out << "SendTime: " << sendTime;
out << std::endl;
out << "Title: " << title;
out << std::endl;
out << "Header: " << header;
out << std::endl;
out << "NoFiles: " << files.size();
out << std::endl;
std::list<MsgFileItem>::iterator it;
for(it = files.begin(); it != files.end(); it++)
{
out << "File: " << it->name;
out << " Size: " << it->size;
out << " Hash: " << it->hash;
out << std::endl;
}
out << std::endl << "--------";
return out << std::endl;
}
//void FileItem::fillsi(SearchItem *si)
//{
// // first copy lowlevel stuff.
// si -> PQItem::copyIDs(this);
// if (hash.length() > 5)
// {
// // use hash.
// si -> data = hash;
// si -> datatype = PQI_SI_DATATYPE_HASH;
// }
// else
// {
// si -> data = name;
// si -> datatype = PQI_SI_DATATYPE_NAME;
// }
// return;
//}
// This uses some helper functions for
// string matching... these
// functions are located at the end
// of this file.
int PQFileItem::match(std::string term)
{
std::string lowerterm = strtolower(term);
std::string haystack = strtolower(path);
if (strstr(haystack.c_str(), lowerterm.c_str()) != NULL)
{
return 1;
}
haystack = strtolower(name);
if (strstr(haystack.c_str(), lowerterm.c_str()) != NULL)
{
return 1;
}
return 0;
}
MediaItem::MediaItem()
{
//std::cerr << "Creating MediaItem()" << std::endl;
return;
}
MediaItem::~MediaItem()
{
//std::cerr << "Deleting MediaItem()" << std::endl;
return;
}
MediaItem *MediaItem::clone()
{
MediaItem *nmi = new MediaItem();
nmi -> copy(this);
return nmi;
}
void MediaItem::copy(const MediaItem *src)
{
// copy fileitem stuff.
PQFileItem::copy(src);
mimetype = src -> mimetype;
title = src -> title;
author = src -> author;
collection = src -> collection;
genre = src -> genre;
len = src -> len;
return;
}
int MediaItem::match(std::string term)
{
std::string lowerterm = strtolower(term);
std::string haystack = strtolower(title);
if (strstr(haystack.c_str(), lowerterm.c_str()) != NULL)
{
return 1;
}
haystack = strtolower(author);
if (strstr(haystack.c_str(), lowerterm.c_str()) != NULL)
{
return 1;
}
haystack = strtolower(collection);
if (strstr(haystack.c_str(), lowerterm.c_str()) != NULL)
{
return 1;
}
haystack = strtolower(genre);
if (strstr(haystack.c_str(), lowerterm.c_str()) != NULL)
{
return 1;
}
return PQFileItem::match(term);
}
/*********************** STRING HELPERS *************************/
std::string strtolower(std::string in)
{
std::string out = in;
for(int i = 0; i < (signed) out.length(); i++)
{
if (isupper(out[i]))
{
out[i] += 'a' - 'A';
}
}
return out;
}
std::string fileextension(std::string in)
{
std::string out;
bool found = false;
for(int i = (signed) in.length() -1; (i >= 0) && (found == false); i--)
{
if (in[i] == '.')
{
found = true;
for(int j = i+1; j < (signed) in.length(); j++)
{
out += in[j];
}
}
}
return strtolower(out);
}
std::list<std::string> createtermlist(std::string in)
{
std::list<std::string> terms;
char str[1024];
strncpy(str, in.c_str(), 1024);
str[1023] = '\0';
int len = strlen(str);
int i;
int sword = 0;
for(i = 0; (i < len - 1) && (str[i] != '\0'); i++)
{
if (isspace(str[i]))
{
str[i] = '\0';
if (i - sword > 0)
{
terms.push_back(std::string(&(str[sword])));
//std::cerr << "Found Search Term: (" << &(str[sword]);
//std::cerr << ")" << std::endl;
}
sword = i+1;
}
}
// do the final term.
if (i - sword > 0)
{
terms.push_back(std::string(&(str[sword])));
//std::cerr << "Found Search Term: (" << &(str[sword]);
//std::cerr << ")" << std::endl;
}
return terms;
}
int match(PQFileItem *fi, SearchItem *si)
{
if (si -> datatype == PQI_SI_DATATYPE_HASH)
{
if (0 == strcmp((fi -> hash).c_str(), (si -> data).c_str()))
return 1;
return 0;
}
else if (si -> datatype == PQI_SI_DATATYPE_NAME)
{
if (0 == strcmp((fi -> name).c_str(), (si -> data).c_str()))
return 1;
return 0;
}
else // try it as terms....
{
std::list<std::string> terms = createtermlist(si -> data);
std::list<std::string>::iterator it;
if (terms.size() == 0)
{
return 0;
}
for(it = terms.begin(); it != terms.end(); it++)
{
if (0 == fi -> match(*it))
{
return 0;
}
}
return 1;
}
}

View File

@ -1,9 +1,9 @@
/*
* "$Id: pqi.h,v 1.8 2007-03-31 09:41:32 rmf24 Exp $"
* libretroshare/src/pqi pqi.h
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2004-2006 by Robert Fernie.
* 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
@ -24,20 +24,22 @@
*/
#ifndef PQI_TOP_HEADER
#define PQI_TOP_HEADER
#ifndef MRK_P3_PUBLIC_INTERFACE_HEADER
#define MRK_P3_PUBLIC_INTERFACE_HEADER
/* This just includes the standard headers required.
*/
// This is the overall include, for public usage
// + extension of the p3 interface.
#include "pqi/pqi_data.h"
#include "pqi/pqi_base.h"
#include "pqi/pqinetwork.h"
#include "serialiser/rsserial.h"
#include "serialiser/rsbaseitems.h"
#include <iostream>
#include <functional>
#include <algorithm>
/********************** SEARCH INTERFACE ***************************/
// this is an interface.... so should be
// classified as virtual = 0;
@ -49,54 +51,24 @@ public:
virtual ~SearchInterface() { return; }
// OutGoing Searches...
// Cache Requests
virtual int SearchSpecific(RsCacheRequest *) = 0;
virtual RsCacheRequest *RequestedSearch() = 0;
virtual int Search(SearchItem *) = 0; // Search All people...
virtual int SearchSpecific(SearchItem *) = 0; // Search One person only...
virtual int CancelSearch(SearchItem *) = 0; // no longer used?
virtual PQFileItem *GetSearchResult() = 0;
// Incoming Searches...
virtual SearchItem *RequestedSearch() = 0;
virtual SearchItem *CancelledSearch() = 0;
virtual int SendSearchResult(PQFileItem *item) = 0;
// Cache Results
virtual int SendSearchResult(RsCacheItem *item) = 0;
virtual RsCacheItem *GetSearchResult() = 0;
// FileTransfer.
virtual PQFileItem *GetFileItem() = 0;
virtual int SendFileItem(PQFileItem *) = 0;
virtual RsFileRequest *GetFileRequest() = 0;
virtual int SendFileRequest(RsFileRequest *) = 0;
virtual RsFileData *GetFileData() = 0;
virtual int SendFileData(RsFileData *) = 0;
};
class ChatInterface
{
public:
ChatInterface() {return; };
virtual ~ChatInterface() {return; };
virtual int SendMsg(ChatItem *item) = 0;
virtual int SendGlobalMsg(ChatItem *ns) = 0;
virtual ChatItem *GetMsg() = 0;
};
// This can potentially be moved to where the
// discovery code is!!!!
class HostItem: public PQItem { };
class DiscoveryInterface
{
public:
virtual ~DiscoveryInterface() { return; }
// Discovery Request.
virtual int DiscoveryRequest(PQItem *) = 0; // item is just for direction.
virtual HostItem *DiscoveryResult() = 0;
};
class P3Interface: public SearchInterface,
public ChatInterface
class P3Interface: public SearchInterface
{
public:
P3Interface() {return; }
@ -105,10 +77,10 @@ virtual ~P3Interface() {return; }
virtual int tick() { return 1; }
virtual int status() { return 1; }
virtual int SendOtherPQItem(PQItem *) = 0;
virtual PQItem *GetOtherPQItem() = 0;
virtual PQItem *SelectOtherPQItem(bool (*tst)(PQItem *)) = 0;
virtual int SendRsRawItem(RsRawItem *) = 0;
virtual RsRawItem *GetRsRawItem() = 0;
};
#endif //MRK_PQI_BASE_HEADER
#endif // PQI_TOP_HEADER

View File

@ -48,384 +48,6 @@ int getPQIsearchId()
return next_search_id++;
}
// SI Operations.
PQItem::PQItem()
:sid(0), type(0), subtype(0), p(0)
{
//std::cerr << "Creating PQItem(0,0)@" << std::endl;
//std::cerr << (void *) this << std::endl;
pqicid_clear(&cid);
return;
}
PQItem::~PQItem()
{
//std::cerr << "Deleting PQItem(" << type << ",";
//std::cerr << subtype << ")@" << (void *) this << std::endl;
return;
}
PQItem::PQItem(int t, int st)
:sid(0), type(t), subtype(st), flags(0), p(0)
{
//std::cerr << "Creating PQItem(" << t << "," << st << ")@";
//std::cerr << (void *) this << std::endl;
pqicid_clear(&cid);
return;
}
PQItem *PQItem::clone()
{
PQItem *npqi = new PQItem();
npqi -> copy(this);
return npqi;
}
void PQItem::copy(const PQItem *pqi)
{
sid = pqi -> sid;
pqicid_copy(&(pqi -> cid), &(cid));
type = pqi -> type;
subtype = pqi -> subtype;
flags = pqi -> flags;
p = pqi -> p;
return;
}
void PQItem::copyIDs(const PQItem *pqi)
{
sid = pqi -> sid;
pqicid_copy(&(pqi -> cid), &(cid));
// Person ref should also be part of the id.
p = pqi -> p;
return;
}
std::ostream &PQItem::print(std::ostream &out)
{
out << "-- PQItem" << std::endl;
out << "CID [" << cid.route[0];
for(int i = 0; i < 10; i++)
out << ":" << cid.route[i];
out << "] SID: " << sid << std::endl;
out << "Type: " << type << "/" << subtype;
out << " Flags: " << flags << std::endl;
out << " Source: ";
if (p == NULL)
{
out << "*Unknown*" << std::endl;
}
else
{
out << p -> Name() << std::endl;
}
return out << "--" << std::endl;
}
int PQItem::cidpop()
{
return pqiroute_getshift(&cid);
}
void PQItem::cidpush(int id)
{
pqiroute_setshift(&cid, id);
return;
}
PQFileItem::PQFileItem()
:PQItem(PQI_ITEM_TYPE_FILEITEM, PQI_FI_SUBTYPE_GENERAL),
reqtype(PQIFILE_STD)
{
//std::cerr << "Creating PQFileItem()" << std::endl;
return;
}
PQFileItem::PQFileItem(int subtype)
:PQItem(PQI_ITEM_TYPE_FILEITEM, subtype),
reqtype(PQIFILE_STD)
{
//std::cerr << "Creating PQFileItem()" << std::endl;
return;
}
PQFileItem::~PQFileItem()
{
//std::cerr << "Deleting PQFileItem()" << std::endl;
return;
}
PQFileItem *PQFileItem::clone()
{
PQFileItem *nfi = new PQFileItem();
nfi -> copy(this);
return nfi;
}
void PQFileItem::copy(const PQFileItem *src)
{
PQItem::copy(src);
hash = src -> hash;
name = src -> name;
path = src -> path;
ext = src -> ext;
size = src -> size;
fileoffset = src -> fileoffset;
chunksize = src -> chunksize;
exttype = src -> exttype;
reqtype = src -> reqtype;
return;
}
std::ostream &PQFileItem::print(std::ostream &out)
{
out << "-------- PQFileItem" << std::endl;
PQItem::print(out);
out << "Name: " << name << std::endl;
out << "Hash: " << hash << std::endl;
out << "Path: " << path << std::endl;
out << "Ext: " << ext << std::endl;
out << "Size: " << size << std::endl;
out << "FileOffset: " << fileoffset << std::endl;
out << "ChunkSize: " << chunksize << std::endl;
out << "Ext/Req Types: " << exttype << "/" << reqtype << std::endl;
return out << "--------" << std::endl;
}
PQFileData::PQFileData()
:PQFileItem(PQI_FI_SUBTYPE_DATA),
datalen(0), data(NULL), fileflags(0)
{
//std::cerr << "Creating PQFileData()" << std::endl;
flags = 0;
return;
}
PQFileData::~PQFileData()
{
if (data != NULL)
{
free(data);
}
//std::cerr << "Deleting PQFileData()" << std::endl;
return;
}
PQFileData *PQFileData::clone()
{
PQFileData *nfd = new PQFileData();
nfd -> copy(this);
return nfd;
}
void PQFileData::copy(const PQFileData *fd)
{
// copy below.
PQItem::copy(fd);
if (data != NULL)
{
free(data);
}
data = malloc(fd -> datalen);
memcpy(data, fd -> data, fd -> datalen);
datalen = fd -> datalen;
fileflags = fd -> fileflags;
return;
}
std::ostream &PQFileData::print(std::ostream &out)
{
out << "-------- PQFileData" << std::endl;
PQItem::print(out);
out << "DataLen: " << datalen << std::endl;
out << "FileFlags: " << fileflags << std::endl;
return out << "--------" << std::endl;
}
int PQFileData::writedata(std::ostream &out)
{
//std::cerr << "PQFileData::writedata() len: " << datalen << std::endl;
if (data != NULL)
{
out.write((char *) data, datalen);
if (out.bad())
{
//std::cerr << "PQFileData::writedata() Bad ostream!" << std::endl;
return -1;
}
return 1;
}
return 1;
}
int PQFileData::readdata(std::istream &in, int maxbytes)
{
if (data != NULL)
{
free(data);
}
data = malloc(maxbytes);
in.read((char *) data, maxbytes);
int read = in.gcount();
// if read < maxread then finished?
if (read < maxbytes)
{
// check if finished.
if (in.eof())
{
isend();
}
else
{
//std::cerr << "pqi_makeFilePkt() Only Read: ";
//std::cerr << read << "/" << maxbytes << " Why?";
//std::cerr << std::endl;
}
// adjust the space.
void *tmpdata = data;
data = malloc(read);
memcpy(data, tmpdata, read);
free(tmpdata);
}
datalen = read;
return 1;
}
int PQFileData::endstream()
{
if (fileflags & PQI_FD_FLAG_ENDSTREAM)
return 1;
return 0;
}
void PQFileData::isend()
{
fileflags |= PQI_FD_FLAG_ENDSTREAM;
return;
}
FileTransferItem::FileTransferItem()
:PQFileItem(PQI_FI_SUBTYPE_TRANSFER),
transferred(0), state(FT_STATE_OKAY),
crate(0), trate(0), in(false), ltransfer(0), lrate(0)
{
//std::cerr << "Creating FileTransferItem()" << std::endl;
return;
}
FileTransferItem::~FileTransferItem()
{
//std::cerr << "Deleting FileTransferItem()" << std::endl;
return;
}
FileTransferItem *FileTransferItem::clone()
{
FileTransferItem *nfd = new FileTransferItem();
nfd -> copy(this);
return nfd;
}
void FileTransferItem::copy(const FileTransferItem *fd)
{
// copy below.
PQFileItem::copy(fd);
transferred = fd -> transferred;
state = fd -> state;
crate = fd -> crate;
trate = fd -> trate;
in = fd -> in;
ltransfer = fd -> ltransfer;
lrate = fd -> lrate;
return;
}
std::ostream &FileTransferItem::print(std::ostream &out)
{
out << "-------- FileTransferItem" << std::endl;
PQFileItem::print(out);
if (in == true)
{
out << "Incoming File.....";
}
else
{
out << "Outgoing File.....";
}
out << "Transferred: " << transferred << std::endl;
out << "Transfer State: " << state << std::endl;
out << "Current/Total Rate: " << crate << "/" << trate << std::endl;
out << "LTransfer/LRate: " << ltransfer << "/" << lrate << std::endl;
return out << "--------" << std::endl;
}
RateCntrlItem::RateCntrlItem()
:PQFileItem(PQI_FI_SUBTYPE_RATE),
total(0), individual(0)
{
//std::cerr << "Creating RateCntrlItem()" << std::endl;
return;
}
RateCntrlItem::~RateCntrlItem()
{
//std::cerr << "Deleting RateCntrlItem()" << std::endl;
return;
}
RateCntrlItem *RateCntrlItem::clone()
{
RateCntrlItem *nfd = new RateCntrlItem();
nfd -> copy(this);
return nfd;
}
void RateCntrlItem::copy(const RateCntrlItem *fd)
{
// copy below.
PQFileItem::copy(fd);
total = fd -> total;
individual = fd -> individual;
return;
}
std::ostream &RateCntrlItem::print(std::ostream &out)
{
out << "-------- RateCntrlItem" << std::endl;
PQFileItem::print(out);
out << "Total Rate: " << total << std::endl;
out << "Individual Rate: " << individual << std::endl;
return out << "--------" << std::endl;
}
// CHANID Operations.
int pqicid_clear(ChanId *cid)

View File

@ -36,6 +36,9 @@
#include "pqi/pqinetwork.h"
/*** Base DataTypes: ****/
#include "serialiser/rsserial.h"
#define PQI_MIN_PORT 1024
#define PQI_MAX_PORT 16000
@ -61,7 +64,7 @@ int pqicid_cmp(const ChanId *cid1, ChanId *cid2);
// So the basic pqi interface defines
//
// 1) Person -> reference object
// 2) PQItem
// 2) RsItem
// 3) PQInterface
// which defines:
// - send/recieve objs
@ -80,7 +83,7 @@ int pqicid_cmp(const ChanId *cid1, ChanId *cid2);
// Base for all Security/Id/Certificate schemes.
// The list of these must be maintained seperately
// from the PQItems....
// from the RsItems....
// Person - includes
@ -198,197 +201,6 @@ private:
};
class PQItem
{
// include serialisation (Boost) functions...
// private copy constructor... prevent copying...
PQItem(const PQItem &) {return; }
public:
PQItem();
PQItem(int t, int st); // initialise with subtypes.
virtual ~PQItem();
// other type of serialise....
virtual std::ostream &print(std::ostream &out);
// copy functions.
virtual PQItem *clone();
void copy(const PQItem *pqi);
void copyIDs(const PQItem *pqi);
// stack operations -> could be converted to STL stack.
int cidpop();
void cidpush(int id);
// data
ChanId cid;
SearchId sid;
int type;
int subtype;
int flags;
Person *p; // This is shallow copied inside to itself,
// Over serialisation - becomes a name....
};
// Some Functional Objects for operations on PQItems
class PQItem_MatchSid
//: public unary_function <PQItem *, bool>
{
unsigned long sid;
public:
explicit PQItem_MatchSid(const unsigned long s) : sid(s) {}
bool operator()(const PQItem *pqi) const
{
if (pqi == NULL)
return false;
return (pqi -> sid == sid);
}
};
class PQItem_MatchType
//: public unary_function <PQItem *, bool>
{
int type, subtype;
public:
explicit PQItem_MatchType(const int t, const int s = 0)
: type(t), subtype(s) {}
bool operator()(const PQItem *pqi) const
{
if (pqi == NULL)
return false;
if (type == pqi -> type)
{
if (subtype == 0)
return true;
return (pqi -> subtype == subtype);
}
return false;
}
};
#define PQIFILE_STD 0x0001
#define PQIFILE_DIRLIST_FILE 0x0002
#define PQIFILE_DIRLIST_DIR 0x0004
class PQFileItem: public PQItem
{
// private copy constructor... prevent copying...
PQFileItem(const PQFileItem &) {return; }
public:
PQFileItem();
PQFileItem(int st); // initialise with subtypes.
virtual ~PQFileItem();
// copy functions.
virtual PQFileItem *clone();
void copy(const PQFileItem *src);
std::ostream &print(std::ostream &out);
virtual int match(std::string term);
std::string hash;
std::string name;
std::string path;
std::string ext;
int size; // total size of file.
long fileoffset; // used for file requests.
long chunksize; // used for file requests.
int reqtype;
int exttype;
};
class PQFileData: public PQFileItem
{
public:
PQFileData();
virtual ~PQFileData();
virtual PQFileData *clone();
void copy(const PQFileData *fd);
virtual std::ostream &print(std::ostream &out);
int writedata(std::ostream &out);
int readdata(std::istream &in, int maxbytes);
int endstream();
void isend();
// data
int datalen;
void *data;
int fileflags;
};
// And finally the Control/Info Interface.
class FileTransferItem: public PQFileItem
{
// private copy constructor... prevent copying...
// FileTransferItem(const FileTransferItem &) {return; }
public:
FileTransferItem();
virtual ~FileTransferItem();
virtual FileTransferItem *clone();
void copy(const FileTransferItem *ft);
virtual std::ostream &print(std::ostream &out);
int transferred;
int state;
float crate;
float trate;
bool in;
int ltransfer;
float lrate;
};
#define FT_STATE_FAILED 0
#define FT_STATE_OKAY 1
#define FT_STATE_COMPLETE 2
class RateCntrlItem: public PQFileItem
{
public:
RateCntrlItem();
virtual ~RateCntrlItem();
virtual RateCntrlItem *clone();
void copy(const RateCntrlItem *ft);
virtual std::ostream &print(std::ostream &out);
float total;
float individual;
};
class RateInterface
{
// controlling data rates.
@ -437,9 +249,6 @@ float bw_in, bw_out, bwMax_in, bwMax_out;
};
/*********************** PQI INTERFACE ******************************\
* The basic exchange interface.
* This inherits the RateInterface, as Bandwidth control
@ -451,19 +260,23 @@ class NetInterface;
class PQInterface: public RateInterface
{
public:
PQInterface() { return; }
PQInterface(std::string id) :peerId(id) { return; }
virtual ~PQInterface() { return; }
virtual int SendItem(PQItem *) = 0;
virtual PQItem *GetItem() = 0;
virtual int SendItem(RsItem *) = 0;
virtual RsItem *GetItem() = 0;
// also there are tick + person id functions.
virtual int tick() { return 0; }
virtual int status() { return 0; }
virtual Person *getContact() { return NULL; }
virtual std::string PeerId() { return peerId; }
// the callback from NetInterface Connection Events.
virtual int notifyEvent(NetInterface *ni, int event) { return 0; }
private:
std::string peerId;
};
/********************** Binary INTERFACE ****************************
@ -474,6 +287,7 @@ virtual int notifyEvent(NetInterface *ni, int event) { return 0; }
#define BIN_FLAGS_NO_CLOSE 0x0001
#define BIN_FLAGS_READABLE 0x0002
#define BIN_FLAGS_WRITEABLE 0x0004
#define BIN_FLAGS_NO_DELETE 0x0008
class BinInterface
{
@ -515,8 +329,8 @@ static const int NET_CONNECT_FAILED = 5;
class NetInterface
{
public:
NetInterface(PQInterface *p_in, Person *person_in)
:p(p_in), person(person_in) { return; }
NetInterface(PQInterface *p_in, std::string id)
:p(p_in), peerId(id) { return; }
virtual ~NetInterface()
{ return; }
@ -528,28 +342,29 @@ virtual int listen() = 0;
virtual int stoplistening() = 0;
virtual int disconnect() = 0;
virtual int reset() = 0;
virtual Person *getContact() { return person; }
virtual std::string PeerId() { return peerId; }
protected:
PQInterface *parent() { return p; }
private:
PQInterface *p;
Person *person;
std::string peerId;
};
class NetBinInterface: public NetInterface, public BinInterface
{
public:
NetBinInterface(PQInterface *parent, Person *person)
:NetInterface(parent, person)
NetBinInterface(PQInterface *parent, std::string id)
:NetInterface(parent, id)
{ return; }
virtual ~NetBinInterface() { return; }
};
#define CHAN_SIGN_SIZE 16
#define CERTSIGNLEN 16
#define PQI_PEERID_LENGTH 16
class certsign
{

View File

@ -1,169 +0,0 @@
/*
* "$Id: pqi_data.h,v 1.8 2007-04-07 08:40:55 rmf24 Exp $"
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2004-2006 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 PQI_ITEM_HEADER
#define PQI_ITEM_HEADER
#include "pqi/pqi_base.h"
#include <list>
#include <string>
#include <iostream>
// Definitions of some of the commonly used classes.
// These will all be made streamable! via Boost C++
class SearchItem: public PQItem
{
public:
SearchItem();
SearchItem(int st);
virtual ~SearchItem();
virtual SearchItem *clone();
void copy(const SearchItem *si);
virtual std::ostream &print(std::ostream &out);
// data
int datatype;
std::string data;
int siflags;
};
int match(PQFileItem *fi, SearchItem *si);
class MediaItem: public PQFileItem
{
public:
MediaItem();
virtual ~MediaItem();
virtual MediaItem *clone();
void copy(const MediaItem *src);
int match(std::string term);
// data.
std::string mimetype;
std::string title;
std::string author;
std::string collection;
std::string genre;
int len;
};
class ChatItem: public PQItem
{
public:
ChatItem();
ChatItem(int st);
virtual ~ChatItem();
virtual ChatItem *clone();
void copy(const ChatItem *si);
virtual std::ostream &print(std::ostream &out);
// data
std::string msg;
// Timestamp (Not transmitted currently!).
// Stamped on arrival.
int epoch;
};
class MsgFileItem
{
public:
std::string name; /* and dir! */
std::string hash;
unsigned long size;
};
class MsgItem: public ChatItem
{
public:
MsgItem();
virtual ~MsgItem();
virtual MsgItem *clone();
void copy(const MsgItem *mi);
std::ostream &print(std::ostream &out);
// Note this breaks the old client....
// Old data.....
//int mode;
//std::string recommendname;
//std::string recommendhash;
//std::string channel;
//int recommendsize;
//int datalen;
//void *data;
// Flags
unsigned long msgflags;
unsigned long sendTime;
std::string title;
std::string header;
std::list<MsgFileItem> files;
};
std::string strtolower(std::string in);
std::string fileextension(std::string in);
std::list<std::string> createtermlist(std::string in);
// IDS
const int PQI_SI_SUBTYPE_SEARCH = 1;
const int PQI_SI_SUBTYPE_CANCEL = 2;
const int PQI_SI_SUBTYPE_FILEREQ = 3;
const int PQI_SI_SUBTYPE_FILECANCEL = 4;
const int PQI_SI_DATATYPE_TERMS = 1;
const int PQI_SI_DATATYPE_HASH = 2;
const int PQI_SI_DATATYPE_NAME = 3;
const int PQI_SI_DATATYPE_DIR = 4;
const int PQI_MI_SUBTYPE_CHAT = 1;
const int PQI_MI_SUBTYPE_MSG = 2;
/* not really used here, but at higher layers */
const unsigned long PQI_MI_FLAGS_OUTGOING = 0x0001;
const unsigned long PQI_MI_FLAGS_PENDING = 0x0002;
const unsigned long PQI_MI_FLAGS_DRAFT = 0x0004;
const unsigned long PQI_MI_FLAGS_NEW = 0x0010;
#endif // PQI_ITEM_HEADER

View File

@ -33,7 +33,7 @@
/*******************************************************************
* pqiarchive provides an archive stream.
* This stores PQItem + Person Reference + Timestamp,
* This stores RsItem + Person Reference + Timestamp,
*
* and allows Objects to be replayed or restored,
* independently of the rest of the pqi system.
@ -41,7 +41,7 @@
*/
#include "pqi/pqiarchive.h"
#include "pqi/pqipacket.h"
#include "serialiser/rsserial.h"
#include <iostream>
#include <fstream>
@ -60,10 +60,13 @@ struct pqiarchive_header
const int PQIARCHIVE_TYPE_PQITEM = 0x0001;
pqiarchive::pqiarchive(BinInterface *bio_in, int bio_flags_in, sslroot *s)
:bio(bio_in), bio_flags(bio_flags_in),
nextPkt(NULL), nextPktTS(0), firstPktTS(0), initTS(0),
sslr(s)
/* PeerId of PQInterface is not important ... as we are archiving
* packets from other people...
*/
pqiarchive::pqiarchive(RsSerialiser *rss, BinInterface *bio_in, int bio_flags_in)
:PQInterface(""), rsSerialiser(rss), bio(bio_in), bio_flags(bio_flags_in),
nextPkt(NULL), nextPktTS(0), firstPktTS(0), initTS(0)
{
{
std::ostringstream out;
@ -112,14 +115,14 @@ pqiarchive::~pqiarchive()
if (nextPkt)
{
pqipkt_delete(nextPkt);
delete nextPkt;
}
return;
}
// Get/Send Items.
int pqiarchive::SendItem(PQItem *si)
int pqiarchive::SendItem(RsItem *si)
{
{
std::ostringstream out;
@ -132,7 +135,8 @@ int pqiarchive::SendItem(PQItem *si)
if (!(bio_flags & BIN_FLAGS_WRITEABLE))
{
delete si;
if (!(bio_flags & BIN_FLAGS_NO_DELETE))
delete si;
return -1;
}
@ -140,7 +144,7 @@ int pqiarchive::SendItem(PQItem *si)
return ret; /* 0 - failure, 1 - success*/
}
PQItem *pqiarchive::GetItem()
RsItem *pqiarchive::GetItem()
{
{
std::ostringstream out;
@ -198,7 +202,7 @@ PQItem *pqiarchive::GetItem()
initTS = time(NULL);
firstPktTS = nextPktTS;
}
PQItem *outPkt = nextPkt;
RsItem *outPkt = nextPkt;
nextPkt = NULL;
if (outPkt != NULL)
@ -237,7 +241,7 @@ int pqiarchive::status()
//
/**************** HANDLE OUTGOING TRANSLATION + TRANSMISSION ******/
int pqiarchive::writePkt(PQItem *pqi)
int pqiarchive::writePkt(RsItem *pqi)
{
{
std::ostringstream out;
@ -245,8 +249,9 @@ int pqiarchive::writePkt(PQItem *pqi)
pqioutput(PQL_DEBUG_ALL, pqiarchivezone, out.str());
}
void *ptr = pqipkt_makepkt(pqi);
if (NULL == ptr)
uint32_t pktsize = rsSerialiser->size(pqi);
void *ptr = malloc(pktsize);
if (!(rsSerialiser->serialise(pqi, ptr, &pktsize)))
{
std::ostringstream out;
out << "pqiarchive::writePkt() Null Pkt generated!";
@ -255,13 +260,30 @@ int pqiarchive::writePkt(PQItem *pqi)
pqi -> print(out);
pqioutput(PQL_ALERT, pqiarchivezone, out.str());
pqipkt_delete(ptr);
delete pqi;
free(ptr);
if (!(bio_flags & BIN_FLAGS_NO_DELETE))
delete pqi;
return 0;
}
/* extract the extra details */
int len = pqipkt_rawlen(ptr);
uint32_t len = getRsItemSize(ptr);
if (len != pktsize)
{
std::ostringstream out;
out << "pqiarchive::writePkt() Length MisMatch: len: " << len;
out << " != pktsize: " << pktsize;
out << std::endl;
out << "Caused By: " << std::endl;
pqi -> print(out);
pqioutput(PQL_ALERT, pqiarchivezone, out.str());
free(ptr);
if (!(bio_flags & BIN_FLAGS_NO_DELETE))
delete pqi;
return 0;
}
if (!(bio->cansend()))
{
@ -272,36 +294,36 @@ int pqiarchive::writePkt(PQItem *pqi)
pqi -> print(out);
pqioutput(PQL_ALERT, pqiarchivezone, out.str());
pqipkt_delete(ptr);
delete pqi;
free(ptr);
if (!(bio_flags & BIN_FLAGS_NO_DELETE))
delete pqi;
return 0;
}
// using the peerid from the item.
if (pqi->PeerId().length() != PQI_PEERID_LENGTH)
{
std::ostringstream out;
out << "pqiarchive::writePkt() Invalid peerId Length!";
out << std::endl;
out << "Caused By: " << std::endl;
pqi -> print(out);
pqioutput(PQL_ALERT, pqiarchivezone, out.str());
free(ptr);
if (!(bio_flags & BIN_FLAGS_NO_DELETE))
delete pqi;
return 0;
}
std::ostringstream out;
out << "Writing Pkt Header" << std::endl;
struct pqiarchive_header hdr;
hdr.type = PQIARCHIVE_TYPE_PQITEM;
hdr.length = len;
hdr.ts = time(NULL);
certsign sig;
// NB: At the moment, the messages we have sent don't have
// pqi->p set, and so they will be discarded......
if (!sslr -> getcertsign((cert *) (pqi -> p), sig))
{
out << "pqiarchive::writePkt() cannot get certsign!";
out << std::endl;
out << "Caused By: " << std::endl;
pqi -> print(out);
pqioutput(PQL_ALERT, pqiarchivezone, out.str());
pqipkt_delete(ptr);
delete pqi;
return 0;
}
memcpy(hdr.personSig, sig.data, CERTSIGNLEN);
memcpy(hdr.personSig, pqi->PeerId().c_str(), PQI_PEERID_LENGTH);
// write packet header.
if (sizeof(hdr) != bio->senddata(&hdr, sizeof(hdr)))
@ -310,8 +332,9 @@ int pqiarchive::writePkt(PQItem *pqi)
out << std::endl;
pqioutput(PQL_ALERT, pqiarchivezone, out.str());
pqipkt_delete(ptr);
delete pqi;
free(ptr);
if (!(bio_flags & BIN_FLAGS_NO_DELETE))
delete pqi;
return 0;
}
@ -325,8 +348,9 @@ int pqiarchive::writePkt(PQItem *pqi)
out << std::endl;
pqioutput(PQL_ALERT, pqiarchivezone, out.str());
pqipkt_delete(ptr);
delete pqi;
free(ptr);
if (!(bio_flags & BIN_FLAGS_NO_DELETE))
delete pqi;
return 0;
}
@ -334,8 +358,9 @@ int pqiarchive::writePkt(PQItem *pqi)
out << " Success!" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqiarchivezone, out.str());
pqipkt_delete(ptr);
delete pqi;
free(ptr);
if (!(bio_flags & BIN_FLAGS_NO_DELETE))
delete pqi;
return 1;
}
@ -345,7 +370,7 @@ int pqiarchive::writePkt(PQItem *pqi)
*
*/
int pqiarchive::readPkt(PQItem **item_out, long *ts_out)
int pqiarchive::readPkt(RsItem **item_out, long *ts_out)
{
{
std::ostringstream out;
@ -362,11 +387,11 @@ int pqiarchive::readPkt(PQItem **item_out, long *ts_out)
struct pqiarchive_header hdr;
// enough space to read any packet.
int maxlen = pqipkt_maxsize();
int maxlen = getRsPktMaxSize();
void *block = malloc(maxlen);
// initial read size: basic packet.
int blen = pqipkt_basesize();
int blen = getRsPktBaseSize();
int tmplen;
@ -394,7 +419,7 @@ int pqiarchive::readPkt(PQItem **item_out, long *ts_out)
}
// workout how much more to read.
int extralen = pqipkt_rawlen(block) - blen;
int extralen = getRsItemSize(block) - blen;
if (extralen > 0)
{
void *extradata = (void *) (((char *) block) + blen);
@ -415,15 +440,11 @@ int pqiarchive::readPkt(PQItem **item_out, long *ts_out)
// create packet, based on header.
std::cerr << "Read Data Block -> Incoming Pkt(";
std::cerr << blen + extralen << ")" << std::endl;
int readbytes = extralen + blen;
PQItem *item = NULL;
if (pqipkt_check(block, readbytes))
{
item = pqipkt_create(block);
}
uint32_t readbytes = extralen + blen;
RsItem *item = rsSerialiser->deserialise(block, &readbytes);
free(block);
if (item == NULL)
{
pqioutput(PQL_ALERT, pqiarchivezone,
@ -431,39 +452,20 @@ int pqiarchive::readPkt(PQItem **item_out, long *ts_out)
return 0;
}
/* get the PersonSign out of the header */
certsign sig;
memcpy(sig.data, hdr.personSig, CERTSIGNLEN);
item -> p = sslr -> findcertsign(sig);
/* if we can't identify the person it is from,
* then we need to discard it!..... (happens
* when they've been removed from our friend list....
/* Cannot detect bad ids here anymore....
* but removed dependancy on the sslroot!
*/
if (item->p==NULL)
{
std::ostringstream out;
out << "pqiarchive::readPkt() Couldn't translate certsign";
out << " into cert for pkt:" << std::endl;
item->print(out);
out << "Discarding!";
pqioutput(PQL_ALERT, pqiarchivezone, out.str());
delete item;
item = NULL;
return 0;
}
else
std::string peerId = "";
for(int i = 0; i < PQI_PEERID_LENGTH; i++)
{
/* copy cid ... to ensure outgoing
* msgs work properly
*/
item->cid = item->p->cid;
peerId += hdr.personSig[i];
}
item->PeerId(peerId);
*item_out = item;
*ts_out = hdr.ts;
/* cid/sid will be wrong */
return 1;
}

View File

@ -28,23 +28,13 @@
#ifndef MRK_PQI_ARCHIVE_STREAMER_HEADER
#define MRK_PQI_ARCHIVE_STREAMER_HEADER
// Only dependent on the base stuff.
#include "pqi/pqi_base.h"
/**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP)
#include "pqi/xpgpcert.h"
#else /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
#include "pqi/sslcert.h"
#endif /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
#include "pqi/pqi.h"
#include <list>
/*******************************************************************
* pqiarchive provides an archive stream.
* This stores PQItem + Person Reference + Timestamp,
* This stores RsItem + Person Reference + Timestamp,
*
* and allows Objects to be replayed or restored,
* independently of the rest of the pqi system.
@ -54,31 +44,32 @@
class pqiarchive: PQInterface
{
public:
pqiarchive(BinInterface *bio_in, int bio_flagsin, sslroot *);
pqiarchive(RsSerialiser *rss, BinInterface *bio_in, int bio_flagsin);
virtual ~pqiarchive();
// PQInterface
virtual int SendItem(PQItem *);
virtual PQItem *GetItem();
virtual int SendItem(RsItem *);
virtual RsItem *GetItem();
virtual int tick();
virtual int status();
virtual void setRealTime(bool r) { realTime = r; }
private:
int writePkt(PQItem *item);
int readPkt(PQItem **item_out, long *ts);
int writePkt(RsItem *item);
int readPkt(RsItem **item_out, long *ts);
// Serialiser
RsSerialiser *rsSerialiser;
// Binary Interface for IO, initialisated at startup.
BinInterface *bio;
unsigned int bio_flags; // only BIN_NO_CLOSE at the moment.
// Temp Storage for transient data.....
PQItem *nextPkt;
RsItem *nextPkt;
long nextPktTS; /* timestamp associated with nextPkt */
long firstPktTS; /* timestamp associated with first read Pkt */
long initTS; /* clock timestamp at first read */
sslroot *sslr;
bool realTime;
};

View File

@ -59,7 +59,7 @@ pqihandler::pqihandler(SecurityPolicy *Global)
int pqihandler::tick()
{
// tick all interfaces...
std::map<int, SearchModule *>::iterator it;
std::map<std::string, SearchModule *>::iterator it;
int moreToTick = 0;
for(it = mods.begin(); it != mods.end(); it++)
{
@ -81,7 +81,7 @@ int pqihandler::tick()
int pqihandler::status()
{
std::map<int, SearchModule *>::iterator it;
std::map<std::string, SearchModule *>::iterator it;
{ // for output
std::ostringstream out;
@ -109,45 +109,35 @@ int pqihandler::status()
int pqihandler::AddSearchModule(SearchModule *mod, int chanid)
bool pqihandler::AddSearchModule(SearchModule *mod)
{
// if chan id set, then use....
// otherwise find empty channel.
int realchanid = -1;
std::map<int, SearchModule *>::iterator it;
if ((chanid > 0) && (mods.find(chanid) == mods.end()))
// if peerid used -> error.
std::map<std::string, SearchModule *>::iterator it;
if (mod->peerid != mod->pqi->PeerId())
{
// okay id.
realchanid = chanid;
// ERROR!
std::ostringstream out;
out << "ERROR peerid != PeerId!" << std::endl;
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
return false;
}
else
{
// find empty chan.
for(int i = 1; (i < 1000) && (realchanid == -1); i++)
{
if (mods.find(i) == mods.end())
{
realchanid = i;
}
}
if (realchanid > 0)
{
std::ostringstream out;
out << "Allocated Chan Id: " << realchanid << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
}
else
{
std::ostringstream out;
out << "Unable to Allocate Channel!" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
return -1;
}
if (mod->peerid == "")
{
// ERROR!
std::ostringstream out;
out << "ERROR peerid == NULL" << std::endl;
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
return false;
}
if (mods.find(mod->peerid) != mods.end())
{
// ERROR!
std::ostringstream out;
out << "ERROR PeerId Module already exists!" << std::endl;
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
return false;
}
// check security.
@ -161,35 +151,26 @@ int pqihandler::AddSearchModule(SearchModule *mod, int chanid)
secpolicy_limit(globsec, mod -> sp);
// store.
mods[realchanid] = mod;
mod -> smi = realchanid;
// experimental ... pushcid.
Person *p = (mod -> pqi) -> getContact();
if (p != NULL)
{
p -> cidpush(realchanid);
}
return realchanid;
mods[mod->peerid] = mod;
return true;
}
int pqihandler::RemoveSearchModule(SearchModule *mod)
bool pqihandler::RemoveSearchModule(SearchModule *mod)
{
std::map<int, SearchModule *>::iterator it;
std::map<std::string, SearchModule *>::iterator it;
for(it = mods.begin(); it != mods.end(); it++)
{
if (mod == it -> second)
{
mods.erase(it);
return 1;
return true;
}
}
return -1;
return false;
}
// dummy output check
int pqihandler::checkOutgoingPQItem(PQItem *item, int global)
int pqihandler::checkOutgoingRsItem(RsItem *item, int global)
{
pqioutput(PQL_WARNING, pqihandlerzone,
"pqihandler::checkOutgoingPQItem() NULL fn");
@ -199,176 +180,115 @@ int pqihandler::checkOutgoingPQItem(PQItem *item, int global)
// generalised output
int pqihandler::HandlePQItem(PQItem *item, int allowglobal)
int pqihandler::HandleRsItem(RsItem *item, int allowglobal)
{
std::map<int, SearchModule *>::iterator it;
std::map<std::string, SearchModule *>::iterator it;
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"pqihandler::HandlePQItem()");
"pqihandler::HandleRsItem()");
if ((!allowglobal) && (!checkOutgoingPQItem(item, allowglobal)))
/* simplified to no global! */
if (allowglobal)
{
/* error */
std::ostringstream out;
out << "pqihandler::HandlePQItem() checkOutgoingPQItem";
out << " Failed on item: " << std::endl;
item -> print(out);
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
out << "pqihandler::HandleSearchItem()";
out << " Cannot send out Global RsItem";
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
delete item;
return -1;
}
// need to get channel id. (and remove from stack)
int chan = item -> cidpop();
if (chan > 0)
if (!checkOutgoingRsItem(item, allowglobal))
{
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"pqihandler::HandlePQItem() Sending to One Channel");
std::ostringstream out;
out << "pqihandler::HandleRsItem() checkOutgoingPQItem";
out << " Failed on item: " << std::endl;
item -> print(out);
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
delete item;
return -1;
}
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"pqihandler::HandleRsItem() Sending to One Channel");
// find module.
if ((it = mods.find(chan)) == mods.end())
{
std::ostringstream out;
out << "pqihandler::HandlePQItem() Invalid chan!";
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
// find module.
if ((it = mods.find(item->PeerId())) == mods.end())
{
std::ostringstream out;
out << "pqihandler::HandleRsItem() Invalid chan!";
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
delete item;
return -1;
}
delete item;
return -1;
}
// check security... is output allowed.
if(0 < secpolicy_check((it -> second) -> sp, 0, PQI_OUTGOING))
{
std::ostringstream out;
out << "pqihandler::HandlePQItem() sending to chan:";
out << it -> first << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
// check security... is output allowed.
if(0 < secpolicy_check((it -> second) -> sp, 0, PQI_OUTGOING))
{
std::ostringstream out;
out << "pqihandler::HandleRsItem() sending to chan:";
out << it -> first << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
// if yes send on item.
((it -> second) -> pqi) -> SendItem(item);
return 1;
}
else
{
std::ostringstream out;
out << "pqihandler::HandlePQItem()";
out << " Sec not approved";
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
delete item;
return -1;
}
// if yes send on item.
((it -> second) -> pqi) -> SendItem(item);
return 1;
}
else
{
if (allowglobal <= 0)
{
std::ostringstream out;
out << "pqihandler::HandleSearchItem()";
out << " invalid routing for non-global searchitem";
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
std::ostringstream out;
out << "pqihandler::HandleRsItem()";
out << " Sec not approved";
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
return -1;
}
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"pqihandler::HandlePQItem() Sending to All Channels");
// loop through all channels.
// for each one.
// find module
// if yes send.
for(it = mods.begin(); it != mods.end(); it++)
{
// check security... is output allowed.
if(0 < secpolicy_check((it -> second) -> sp, 0, PQI_OUTGOING))
{
std::ostringstream out;
out << "pqihandler::HandlePQItem()";
out << "Sending to chan:" << it -> first;
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
// if yes send on item.
((it -> second) -> pqi) -> SendItem(item -> clone());
}
else
{
std::ostringstream out;
out << "pqihandler::HandlePQItem()";
out << " List Send - Not in this channel!";
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
}
}
// now we can clean up!
delete item;
return 1;
return -1;
}
// if successfully sent to at least one.
return 1;
}
// 4 very similar outputs.....
int pqihandler::Search(SearchItem *ns)
int pqihandler::SearchSpecific(RsCacheRequest *ns)
{
return HandlePQItem(ns, 1);
return HandleRsItem(ns, 0);
}
/* This is called when we only want it to go to 1 person.... */
int pqihandler::SearchSpecific(SearchItem *ns)
int pqihandler::SendSearchResult(RsCacheItem *ns)
{
return HandlePQItem(ns, 0);
return HandleRsItem(ns, 0);
}
int pqihandler::CancelSearch(SearchItem *ns)
int pqihandler::SendFileRequest(RsFileRequest *ns)
{
return HandlePQItem(ns, 1);
return HandleRsItem(ns, 0);
}
int pqihandler::SendFileItem(PQFileItem *ns)
int pqihandler::SendFileData(RsFileData *ns)
{
return HandlePQItem(ns, 0);
return HandleRsItem(ns, 0);
}
int pqihandler::SendSearchResult(PQFileItem *ns)
{
return HandlePQItem(ns, 0);
}
int pqihandler::SendMsg(ChatItem *ns)
{
/* switch from 1 -> 0 for specific directed Msg */
return HandlePQItem(ns, 0);
}
int pqihandler::SendGlobalMsg(ChatItem *ns)
{
return HandlePQItem(ns, 1);
}
int pqihandler::SendOtherPQItem(PQItem *ns)
int pqihandler::SendRsRawItem(RsRawItem *ns)
{
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"pqihandler::SendOtherPQItem()");
return HandlePQItem(ns, 1);
"pqihandler::SendRsRawItem()");
return HandleRsItem(ns, 0);
}
// inputs. This is a very basic
// system that is completely biased and slow...
// someone please fix.
int pqihandler::GetItems()
{
std::map<int, SearchModule *>::iterator it;
std::map<std::string, SearchModule *>::iterator it;
PQItem *item;
RsItem *item;
int count = 0;
// loop through modules....
@ -391,9 +311,14 @@ int pqihandler::GetItems()
pqioutput(PQL_DEBUG_BASIC,
pqihandlerzone, out.str());
// got one!....
// update routing.
item -> cidpush(mod -> smi);
if (item->PeerId() != (mod->pqi)->PeerId())
{
/* ERROR */
pqioutput(PQL_ALERT,
pqihandlerzone, "ERROR PeerIds dont match!");
item->PeerId(mod->pqi->PeerId());
}
SortnStoreItem(item);
count++;
}
@ -424,150 +349,162 @@ int pqihandler::GetItems()
void pqihandler::SortnStoreItem(PQItem *item)
void pqihandler::SortnStoreItem(RsItem *item)
{
// some template comparors for sorting incoming.
const static PQItem_MatchType match_fileitem(PQI_ITEM_TYPE_FILEITEM,
0);
const static PQItem_MatchType match_result(PQI_ITEM_TYPE_FILEITEM,
PQI_FI_SUBTYPE_GENERAL);
/* get class type / subtype out of the item */
uint8_t vers = item -> PacketVersion();
uint8_t cls = item -> PacketClass();
uint8_t type = item -> PacketType();
uint8_t subtype = item -> PacketSubType();
const static PQItem_MatchType match_endsrch(PQI_ITEM_TYPE_SEARCHITEM,
PQI_SI_SUBTYPE_CANCEL);
const static PQItem_MatchType match_reqsrch(PQI_ITEM_TYPE_SEARCHITEM,
PQI_SI_SUBTYPE_SEARCH);
const static PQItem_MatchType match_info(PQI_ITEM_TYPE_INFOITEM, 0);
const static PQItem_MatchType match_chat(PQI_ITEM_TYPE_CHATITEM, 0);
if (match_fileitem(item))
/* whole Version reserved for SERVICES/CACHES */
if (vers == RS_PKT_VERSION_SERVICE)
{
if (match_result(item))
{
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> Result");
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> Service");
in_service.push_back(item);
item = NULL;
return;
}
in_result.push_back(item);
if (vers != RS_PKT_VERSION1)
{
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> Invalid VERSION! Deleting!");
delete item;
item = NULL;
return;
}
switch(cls)
{
case RS_PKT_CLASS_BASE:
switch(type)
{
case RS_PKT_TYPE_CACHE:
switch(subtype)
{
case RS_PKT_SUBTYPE_CACHE_REQUEST:
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> Cache Request");
in_search.push_back(item);
item = NULL;
break;
case RS_PKT_SUBTYPE_CACHE_ITEM:
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> Cache Result");
in_result.push_back(item);
item = NULL;
break;
default:
break; /* no match! */
}
else
{
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> FileItem");
in_file.push_back(item);
}
}
else if (match_endsrch(item))
{
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> Cancel Search");
break;
case RS_PKT_TYPE_FILE:
switch(subtype)
{
case RS_PKT_SUBTYPE_FI_REQUEST:
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> File Request");
in_request.push_back(item);
item = NULL;
break;
case RS_PKT_SUBTYPE_FI_DATA:
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> File Data");
in_data.push_back(item);
item = NULL;
break;
default:
break; /* no match! */
}
break;
default:
break; /* no match! */
}
break;
default:
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> Unknown");
break;
in_endsrch.push_back(item);
}
else if (match_reqsrch(item))
if (item)
{
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> Search Request");
in_reqsrch.push_back(item);
}
else if (match_chat(item))
{
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> Chat");
in_chat.push_back(item);
}
else if (match_info(item))
{
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> Info");
in_info.push_back(item);
}
else
{
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> Other");
in_other.push_back(item);
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
"SortnStore -> Deleting Unsorted Item");
delete item;
}
return;
}
// much like the input stuff.
PQFileItem *pqihandler::GetSearchResult()
RsCacheItem *pqihandler::GetSearchResult()
{
if (in_result.size() != 0)
{
PQFileItem *fi = (PQFileItem *) in_result.front();
RsCacheItem *fi = dynamic_cast<RsCacheItem *>(in_result.front());
if (!fi) { delete in_result.front(); }
in_result.pop_front();
return fi;
}
return NULL;
}
SearchItem *pqihandler::RequestedSearch()
RsCacheRequest *pqihandler::RequestedSearch()
{
if (in_reqsrch.size() != 0)
if (in_search.size() != 0)
{
SearchItem *si = (SearchItem *) in_reqsrch.front();
in_reqsrch.pop_front();
return si;
}
return NULL;
}
SearchItem * pqihandler::CancelledSearch()
{
if (in_endsrch.size() != 0)
{
SearchItem *si = (SearchItem *) in_endsrch.front();
in_endsrch.pop_front();
return si;
}
return NULL;
}
PQFileItem *pqihandler::GetFileItem()
{
if (in_file.size() != 0)
{
PQFileItem *fi = (PQFileItem *) in_file.front();
in_file.pop_front();
RsCacheRequest *fi = dynamic_cast<RsCacheRequest *>(in_search.front());
if (!fi) { delete in_search.front(); }
in_search.pop_front();
return fi;
}
return NULL;
}
// Chat Interface
ChatItem *pqihandler::GetMsg()
RsFileRequest *pqihandler::GetFileRequest()
{
if (in_chat.size() != 0)
if (in_request.size() != 0)
{
ChatItem *ci = (ChatItem *) in_chat.front();
in_chat.pop_front();
return ci;
RsFileRequest *fi = dynamic_cast<RsFileRequest *>(in_request.front());
if (!fi) { delete in_request.front(); }
in_request.pop_front();
return fi;
}
return NULL;
}
PQItem *pqihandler::GetOtherPQItem()
RsFileData *pqihandler::GetFileData()
{
if (in_other.size() != 0)
if (in_data.size() != 0)
{
PQItem *pqi = in_other.front();
in_other.pop_front();
return pqi;
RsFileData *fi = dynamic_cast<RsFileData *>(in_data.front());
if (!fi) { delete in_data.front(); }
in_data.pop_front();
return fi;
}
return NULL;
}
PQItem *pqihandler::SelectOtherPQItem(bool (*tst)(PQItem *))
RsRawItem *pqihandler::GetRsRawItem()
{
std::list<PQItem *>::iterator it;
it = find_if(in_other.begin(), in_other.end(), *tst);
if (it != in_other.end())
if (in_service.size() != 0)
{
PQItem *pqi = (*it);
in_other.erase(it);
return pqi;
RsRawItem *fi = dynamic_cast<RsRawItem *>(in_service.front());
if (!fi) { delete in_service.front(); }
in_service.pop_front();
return fi;
}
return NULL;
}
@ -577,7 +514,7 @@ static const float MIN_RATE = 0.01; // 10 B/s
// internal fn to send updates
int pqihandler::UpdateRates()
{
std::map<int, SearchModule *>::iterator it;
std::map<std::string, SearchModule *>::iterator it;
int num_sm = mods.size();
float avail_in = getMaxRate(true);

View File

@ -50,7 +50,7 @@
class SearchModule
{
public:
int smi; // id.
std::string peerid;
PQInterface *pqi;
SecurityPolicy *sp;
};
@ -62,39 +62,30 @@ class pqihandler: public P3Interface
{
public:
pqihandler(SecurityPolicy *Global);
int AddSearchModule(SearchModule *mod, int chanid = -1);
int RemoveSearchModule(SearchModule *mod);
bool AddSearchModule(SearchModule *mod);
bool RemoveSearchModule(SearchModule *mod);
// P3Interface.
// 4 very similar outputs.....
virtual int Search(SearchItem *ns);
virtual int SearchSpecific(SearchItem *ns); /* search one person only */
virtual int CancelSearch(SearchItem *ns); /* no longer used? */
virtual int SendSearchResult(PQFileItem *);
virtual int SearchSpecific(RsCacheRequest *ns);
virtual int SendSearchResult(RsCacheItem *);
// inputs.
virtual PQFileItem * GetSearchResult();
virtual SearchItem * RequestedSearch();
virtual SearchItem * CancelledSearch();
virtual RsCacheRequest * RequestedSearch();
virtual RsCacheItem * GetSearchResult();
// file i/o
virtual int SendFileItem(PQFileItem *ns);
virtual PQFileItem * GetFileItem();
// Chat Interface
virtual int SendMsg(ChatItem *item);
virtual int SendGlobalMsg(ChatItem *ns); /* needed until chat complete */
virtual ChatItem *GetMsg();
virtual int SendFileRequest(RsFileRequest *ns);
virtual int SendFileData(RsFileData *ns);
virtual RsFileRequest * GetFileRequest();
virtual RsFileData * GetFileData();
// Rest of P3Interface
virtual int tick();
virtual int status();
// Control Interface
virtual int SendOtherPQItem(PQItem *);
virtual PQItem *GetOtherPQItem();
virtual PQItem *SelectOtherPQItem(bool (*tst)(PQItem *));
// Service Data Interface
virtual int SendRsRawItem(RsRawItem *);
virtual RsRawItem *GetRsRawItem();
// rate control.
void setMaxIndivRate(bool in, float val);
@ -106,19 +97,19 @@ float getMaxRate(bool in);
/* check to be overloaded by those that can
* generates warnings otherwise
*/
virtual int checkOutgoingPQItem(PQItem *item, int global);
virtual int checkOutgoingRsItem(RsItem *item, int global);
int HandlePQItem(PQItem *ns, int allowglobal);
int HandleRsItem(RsItem *ns, int allowglobal);
int GetItems();
void SortnStoreItem(PQItem *item);
void SortnStoreItem(RsItem *item);
std::map<int, SearchModule *> mods;
std::map<std::string, SearchModule *> mods;
SecurityPolicy *globsec;
// Temporary storage...
std::list<PQItem *> in_result, in_endsrch, in_reqsrch, in_reqfile,
in_file, in_chat, in_info, in_host, in_other;
std::list<RsItem *> in_result, in_search,
in_request, in_data, in_service;
private:

View File

@ -45,7 +45,8 @@
// Test Interface (LoopBack)
pqiloopback::pqiloopback()
pqiloopback::pqiloopback(std::string id)
:PQInterface(id)
{
//std::cerr << "pqiloopback construction()" << std::endl;
// rates are irrelevant..... no B/W consumed.
@ -62,19 +63,20 @@ pqiloopback::~pqiloopback()
return;
}
int pqiloopback::SendItem(PQItem *i)
int pqiloopback::SendItem(RsItem *i)
{
i -> p = getContact();
i -> flags |= PQI_ITEM_FLAG_LOCAL;
// contact Id should be correct already!
//i -> p = getContact();
//i -> flags |= PQI_ITEM_FLAG_LOCAL;
objs.push_back(i);
return 1;
}
PQItem * pqiloopback::GetItem()
RsItem * pqiloopback::GetItem()
{
if (objs.size() > 0)
{
PQItem *pqi = objs.front();
RsItem *pqi = objs.front();
objs.pop_front();
// breaks the module, through ssl dependance.
// but necessary for running system..
@ -84,25 +86,6 @@ PQItem * pqiloopback::GetItem()
return NULL;
}
int pqiloopback::GetFile(PQFileItem *item, std::ostream &in)
{
return 1;
}
int pqiloopback::SendFile(PQFileItem *, std::istream &out)
{
return 1;
}
Person *pqiloopback::getContact()
{
sslroot *root = getSSLRoot();
cert *c = root -> getOwnCert();
return c;
}
// // PQI interface.
int pqiloopback::tick()
{

View File

@ -42,26 +42,20 @@
class pqiloopback: public PQInterface
{
public:
pqiloopback();
pqiloopback(std::string id);
virtual ~pqiloopback();
// search Interface.
virtual int SendItem(PQItem *item);
virtual PQItem *GetItem();
virtual int GetFile(PQFileItem *item, std::ostream &in);
virtual int SendFile(PQFileItem *item, std::istream &out);
virtual int SendItem(RsItem *item);
virtual RsItem *GetItem();
// PQI interface.
virtual int tick();
virtual int status();
virtual Person *getContact();
virtual int notifyEvent(NetInterface *ni, int event) { return 0; } /* Not used */
private:
std::list<PQItem *> objs;
std::list<RsItem *> objs;
};
#endif //MRK_PQI_LOOPBACK_HEADER

View File

@ -40,6 +40,7 @@
//socket blocking/options.
#include <fcntl.h>
#include <inttypes.h>
#else
@ -135,6 +136,13 @@ int unix_getsockopt_error(int sockfd, int *err);
int WinToUnixError(int error);
#endif
/***** From http://www.codeproject.com/KB/cpp/endianness.aspx
#define ntohll(x) (((int64_t)(ntohl((int32_t)((x << 32) >> 32))) << 32) |
(uint32_t) ntohl(((int32_t)(x >> 32))))
#define htonll(x) ntohll(x)
*****/
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,79 +0,0 @@
/*
* "$Id: pqipacket.h,v 1.6 2007-02-18 21:46:49 rmf24 Exp $"
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2004-2006 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_PACKET_HEADER
#define MRK_PQI_PACKET_HEADER
/* This is a set of functions for packaging
* the search queries/replies/data into packets
*
* Currently it makes very simple 1kb packets.
*
*/
// The standard data types and the search interface.
#include "pqi/pqi.h"
// defs for streams.
#include <iostream>
typedef void pqipkt;
// Handle Incoming Pkts......
// constants
int pqipkt_basesize();
int pqipkt_maxsize();
// determine properties. (possible from incomplete pkt).
int pqipkt_rawlen(pqipkt *);
bool pqipkt_check(pqipkt *pkt, int size);
PQItem *pqipkt_create(pqipkt *block);
// Outgoing Pkts.... (These are raw packets....(a chunk of data))
pqipkt *pqipkt_makepkt(PQItem *pqi);
// delete the raw packet (allocated using above).
void pqipkt_delete(pqipkt *);
// print packet.
//
void pqipkt_print(pqipkt *pkt);
// Type Extension methods for PQTunnel.
class PQTunnel;
class PQTunnelInit;
int registerTunnelType(int subtype, PQTunnel *(*fn)(void *d, int n));
PQTunnel *createTunnelType(int subtype, void *d, int n);
int registerTunnelInitType(int subtype, PQTunnelInit *(*fn)(void *d, int n));
PQTunnelInit *createTunnelInitType(int subtype, void *d, int n);
#endif //MRK_PQI_PACKET_HEADER

View File

@ -1,5 +1,5 @@
/*
* "$Id: pqiperson.cc,v 1.9 2007-02-18 21:46:49 rmf24 Exp $"
* libretroshare/src/pqi pqiperson.cc
*
* 3P/PQI network interface for RetroShare.
*
@ -25,7 +25,6 @@
#include "pqi/pqi.h"
#include <list>
@ -37,8 +36,8 @@ const int pqipersonzone = 82371;
#include <sstream>
pqiperson::pqiperson(cert *c)
:sslcert(c), active(false), activepqi(NULL),
pqiperson::pqiperson(cert *c, std::string id)
:PQInterface(id), sslcert(c), active(false), activepqi(NULL),
inConnectAttempt(false), waittimes(0)
{
sroot = getSSLRoot();
@ -77,7 +76,7 @@ pqiperson::~pqiperson()
// The PQInterface interface.
int pqiperson::SendItem(PQItem *i)
int pqiperson::SendItem(RsItem *i)
{
std::ostringstream out;
out << "pqiperson::SendItem()";
@ -91,15 +90,13 @@ int pqiperson::SendItem(PQItem *i)
out << " Not Active: Used to put in ToGo Store";
out << std::endl;
out << " Now deleting...";
// no longer storing in togo...
//togo.push_back(i);
delete i;
}
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
return 0; // queued.
}
PQItem *pqiperson::GetItem()
RsItem *pqiperson::GetItem()
{
if (active)
return activepqi -> GetItem();
@ -184,27 +181,7 @@ int pqiperson::tick()
}
}
}
// if active and togo!.
else if (togo.size() > 0)
{
while(togo.size() > 0)
{
PQItem *item = togo.front();
togo.pop_front();
std::ostringstream out;
out << "pqiperson::tick() Sending on Stored Item";
out << " to activepqi @ " << (void *) activepqi;
out << std::endl;
item -> print(out);
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
activepqi -> SendItem(item);
}
activeTick = 1;
}
return activeTick;
}

View File

@ -1,5 +1,5 @@
/*
* "$Id: pqiperson.h,v 1.7 2007-02-18 21:46:49 rmf24 Exp $"
* libretroshare/src/pqi pqiperson.h
*
* 3P/PQI network interface for RetroShare.
*
@ -60,9 +60,9 @@ static const int CONNECT_FAILED = 5;
class pqiconnect: public pqistreamer, public NetInterface
{
public:
pqiconnect(NetBinInterface *ni_in)
:pqistreamer(ni_in, 0), // pqistreamer will cleanup NetInterface.
NetInterface(NULL, NULL), // No need for callback.
pqiconnect(RsSerialiser *rss, NetBinInterface *ni_in)
:pqistreamer(rss, ni_in->PeerId(), ni_in, 0), // pqistreamer will cleanup NetInterface.
NetInterface(NULL, ni_in->PeerId()), // No need for callback.
ni(ni_in)
{
if (!ni_in)
@ -84,15 +84,15 @@ virtual int reset() { return ni -> reset(); }
virtual int disconnect() { return ni -> reset(); }
// get the contact from the net side!
virtual Person *getContact()
virtual std::string PeerId()
{
if (ni)
{
return ni->getContact();
return ni->PeerId();
}
else
{
return PQInterface::getContact();
return PQInterface::PeerId();
}
}
@ -108,7 +108,7 @@ protected:
class pqiperson: public PQInterface
{
public:
pqiperson(cert *c);
pqiperson(cert *c, std::string id);
virtual ~pqiperson(); // must clean up children.
// control of the connection.
@ -119,8 +119,8 @@ int autoconnect(bool);
int addChildInterface(pqiconnect *pqi);
// The PQInterface interface.
virtual int SendItem(PQItem *);
virtual PQItem *GetItem();
virtual int SendItem(RsItem *);
virtual RsItem *GetItem();
virtual int status();
virtual int tick();
@ -135,8 +135,6 @@ virtual void setMaxRate(bool in, float val);
private:
// outgoing PQItems can be queued (nothing else).
std::list<PQItem *> togo;
std::list<pqiconnect *> kids;
cert *sslcert;
bool active;

View File

@ -3,7 +3,7 @@
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2004-2006 by Robert Fernie.
* 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
@ -28,23 +28,9 @@
#include "pqi/pqipersongrp.h"
/*
#include "pqi/pqiproxy.h"
#include "pqi/pqitunnelproxy.h"
*/
#include "pqi/p3disc.h"
#include "pqi/p3channel.h"
#include "pqi/pqissl.h"
#include "pqi/pqissllistener.h"
/*
* #include "pqi/pqiudpproxy.h"
* #include "pqi/pqissludp.h"
*/
#ifdef PQI_USE_PROXY
#include "pqi/pqiudpproxy.h"
#include "pqi/pqissludp.h"
@ -57,25 +43,11 @@
const int pqipersongrpzone = 354;
// get the Tunnel and TunnelInit packets from the queue.
bool isTunnelItem(PQItem *item)
{
if (item -> type == PQI_ITEM_TYPE_TUNNELITEM)
return true;
return false;
}
bool isTunnelInitItem(PQItem *item)
{
if (item -> type == PQI_ITEM_TYPE_TUNNELINITITEM)
return true;
return false;
}
// handle the tunnel services.
int pqipersongrp::tickTunnelServer()
int pqipersongrp::tickServiceRecv()
{
PQItem *pqi = NULL;
RsRawItem *pqi = NULL;
int i = 0;
{
std::ostringstream out;
@ -83,16 +55,9 @@ int pqipersongrp::tickTunnelServer()
pqioutput(PQL_DEBUG_ALL, pqipersongrpzone, out.str());
}
PQTunnelServer::tick();
//p3ServiceServer::tick();
while(NULL != (pqi = SelectOtherPQItem(isTunnelInitItem)))
{
++i;
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone,
"pqipersongrp::tickTunnelServer() Incoming TunnelInitItem");
incoming(pqi);
}
while(NULL != (pqi = SelectOtherPQItem(isTunnelItem)))
while(NULL != (pqi = GetRsRawItem()))
{
++i;
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone,
@ -100,13 +65,33 @@ int pqipersongrp::tickTunnelServer()
incoming(pqi);
}
if (0 < i)
{
return 1;
}
return 0;
}
// handle the tunnel services.
int pqipersongrp::tickServiceSend()
{
RsRawItem *pqi = NULL;
int i = 0;
{
std::ostringstream out;
out << "pqipersongrp::tickServiceSend()";
pqioutput(PQL_DEBUG_ALL, pqipersongrpzone, out.str());
}
p3ServiceServer::tick();
while(NULL != (pqi = outgoing()))
{
++i;
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone,
"pqipersongrp::tickTunnelServer() OutGoing PQItem");
"pqipersongrp::tickTunnelServer() OutGoing RsItem");
SendOtherPQItem(pqi);
SendRsRawItem(pqi);
}
if (0 < i)
{
@ -118,20 +103,16 @@ int pqipersongrp::tickTunnelServer()
// inits
pqipersongrp::pqipersongrp(SecurityPolicy *glob, sslroot *sr, unsigned long flags)
:pqihandler(glob), sslr(sr), p3d(NULL),
:pqihandler(glob), sslr(sr),
#ifdef PQI_USE_PROXY
p3p(NULL),
#endif
initFlags(flags)
{
// add a p3proxy & p3disc.
p3d = new p3disc(sr);
#ifdef PQI_USE_PROXY
p3p = new p3udpproxy(p3d);
#endif
#ifdef PQI_USE_CHANNELS
p3c = new p3channel(sr);
#endif
if (!(sr -> active()))
{
@ -191,8 +172,6 @@ pqipersongrp::pqipersongrp(SecurityPolicy *glob, sslroot *sr, unsigned long flag
//addService(new PQTStst());
//registerTunnelType(PQI_TUNNEL_TST_TYPE, createPQTStst);
addService(p3d);
registerTunnelType(PQI_TUNNEL_DISC_ITEM_TYPE, createDiscItems);
#ifdef PQI_USE_PROXY
addService(p3p);
@ -200,11 +179,6 @@ pqipersongrp::pqipersongrp(SecurityPolicy *glob, sslroot *sr, unsigned long flag
registerTunnelInitType(PQI_TUNNEL_PROXY_TYPE, createPQTunnelProxyInit);
#endif
#ifdef PQI_USE_CHANNELS
addService(p3c);
registerTunnelType(PQI_TUNNEL_CHANNEL_ITEM_TYPE, createChannelItems);
#endif
return;
}
@ -221,9 +195,15 @@ int pqipersongrp::tick()
#ifdef PQI_USE_PROXY
pqiudpl->tick();
#endif
tickTunnelServer();
int i = 0;
return pqihandler::tick();
if (tickServiceSend()) i = 1;
if (pqihandler::tick()) i = 1; /* does actual Send/Recv */
if (tickServiceRecv()) i = 1;
return 1;
}
@ -251,9 +231,28 @@ int pqipersongrp::cert_accept(cert *a)
return -1;
}
pqiperson *pqip = new pqiperson(a);
{
std::ostringstream out;
out << "pqipersongrp::cert_accept() PeerId: " << a->PeerId();
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, out.str());
}
pqiperson *pqip = new pqiperson(a, a->PeerId());
pqissl *pqis = new pqissl(a, pqil, pqip);
pqiconnect *pqisc = new pqiconnect(pqis);
/* construct the serialiser ....
* Needs:
* * FileItem
* * FileData
* * ServiceGeneric
*/
RsSerialiser *rss = new RsSerialiser();
rss->addSerialType(new RsFileItemSerialiser());
rss->addSerialType(new RsCacheItemSerialiser());
rss->addSerialType(new RsServiceSerialiser());
pqiconnect *pqisc = new pqiconnect(rss, pqis);
pqip -> addChildInterface(pqisc);
@ -275,7 +274,7 @@ int pqipersongrp::cert_accept(cert *a)
// attach to pqihandler
SearchModule *sm = new SearchModule();
sm -> smi = 2;
sm -> peerid = a->PeerId();
sm -> pqi = pqip;
sm -> sp = secpolicy_create();
@ -288,7 +287,7 @@ int pqipersongrp::cert_accept(cert *a)
int pqipersongrp::cert_deny(cert *a)
{
std::map<int, SearchModule *>::iterator it;
std::map<std::string, SearchModule *>::iterator it;
SearchModule *mod;
bool found = false;
@ -299,8 +298,8 @@ int pqipersongrp::cert_deny(cert *a)
for(it = mods.begin(); (!found) && (it != mods.end());it++)
{
mod = it -> second;
if (a == (cert *) ((pqiperson *)
(mod -> pqi)) -> getContact())
pqiperson *p = (pqiperson *) mod -> pqi;
if (a->PeerId() == p->PeerId())
{
found = true;
}
@ -321,7 +320,7 @@ int pqipersongrp::cert_deny(cert *a)
int pqipersongrp::cert_auto(cert *a, bool b)
{
std::map<int, SearchModule *>::iterator it;
std::map<std::string, SearchModule *>::iterator it;
if (b)
{
cert_accept(a);
@ -330,7 +329,7 @@ int pqipersongrp::cert_auto(cert *a, bool b)
{
SearchModule *mod = it -> second;
pqiperson *p = (pqiperson *) mod -> pqi;
if (a == (cert *) p -> getContact())
if (a->PeerId() == p->PeerId())
{
p -> autoconnect(b);
return 1;
@ -407,74 +406,3 @@ int pqipersongrp::load_config()
}
/* Overloaded PQItem Check */
int pqipersongrp::checkOutgoingPQItem(PQItem *item, int global)
{
/* check cid vs Person */
if ((global) && (item->cid.route[0] == 0))
{
/* allowed through as for all! */
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone,
"pqipersongrp::checkOutgoingPQItem() Allowing global");
return 1;
}
if ((!global) && (item->cid.route[0] == 0))
{
/* not allowed for all! */
std::ostringstream out;
out << "Bad CID on non-global traffic" << std::endl;
item -> print(out);
pqioutput(PQL_ALERT, pqipersongrpzone,out.str());
return 0;
}
if (item -> p == NULL)
{
pqioutput(PQL_ALERT, pqipersongrpzone,
"pqipersongrp::checkOutgoingPQItem() ERROR: NULL Person");
std::ostringstream out;
item -> print(out);
pqioutput(PQL_ALERT, pqipersongrpzone,out.str());
return 0;
}
cert *c = (cert *) item -> p;
if (0 != pqicid_cmp(&(c -> cid), &(item -> cid)))
{
std::ostringstream out;
out << "pqipersongrp::checkOutgoingPQItem() c->cid != item->cid";
out << std::endl;
out << "c -> CID [" << c->cid.route[0];
for(int i = 0; i < 10; i++)
{
out << ":" << c->cid.route[i];
}
out << "]" << std::endl;
out << "item -> CID [" << item->cid.route[0];
for(int i = 0; i < 10; i++)
{
out << ":" << item->cid.route[i];
}
out << "]" << std::endl;
item -> print(out);
pqioutput(PQL_ALERT, pqipersongrpzone,out.str());
pqicid_copy(&(c->cid), &(item->cid));
}
/* check the top one */
return 1;
}

View File

@ -30,7 +30,7 @@
#include "pqi/pqihandler.h"
#include "pqi/pqiperson.h"
#include "pqi/pqitunnel.h"
#include "pqi/pqiservice.h"
// So this is a specific implementation
@ -50,12 +50,17 @@ const unsigned long PQIPERSON_NO_SSLLISTENER = 0x0001;
const unsigned long PQIPERSON_ALL_BW_LIMITED = 0x0010;
class p3disc;
class p3channel;
#ifdef PQI_USE_DISC
class p3disc;
#endif
#ifdef PQI_USE_CHANNELS
class p3channel;
#endif
class pqissllistener;
class pqipersongrp: public pqihandler, public PQTunnelServer
class pqipersongrp: public pqihandler, public p3ServiceServer
{
public:
pqipersongrp(SecurityPolicy *, sslroot *sr, unsigned long flags);
@ -77,7 +82,9 @@ virtual int status();
// + SearchInterface which should automatically handle stuff
// acess to services.
#ifdef PQI_USE_DISC
p3disc *getP3Disc() { return p3d; }
#endif
#ifdef PQI_USE_PROXY
p3proxy *getP3Proxy() { return p3p; }
@ -88,22 +95,25 @@ virtual int status();
#endif
protected:
/* Overloaded PQItem Check
/* Overloaded RsItem Check
* checks item->cid vs Person
*/
virtual int checkOutgoingPQItem(PQItem *item, int global);
virtual int checkOutgoingRsItem(RsItem *item, int global) { return 1; }
private:
// The tunnelserver operation.
int tickTunnelServer();
int tickServiceRecv();
int tickServiceSend();
pqissllistener *pqil;
sslroot *sslr;
#ifdef PQI_USE_DISC
p3disc *p3d;
#endif
#ifdef PQI_USE_PROXY
p3proxy *p3p;
pqiudplistener *pqiudpl;

View File

@ -28,12 +28,11 @@
#ifndef MRK_PQI_SECURITY_HEADER
#define MRK_PQI_SECURITY_HEADER
#include "pqi/pqi.h"
#include "pqi/pqipacket.h"
#define PQI_INCOMING 2
#define PQI_OUTGOING 5
#include <string>
//structure.
typedef struct sec_policy
{

View File

@ -0,0 +1,183 @@
/*
* libretroshare/src/pqi pqiservice.cc
*
* 3P/PQI network interface 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 "pqi/pqiservice.h"
#include "pqi/pqidebug.h"
#include <sstream>
const int pqiservicezone = 60478;
p3ServiceServer::p3ServiceServer()
{
pqioutput(PQL_DEBUG_BASIC, pqiservicezone,
"p3ServiceServer::p3ServiceServer()");
rrit = services.begin();
return;
}
int p3ServiceServer::addService(pqiService *ts)
{
pqioutput(PQL_DEBUG_BASIC, pqiservicezone,
"p3ServiceServer::addService()");
std::map<int, pqiService *>::iterator it;
it = services.find(ts -> getType());
if (it != services.end())
{
// it exists already!
return -1;
}
services[ts -> getType()] = ts;
rrit = services.begin();
return 1;
}
int p3ServiceServer::incoming(RsRawItem *item)
{
pqioutput(PQL_DEBUG_BASIC, pqiservicezone,
"p3ServiceServer::incoming()");
{
std::ostringstream out;
out << "p3ServiceServer::incoming() PacketId: ";
out << std::hex << item -> PacketId() << std::endl;
out << "Looking for Service: ";
out << (item -> PacketId() & 0xffffff00) << std::dec << std::endl;
out << "Item:" << std::endl;
item -> print(out);
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str());
}
std::map<int, pqiService *>::iterator it;
it = services.find(item -> PacketId() & 0xffffff00);
if (it == services.end())
{
pqioutput(PQL_DEBUG_BASIC, pqiservicezone,
"p3ServiceServer::incoming() Service: No Service - deleting");
// delete it.
delete item;
// it exists already!
return -1;
}
{
std::ostringstream out;
out << "p3ServiceServer::incoming() Sending to";
out << it -> second << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str());
return (it->second) -> receive(item);
}
delete item;
return -1;
}
RsRawItem *p3ServiceServer::outgoing()
{
pqioutput(PQL_DEBUG_ALL, pqiservicezone,
"p3ServiceServer::outgoing()");
if (rrit != services.end())
{
rrit++;
}
else
{
rrit = services.begin();
}
std::map<int, pqiService *>::iterator sit = rrit;
// run to the end.
RsRawItem *item;
// run through to the end,
for(;rrit != services.end();rrit++)
{
if (NULL != (item = (rrit -> second) -> send()))
{
std::ostringstream out;
out << "p3ServiceServer::outgoing() Got Item From:";
out << rrit -> second << std::endl;
item -> print(out);
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str());
return item;
}
}
// from the beginning to where we started.
for(rrit = services.begin();rrit != sit; rrit++)
{
if (NULL != (item = (rrit -> second) -> send()))
{
std::ostringstream out;
out << "p3ServiceServer::outgoing() Got Item From:";
out << rrit -> second << std::endl;
item -> print(out);
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str());
return item;
}
}
return NULL;
}
int p3ServiceServer::tick()
{
pqioutput(PQL_DEBUG_ALL, pqiservicezone,
"p3ServiceServer::tick()");
std::map<int, pqiService *>::iterator it;
// from the beginning to where we started.
for(it = services.begin();it != services.end(); it++)
{
std::ostringstream out;
out << "p3ServiceServer::service id:" << it -> first;
out << " -> Service: " << it -> second;
out << std::endl;
pqioutput(PQL_DEBUG_ALL, pqiservicezone, out.str());
// now we should actually tick the service.
(it -> second) -> tick();
}
return 1;
}

View File

@ -0,0 +1,99 @@
/*
* libretroshare/src/pqi pqiservice.h
*
* 3P/PQI network interface 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 PQI_SERVICE_HEADER
#define PQI_SERVICE_HEADER
#include "pqi/pqi_base.h"
// PQI Service, is a generic lower layer on which services can run on.
//
// these packets get passed through the
// server, to a service that is registered.
//
// example services:
// proxytunnel. -> p3proxy.
// sockettunnel
// -> either broadcast (attach to
// open socket instead
// of broadcast address)
// -> or requested/signon.
//
// games,
// voice
// video
//
//
// DataType is defined in the serialiser directory.
class RsRawItem;
class pqiService
{
protected:
pqiService(uint32_t t) // our type of packets.
:type(t) { return; }
virtual ~pqiService() { return; }
public:
//
virtual int receive(RsRawItem *) = 0;
virtual RsRawItem * send() = 0;
int getType() { return type; }
virtual int tick() { return 0; }
private:
int type;
};
#include <map>
class p3ServiceServer
{
public:
p3ServiceServer();
int addService(pqiService *);
int incoming(RsRawItem *);
RsRawItem *outgoing();
int tick();
private:
std::map<int, pqiService *> services;
std::map<int, pqiService *>::iterator rrit;
};
#endif // PQI_SERVICE_HEADER

View File

@ -86,7 +86,8 @@ static const int PQISSL_SSL_CONNECT_TIMEOUT = 30;
*/
pqissl::pqissl(cert *c, pqissllistener *l, PQInterface *parent)
:NetBinInterface(parent, c),
//:NetBinInterface(parent, c),
:NetBinInterface(parent, parent->PeerId()),
waiting(WAITING_NOT), active(false), certvalid(false),
sslmode(PQISSL_ACTIVE), ssl_connection(NULL), sockfd(-1),
sslcert(c), sslccr(NULL), pqil(l), // no init for remote_addr.
@ -98,6 +99,12 @@ pqissl::pqissl(cert *c, pqissllistener *l, PQInterface *parent)
{
sslccr = getSSLRoot();
{
std::ostringstream out;
out << "pqissl for PeerId: " << PeerId();
pqioutput(PQL_ALERT, pqisslzone, out.str());
}
// check certificate
/**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP)

View File

@ -27,7 +27,8 @@
#include "pqi/pqistreamer.h"
#include "pqi/pqipacket.h"
#include "serialiser/rsserial.h"
#include "serialiser/rsbaseitems.h" /***** For RsFileData *****/
#include <iostream>
#include <fstream>
@ -36,10 +37,10 @@
const int pqistreamerzone = 8221;
const int PQISTREAM_ABS_MAX = 10000000; /* 10 MB/sec (actually per loop) */
const int PQISTREAM_ABS_MAX = 100000000; /* 100 MB/sec (actually per loop) */
pqistreamer::pqistreamer(BinInterface *bio_in, int bio_flags_in)
:bio(bio_in), bio_flags(bio_flags_in),
pqistreamer::pqistreamer(RsSerialiser *rss, std::string id, BinInterface *bio_in, int bio_flags_in)
:PQInterface(id), rsSerialiser(rss), bio(bio_in), bio_flags(bio_flags_in),
pkt_wpending(NULL),
totalRead(0), totalSent(0),
currRead(0), currSent(0),
@ -48,7 +49,7 @@ pqistreamer::pqistreamer(BinInterface *bio_in, int bio_flags_in)
avgLastUpdate = currReadTS = currSentTS = time(NULL);
/* allocated once */
pkt_rpend_size = pqipkt_maxsize();
pkt_rpend_size = getRsPktMaxSize();
pkt_rpending = malloc(pkt_rpend_size);
// 100 B/s (minimal)
@ -107,7 +108,7 @@ pqistreamer::~pqistreamer()
{
void *pkt = out_pkt.front();
out_pkt.pop_front();
pqipkt_delete(pkt);
free(pkt);
}
// clean up outgoing (data packets)
@ -115,12 +116,12 @@ pqistreamer::~pqistreamer()
{
void *pkt = out_data.front();
out_data.pop_front();
pqipkt_delete(pkt);
free(pkt);
}
if (pkt_wpending)
{
pqipkt_delete(pkt_wpending);
free(pkt_wpending);
pkt_wpending = NULL;
}
@ -129,7 +130,7 @@ pqistreamer::~pqistreamer()
// clean up outgoing.
while(incoming.size() > 0)
{
PQItem *i = incoming.front();
RsItem *i = incoming.front();
incoming.pop_front();
delete i;
}
@ -138,7 +139,7 @@ pqistreamer::~pqistreamer()
// Get/Send Items.
int pqistreamer::SendItem(PQItem *si)
int pqistreamer::SendItem(RsItem *si)
{
{
std::ostringstream out;
@ -150,7 +151,7 @@ int pqistreamer::SendItem(PQItem *si)
return queue_outpqi(si);
}
PQItem *pqistreamer::GetItem()
RsItem *pqistreamer::GetItem()
{
{
std::ostringstream out;
@ -158,12 +159,12 @@ PQItem *pqistreamer::GetItem()
pqioutput(PQL_DEBUG_ALL, pqistreamerzone, out.str());
}
std::list<PQItem *>::iterator it;
std::list<RsItem *>::iterator it;
it = incoming.begin();
if (it == incoming.end()) { return NULL; }
PQItem *osr = (*it);
RsItem *osr = (*it);
incoming.erase(it);
return osr;
}
@ -175,14 +176,7 @@ int pqistreamer::tick()
std::ostringstream out;
out << "pqistreamer::tick()";
out << std::endl;
if (getContact())
{
out << getContact() -> Name() << ": currRead/Sent: " << currRead << "/" << currSent;
}
else
{
out << "Unknown Contact" << ": currRead/Sent: " << currRead << "/" << currSent;
}
out << PeerId() << ": currRead/Sent: " << currRead << "/" << currSent;
out << std::endl;
pqioutput(PQL_DEBUG_ALL, pqistreamerzone, out.str());
@ -210,10 +204,8 @@ int pqistreamer::tick()
std::ostringstream out;
out << "pqistreamer::tick() Queued Data:";
if (getContact())
{
out << " for " << getContact() -> Name();
}
out << " for " << PeerId();
if (bio->isactive())
{
out << " (active)";
@ -227,7 +219,7 @@ int pqistreamer::tick()
int total = 0;
for(it = out_pkt.begin(); it != out_pkt.end(); it++)
{
total += pqipkt_rawlen(*it);
total += getRsItemSize(*it);
}
out << "\t Out Packets [" << out_pkt.size() << "] => " << total;
@ -236,7 +228,7 @@ int pqistreamer::tick()
total = 0;
for(it = out_data.begin(); it != out_data.end(); it++)
{
total += pqipkt_rawlen(*it);
total += getRsItemSize(*it);
}
out << "\t Out Data [" << out_data.size() << "] => " << total;
@ -277,7 +269,7 @@ int pqistreamer::status()
//
/**************** HANDLE OUTGOING TRANSLATION + TRANSMISSION ******/
int pqistreamer::queue_outpqi(PQItem *pqi)
int pqistreamer::queue_outpqi(RsItem *pqi)
{
{
std::ostringstream out;
@ -286,12 +278,13 @@ int pqistreamer::queue_outpqi(PQItem *pqi)
}
/* decide which type of packet it is */
PQFileData *dta = dynamic_cast<PQFileData *>(pqi);
RsFileData *dta = dynamic_cast<RsFileData *>(pqi);
bool isCntrl = (dta == NULL);
void *ptr = pqipkt_makepkt(pqi);
if (NULL != ptr)
uint32_t pktsize = rsSerialiser->size(pqi);
void *ptr = malloc(pktsize);
if (rsSerialiser->serialise(pqi, ptr, &pktsize))
{
if (isCntrl)
{
@ -304,6 +297,11 @@ int pqistreamer::queue_outpqi(PQItem *pqi)
delete pqi;
return 1;
}
else
{
/* cleanup serialiser */
free(ptr);
}
std::ostringstream out;
out << "pqistreamer::queue_outpqi() Null Pkt generated!";
@ -316,7 +314,7 @@ int pqistreamer::queue_outpqi(PQItem *pqi)
return 1; // keep error internal.
}
int pqistreamer::handleincomingitem(PQItem *pqi)
int pqistreamer::handleincomingitem(RsItem *pqi)
{
{
std::ostringstream out;
@ -325,7 +323,7 @@ int pqistreamer::handleincomingitem(PQItem *pqi)
}
// Use overloaded Contact function
pqi -> p = getContact();
pqi -> PeerId(PeerId());
incoming.push_back(pqi);
return 1;
}
@ -351,7 +349,7 @@ int pqistreamer::handleoutgoing()
/* if we are not active - clear anything in the queues. */
for(it = out_pkt.begin(); it != out_pkt.end(); )
{
pqipkt_delete(*it);
free(*it);
it = out_pkt.erase(it);
std::ostringstream out;
@ -360,7 +358,7 @@ int pqistreamer::handleoutgoing()
}
for(it = out_data.begin(); it != out_data.end(); )
{
pqipkt_delete(*it);
free(*it);
it = out_data.erase(it);
std::ostringstream out;
@ -371,7 +369,7 @@ int pqistreamer::handleoutgoing()
/* also remove the pending packets */
if (pkt_wpending)
{
pqipkt_delete(pkt_wpending);
free(pkt_wpending);
pkt_wpending = NULL;
}
@ -413,7 +411,7 @@ int pqistreamer::handleoutgoing()
std::ostringstream out;
out << "Sending Out Pkt!";
// write packet.
len = pqipkt_rawlen(pkt_wpending);
len = getRsItemSize(pkt_wpending);
if (len != (ss = bio->senddata(pkt_wpending, len)))
{
out << "Problems with Send Data!";
@ -429,7 +427,7 @@ int pqistreamer::handleoutgoing()
out << " Success!" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqistreamerzone, out.str());
pqipkt_delete(pkt_wpending);
free(pkt_wpending);
pkt_wpending = NULL;
sentbytes += len;
@ -465,10 +463,10 @@ int pqistreamer::handleincoming()
void *block = pkt_rpending;
// initial read size: basic packet.
int blen = pqipkt_basesize();
int blen = getRsPktBaseSize();
int tmplen;
int pktlen;
uint32_t pktlen;
int maxin = inAllowedBytes();
while((maxin > readbytes) && (bio->moretoread()))
@ -512,7 +510,7 @@ int pqistreamer::handleincoming()
pktlen = tmplen;
// workout how much more to read.
int extralen = pqipkt_rawlen(block) - blen;
int extralen = getRsItemSize(block) - blen;
if (extralen > maxlen - blen)
{
pqioutput(PQL_ALERT, pqistreamerzone, "ERROR: Read Packet too Big!");
@ -553,11 +551,7 @@ int pqistreamer::handleincoming()
pqioutput(PQL_DEBUG_BASIC, pqistreamerzone, out.str());
}
PQItem *pkt = NULL;
if (pqipkt_check(block, pktlen))
{
pkt = pqipkt_create(block);
}
RsItem *pkt = rsSerialiser->deserialise(block, &pktlen);
if ((pkt != NULL) && (0 < handleincomingitem(pkt)))
{
@ -589,7 +583,7 @@ float pqistreamer::outTimeSlice()
pqioutput(PQL_DEBUG_ALL, pqistreamerzone, out.str());
}
fixme("pqistreamer::outTimeSlice()", 1);
//fixme("pqistreamer::outTimeSlice()", 1);
return 1;
}

View File

@ -1,9 +1,9 @@
/*
* "$Id: pqistreamer.h,v 1.10 2007-02-18 21:46:50 rmf24 Exp $"
* libretroshare/src/pqi pqistreamer.h
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2004-2006 by Robert Fernie.
* 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
@ -24,7 +24,6 @@
*/
#ifndef MRK_PQI_STREAMER_HEADER
#define MRK_PQI_STREAMER_HEADER
@ -41,12 +40,12 @@
class pqistreamer: public PQInterface
{
public:
pqistreamer(BinInterface *bio_in, int bio_flagsin);
pqistreamer(RsSerialiser *rss, std::string peerid, BinInterface *bio_in, int bio_flagsin);
virtual ~pqistreamer();
// PQInterface
virtual int SendItem(PQItem *);
virtual PQItem *GetItem();
virtual int SendItem(RsItem *);
virtual RsItem *GetItem();
virtual int tick();
virtual int status();
@ -55,8 +54,8 @@ virtual int status();
/* Implementation */
// to filter functions - detect filecancel/data and act!
int queue_outpqi( PQItem *i);
int handleincomingitem(PQItem *i);
int queue_outpqi( RsItem *i);
int handleincomingitem(RsItem *i);
// ticked regularly (manages out queues and sending
// via above interfaces.
@ -72,6 +71,8 @@ void outSentBytes(int );
int inAllowedBytes();
void inReadBytes(int );
// RsSerialiser - determines which packets can be serialised.
RsSerialiser *rsSerialiser;
// Binary Interface for IO, initialisated at startup.
BinInterface *bio;
unsigned int bio_flags; // only BIN_NO_CLOSE at the moment.
@ -83,7 +84,7 @@ void inReadBytes(int );
// Temp Storage for transient data.....
std::list<void *> out_pkt; // Cntrl / Search / Results queue
std::list<void *> out_data; // FileData - secondary queue.
std::list<PQItem *> incoming;
std::list<RsItem *> incoming;
// data for network stats.
int totalRead;

View File

@ -1,482 +0,0 @@
/*
* "$Id: pqisupernode.cc,v 1.3 2007-02-18 21:46:50 rmf24 Exp $"
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2004-2006 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 "pqi/pqisupernode.h"
/*
#include "pqi/pqiproxy.h"
#include "pqi/pqitunnelproxy.h"
*/
#include "pqi/p3disc.h"
#include "pqi/p3channel.h"
#include "pqi/pqissl.h"
#include "pqi/pqissllistener.h"
/*
* #include "pqi/pqiudpproxy.h"
* #include "pqi/pqissludp.h"
*/
#ifdef PQI_USE_PROXY
#include "pqi/pqiudpproxy.h"
#include "pqi/pqissludp.h"
#endif
//#include "pqi/pqitunneltst.h"
#include "pqi/pqidebug.h"
#include <sstream>
const int pqisupernodezone = 65904;
// get the Tunnel and TunnelInit packets from the queue.
bool isTunnelItem(PQItem *item)
{
if (item -> type == PQI_ITEM_TYPE_TUNNELITEM)
return true;
return false;
}
bool isTunnelInitItem(PQItem *item)
{
if (item -> type == PQI_ITEM_TYPE_TUNNELINITITEM)
return true;
return false;
}
// handle the tunnel services.
int pqisupernode::tickTunnelServer()
{
PQItem *pqi = NULL;
{
std::ostringstream out;
out << "pqisupernode::tickTunnelServer()";
pqioutput(PQL_DEBUG_ALL, pqisupernodezone, out.str());
}
PQTunnelServer::tick();
while(NULL != (pqi = SelectOtherPQItem(isTunnelInitItem)))
{
pqioutput(PQL_DEBUG_BASIC, pqisupernodezone,
"pqisupernode::tickTunnelServer() Incoming TunnelInitItem");
incoming(pqi);
}
while(NULL != (pqi = SelectOtherPQItem(isTunnelItem)))
{
pqioutput(PQL_DEBUG_BASIC, pqisupernodezone,
"pqisupernode::tickTunnelServer() Incoming TunnelItem");
incoming(pqi);
}
while(NULL != (pqi = outgoing()))
{
pqioutput(PQL_DEBUG_BASIC, pqisupernodezone,
"pqisupernode::tickTunnelServer() OutGoing PQItem");
SendOtherPQItem(pqi);
}
return 1;
}
// inits
pqisupernode::pqisupernode(SecurityPolicy *glob, sslroot *sr)
:pqihandler(glob), sslr(sr), p3d(NULL)
#ifdef PQI_USE_PROXY
,p3p(NULL)
#endif
{
// add a p3proxy & p3disc.
p3d = new p3disc(sr);
#ifdef PQI_USE_PROXY
p3p = new p3udpproxy(p3d);
#endif
if (!(sr -> active()))
{
pqioutput(PQL_ALERT, pqisupernodezone, "sslroot not active... exiting!");
exit(1);
}
// make listen
Person *us = sr -> getOwnCert();
if (us != NULL)
{
pqisslnode = new pqisslsupernode(us -> localaddr, this);
#ifdef PQI_USE_PROXY
pqiudpl = new pqiudplistener((p3udpproxy *) p3p,
us -> localaddr);
#endif
}
else
{
pqioutput(PQL_ALERT, pqisupernodezone, "No Us! what are we!");
exit(1);
}
addService(p3d);
registerTunnelType(PQI_TUNNEL_DISC_ITEM_TYPE, createDiscItems);
#ifdef PQI_USE_PROXY
addService(p3p);
registerTunnelType(PQI_TUNNEL_PROXY_TYPE, createPQTunnelProxy);
registerTunnelInitType(PQI_TUNNEL_PROXY_TYPE, createPQTunnelProxyInit);
#endif
return;
}
int pqisupernode::run()
{
while(1)
{
sleep(1);
tick();
}
return 1;
}
int pqisupernode::tick()
{
pqisslnode -> tick();
#ifdef PQI_USE_PROXY
pqiudpl->tick();
#endif
tickTunnelServer();
return pqihandler::tick();
}
int pqisupernode::status()
{
pqisslnode -> status();
#ifdef PQI_USE_PROXY
pqiudpl->status();
#endif
return pqihandler::status();
}
// control the connections.
int pqisupernode::cert_accept(cert *a)
{
/* this function does nothing */
pqioutput(PQL_ALERT, pqisupernodezone,
"pqisupernode::cert_accept() Null Fn.");
return -1;
}
int pqisupernode::cert_deny(cert *a)
{
std::map<int, SearchModule *>::iterator it;
SearchModule *mod;
bool found = false;
// if used find search module....
if (a -> InUse())
{
// find module.
for(it = mods.begin(); (!found) && (it != mods.end());it++)
{
mod = it -> second;
if (a == (cert *) ((pqiperson *)
(mod -> pqi)) -> getContact())
{
found = true;
}
}
if (found)
{
RemoveSearchModule(mod);
secpolicy_delete(mod -> sp);
pqiperson *p = (pqiperson *) mod -> pqi;
p -> reset();
delete p;
a -> InUse(false);
}
}
a -> Accepted(false);
return 1;
}
int pqisupernode::cert_auto(cert *a, bool b)
{
pqioutput(PQL_ALERT, pqisupernodezone,
"pqisupernode::cert_auto() Null Fn.");
return 1;
}
int pqisupernode::restart_listener()
{
pqisslnode -> resetlisten();
cert *own = sslr -> getOwnCert();
pqisslnode -> setListenAddr(own -> localaddr);
pqisslnode -> setuplisten();
#ifdef PQI_USE_PROXY
pqiudpl -> resetlisten();
pqiudpl -> setListenAddr(own -> localaddr);
pqiudpl -> setuplisten();
#endif
return 1;
}
static const std::string pqih_ftr("PQIH_FTR");
int pqisupernode::save_config()
{
char line[512];
sprintf(line, "%f %f %f %f", getMaxRate(true), getMaxRate(false),
getMaxIndivRate(true), getMaxIndivRate(false));
sslr -> setSetting(pqih_ftr, std::string(line));
return 1;
}
int pqisupernode::load_config()
{
std::string line = sslr -> getSetting(pqih_ftr);
float mri, mro, miri, miro;
if (4 == sscanf(line.c_str(), "%f %f %f %f", &mri, &mro, &miri, &miro))
{
setMaxRate(true, mri);
setMaxRate(false, mro);
setMaxIndivRate(true, miri);
setMaxIndivRate(false, miro);
}
else
{
pqioutput(PQL_DEBUG_BASIC, pqisupernodezone,
"pqisupernode::load_config() Loading Default Rates!");
setMaxRate(true, 20.0);
setMaxRate(false, 20.0);
setMaxIndivRate(true, 5.0);
setMaxIndivRate(false, 5.0);
}
return 1;
}
/* Overloaded PQItem Check */
int pqisupernode::checkOutgoingPQItem(PQItem *item, int global)
{
/* check cid vs Person */
if ((global) && (item->cid.route[0] == 0))
{
/* allowed through as for all! */
pqioutput(PQL_DEBUG_BASIC, pqisupernodezone,
"pqisupernode::checkOutgoingPQItem() Allowing global");
return 1;
}
if (item -> p == NULL)
{
pqioutput(PQL_ALERT, pqisupernodezone,
"pqisupernode::checkOutgoingPQItem() ERROR: NULL Person");
std::ostringstream out;
item -> print(out);
pqioutput(PQL_ALERT, pqisupernodezone,out.str());
return 0;
}
cert *c = (cert *) item -> p;
if (0 != pqicid_cmp(&(c -> cid), &(item -> cid)))
{
std::ostringstream out;
out << "pqisupernode::checkOutgoingPQItem() c->cid != item->cid";
out << std::endl;
out << "c -> CID [" << c->cid.route[0];
for(int i = 0; i < 10; i++)
{
out << ":" << c->cid.route[i];
}
out << "]" << std::endl;
out << "item -> CID [" << item->cid.route[0];
for(int i = 0; i < 10; i++)
{
out << ":" << item->cid.route[i];
}
out << "]" << std::endl;
item -> print(out);
pqioutput(PQL_ALERT, pqisupernodezone,out.str());
pqicid_copy(&(c->cid), &(item->cid));
}
/* check the top one */
return 1;
}
int pqisupernode::recvdConnection(int fd, SSL *in_connection,
cert *peer, struct sockaddr_in *raddr)
{
/* so we need to accept the certificate */
if (peer -> InUse())
{
pqioutput(PQL_DEBUG_BASIC, pqisupernodezone,
"pqisupernode::recvdConnection() Cert in Use!");
return -1;
}
pqiperson *pqip = new pqiperson(peer);
pqissl *pqis = new pqissl(peer, pqisslnode, pqip);
pqiconnect *pqisc = new pqiconnect(pqis);
pqip -> addChildInterface(pqisc);
/* first set the certificate options off! */
/* listening off, connecting off */
// setup no behaviour. (no remote address)
//
// add the certificate to sslroot...
sslr -> addUntrustedCertificate(peer);
peer -> InUse(true);
peer -> Accepted(true);
peer -> WillListen(false);
peer -> WillConnect(false);
peer -> Manual(true);
// attach to pqihandler
SearchModule *sm = new SearchModule();
sm -> smi = 2;
sm -> pqi = pqip;
sm -> sp = secpolicy_create();
// reset it to start it working.
pqis -> reset();
AddSearchModule(sm); // call to pqihandler....
pqis -> accept(in_connection, fd, *raddr);
/* finally tell the system to listen - if the connection fails */
peer -> WillListen(true);
/* done! */
return 1;
}
/************************ PQI SSL SUPER NODE ****************************
*
* This is the special listener, that accepts all connections.
*
*/
pqisslsupernode::pqisslsupernode(struct sockaddr_in addr, pqisupernode *grp)
:pqissllistener(addr), psn(grp)
{
return;
}
pqisslsupernode::~pqisslsupernode()
{
return;
}
int pqisslsupernode::completeConnection(int fd, SSL *ssl, struct sockaddr_in &remote_addr)
{
/* first attempt a pqissllistener connect (ie if we are listening for it!)
*
* if this fails, try adding it!
*/
if (0 < pqissllistener::completeConnection(fd,ssl, remote_addr))
{
return 1; /* done! */
}
/* else ask the pqisupernode to create it! */
// Get the Peer Certificate....
/**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP)
XPGP *peercert = SSL_get_peer_pgp_certificate(ssl);
#else /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
X509 *peercert = SSL_get_peer_certificate(ssl);
#endif /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
if (peercert == NULL)
{
pqioutput(PQL_WARNING, pqisupernodezone,
"pqisslsupernode::completeConnection() Peer Did Not Provide Cert!");
return -1;
}
// save certificate... (and ip locations)
/* the first registerCertificate can fail,
* but this is in pqissllistener ....
* so this one should succeed.
*/
/**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP)
cert *npc = sslccr -> registerCertificateXPGP(peercert, remote_addr, true);
#else /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
cert *npc = sslccr -> registerCertificate(peercert, remote_addr, true);
#endif /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
if ((npc == NULL) || (npc -> Connected()))
{
std::ostringstream out;
out << "No Matching Certificate/Already Connected";
out << " for Connection:" << inet_ntoa(remote_addr.sin_addr);
out << std::endl;
out << "Shutting it down!" << std::endl;
pqioutput(PQL_WARNING, pqisupernodezone, out.str());
return -1;
}
// hand off ssl conection.
psn -> recvdConnection(fd, ssl, npc, &remote_addr);
return 1;
}

View File

@ -1,166 +0,0 @@
/*
* "$Id: pqisupernode.h,v 1.2 2007-02-18 21:46:50 rmf24 Exp $"
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2004-2006 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_SUPER_NODE_HEADER
#define MRK_PQI_SUPER_NODE_HEADER
#include "pqi/pqihandler.h"
#include "pqi/pqiperson.h"
#include "pqi/pqitunnel.h"
#include "pqi/pqissllistener.h"
/*****************************************************************
* So a super node, is a very special being,
* and used to assist in the setup of a retro share network.
*
* It role is to accept all connections,
* and allow discovery/proxying for facilitating connections.
*
* Therefore this interface includes
* both a p3disc + p3udpproxy, but
* doesn't allow any other traffic through....
*
* each person will only include a pqissl (generated by the listener).
*
* The tricky part is allowing the pqissl to be
* generated on the fly, as the connections are made!
*
*/
class p3proxy;
class p3disc;
class pqiudplistener;
class pqisslsupernode;
class pqisupernode: public pqihandler, public PQTunnelServer
{
public:
pqisupernode(SecurityPolicy *, sslroot *sr);
// overloaded from pqihandler -> null fns
virtual int Search(SearchItem *ns) { if (ns) delete ns; return 1; }
virtual int CancelSearch(SearchItem *ns) { if (ns) delete ns; return 1; }
virtual int SendSearchResult(PQFileItem *ns){ if (ns) delete ns; return 1; }
// inputs.
virtual PQFileItem * GetSearchResult() { return NULL; }
virtual SearchItem * RequestedSearch() { return NULL; }
virtual SearchItem * CancelledSearch() { return NULL; }
// file i/o
virtual int SendFileItem(PQFileItem *ns) { if (ns) delete ns; return 1; }
virtual PQFileItem * GetFileItem() { return NULL; }
// Chat Interface
virtual int SendMsg(ChatItem *ns) { if (ns) delete ns; return 1; }
virtual ChatItem *GetMsg() { return NULL; }
// end of overloaded from pqihandler -> null fns
// control the connections.
int cert_accept(cert *a);
int cert_deny(cert *a);
int cert_auto(cert *a, bool b);
int restart_listener();
int save_config();
int load_config();
// tick interfaces.
virtual int run();
virtual int tick();
virtual int status();
// the pqisslsupernode, is derived from the pqissllistener,
// except it doesn't track who it should listen for.
// instead each connection is accepted blind,
// and passed to the pqisupernode. which can attach it
// to a pqissl, if desired....
//
// The first basic version of this will accept up to a total
// limit......
virtual int recvdConnection(int fd, SSL *in_connection,
cert *peer, struct sockaddr_in *raddr);
// overloaded functions to disable various features of pqihandler
// + SearchInterface which should automatically handle stuff
// acess to services.
p3disc *getP3Disc() { return p3d; }
p3proxy *getP3Proxy() { return p3p; }
protected:
/* Overloaded PQItem Check
* checks item->cid vs Person
*/
virtual int checkOutgoingPQItem(PQItem *item, int global);
private:
// The tunnelserver operation.
int tickTunnelServer();
pqisslsupernode *pqisslnode;
pqiudplistener *pqiudpl;
sslroot *sslr;
p3disc *p3d;
p3proxy *p3p;
};
class pqisslsupernode: public pqissllistener
{
public:
pqisslsupernode(struct sockaddr_in addr, pqisupernode *grp);
virtual ~pqisslsupernode();
//virtual int tick();
//virtual int status();
virtual int completeConnection(int sockfd, SSL *in_connection, struct sockaddr_in &raddr);
private:
pqisupernode *psn;
};
#endif // MRK_PQI_SUPER_NODE_HEADER

View File

@ -27,7 +27,6 @@
#include "xpgpcert.h"
#include "pqipacket.h"
#include "pqinetwork.h"

View File

@ -73,9 +73,11 @@ virtual ~cert();
virtual std::string Signature();
std::string Hash();
void Hash(std::string);
std::string PeerId() { return Signature(); }
XPGP *certificate;
std::string hash;
std::string peerid;
};