mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Commit of the new UDP Connection methods and
the rewrite of the retroshare core networking stack. This check-in commits the changes to the pqi code, and provides the majority of the improvements. (1) Introduced new interfaces for DHT and UPnP abstraction: p3dhtmgr.h, p3upnpmgr.h (2) Introduces abstraction for Authentication: p3authmgr.h (3) New Connection Manager to coordinate networking code: p3connmgr.h (4) New Configuration Manager: p3cfgmgr.h This library has been significantly modified to support DHT synced connections to enable connections between Firewalled Friends. The connection code has been rewritten within a new framework, which should make extensions easier to code. Also removed significant amount of old code relating to Tunnels, Channels etc. This will be recycled later as higher level services that should not be part of the core networking library. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@306 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
de0ce110b9
commit
6435357c07
@ -3,42 +3,40 @@ RS_TOP_DIR = ..
|
||||
include ../make.opt
|
||||
|
||||
# All the executables that should be generated.
|
||||
EXECS = # test_p3items
|
||||
|
||||
BASE_OBJ = pqi_base.o \
|
||||
pqidebug.o pqisecurity.o pqinetwork.o \
|
||||
pqibin.o pqimon.o \
|
||||
EXECS = dht_test conn_test # test_p3items
|
||||
|
||||
BASE_OBJ = pqi_base.o pqidebug.o pqisecurity.o pqinetwork.o
|
||||
LOOP_OBJ = pqiloopback.o
|
||||
STREAM_OBJ = pqistreamer.o pqiarchive.o pqibin.o
|
||||
MGR_OBJ = pqimonitor.o p3dhtmgr.o p3connmgr.o p3cfgmgr.o p3authmgr.o
|
||||
GRP_OBJ = pqiperson.o pqihandler.o pqiservice.o pqipersongrp.o
|
||||
|
||||
ifdef PQI_USE_XPGP
|
||||
SSL_OBJ = xpgpcert.o
|
||||
SSL_OBJ = authxpgp.o
|
||||
#xpgpcert.o
|
||||
# Disabled for release... EXECS += p3supernode
|
||||
else
|
||||
SSL_OBJ = sslcert.o
|
||||
endif
|
||||
|
||||
SSL_OBJ += pqissl.o pqissllistener.o
|
||||
GRP_OBJ = pqiperson.o pqihandler.o pqiservice.o pqipersongrp.o
|
||||
STREAM_OBJ = pqistreamer.o pqiarchive.o
|
||||
SSL_OBJ += pqissl.o pqissllistener.o pqisslpersongrp.o
|
||||
UDP_OBJ = pqissludp.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
|
||||
# Old code - no longer used!
|
||||
#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) $(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)
|
||||
$(STREAM_OBJ) \
|
||||
$(MGR_OBJ) \
|
||||
$(SSL_OBJ) \
|
||||
$(UDP_OBJ) \
|
||||
$(GRP_OBJ)
|
||||
|
||||
# Linux only parts.
|
||||
ifeq ($(OS),Linux)
|
||||
@ -85,14 +83,20 @@ librs: $(OBJ)
|
||||
|
||||
$(OBJ) : $(HDR)
|
||||
|
||||
p3supernode: p3supernode.o librs
|
||||
$(CC) $(CFLAGS) -o p3supernode p3supernode.o $(RSLIBS)
|
||||
#p3supernode: p3supernode.o librs
|
||||
# $(CC) $(CFLAGS) -o p3supernode p3supernode.o $(RSLIBS)
|
||||
|
||||
dht_test: dht_test.o librs
|
||||
$(CC) $(CFLAGS) -o dht_test dht_test.o $(RSLIBS)
|
||||
|
||||
conn_test: conn_test.o librs
|
||||
$(CC) $(CFLAGS) -o conn_test conn_test.o $(RSLIBS)
|
||||
|
||||
.cc.o:
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
clean:
|
||||
-/bin/rm $(OBJ) p3supernode.o
|
||||
-/bin/rm $(OBJ)
|
||||
|
||||
clobber: clean
|
||||
-/bin/rm $(EXECS) $(LIBPQIA) $(LIBPQISO)
|
||||
|
1771
libretroshare/src/pqi/authxpgp.cc
Normal file
1771
libretroshare/src/pqi/authxpgp.cc
Normal file
File diff suppressed because it is too large
Load Diff
177
libretroshare/src/pqi/authxpgp.h
Normal file
177
libretroshare/src/pqi/authxpgp.h
Normal file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* libretroshare/src/pqi: authxpgp.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 MRK_AUTH_SSL_XPGP_HEADER
|
||||
#define MRK_AUTH_SSL_XPGP_HEADER
|
||||
|
||||
/* This is the trial XPGP version
|
||||
*
|
||||
* It has to be compiled against XPGP ssl version.
|
||||
* this is only a hacked up version, merging
|
||||
* (so both can operate in parallel will happen later)
|
||||
*
|
||||
*/
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "util/rsthreads.h"
|
||||
|
||||
#include "pqi/pqi_base.h"
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "pqi/p3authmgr.h"
|
||||
|
||||
class AuthXPGP;
|
||||
|
||||
|
||||
class xpgpcert
|
||||
{
|
||||
public:
|
||||
xpgpcert(XPGP *xpgp, std::string id);
|
||||
|
||||
/* certificate parameters */
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::string location;
|
||||
std::string org;
|
||||
std::string email;
|
||||
|
||||
std::string fpr;
|
||||
std::list<std::string> signers;
|
||||
|
||||
/* Auth settings */
|
||||
|
||||
uint32_t trustLvl;
|
||||
bool ownsign;
|
||||
bool trusted;
|
||||
|
||||
/* INTERNAL Parameters */
|
||||
XPGP *certificate;
|
||||
};
|
||||
|
||||
class AuthXPGP: public p3AuthMgr
|
||||
{
|
||||
public:
|
||||
|
||||
/* Initialisation Functions (Unique) */
|
||||
AuthXPGP();
|
||||
virtual bool active();
|
||||
virtual int InitAuth(const char *srvr_cert, const char *priv_key,
|
||||
const char *passwd);
|
||||
virtual bool CloseAuth();
|
||||
virtual int setConfigDirectories(const char *cdir, const char *ndir);
|
||||
|
||||
/*********** Overloaded Functions from p3AuthMgr **********/
|
||||
|
||||
/* get Certificate Ids */
|
||||
|
||||
virtual std::string OwnId();
|
||||
virtual bool getAllList(std::list<std::string> &ids);
|
||||
virtual bool getAuthenticatedList(std::list<std::string> &ids);
|
||||
virtual bool getUnknownList(std::list<std::string> &ids);
|
||||
|
||||
/* get Details from the Certificates */
|
||||
|
||||
virtual bool isValid(std::string id);
|
||||
virtual bool isAuthenticated(std::string id);
|
||||
virtual std::string getName(std::string id);
|
||||
virtual bool getDetails(std::string id, pqiAuthDetails &details);
|
||||
|
||||
/* Load/Save certificates */
|
||||
|
||||
virtual bool LoadCertificateFromString(std::string pem, std::string &id);
|
||||
virtual std::string SaveCertificateToString(std::string id);
|
||||
virtual bool LoadCertificateFromFile(std::string filename, std::string &id);
|
||||
virtual bool SaveCertificateToFile(std::string id, std::string filename);
|
||||
|
||||
/* Signatures */
|
||||
|
||||
virtual bool AuthCertificate(std::string uid);
|
||||
virtual bool SignCertificate(std::string id);
|
||||
virtual bool RevokeCertificate(std::string id);
|
||||
virtual bool TrustCertificate(std::string id, bool trust);
|
||||
|
||||
/* Sign / Encrypt / Verify Data (TODO) */
|
||||
|
||||
|
||||
/**** NEW functions we've added ****/
|
||||
|
||||
|
||||
/*********** Overloaded Functions from p3AuthMgr **********/
|
||||
|
||||
private:
|
||||
|
||||
/* Helper Functions */
|
||||
SSL_CTX *getCTX();
|
||||
|
||||
bool getXPGPid(XPGP *xpgp, std::string &xpgpid);
|
||||
bool ProcessXPGP(XPGP *xpgp, std::string &id);
|
||||
XPGP * loadXPGPFromDER(char *data, uint32_t len);
|
||||
XPGP * loadXPGPFromPEM(std::string pem);
|
||||
XPGP * loadXPGPFromFile(std::string fname, std::string hash);
|
||||
bool saveXPGPToFile(XPGP *xpgp, std::string fname, std::string &hash);
|
||||
|
||||
/*********** LOCKED Functions ******/
|
||||
bool locked_FindCert(std::string id, xpgpcert **cert);
|
||||
|
||||
|
||||
/* Data */
|
||||
RsMutex xpgpMtx; /**** LOCKING */
|
||||
|
||||
int init;
|
||||
std::string mCertDir;
|
||||
std::string mNeighDir;
|
||||
|
||||
SSL_CTX *sslctx;
|
||||
XPGP_KEYRING *pgp_keyring;
|
||||
|
||||
std::string mOwnId;
|
||||
xpgpcert *mOwnCert;
|
||||
EVP_PKEY *pkey;
|
||||
|
||||
std::map<std::string, xpgpcert *> mCerts;
|
||||
|
||||
};
|
||||
|
||||
/* Helper Functions */
|
||||
int printSSLError(SSL *ssl, int retval, int err, unsigned long err2, std::ostream &out);
|
||||
std::string getX509NameString(X509_NAME *name);
|
||||
std::string getX509CNString(X509_NAME *name);
|
||||
|
||||
std::string getX509OrgString(X509_NAME *name);
|
||||
std::string getX509LocString(X509_NAME *name);
|
||||
std::string getX509CountryString(X509_NAME *name);
|
||||
|
||||
std::list<std::string> getXPGPsigners(XPGP *cert);
|
||||
std::string getXPGPInfo(XPGP *cert);
|
||||
std::string getXPGPAuthCode(XPGP *xpgp);
|
||||
|
||||
int LoadCheckXPGPandGetName(const char *cert_file, std::string &userName);
|
||||
|
||||
|
||||
#endif // MRK_SSL_XPGP_CERT_HEADER
|
350
libretroshare/src/pqi/conn_test.cc
Normal file
350
libretroshare/src/pqi/conn_test.cc
Normal file
@ -0,0 +1,350 @@
|
||||
|
||||
|
||||
#include "pqi/p3connmgr.h"
|
||||
|
||||
|
||||
/***** Test for the new DHT system *****/
|
||||
|
||||
|
||||
#include "util/rsnet.h"
|
||||
#include "util/rsthreads.h"
|
||||
#include "util/rsprint.h"
|
||||
#include "pqi/p3dhtmgr.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/pqisecurity.h"
|
||||
#include "pqi/pqipersongrp.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "tcponudp/udpsorter.h"
|
||||
|
||||
/***** Test Framework *****/
|
||||
|
||||
const int NumOfPeers = 10;
|
||||
std::string peerIds[NumOfPeers] =
|
||||
{"PEER01",
|
||||
"PEER02", /* Always online, no notify */
|
||||
"PEER03", /* notify/online at 20sec */
|
||||
"PEER04", /* Always online, notify at 30 sec */
|
||||
"PEER05",
|
||||
"PEER06", /* notify/online at 50sec */
|
||||
"PEER07",
|
||||
"PEER08",
|
||||
"PEER09", /* notify/online at 80sec */
|
||||
"PEER10"};
|
||||
|
||||
#define STUN_PORT 7777
|
||||
|
||||
std::string ownId = "OWNID-AAAA";
|
||||
time_t ownPublishTs;
|
||||
|
||||
RsMutex frmMtx;
|
||||
std::list<std::string> searchIds;
|
||||
std::list<uint32_t> searchModes;
|
||||
|
||||
std::map<std::string, bool> onlineMap;
|
||||
std::map<uint32_t, std::string> notifyMap;
|
||||
|
||||
void initTestData()
|
||||
{
|
||||
ownPublishTs = 0;
|
||||
/* setup Peers that are online always */
|
||||
bool online;
|
||||
uint32_t ts;
|
||||
for(int i = 0; i < NumOfPeers; i++)
|
||||
{
|
||||
online = false;
|
||||
if ((i == 1) || (i == 3))
|
||||
{
|
||||
online = true;
|
||||
}
|
||||
onlineMap[peerIds[i]] = online;
|
||||
|
||||
if ((i == 2) || (i == 3) ||
|
||||
(i == 5) || (i == 8))
|
||||
{
|
||||
ts = i * 10;
|
||||
notifyMap[ts] = peerIds[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void respondPublish()
|
||||
{
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
if (!ownPublishTs)
|
||||
{
|
||||
std::cerr << "Own ID first published!" << std::endl;
|
||||
ownPublishTs = time(NULL);
|
||||
}
|
||||
frmMtx.unlock(); /* UNLOCK TEST FRAMEWORK MUTEX */
|
||||
}
|
||||
|
||||
void respondSearch(p3DhtMgr *mgr, std::string id, uint32_t mode)
|
||||
{
|
||||
std::cerr << "Checking for Search Results" << std::endl;
|
||||
time_t now = time(NULL);
|
||||
bool doNotify = false;
|
||||
bool doOnline = false;
|
||||
std::string notifyId;
|
||||
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
if ((mode == DHT_MODE_NOTIFY) && (ownPublishTs))
|
||||
{
|
||||
/* */
|
||||
std::map<uint32_t, std::string>::iterator it;
|
||||
uint32_t delta_t = now - ownPublishTs;
|
||||
it = notifyMap.begin();
|
||||
if (it != notifyMap.end())
|
||||
{
|
||||
if (it->first <= delta_t)
|
||||
{
|
||||
notifyId = it->second;
|
||||
onlineMap[notifyId] = true;
|
||||
notifyMap.erase(it);
|
||||
doNotify = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (mode == DHT_MODE_SEARCH)
|
||||
{
|
||||
|
||||
/* translate */
|
||||
std::map<std::string, bool>::iterator mit;
|
||||
for(mit = onlineMap.begin(); (mit != onlineMap.end()) &&
|
||||
(RsUtil::HashId(mit->first, false) != id); mit++);
|
||||
|
||||
if (mit != onlineMap.end())
|
||||
{
|
||||
doOnline = mit->second;
|
||||
}
|
||||
}
|
||||
|
||||
frmMtx.unlock(); /* UNLOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
uint32_t type = 0;
|
||||
|
||||
struct sockaddr_in laddr;
|
||||
inet_aton("10.0.0.129", &(laddr.sin_addr));
|
||||
laddr.sin_port = htons(7812);
|
||||
laddr.sin_family = AF_INET;
|
||||
|
||||
struct sockaddr_in raddr;
|
||||
inet_aton("127.0.0.1", &(raddr.sin_addr));
|
||||
raddr.sin_port = htons(STUN_PORT);
|
||||
raddr.sin_family = AF_INET;
|
||||
|
||||
if (doNotify)
|
||||
{
|
||||
std::cerr << "Responding to Notify: id:" << notifyId << std::endl;
|
||||
mgr->dhtResultNotify(RsUtil::HashId(notifyId, true));
|
||||
}
|
||||
|
||||
if (doOnline)
|
||||
{
|
||||
std::cerr << "Responding to Search" << std::endl;
|
||||
mgr->dhtResultSearch(id, laddr, raddr, type, "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***** Test Framework *****/
|
||||
|
||||
class DhtMgrTester: public p3DhtMgr
|
||||
{
|
||||
|
||||
/* Implementation */
|
||||
public:
|
||||
|
||||
DhtMgrTester(std::string id, pqiConnectCb *cb)
|
||||
:p3DhtMgr(id, cb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Blocking calls (only from thread) */
|
||||
virtual bool dhtPublish(std::string id,
|
||||
struct sockaddr_in &laddr, struct sockaddr_in &raddr,
|
||||
uint32_t type, std::string sign)
|
||||
{
|
||||
std::cerr << "DhtMgrTester::dhtPublish() id: " << RsUtil::BinToHex(id);
|
||||
std::cerr << " laddr: " << inet_ntoa(laddr.sin_addr) << " lport: " << ntohs(laddr.sin_port);
|
||||
std::cerr << " raddr: " << inet_ntoa(raddr.sin_addr) << " rport: " << ntohs(raddr.sin_port);
|
||||
std::cerr << " type: " << type << " sign: " << sign;
|
||||
std::cerr << std::endl;
|
||||
|
||||
respondPublish();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool dhtNotify(std::string peerid, std::string ownid, std::string sign)
|
||||
{
|
||||
std::cerr << "DhtMgrTester::dhtNotify() id: " << RsUtil::BinToHex(peerid) << ", ownId: " << RsUtil::BinToHex(ownId);
|
||||
std::cerr << " sign: " << sign;
|
||||
std::cerr << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool dhtSearch(std::string id, uint32_t mode)
|
||||
{
|
||||
std::cerr << "DhtMgrTester::dhtSearch(id: " << RsUtil::BinToHex(id) << ", mode: " << mode << ")" << std::endl;
|
||||
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
searchIds.push_back(id);
|
||||
searchModes.push_back(mode);
|
||||
frmMtx.unlock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* OVERLOAD THE ConnMgr - to insert peers */
|
||||
class p3TestConnMgr: public p3ConnectMgr
|
||||
{
|
||||
public:
|
||||
p3TestConnMgr(int mode)
|
||||
:p3ConnectMgr(new p3DummyAuthMgr()), mTestMode(mode) { return; }
|
||||
|
||||
protected:
|
||||
/* must be virtual for testing */
|
||||
virtual void loadConfiguration()
|
||||
{
|
||||
|
||||
/* setup own address */
|
||||
ownState.id = ownId;
|
||||
ownState.name = "SELF NAME";
|
||||
ownState.localaddr.sin_family = AF_INET;
|
||||
inet_aton("127.0.0.1", &(ownState.localaddr.sin_addr));
|
||||
ownState.localaddr.sin_port = htons(7812);
|
||||
ownState.netMode = RS_NET_MODE_UDP;
|
||||
ownState.visState = RS_VIS_STATE_STD;
|
||||
|
||||
/* others not important */
|
||||
//ownState.state = 0;
|
||||
//ownState.actions = 0;
|
||||
|
||||
|
||||
if (mTestMode == 1) /* Add to Stun List */
|
||||
{
|
||||
for(int i = 0; i < NumOfPeers; i++)
|
||||
{
|
||||
mStunList.push_back(peerIds[i]);
|
||||
}
|
||||
}
|
||||
else if (mTestMode == 2) /* add to peers */
|
||||
{
|
||||
/* add in as peers */
|
||||
//addPeer();
|
||||
for(int i = 0; i < NumOfPeers; i++)
|
||||
{
|
||||
if (i < 5)
|
||||
{
|
||||
mStunList.push_back(RsUtil::HashId(peerIds[i]));
|
||||
}
|
||||
else
|
||||
{
|
||||
addFriend(peerIds[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
uint32_t mTestMode;
|
||||
};
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
time_t startTime = time(NULL);
|
||||
/* setup system */
|
||||
initTestData();
|
||||
|
||||
/* setup a Stunner to respond to ConnMgr */
|
||||
|
||||
struct sockaddr_in saddr;
|
||||
saddr.sin_family = AF_INET;
|
||||
inet_aton("127.0.0.1", &(saddr.sin_addr));
|
||||
saddr.sin_port = htons(STUN_PORT);
|
||||
UdpSorter stunner(saddr); /* starts a receiving thread */
|
||||
|
||||
p3TestConnMgr connMgr(2);
|
||||
DhtMgrTester dhtTester(ownId, &connMgr);
|
||||
|
||||
/* now add in some peers */
|
||||
connMgr.setDhtMgr(&dhtTester);
|
||||
connMgr.setUpnpMgr(NULL);
|
||||
|
||||
/************ ADD pqipersongrp as pqimonitor *****************/
|
||||
|
||||
SecurityPolicy *pol = secpolicy_create();
|
||||
unsigned long flags = 0;
|
||||
pqipersongrp *pqipg = new pqipersongrpDummy(pol, flags);
|
||||
|
||||
connMgr.addMonitor(pqipg);
|
||||
|
||||
/************ ADD pqipersongrp as pqimonitor *****************/
|
||||
|
||||
|
||||
/* startup dht */
|
||||
std::cerr << "Starting up DhtTester()" << std::endl;
|
||||
dhtTester.start();
|
||||
|
||||
/* wait for a little before switching on */
|
||||
sleep(1);
|
||||
|
||||
std::cerr << "Switching on DhtTester()" << std::endl;
|
||||
dhtTester.setDhtOn(true);
|
||||
|
||||
/* wait loop */
|
||||
while(1)
|
||||
{
|
||||
sleep(1);
|
||||
|
||||
connMgr.tick();
|
||||
pqipg->tick();
|
||||
|
||||
/* handle async search */
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
std::string id;
|
||||
uint32_t mode;
|
||||
bool doRespond = false;
|
||||
if (searchIds.size() > 0)
|
||||
{
|
||||
id = searchIds.front();
|
||||
mode = searchModes.front();
|
||||
doRespond = true;
|
||||
searchIds.pop_front();
|
||||
searchModes.pop_front();
|
||||
}
|
||||
|
||||
frmMtx.unlock(); /* UNLOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
if (doRespond)
|
||||
{
|
||||
respondSearch(&dhtTester, id, mode);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
295
libretroshare/src/pqi/dht_test.cc
Normal file
295
libretroshare/src/pqi/dht_test.cc
Normal file
@ -0,0 +1,295 @@
|
||||
|
||||
|
||||
/***** Test for the new DHT system *****/
|
||||
|
||||
|
||||
#include "util/rsnet.h"
|
||||
#include "util/rsthreads.h"
|
||||
#include "util/rsprint.h"
|
||||
|
||||
#include "pqi/p3dhtmgr.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
/***** Test Framework *****/
|
||||
|
||||
const int NumOfPeers = 10;
|
||||
std::string peerIds[NumOfPeers] =
|
||||
{"PEER01",
|
||||
"PEER02", /* Always online, no notify */
|
||||
"PEER03", /* notify/online at 20sec */
|
||||
"PEER04", /* Always online, notify at 30 sec */
|
||||
"PEER05",
|
||||
"PEER06", /* notify/online at 50sec */
|
||||
"PEER07",
|
||||
"PEER08",
|
||||
"PEER09", /* notify/online at 80sec */
|
||||
"PEER10"};
|
||||
|
||||
std::string ownId = "AAAA";
|
||||
time_t ownPublishTs;
|
||||
|
||||
RsMutex frmMtx;
|
||||
std::list<std::string> searchIds;
|
||||
std::list<uint32_t> searchModes;
|
||||
|
||||
std::map<std::string, bool> onlineMap;
|
||||
std::map<uint32_t, std::string> notifyMap;
|
||||
|
||||
void initTestData()
|
||||
{
|
||||
ownPublishTs = 0;
|
||||
/* setup Peers that are online always */
|
||||
bool online;
|
||||
uint32_t ts;
|
||||
for(int i = 0; i < NumOfPeers; i++)
|
||||
{
|
||||
online = false;
|
||||
if ((i == 1) || (i == 3))
|
||||
{
|
||||
online = true;
|
||||
}
|
||||
onlineMap[peerIds[i]] = online;
|
||||
|
||||
if ((i == 2) || (i == 3) ||
|
||||
(i == 5) || (i == 8))
|
||||
{
|
||||
ts = i * 10;
|
||||
notifyMap[ts] = peerIds[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void respondPublish()
|
||||
{
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
if (!ownPublishTs)
|
||||
{
|
||||
std::cerr << "Own ID first published!" << std::endl;
|
||||
ownPublishTs = time(NULL);
|
||||
}
|
||||
frmMtx.unlock(); /* UNLOCK TEST FRAMEWORK MUTEX */
|
||||
}
|
||||
|
||||
void respondSearch(p3DhtMgr *mgr, std::string id, uint32_t mode)
|
||||
{
|
||||
std::cerr << "Checking for Search Results" << std::endl;
|
||||
time_t now = time(NULL);
|
||||
bool doNotify = false;
|
||||
bool doOnline = false;
|
||||
std::string notifyId;
|
||||
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
if ((mode == DHT_MODE_NOTIFY) && (ownPublishTs))
|
||||
{
|
||||
/* */
|
||||
std::map<uint32_t, std::string>::iterator it;
|
||||
uint32_t delta_t = now - ownPublishTs;
|
||||
it = notifyMap.begin();
|
||||
if (it != notifyMap.end())
|
||||
{
|
||||
if (it->first <= delta_t)
|
||||
{
|
||||
notifyId = it->second;
|
||||
onlineMap[notifyId] = true;
|
||||
notifyMap.erase(it);
|
||||
doNotify = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (mode == DHT_MODE_SEARCH)
|
||||
{
|
||||
/* translate */
|
||||
std::map<std::string, bool>::iterator mit;
|
||||
for(mit = onlineMap.begin(); (mit != onlineMap.end()) &&
|
||||
(RsUtil::HashId(mit->first, false) != id); mit++);
|
||||
|
||||
if (mit != onlineMap.end())
|
||||
{
|
||||
doOnline = mit->second;
|
||||
}
|
||||
}
|
||||
|
||||
frmMtx.unlock(); /* UNLOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
uint32_t type = 0;
|
||||
|
||||
struct sockaddr_in laddr;
|
||||
inet_aton("10.0.0.129", &(laddr.sin_addr));
|
||||
laddr.sin_port = htons(7812);
|
||||
laddr.sin_family = AF_INET;
|
||||
|
||||
struct sockaddr_in raddr;
|
||||
inet_aton("10.0.0.19", &(raddr.sin_addr));
|
||||
raddr.sin_port = htons(7812);
|
||||
raddr.sin_family = AF_INET;
|
||||
|
||||
if (doNotify)
|
||||
{
|
||||
std::cerr << "Responding to Notify" << std::endl;
|
||||
mgr->dhtResultNotify(RsUtil::HashId(notifyId, true));
|
||||
}
|
||||
|
||||
if (doOnline)
|
||||
{
|
||||
std::cerr << "Responding to Search" << std::endl;
|
||||
mgr->dhtResultSearch(id, laddr, raddr, type, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/***** Test Framework *****/
|
||||
|
||||
|
||||
|
||||
|
||||
class DhtMgrTester: public p3DhtMgr
|
||||
{
|
||||
|
||||
/* Implementation */
|
||||
public:
|
||||
|
||||
DhtMgrTester(std::string id, pqiConnectCb *cb)
|
||||
:p3DhtMgr(id, cb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Blocking calls (only from thread) */
|
||||
virtual bool dhtPublish(std::string id,
|
||||
struct sockaddr_in &laddr, struct sockaddr_in &raddr,
|
||||
uint32_t type, std::string sign)
|
||||
{
|
||||
std::cerr << "DhtMgrTester::dhtPublish() id: " << RsUtil::BinToHex(id);
|
||||
std::cerr << " laddr: " << inet_ntoa(laddr.sin_addr) << " lport: " << ntohs(laddr.sin_port);
|
||||
std::cerr << " raddr: " << inet_ntoa(raddr.sin_addr) << " rport: " << ntohs(raddr.sin_port);
|
||||
std::cerr << " type: " << type << " sign: " << sign;
|
||||
std::cerr << std::endl;
|
||||
|
||||
respondPublish();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool dhtNotify(std::string peerid, std::string ownid, std::string sign)
|
||||
{
|
||||
std::cerr << "DhtMgrTester::dhtNotify() id: " << RsUtil::BinToHex(peerid) << ", ownId: " << RsUtil::BinToHex(ownId);
|
||||
std::cerr << " sign: " << sign;
|
||||
std::cerr << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool dhtSearch(std::string id, uint32_t mode)
|
||||
{
|
||||
std::cerr << "DhtMgrTester::dhtSearch(id: " << RsUtil::BinToHex(id) << ", mode: " << mode << ")" << std::endl;
|
||||
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
searchIds.push_back(id);
|
||||
searchModes.push_back(mode);
|
||||
frmMtx.unlock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
time_t startTime = time(NULL);
|
||||
bool haveOwnAddress = false;
|
||||
/* setup system */
|
||||
initTestData();
|
||||
|
||||
pqiConnectCbDummy cbTester;
|
||||
DhtMgrTester dhtTester(ownId, &cbTester);
|
||||
|
||||
/* now add in some peers */
|
||||
|
||||
/* startup dht */
|
||||
std::cerr << "Starting up DhtTester()" << std::endl;
|
||||
dhtTester.start();
|
||||
|
||||
/* wait for a little before switching on */
|
||||
sleep(1);
|
||||
|
||||
std::cerr << "Switching on DhtTester()" << std::endl;
|
||||
dhtTester.setDhtOn(true);
|
||||
|
||||
std::cerr << "Adding a List of Peers" << std::endl;
|
||||
for(int i = 0; i < NumOfPeers; i++)
|
||||
{
|
||||
dhtTester.findPeer(peerIds[i]);
|
||||
}
|
||||
|
||||
|
||||
/* wait loop */
|
||||
while(1)
|
||||
{
|
||||
std::cerr << "Main waiting..." << std::endl;
|
||||
sleep(3);
|
||||
|
||||
/* handle async search */
|
||||
frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
std::string id;
|
||||
uint32_t mode;
|
||||
bool doRespond = false;
|
||||
if (searchIds.size() > 0)
|
||||
{
|
||||
id = searchIds.front();
|
||||
mode = searchModes.front();
|
||||
doRespond = true;
|
||||
searchIds.pop_front();
|
||||
searchModes.pop_front();
|
||||
}
|
||||
|
||||
frmMtx.unlock(); /* UNLOCK TEST FRAMEWORK MUTEX */
|
||||
|
||||
if (doRespond)
|
||||
{
|
||||
respondSearch(&dhtTester, id, mode);
|
||||
}
|
||||
|
||||
if (!haveOwnAddress)
|
||||
{
|
||||
if (time(NULL) - startTime > 20)
|
||||
{
|
||||
std::cerr << "Setting Own Address!" << std::endl;
|
||||
haveOwnAddress = true;
|
||||
|
||||
uint32_t type = DHT_ADDR_UDP;
|
||||
|
||||
struct sockaddr_in laddr;
|
||||
inet_aton("10.0.0.111", &(laddr.sin_addr));
|
||||
laddr.sin_port = htons(7812);
|
||||
laddr.sin_family = AF_INET;
|
||||
|
||||
struct sockaddr_in raddr;
|
||||
inet_aton("10.0.0.11", &(raddr.sin_addr));
|
||||
raddr.sin_port = htons(7812);
|
||||
raddr.sin_family = AF_INET;
|
||||
|
||||
dhtTester.setExternalInterface(laddr, raddr, type);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
226
libretroshare/src/pqi/p3authmgr.cc
Normal file
226
libretroshare/src/pqi/p3authmgr.cc
Normal file
@ -0,0 +1,226 @@
|
||||
/*
|
||||
* libretroshare/src/pqi: p3authmgr.cc
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2007-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/p3authmgr.h"
|
||||
|
||||
pqiAuthDetails::pqiAuthDetails()
|
||||
:trustLvl(0), ownsign(false), trusted(0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
p3DummyAuthMgr::p3DummyAuthMgr()
|
||||
{
|
||||
/* for the truely dummy option */
|
||||
mOwnId = "OWNID";
|
||||
|
||||
pqiAuthDetails ownDetails;
|
||||
ownDetails.id = mOwnId;
|
||||
ownDetails.name = "Youself";
|
||||
ownDetails.email = "me@me.com";
|
||||
ownDetails.location = "here";
|
||||
ownDetails.org = "me.com";
|
||||
|
||||
ownDetails.trustLvl = 6;
|
||||
ownDetails.ownsign = true;
|
||||
ownDetails.trusted = true;
|
||||
|
||||
/* ignoring fpr and signers */
|
||||
|
||||
mPeerList[mOwnId] = ownDetails;
|
||||
|
||||
}
|
||||
|
||||
p3DummyAuthMgr::p3DummyAuthMgr(std::string ownId, std::list<pqiAuthDetails> peers)
|
||||
{
|
||||
mOwnId = ownId;
|
||||
bool addedOwn = false;
|
||||
|
||||
std::list<pqiAuthDetails>::iterator it;
|
||||
for(it = peers.begin(); it != peers.end(); it++)
|
||||
{
|
||||
mPeerList[it->id] = (*it);
|
||||
if (it->id == ownId)
|
||||
{
|
||||
addedOwn = true;
|
||||
}
|
||||
}
|
||||
if (!addedOwn)
|
||||
{
|
||||
pqiAuthDetails ownDetails;
|
||||
ownDetails.id = mOwnId;
|
||||
ownDetails.name = "Youself";
|
||||
ownDetails.email = "me@me.com";
|
||||
ownDetails.location = "here";
|
||||
ownDetails.org = "me.com";
|
||||
|
||||
ownDetails.trustLvl = 6;
|
||||
ownDetails.ownsign = true;
|
||||
ownDetails.trusted = true;
|
||||
|
||||
/* ignoring fpr and signers */
|
||||
|
||||
mPeerList[mOwnId] = ownDetails;
|
||||
}
|
||||
}
|
||||
|
||||
bool p3DummyAuthMgr:: active()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int p3DummyAuthMgr::InitAuth(const char *srvr_cert, const char *priv_key,
|
||||
const char *passwd)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool p3DummyAuthMgr::CloseAuth()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int p3DummyAuthMgr::setConfigDirectories(const char *cdir, const char *ndir)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string p3DummyAuthMgr::OwnId()
|
||||
{
|
||||
return mOwnId;
|
||||
}
|
||||
|
||||
bool p3DummyAuthMgr::getAllList(std::list<std::string> &ids)
|
||||
{
|
||||
std::map<std::string, pqiAuthDetails>::iterator it;
|
||||
for(it = mPeerList.begin(); it != mPeerList.end(); it++)
|
||||
{
|
||||
ids.push_back(it->first);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3DummyAuthMgr::getAuthenticatedList(std::list<std::string> &ids)
|
||||
{
|
||||
std::map<std::string, pqiAuthDetails>::iterator it;
|
||||
for(it = mPeerList.begin(); it != mPeerList.end(); it++)
|
||||
{
|
||||
if (it->second.trustLvl > 3)
|
||||
{
|
||||
ids.push_back(it->first);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3DummyAuthMgr::getUnknownList(std::list<std::string> &ids)
|
||||
{
|
||||
std::map<std::string, pqiAuthDetails>::iterator it;
|
||||
for(it = mPeerList.begin(); it != mPeerList.end(); it++)
|
||||
{
|
||||
if (it->second.trustLvl <= 3)
|
||||
{
|
||||
ids.push_back(it->first);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3DummyAuthMgr::isValid(std::string id)
|
||||
{
|
||||
std::map<std::string, pqiAuthDetails>::iterator it;
|
||||
return (mPeerList.end() != mPeerList.find(id));
|
||||
}
|
||||
|
||||
|
||||
bool p3DummyAuthMgr::isAuthenticated(std::string id)
|
||||
{
|
||||
std::map<std::string, pqiAuthDetails>::iterator it;
|
||||
if (mPeerList.end() != (it = mPeerList.find(id)))
|
||||
{
|
||||
return (it->second.trustLvl > 3);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string p3DummyAuthMgr::getName(std::string id)
|
||||
{
|
||||
std::map<std::string, pqiAuthDetails>::iterator it;
|
||||
if (mPeerList.end() != (it = mPeerList.find(id)))
|
||||
{
|
||||
return it->second.name;
|
||||
}
|
||||
std::string empty("");
|
||||
return empty;
|
||||
}
|
||||
|
||||
bool p3DummyAuthMgr::getDetails(std::string id, pqiAuthDetails &details)
|
||||
{
|
||||
std::map<std::string, pqiAuthDetails>::iterator it;
|
||||
if (mPeerList.end() != (it = mPeerList.find(id)))
|
||||
{
|
||||
details = it->second;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3DummyAuthMgr::LoadCertificateFromString(std::string pem, std::string &id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string p3DummyAuthMgr::SaveCertificateToString(std::string id)
|
||||
{
|
||||
std::string dummy("CERT STRING");
|
||||
return dummy;
|
||||
}
|
||||
|
||||
bool p3DummyAuthMgr::LoadCertificateFromFile(std::string filename, std::string &id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3DummyAuthMgr::SaveCertificateToFile(std::string id, std::string filename)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Signatures */
|
||||
bool p3DummyAuthMgr::SignCertificate(std::string id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3DummyAuthMgr::RevokeCertificate(std::string id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3DummyAuthMgr::TrustCertificate(std::string id, bool trust)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
164
libretroshare/src/pqi/p3authmgr.h
Normal file
164
libretroshare/src/pqi/p3authmgr.h
Normal file
@ -0,0 +1,164 @@
|
||||
/*
|
||||
* libretroshare/src/pqi: p3authmgr.h
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2007-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 RS_GENERIC_AUTH_HEADER
|
||||
#define RS_GENERIC_AUTH_HEADER
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
/************** GENERIC AUTHENTICATION MANAGER ***********
|
||||
* Provides a common interface for certificates.
|
||||
*
|
||||
* Initialisation must be done in derived classes
|
||||
*
|
||||
* Key features:
|
||||
* everything indexed by std::string id;
|
||||
* has auth perspective: authed / not authed - different to friends.
|
||||
* load/save certificates as strings or files.
|
||||
*
|
||||
*/
|
||||
|
||||
class p3AuthMgr;
|
||||
extern p3AuthMgr *authMgr;
|
||||
|
||||
p3AuthMgr *getAuthMgr();
|
||||
|
||||
class pqiAuthDetails
|
||||
{
|
||||
public:
|
||||
pqiAuthDetails();
|
||||
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::string email;
|
||||
std::string location;
|
||||
std::string org;
|
||||
|
||||
std::string fpr; /* fingerprint */
|
||||
std::list<std::string> signers;
|
||||
|
||||
uint32_t trustLvl;
|
||||
|
||||
bool ownsign;
|
||||
bool trusted;
|
||||
};
|
||||
|
||||
|
||||
class p3AuthMgr
|
||||
{
|
||||
public:
|
||||
|
||||
/* initialisation -> done by derived classes */
|
||||
virtual bool active() = 0;
|
||||
virtual int InitAuth(const char *srvr_cert, const char *priv_key,
|
||||
const char *passwd) = 0;
|
||||
virtual bool CloseAuth() = 0;
|
||||
virtual int setConfigDirectories(const char *cdir, const char *ndir) = 0;
|
||||
|
||||
/* get Certificate Ids */
|
||||
|
||||
virtual std::string OwnId() = 0;
|
||||
virtual bool getAllList(std::list<std::string> &ids) = 0;
|
||||
virtual bool getAuthenticatedList(std::list<std::string> &ids) = 0;
|
||||
virtual bool getUnknownList(std::list<std::string> &ids) = 0;
|
||||
|
||||
/* get Details from the Certificates */
|
||||
|
||||
virtual bool isValid(std::string id) = 0;
|
||||
virtual bool isAuthenticated(std::string id) = 0;
|
||||
virtual std::string getName(std::string id) = 0;
|
||||
virtual bool getDetails(std::string id, pqiAuthDetails &details) = 0;
|
||||
|
||||
/* Load/Save certificates */
|
||||
|
||||
virtual bool LoadCertificateFromString(std::string pem, std::string &id) = 0;
|
||||
virtual std::string SaveCertificateToString(std::string id) = 0;
|
||||
virtual bool LoadCertificateFromFile(std::string filename, std::string &id) = 0;
|
||||
virtual bool SaveCertificateToFile(std::string id, std::string filename) = 0;
|
||||
|
||||
/* Signatures */
|
||||
virtual bool AuthCertificate(std::string uid) = 0;
|
||||
virtual bool SignCertificate(std::string id) = 0;
|
||||
virtual bool RevokeCertificate(std::string id) = 0;
|
||||
virtual bool TrustCertificate(std::string id, bool trust) = 0;
|
||||
|
||||
/* Sign / Encrypt / Verify Data (TODO) */
|
||||
//virtual bool encryptData(std::string recipientId, std::string plaindata, std::string &result);
|
||||
|
||||
};
|
||||
|
||||
|
||||
class p3DummyAuthMgr: public p3AuthMgr
|
||||
{
|
||||
public:
|
||||
|
||||
p3DummyAuthMgr();
|
||||
p3DummyAuthMgr(std::string ownId, std::list<pqiAuthDetails> peers);
|
||||
|
||||
/* initialisation -> done by derived classes */
|
||||
virtual bool active();
|
||||
virtual int InitAuth(const char *srvr_cert, const char *priv_key,
|
||||
const char *passwd);
|
||||
virtual bool CloseAuth();
|
||||
virtual int setConfigDirectories(const char *cdir, const char *ndir);
|
||||
|
||||
/* get Certificate Ids */
|
||||
|
||||
virtual std::string OwnId();
|
||||
virtual bool getAllList(std::list<std::string> &ids);
|
||||
virtual bool getAuthenticatedList(std::list<std::string> &ids);
|
||||
virtual bool getUnknownList(std::list<std::string> &ids);
|
||||
|
||||
/* get Details from the Certificates */
|
||||
|
||||
virtual bool isValid(std::string id);
|
||||
virtual bool isAuthenticated(std::string id);
|
||||
virtual std::string getName(std::string id);
|
||||
virtual bool getDetails(std::string id, pqiAuthDetails &details);
|
||||
|
||||
/* Load/Save certificates */
|
||||
|
||||
virtual bool LoadCertificateFromString(std::string pem, std::string &id);
|
||||
virtual std::string SaveCertificateToString(std::string id);
|
||||
virtual bool LoadCertificateFromFile(std::string filename, std::string &id);
|
||||
virtual bool SaveCertificateToFile(std::string id, std::string filename);
|
||||
|
||||
/* Signatures */
|
||||
|
||||
virtual bool SignCertificate(std::string id);
|
||||
virtual bool RevokeCertificate(std::string id);
|
||||
virtual bool TrustCertificate(std::string id, bool trust);
|
||||
|
||||
std::string mOwnId;
|
||||
std::map<std::string, pqiAuthDetails> mPeerList;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
242
libretroshare/src/pqi/p3cfgmgr.cc
Normal file
242
libretroshare/src/pqi/p3cfgmgr.cc
Normal file
@ -0,0 +1,242 @@
|
||||
/*
|
||||
* libretroshare/src/pqi: p3cfgmgr.cc
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2007-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/p3cfgmgr.h"
|
||||
#include "pqi/pqibin.h"
|
||||
#include "pqi/pqiarchive.h"
|
||||
|
||||
|
||||
|
||||
|
||||
p3ConfigMgr::p3ConfigMgr(std::string dir, std::string fname, std::string signame)
|
||||
:basedir(dir), metafname(fname), metasigfname(signame)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void p3ConfigMgr::tick()
|
||||
{
|
||||
bool toSave = false;
|
||||
|
||||
/* iterate through and check if any have changed */
|
||||
std::map<uint32_t, pqiConfig *>::iterator it;
|
||||
for(it = configs.begin(); it != configs.end(); it++)
|
||||
{
|
||||
if (it->second->ConfInd.Changed(0))
|
||||
{
|
||||
toSave = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (toSave)
|
||||
{
|
||||
saveConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void p3ConfigMgr::saveConfiguration()
|
||||
{
|
||||
/* setup metaconfig */
|
||||
|
||||
std::map<uint32_t, pqiConfig *>::iterator it;
|
||||
for(it = configs.begin(); it != configs.end(); it++)
|
||||
{
|
||||
if (it->second->ConfInd.Changed(1))
|
||||
{
|
||||
it->second->saveConfiguration(basedir);
|
||||
}
|
||||
/* save metaconfig */
|
||||
}
|
||||
|
||||
/* sign the hash of the data */
|
||||
|
||||
|
||||
/* write signature to configuration */
|
||||
}
|
||||
|
||||
void p3ConfigMgr::loadConfiguration()
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void p3ConfigMgr::addConfiguration(uint32_t type, pqiConfig *conf)
|
||||
{
|
||||
configs[type] = conf;
|
||||
}
|
||||
|
||||
|
||||
p3Config::p3Config(uint32_t t, std::string name)
|
||||
:pqiConfig(t, name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool p3Config::loadConfiguration(std::string basedir, std::string &loadHash)
|
||||
{
|
||||
std::list<RsItem *> load;
|
||||
std::list<RsItem *>::iterator it;
|
||||
|
||||
std::string fname = basedir;
|
||||
if (fname != "")
|
||||
fname += "/";
|
||||
fname += Filename();
|
||||
|
||||
BinFileInterface *bio = new BinFileInterface(fname.c_str(),
|
||||
BIN_FLAGS_READABLE | BIN_FLAGS_HASH_DATA);
|
||||
pqiarchive archive(setupSerialiser(), bio, BIN_FLAGS_READABLE);
|
||||
RsItem *item = NULL;
|
||||
|
||||
while(NULL != (item = archive.GetItem()))
|
||||
{
|
||||
load.push_back(item);
|
||||
}
|
||||
/* check hash */
|
||||
std::string hashstr = archive.gethash();
|
||||
|
||||
if (hashstr != loadHash)
|
||||
{
|
||||
/* bad load */
|
||||
for(it = load.begin(); it != load.end(); it++)
|
||||
{
|
||||
delete (*it);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
setHash(hashstr);
|
||||
|
||||
/* else okay */
|
||||
return loadList(load);
|
||||
}
|
||||
|
||||
|
||||
bool p3Config::saveConfiguration(std::string basedir)
|
||||
{
|
||||
bool toKeep;
|
||||
std::list<RsItem *> toSave = saveList(toKeep);
|
||||
|
||||
std::string fname = basedir;
|
||||
if (fname != "")
|
||||
fname += "/";
|
||||
fname += Filename();
|
||||
|
||||
BinFileInterface *bio = new BinFileInterface(fname.c_str(),
|
||||
BIN_FLAGS_WRITEABLE | BIN_FLAGS_HASH_DATA);
|
||||
|
||||
uint32_t arch_flags = BIN_FLAGS_WRITEABLE;
|
||||
if (toKeep)
|
||||
arch_flags |= BIN_FLAGS_NO_DELETE;
|
||||
|
||||
pqiarchive archive(setupSerialiser(), bio, arch_flags);
|
||||
std::list<RsItem *>::iterator it;
|
||||
for(it = toSave.begin(); it != toSave.end(); it++)
|
||||
{
|
||||
archive.SendItem(*it);
|
||||
}
|
||||
|
||||
/* store the hash */
|
||||
setHash(archive.gethash());
|
||||
|
||||
/* else okay */
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**************************** CONFIGURATION CLASSES ********************/
|
||||
|
||||
p3GeneralConfig::p3GeneralConfig()
|
||||
:p3Config(CONFIG_TYPE_GENERAL, "gen.set")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// General Configuration System
|
||||
std::string p3GeneralConfig::getSetting(std::string opt)
|
||||
{
|
||||
/* extract from config */
|
||||
std::map<std::string, std::string>::iterator it;
|
||||
if (settings.end() == (it = settings.find(opt)))
|
||||
{
|
||||
std::string nullstring;
|
||||
return nullstring;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void p3GeneralConfig::setSetting(std::string opt, std::string val)
|
||||
{
|
||||
/* extract from config */
|
||||
std::map<std::string, std::string>::iterator it;
|
||||
if (settings.end() != (it = settings.find(opt)))
|
||||
{
|
||||
if (it->second == val)
|
||||
{
|
||||
/* no change */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ConfInd.IndicateChanged();
|
||||
settings[opt] = val;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* TODO ******/
|
||||
|
||||
RsSerialiser *p3GeneralConfig::setupSerialiser()
|
||||
{
|
||||
RsSerialiser *rss = NULL;
|
||||
return rss;
|
||||
}
|
||||
|
||||
std::list<RsItem *> p3GeneralConfig::saveList(bool &cleanup)
|
||||
{
|
||||
cleanup = false;
|
||||
std::list<RsItem *> savelist;
|
||||
//RsGenConfItem *item = ...
|
||||
std::map<std::string, std::string>::iterator it;
|
||||
for(it = settings.begin(); it != settings.end(); it++)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
return savelist;
|
||||
}
|
||||
|
||||
|
||||
bool p3GeneralConfig::loadList(std::list<RsItem *> load)
|
||||
{
|
||||
/* add into settings */
|
||||
|
||||
return false;
|
||||
}
|
||||
|
156
libretroshare/src/pqi/p3cfgmgr.h
Normal file
156
libretroshare/src/pqi/p3cfgmgr.h
Normal file
@ -0,0 +1,156 @@
|
||||
/*
|
||||
* libretroshare/src/pqi: p3cfgmgr.h
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2007-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 P3_CONFIG_MGR_HEADER
|
||||
#define P3_CONFIG_MGR_HEADER
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "pqi/pqi_base.h"
|
||||
#include "pqi/pqiindic.h"
|
||||
#include "pqi/pqinetwork.h"
|
||||
|
||||
/***** Configuration Management *****
|
||||
*
|
||||
* we need to store:
|
||||
* (1) Certificates.
|
||||
* (2) List of Friends / Net Configuration
|
||||
* (3) Stun List. / DHT peers.
|
||||
* (4) general config.
|
||||
*
|
||||
*
|
||||
* At top level we need:
|
||||
*
|
||||
* - type / filename / size / hash -
|
||||
* and the file signed...
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
const uint32_t CONFIG_TYPE_GENERAL = 0x0001;
|
||||
const uint32_t CONFIG_TYPE_STUNLIST = 0x0002;
|
||||
const uint32_t CONFIG_TYPE_FSERVER = 0x0003;
|
||||
const uint32_t CONFIG_TYPE_PEERS = 0x0004;
|
||||
|
||||
class pqiConfig
|
||||
{
|
||||
public:
|
||||
pqiConfig(uint32_t t, std::string defaultname)
|
||||
:ConfInd(2), type(t), filename(defaultname)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
virtual bool loadConfiguration(std::string filename, std::string &load) = 0;
|
||||
virtual bool saveConfiguration(std::string filename) = 0;
|
||||
|
||||
Indicator ConfInd;
|
||||
|
||||
uint32_t Type() { return type; }
|
||||
std::string Filename() { return filename; }
|
||||
std::string Hash() { return hash; }
|
||||
|
||||
protected:
|
||||
void setHash(std::string h) { hash = h; }
|
||||
|
||||
private:
|
||||
uint32_t type;
|
||||
std::string filename;
|
||||
std::string hash;
|
||||
};
|
||||
|
||||
|
||||
class p3ConfigMgr
|
||||
{
|
||||
public:
|
||||
p3ConfigMgr(std::string bdir, std::string fname, std::string signame);
|
||||
|
||||
void tick();
|
||||
void saveConfiguration();
|
||||
void loadConfiguration();
|
||||
void addConfiguration(uint32_t type, pqiConfig *conf);
|
||||
|
||||
private:
|
||||
|
||||
std::map<uint32_t, pqiConfig *> configs;
|
||||
|
||||
std::string basedir;
|
||||
std::string metafname;
|
||||
std::string metasigfname;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class p3Config: public pqiConfig
|
||||
{
|
||||
public:
|
||||
|
||||
p3Config(uint32_t t, std::string name);
|
||||
|
||||
virtual bool loadConfiguration(std::string basedir, std::string &loadHash);
|
||||
virtual bool saveConfiguration(std::string basedir);
|
||||
|
||||
protected:
|
||||
|
||||
/* Key Functions to be overloaded for Full Configuration */
|
||||
virtual RsSerialiser *setupSerialiser() = 0;
|
||||
virtual std::list<RsItem *> saveList(bool &cleanup) = 0;
|
||||
virtual bool loadList(std::list<RsItem *> load) = 0;
|
||||
|
||||
|
||||
}; /* end of p3Config */
|
||||
|
||||
|
||||
class p3GeneralConfig: public p3Config
|
||||
{
|
||||
public:
|
||||
p3GeneralConfig();
|
||||
|
||||
// General Configuration System
|
||||
std::string getSetting(std::string opt);
|
||||
void setSetting(std::string opt, std::string val);
|
||||
|
||||
protected:
|
||||
|
||||
/* Key Functions to be overloaded for Full Configuration */
|
||||
virtual RsSerialiser *setupSerialiser();
|
||||
virtual std::list<RsItem *> saveList(bool &cleanup);
|
||||
virtual bool loadList(std::list<RsItem *> load);
|
||||
|
||||
private:
|
||||
|
||||
std::map<std::string, std::string> settings;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // P3_CONFIG_MGR_HEADER
|
File diff suppressed because it is too large
Load Diff
@ -1,314 +0,0 @@
|
||||
/*
|
||||
* "$Id: p3channel.h,v 1.6 2007-03-05 21:26:03 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_CHANNEL_H
|
||||
#define MRK_P3_CHANNEL_H
|
||||
|
||||
#include "pqi/pqichannel.h"
|
||||
|
||||
/****
|
||||
* This is our channel class.
|
||||
* It performs various functions.
|
||||
* 1) collect channel messages.
|
||||
* 2) save/restore messages.
|
||||
* 3) manage their downloads....
|
||||
* 4) rebroadcast messages.
|
||||
*
|
||||
* You need to be able to categorise the channels
|
||||
* 1) Favourites.
|
||||
* 2) Standard Subscription
|
||||
* 3) Listen
|
||||
* 4) Others.
|
||||
*
|
||||
* The first three groups will be maintained.
|
||||
*
|
||||
* Controllable how long lists are maintained. (1 week standard)
|
||||
*
|
||||
* Messages are rebroadcast, At a random interval (0 - 4 hours) after
|
||||
* receiving the message.
|
||||
*
|
||||
* Popularity rating on how much each is rebroadcast.
|
||||
*
|
||||
*
|
||||
* There should be a couple of rating schemes to decide
|
||||
* on how long something stays downloaded.
|
||||
*
|
||||
* 1) Time, Old stuff first.
|
||||
* 2) Volume....
|
||||
* 3) Size.
|
||||
* 4) Popularity.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <time.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"
|
||||
|
||||
/* Size of these should match the RsInterface (for ease of use ) - 16 bytes */
|
||||
|
||||
//#define CHAN_SIGN_SIZE 16
|
||||
|
||||
class channelSign
|
||||
{
|
||||
public:
|
||||
bool operator<(const channelSign &s) const;
|
||||
bool operator==(const channelSign &s) const;
|
||||
std::ostream& print(std::ostream&) const;
|
||||
std::ostream& printHex(std::ostream&) const;
|
||||
char sign[CHAN_SIGN_SIZE];
|
||||
|
||||
};
|
||||
|
||||
typedef channelSign MsgHash;
|
||||
|
||||
class channelKey
|
||||
{
|
||||
public:
|
||||
channelKey(EVP_PKEY *k);
|
||||
channelKey();
|
||||
virtual ~channelKey();
|
||||
|
||||
bool valid();
|
||||
int load(const unsigned char *d, int len);
|
||||
int setKey(EVP_PKEY *k);
|
||||
int out(unsigned char *d, int len);
|
||||
|
||||
bool operator<(const channelKey &k) const;
|
||||
bool operator==(const channelKey &k) const;
|
||||
std::ostream& print(std::ostream&) const;
|
||||
|
||||
channelSign getSign() const;
|
||||
EVP_PKEY * getKey() const;
|
||||
|
||||
private:
|
||||
int calcSign();
|
||||
|
||||
EVP_PKEY *key;
|
||||
char sign[CHAN_SIGN_SIZE];
|
||||
};
|
||||
|
||||
typedef time_t TimeStamp;
|
||||
|
||||
//class TimeStamp
|
||||
//{
|
||||
// public:
|
||||
//
|
||||
// int yr, month, day, hour, min, sec;
|
||||
//};
|
||||
//
|
||||
|
||||
class chanMsgSummary
|
||||
{
|
||||
public:
|
||||
std::string msg;
|
||||
MsgHash mh;
|
||||
int nofiles;
|
||||
int totalsize;
|
||||
TimeStamp recvd;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// This is used For Msg + Info storage.
|
||||
class channelMsg
|
||||
{
|
||||
public:
|
||||
channelMsg(PQChanItem *in, TimeStamp now, TimeStamp reb);
|
||||
|
||||
PQChanItem *msg;
|
||||
|
||||
int receivedCount;
|
||||
TimeStamp recvTime;
|
||||
|
||||
bool rebroadcast;
|
||||
TimeStamp rbcTime;
|
||||
|
||||
bool downloaded;
|
||||
TimeStamp dldTime;
|
||||
|
||||
bool save;
|
||||
};
|
||||
|
||||
// a little helper function.
|
||||
channelSign getChannelSign(PQChanItem *ci);
|
||||
channelKey * getChannelKey(PQChanItem *ci);
|
||||
MsgHash getMsgHash(PQChanItem *ci);
|
||||
|
||||
class pqichannel
|
||||
{
|
||||
public:
|
||||
|
||||
pqichannel(sslroot *, channelKey *, std::string title, int mode);
|
||||
virtual ~pqichannel() { return; }
|
||||
|
||||
// retrieval.
|
||||
|
||||
channelMsg *findMsg(MsgHash mh);
|
||||
int getMsgSummary(std::list<chanMsgSummary> &summary);
|
||||
|
||||
|
||||
int processMsg(PQChanItem *in);
|
||||
int pruneOldMsgs();
|
||||
|
||||
// check packet signature (with channel key)
|
||||
// check key matches ours.
|
||||
// if we have it, increment the counter.
|
||||
// else add in.
|
||||
|
||||
// fill with outgoing
|
||||
int reBroadcast(std::list<PQTunnel *> &outgoing);
|
||||
|
||||
channelSign getSign();
|
||||
channelKey *getKey();
|
||||
|
||||
int getMode() { return mode; }
|
||||
std::string getName() { return channelTitle; }
|
||||
float getRanking() { return ranking; }
|
||||
int getMsgCount() { return msgByHash.size(); }
|
||||
|
||||
std::ostream& print(std::ostream&);
|
||||
|
||||
protected:
|
||||
sslroot *sroot;
|
||||
|
||||
private:
|
||||
|
||||
// analysis functions
|
||||
TimeStamp getCurrentTimeStamp();
|
||||
bool checkPktSignature(PQChanItem*);
|
||||
//MsgHash getPktHash(PQChanItem*);
|
||||
|
||||
int mode; // Fav, Sub, Listen, Other.
|
||||
std::map<MsgHash, channelMsg *> msgByHash;
|
||||
|
||||
std::string channelTitle;
|
||||
float ranking;
|
||||
|
||||
protected: // needed by pqichanneler.
|
||||
channelKey *key;
|
||||
};
|
||||
|
||||
// specialisation with the private key, and output.
|
||||
class pqichanneler: public pqichannel
|
||||
{
|
||||
public:
|
||||
pqichanneler(sslroot *s,
|
||||
channelKey *priv, channelKey *pub,
|
||||
std::string title);
|
||||
|
||||
virtual ~pqichanneler() { return; }
|
||||
|
||||
// Takes a partially constructed Msg,
|
||||
// fills in the signature....
|
||||
// then all it has to do is pass it
|
||||
// to the pqichannel which will handle the
|
||||
// distribution.
|
||||
int sendmsg(PQChanItem *);
|
||||
|
||||
private:
|
||||
channelKey *privkey;
|
||||
};
|
||||
|
||||
|
||||
class p3channel: public PQTunnelService
|
||||
{
|
||||
public:
|
||||
p3channel(sslroot *r);
|
||||
virtual ~p3channel();
|
||||
|
||||
// PQTunnelService functions.
|
||||
virtual int receive(PQTunnel *);
|
||||
virtual PQTunnel *send();
|
||||
|
||||
virtual int tick();
|
||||
|
||||
// doesn't use the init functions.
|
||||
virtual int receive(PQTunnelInit *i) { delete i; return 1; }
|
||||
virtual PQTunnelInit *sendInit() { return NULL; }
|
||||
|
||||
// End of PQTunnelService functions.
|
||||
|
||||
// load and save configuration.
|
||||
int save_configuration();
|
||||
int load_configuration();
|
||||
|
||||
// test functions.
|
||||
int generateRandomMsg();
|
||||
int generateRandomKeys(channelKey *priv, channelKey *pub);
|
||||
|
||||
// retrieval fns.
|
||||
pqichannel *findChannel(channelSign s);
|
||||
int getChannelList(std::list<pqichannel *> &chans);
|
||||
|
||||
private:
|
||||
|
||||
// so we need an interface for the data.
|
||||
|
||||
int handleIncoming();
|
||||
|
||||
int printMsgs();
|
||||
|
||||
// first storage.
|
||||
std::map<channelSign, pqichannel *> channels;
|
||||
|
||||
|
||||
//
|
||||
int reBroadcast();
|
||||
// maintainance.
|
||||
int pruneOldMsgs();
|
||||
|
||||
// counters.
|
||||
int ts_nextlp;
|
||||
int min10Count;
|
||||
|
||||
std::list<cert *> discovered;
|
||||
sslroot *sroot;
|
||||
|
||||
// Storage for incoming/outgoing.
|
||||
std::list<PQItem *> inpkts;
|
||||
std::list<PQItem *> outpkts;
|
||||
};
|
||||
|
||||
#endif // MRK_P3_CHANNEL_H
|
1823
libretroshare/src/pqi/p3connmgr.cc
Normal file
1823
libretroshare/src/pqi/p3connmgr.cc
Normal file
File diff suppressed because it is too large
Load Diff
285
libretroshare/src/pqi/p3connmgr.h
Normal file
285
libretroshare/src/pqi/p3connmgr.h
Normal file
@ -0,0 +1,285 @@
|
||||
/*
|
||||
* libretroshare/src/pqi: p3connmgr.h
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MRK_PQI_CONNECTION_MANAGER_HEADER
|
||||
#define MRK_PQI_CONNECTION_MANAGER_HEADER
|
||||
|
||||
#include "pqi/pqimonitor.h"
|
||||
#include "pqi/p3dhtmgr.h"
|
||||
#include "pqi/p3upnpmgr.h"
|
||||
#include "pqi/p3authmgr.h"
|
||||
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
|
||||
#include "util/rsthreads.h"
|
||||
|
||||
const uint32_t RS_VIS_STATE_NODISC = 0x0001;
|
||||
const uint32_t RS_VIS_STATE_NODHT = 0x0002;
|
||||
|
||||
const uint32_t RS_VIS_STATE_STD = 0x0000;
|
||||
const uint32_t RS_VIS_STATE_GRAY = RS_VIS_STATE_NODHT;
|
||||
const uint32_t RS_VIS_STATE_DARK = RS_VIS_STATE_NODISC | RS_VIS_STATE_NODHT;
|
||||
const uint32_t RS_VIS_STATE_BROWN = RS_VIS_STATE_NODISC;
|
||||
|
||||
const uint32_t RS_NET_MODE_UNKNOWN = 0x0000;
|
||||
const uint32_t RS_NET_MODE_EXT = 0x0001;
|
||||
const uint32_t RS_NET_MODE_UPNP = 0x0002;
|
||||
const uint32_t RS_NET_MODE_UDP = 0x0003;
|
||||
const uint32_t RS_NET_MODE_ERROR = 0x0004;
|
||||
|
||||
|
||||
/* order of attempts ... */
|
||||
const uint32_t RS_NET_CONN_TCP_ALL = 0x000f;
|
||||
const uint32_t RS_NET_CONN_UDP_ALL = 0x00f0;
|
||||
|
||||
const uint32_t RS_NET_CONN_TCP_LOCAL = 0x0001;
|
||||
const uint32_t RS_NET_CONN_TCP_EXTERNAL = 0x0002;
|
||||
const uint32_t RS_NET_CONN_UDP_DHT_SYNC = 0x0010;
|
||||
|
||||
|
||||
class peerAddrInfo
|
||||
{
|
||||
public:
|
||||
peerAddrInfo(); /* init */
|
||||
|
||||
bool found;
|
||||
uint32_t type;
|
||||
struct sockaddr_in laddr, raddr;
|
||||
time_t ts;
|
||||
};
|
||||
|
||||
class peerConnectAddress
|
||||
{
|
||||
public:
|
||||
peerConnectAddress(); /* init */
|
||||
|
||||
struct sockaddr_in addr;
|
||||
uint32_t type;
|
||||
time_t ts;
|
||||
};
|
||||
|
||||
class peerConnectState
|
||||
{
|
||||
public:
|
||||
peerConnectState(); /* init */
|
||||
|
||||
std::string id;
|
||||
std::string name;
|
||||
|
||||
uint32_t state;
|
||||
uint32_t actions;
|
||||
|
||||
uint32_t netMode; /* EXT / UPNP / UDP / INVALID */
|
||||
|
||||
/* Fix this up! */
|
||||
|
||||
// public for the moment.
|
||||
struct sockaddr_in lastaddr, localaddr, serveraddr;
|
||||
|
||||
/* determines how public this peer wants to be...
|
||||
*
|
||||
* STD = advertise to Peers / DHT checking etc
|
||||
* GRAY = share with friends / but not DHT
|
||||
* DARK = hidden from all
|
||||
* BROWN? = hidden from friends / but on DHT
|
||||
*/
|
||||
|
||||
uint32_t visState; /* STD, GRAY, DARK */
|
||||
|
||||
uint32_t source; /* most current source */
|
||||
peerAddrInfo dht;
|
||||
peerAddrInfo disc;
|
||||
peerAddrInfo peer;
|
||||
|
||||
/* a list of connect attempts to make (in order) */
|
||||
bool inConnAttempt;
|
||||
time_t connAttemptTS;
|
||||
peerConnectAddress currentConnAddr;
|
||||
std::list<peerConnectAddress> connAddrs;
|
||||
|
||||
|
||||
/* stuff here un-used at the moment */
|
||||
|
||||
|
||||
time_t lc_timestamp; // last connect timestamp
|
||||
time_t lr_timestamp; // last receive timestamp
|
||||
|
||||
time_t nc_timestamp; // next connect timestamp.
|
||||
time_t nc_timeintvl; // next connect time interval.
|
||||
};
|
||||
|
||||
|
||||
class p3ConnectMgr: public pqiConnectCb, public p3Config
|
||||
{
|
||||
public:
|
||||
|
||||
p3ConnectMgr(p3AuthMgr *authMgr);
|
||||
|
||||
void tick();
|
||||
|
||||
/*************** Setup ***************************/
|
||||
void setDhtMgr(p3DhtMgr *dmgr) { mDhtMgr = dmgr; }
|
||||
void setUpnpMgr(p3UpnpMgr *umgr) { mUpnpMgr = umgr; }
|
||||
bool checkNetAddress(); /* check our address is sensible */
|
||||
|
||||
/*************** External Control ****************/
|
||||
bool retryConnect(std::string id);
|
||||
|
||||
bool getUPnPState();
|
||||
bool getUPnPEnabled();
|
||||
bool getDHTEnabled();
|
||||
|
||||
bool setLocalAddress(std::string id, struct sockaddr_in addr);
|
||||
bool setExtAddress(std::string id, struct sockaddr_in addr);
|
||||
bool setNetworkMode(std::string id, uint32_t netMode);
|
||||
|
||||
/* add/remove friends */
|
||||
bool addFriend(std::string);
|
||||
bool removeFriend(std::string);
|
||||
bool addNeighbour(std::string);
|
||||
|
||||
/*************** External Control ****************/
|
||||
|
||||
/* access to network details (called through Monitor) */
|
||||
const std::string getOwnId();
|
||||
bool getOwnNetStatus(peerConnectState &state);
|
||||
|
||||
bool isFriend(std::string id);
|
||||
bool getFriendNetStatus(std::string id, peerConnectState &state);
|
||||
bool getOthersNetStatus(std::string id, peerConnectState &state);
|
||||
|
||||
void getOnlineList(std::list<std::string> &peers);
|
||||
void getFriendList(std::list<std::string> &peers);
|
||||
void getOthersList(std::list<std::string> &peers);
|
||||
|
||||
|
||||
/**************** handle monitors *****************/
|
||||
void addMonitor(pqiMonitor *mon);
|
||||
void removeMonitor(pqiMonitor *mon);
|
||||
|
||||
/******* overloaded from pqiConnectCb *************/
|
||||
virtual void peerStatus(std::string id,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||
uint32_t type, uint32_t mode, uint32_t source);
|
||||
virtual void peerConnectRequest(std::string id, uint32_t type);
|
||||
virtual void stunStatus(std::string id, struct sockaddr_in addr, uint32_t flags);
|
||||
|
||||
/****************** Connections *******************/
|
||||
bool connectAttempt(std::string id, struct sockaddr_in &addr, uint32_t &type);
|
||||
bool connectResult(std::string id, bool success, uint32_t flags);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/* Internal Functions */
|
||||
void netTick();
|
||||
void netStartup();
|
||||
|
||||
/* startup the bits */
|
||||
void netDhtInit();
|
||||
void netUdpInit();
|
||||
void netStunInit();
|
||||
|
||||
|
||||
|
||||
|
||||
void netInit();
|
||||
|
||||
void netExtInit();
|
||||
void netExtCheck();
|
||||
|
||||
void netUpnpInit();
|
||||
void netUpnpCheck();
|
||||
|
||||
void netUdpCheck();
|
||||
|
||||
/* Udp / Stun functions */
|
||||
bool udpInternalAddress(struct sockaddr_in iaddr);
|
||||
bool udpExtAddressCheck();
|
||||
void udpStunPeer(std::string id, struct sockaddr_in &addr);
|
||||
|
||||
void stunInit();
|
||||
bool stunCheck();
|
||||
void stunCollect(std::string id, struct sockaddr_in addr, uint32_t flags);
|
||||
|
||||
/* monitor control */
|
||||
void tickMonitors();
|
||||
|
||||
|
||||
/* temporary for testing */
|
||||
virtual void loadConfiguration() { return; }
|
||||
|
||||
protected:
|
||||
/*****************************************************************/
|
||||
/*********************** p3config ******************************/
|
||||
/* Key Functions to be overloaded for Full Configuration */
|
||||
virtual RsSerialiser *setupSerialiser();
|
||||
virtual std::list<RsItem *> saveList(bool &cleanup);
|
||||
virtual bool loadList(std::list<RsItem *> load);
|
||||
/*****************************************************************/
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
void setupOwnNetConfig(RsPeerConfigItem *item);
|
||||
void addPeer(RsPeerConfigItem *item);
|
||||
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
p3AuthMgr *mAuthMgr;
|
||||
p3DhtMgr *mDhtMgr;
|
||||
p3UpnpMgr *mUpnpMgr;
|
||||
|
||||
RsMutex connMtx; /* protects below */
|
||||
|
||||
time_t mNetInitTS;
|
||||
uint32_t mNetStatus;
|
||||
uint32_t mStunStatus;
|
||||
bool mStatusChanged;
|
||||
|
||||
std::list<pqiMonitor *> clients;
|
||||
|
||||
|
||||
/* external Address determination */
|
||||
bool mUpnpAddrValid, mStunAddrValid;
|
||||
struct sockaddr_in mUpnpExtAddr;
|
||||
struct sockaddr_in mStunExtAddr;
|
||||
|
||||
|
||||
/* these are protected for testing */
|
||||
protected:
|
||||
|
||||
void addPeer(std::string id, std::string name); /* tmp fn */
|
||||
|
||||
peerConnectState ownState;
|
||||
|
||||
std::list<std::string> mStunList;
|
||||
std::map<std::string, peerConnectState> mFriendList;
|
||||
std::map<std::string, peerConnectState> mOthersList;
|
||||
};
|
||||
|
||||
#endif // MRK_PQI_CONNECTION_MANAGER_HEADER
|
1337
libretroshare/src/pqi/p3dhtmgr.cc
Normal file
1337
libretroshare/src/pqi/p3dhtmgr.cc
Normal file
File diff suppressed because it is too large
Load Diff
211
libretroshare/src/pqi/p3dhtmgr.h
Normal file
211
libretroshare/src/pqi/p3dhtmgr.h
Normal file
@ -0,0 +1,211 @@
|
||||
/*
|
||||
* libretroshare/src/pqi: p3dhtmgr.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 MRK_P3_DHT_MANAGER_HEADER
|
||||
#define MRK_P3_DHT_MANAGER_HEADER
|
||||
|
||||
/* Interface class for DHT data */
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "pqi/pqinetwork.h"
|
||||
|
||||
#include "util/rsthreads.h"
|
||||
#include "pqi/pqimonitor.h"
|
||||
|
||||
/* All other #defs are in .cc */
|
||||
#define DHT_ADDR_INVALID 0xff
|
||||
#define DHT_ADDR_TCP 0x01
|
||||
#define DHT_ADDR_UDP 0x02
|
||||
|
||||
|
||||
/* for DHT peer STATE */
|
||||
#define DHT_PEER_INIT 0
|
||||
#define DHT_PEER_SEARCH 1
|
||||
#define DHT_PEER_FOUND 2
|
||||
|
||||
/* for DHT peer STATE (ownEntry) */
|
||||
#define DHT_PEER_ADDR_KNOWN 3
|
||||
#define DHT_PEER_PUBLISHED 4
|
||||
|
||||
/* Interface with Real DHT Implementation */
|
||||
#define DHT_MODE_SEARCH 1
|
||||
#define DHT_MODE_PUBLISH 1
|
||||
#define DHT_MODE_NOTIFY 2
|
||||
|
||||
|
||||
class dhtPeerEntry
|
||||
{
|
||||
public:
|
||||
dhtPeerEntry();
|
||||
|
||||
std::string id;
|
||||
uint32_t state;
|
||||
time_t lastTS;
|
||||
|
||||
uint32_t notifyPending;
|
||||
time_t notifyTS;
|
||||
|
||||
struct sockaddr_in laddr, raddr;
|
||||
uint32_t type; /* ADDR_TYPE as defined above */
|
||||
|
||||
std::string hash1; /* SHA1 Hash of id */
|
||||
std::string hash2; /* SHA1 Hash of reverse Id */
|
||||
};
|
||||
|
||||
class p3DhtMgr: public RsThread
|
||||
{
|
||||
/*
|
||||
*/
|
||||
public:
|
||||
p3DhtMgr(std::string id, pqiConnectCb *cb);
|
||||
|
||||
/********** External DHT Interface ************************
|
||||
* These Functions are the external interface
|
||||
* for the DHT, and must be non-blocking and return quickly
|
||||
*/
|
||||
|
||||
void setDhtOn(bool on);
|
||||
bool getDhtOn();
|
||||
bool getDhtActive();
|
||||
|
||||
/* set key data */
|
||||
bool setExternalInterface(struct sockaddr_in laddr,
|
||||
struct sockaddr_in raddr, uint32_t type);
|
||||
|
||||
/* add / remove peers */
|
||||
bool findPeer(std::string id);
|
||||
bool dropPeer(std::string id);
|
||||
|
||||
/* post DHT key saying we should connect (callback when done) */
|
||||
bool notifyPeer(std::string id);
|
||||
|
||||
/* extract current peer status */
|
||||
bool getPeerStatus(std::string id,
|
||||
struct sockaddr_in &laddr, struct sockaddr_in &raddr,
|
||||
uint32_t &type, uint32_t &mode);
|
||||
|
||||
/* stun */
|
||||
bool addStun(std::string id);
|
||||
bool doneStun();
|
||||
|
||||
/********** Higher Level DHT Work Functions ************************
|
||||
* These functions translate from the strings/addresss to
|
||||
* key/value pairs.
|
||||
*/
|
||||
public:
|
||||
|
||||
/* results from DHT proper */
|
||||
virtual bool dhtResultNotify(std::string id);
|
||||
virtual bool dhtResultSearch(std::string id,
|
||||
struct sockaddr_in &laddr, struct sockaddr_in &raddr,
|
||||
uint32_t type, std::string sign);
|
||||
|
||||
protected:
|
||||
|
||||
/* can block briefly (called only from thread) */
|
||||
virtual bool dhtPublish(std::string id,
|
||||
struct sockaddr_in &laddr,
|
||||
struct sockaddr_in &raddr,
|
||||
uint32_t type, std::string sign);
|
||||
|
||||
virtual bool dhtNotify(std::string peerid, std::string ownId,
|
||||
std::string sign);
|
||||
virtual bool dhtSearch(std::string id, uint32_t mode);
|
||||
|
||||
|
||||
/********** Actual DHT Work Functions ************************
|
||||
* These involve a very simple LOW-LEVEL interface ...
|
||||
*
|
||||
* publish
|
||||
* search
|
||||
* result
|
||||
*
|
||||
*/
|
||||
|
||||
public:
|
||||
|
||||
/* Feedback callback (handled here) */
|
||||
virtual bool resultDHT(std::string key, std::string value);
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool init();
|
||||
virtual bool shutdown();
|
||||
virtual bool dhtActive();
|
||||
virtual int status(std::ostream &out);
|
||||
|
||||
virtual bool publishDHT(std::string key, std::string value, uint32_t ttl);
|
||||
virtual bool searchDHT(std::string key);
|
||||
|
||||
|
||||
|
||||
/********** Internal DHT Threading ************************
|
||||
*
|
||||
*/
|
||||
|
||||
public:
|
||||
|
||||
virtual void run();
|
||||
|
||||
private:
|
||||
|
||||
/* search scheduling */
|
||||
void checkDHTStatus();
|
||||
int checkStunState();
|
||||
int doStun();
|
||||
int checkPeerDHTKeys();
|
||||
int checkOwnDHTKeys();
|
||||
int checkNotifyDHT();
|
||||
|
||||
void clearDhtData();
|
||||
|
||||
|
||||
/* other feedback through callback */
|
||||
pqiConnectCb *connCb;
|
||||
|
||||
/* protected by Mutex */
|
||||
RsMutex dhtMtx;
|
||||
|
||||
bool mDhtOn; /* User desired state */
|
||||
bool mDhtModifications; /* any user requests? */
|
||||
|
||||
dhtPeerEntry ownEntry;
|
||||
time_t ownNotifyTS;
|
||||
std::map<std::string, dhtPeerEntry> peers;
|
||||
|
||||
std::list<std::string> stunIds;
|
||||
bool mStunRequired;
|
||||
|
||||
uint32_t mDhtState;
|
||||
time_t mDhtActiveTS;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // MRK_P3_DHT_MANAGER_HEADER
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* "$Id: pqistunner.h,v 1.2 2007-02-18 21:46:50 rmf24 Exp $"
|
||||
* libretroshare/src/pqi: p3upnpmgr.h
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2004-2006 by Robert Fernie.
|
||||
* Copyright 2004-2007 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,45 +24,35 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MRK_P3_UPNP_MANAGER_H
|
||||
#define MRK_P3_UPNP_MANAGER_H
|
||||
|
||||
|
||||
|
||||
/* platform independent networking... */
|
||||
#include "util/rsthreads.h"
|
||||
#include "pqi/pqinetwork.h"
|
||||
|
||||
|
||||
class pqistunner
|
||||
class p3UpnpMgr: public RsThread
|
||||
{
|
||||
public:
|
||||
|
||||
pqistunner(struct sockaddr_in addr);
|
||||
virtual ~p3UpnpMgr() { return; }
|
||||
|
||||
int setListenAddr(struct sockaddr_in addr);
|
||||
int setuplisten();
|
||||
/* External Interface */
|
||||
virtual void enableUPnP(bool on) = 0;
|
||||
virtual void shutdownUPnP() = 0;
|
||||
|
||||
int resetlisten();
|
||||
virtual bool getUPnPEnabled() = 0;
|
||||
virtual bool getUPnPActive() = 0;
|
||||
|
||||
int stun(struct sockaddr_in stun_addr);
|
||||
/* the address that the listening port is on */
|
||||
virtual void setInternalPort(unsigned short iport_in) = 0;
|
||||
virtual void setExternalPort(unsigned short eport_in) = 0;
|
||||
|
||||
bool response(void *stun_pkt, int size, struct sockaddr_in &addr);
|
||||
int recvfrom(void *data, int *size, struct sockaddr_in &addr);
|
||||
int reply(void *data, int size, struct sockaddr_in &addr);
|
||||
|
||||
private:
|
||||
|
||||
/************************** Basic Functionality ******************/
|
||||
|
||||
bool generate_stun_pkt(void *stun_pkt, int *len);
|
||||
void * generate_stun_reply(struct sockaddr_in *stun_addr, int *len);
|
||||
|
||||
|
||||
int sockfd;
|
||||
bool active;
|
||||
void *stunpkt;
|
||||
unsigned int stunpktlen;
|
||||
|
||||
struct sockaddr_in laddr, stun_addr;
|
||||
/* as determined by uPnP */
|
||||
virtual bool getInternalAddress(struct sockaddr_in &addr) = 0;
|
||||
virtual bool getExternalAddress(struct sockaddr_in &addr) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* MRK_P3_UPNP_MANAGER_H */
|
||||
|
@ -279,18 +279,24 @@ virtual int notifyEvent(NetInterface *ni, int event) { return 0; }
|
||||
std::string peerId;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**** Consts for pqiperson -> placed here for NetBinDummy usage() */
|
||||
|
||||
const uint32_t PQI_CONNECT_TCP = 0x0001;
|
||||
const uint32_t PQI_CONNECT_UDP = 0x0002;
|
||||
|
||||
|
||||
/********************** Binary INTERFACE ****************************
|
||||
* This defines the binary interface used by Network/loopback/file
|
||||
* interfaces
|
||||
*
|
||||
* Flags are passed to BinInterfaces, and serialisers
|
||||
*/
|
||||
|
||||
#define BIN_FLAGS_NO_CLOSE 0x0001
|
||||
#define BIN_FLAGS_READABLE 0x0002
|
||||
#define BIN_FLAGS_WRITEABLE 0x0004
|
||||
#define BIN_FLAGS_NO_DELETE 0x0008
|
||||
#define BIN_FLAGS_HASHDATA 0x0010
|
||||
#define BIN_FLAGS_HASH_DATA 0x0010
|
||||
|
||||
class BinInterface
|
||||
{
|
||||
@ -306,6 +312,8 @@ virtual int netstatus() = 0;
|
||||
virtual int isactive() = 0;
|
||||
virtual bool moretoread() = 0;
|
||||
virtual bool cansend() = 0;
|
||||
virtual std::string gethash() = 0;
|
||||
|
||||
/* used by pqistreamer to limit transfers */
|
||||
virtual bool bandwidthLimited() { return true; }
|
||||
};
|
||||
@ -340,7 +348,7 @@ virtual ~NetInterface()
|
||||
|
||||
// virtual int tick() = 0; // Already defined for BinInterface.
|
||||
|
||||
virtual int connectattempt() = 0;
|
||||
virtual int connect(struct sockaddr_in raddr) = 0;
|
||||
virtual int listen() = 0;
|
||||
virtual int stoplistening() = 0;
|
||||
virtual int disconnect() = 0;
|
||||
|
@ -1,22 +0,0 @@
|
||||
#ifndef PQI_ADDR_STORE_H
|
||||
#define PQI_ADDR_STORE_H
|
||||
|
||||
#include "pqi/pqinetwork.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class pqiAddrStore
|
||||
{
|
||||
public:
|
||||
virtual ~pqiAddrStore() { return; }
|
||||
/* pqiAddrStore ... called prior to connect */
|
||||
virtual bool addrFriend(std::string id, struct sockaddr_in &addr, unsigned int &flags) = 0;
|
||||
};
|
||||
|
||||
|
||||
/* implemented elsewhere, to provide pqi with AddrStore */
|
||||
|
||||
extern pqiAddrStore *getAddrStore();
|
||||
|
||||
|
||||
#endif /* PQI_ADDR_STORE_H */
|
@ -469,5 +469,11 @@ int pqiarchive::readPkt(RsItem **item_out, long *ts_out)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**** Hashing Functions ****/
|
||||
std::string pqiarchive::gethash()
|
||||
{
|
||||
return bio->gethash();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -55,6 +55,9 @@ virtual int tick();
|
||||
virtual int status();
|
||||
|
||||
virtual void setRealTime(bool r) { realTime = r; }
|
||||
|
||||
std::string gethash();
|
||||
|
||||
private:
|
||||
int writePkt(RsItem *item);
|
||||
int readPkt(RsItem **item_out, long *ts);
|
||||
|
@ -28,8 +28,8 @@
|
||||
|
||||
#include "pqi/pqibin.h"
|
||||
|
||||
BinFileInterface::BinFileInterface(char *fname, int flags)
|
||||
:bin_flags(flags), buf(NULL)
|
||||
BinFileInterface::BinFileInterface(const char *fname, int flags)
|
||||
:bin_flags(flags), buf(NULL), hash(NULL)
|
||||
{
|
||||
/* if read + write - open r+ */
|
||||
if ((bin_flags & BIN_FLAGS_READABLE) &&
|
||||
@ -75,6 +75,10 @@ BinFileInterface::BinFileInterface(char *fname, int flags)
|
||||
size = 0;
|
||||
}
|
||||
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
hash = new pqihash();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -95,6 +99,10 @@ int BinFileInterface::senddata(void *data, int len)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
hash->addData(data, len);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -107,15 +115,33 @@ int BinFileInterface::readdata(void *data, int len)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
hash->addData(data, len);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
std::string BinFileInterface::gethash()
|
||||
{
|
||||
std::string hashstr;
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
hash->Complete(hashstr);
|
||||
}
|
||||
return hashstr;
|
||||
}
|
||||
|
||||
|
||||
BinMemInterface::BinMemInterface(int defsize, int flags)
|
||||
:bin_flags(flags), buf(NULL), size(defsize),
|
||||
recvsize(0), readloc(0)
|
||||
recvsize(0), readloc(0), hash(NULL)
|
||||
{
|
||||
buf = malloc(defsize);
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
hash = new pqihash();
|
||||
}
|
||||
}
|
||||
|
||||
BinMemInterface::~BinMemInterface()
|
||||
@ -145,6 +171,10 @@ int BinMemInterface::senddata(void *data, int len)
|
||||
return -1;
|
||||
}
|
||||
memcpy((char *) buf + recvsize, data, len);
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
hash->addData(data, len);
|
||||
}
|
||||
recvsize += len;
|
||||
return len;
|
||||
}
|
||||
@ -158,8 +188,243 @@ int BinMemInterface::readdata(void *data, int len)
|
||||
return -1;
|
||||
}
|
||||
memcpy(data, (char *) buf + readloc, len);
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
hash->addData(data, len);
|
||||
}
|
||||
readloc += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string BinMemInterface::gethash()
|
||||
{
|
||||
std::string hashstr;
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
hash->Complete(hashstr);
|
||||
}
|
||||
return hashstr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
void printNetBinID(std::ostream &out, std::string id, uint32_t t)
|
||||
{
|
||||
out << "NetBinId(" << id << ",";
|
||||
if (t == PQI_CONNECT_TCP)
|
||||
{
|
||||
out << "TCP)";
|
||||
}
|
||||
else
|
||||
{
|
||||
out << "UDP)";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************** NetBinDummy ******************************
|
||||
* A test framework,
|
||||
*
|
||||
*/
|
||||
|
||||
#include "pqi/pqiperson.h"
|
||||
|
||||
const uint32_t DEFAULT_DUMMY_DELTA = 5;
|
||||
|
||||
NetBinDummy::NetBinDummy(PQInterface *parent, std::string id, uint32_t t)
|
||||
:NetBinInterface(parent, id), type(t), dummyConnected(false),
|
||||
toConnect(false), connectDelta(DEFAULT_DUMMY_DELTA)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Net Interface
|
||||
int NetBinDummy::connect(struct sockaddr_in raddr)
|
||||
{
|
||||
std::cerr << "NetBinDummy::connect(";
|
||||
std::cerr << inet_ntoa(raddr.sin_addr) << ":";
|
||||
std::cerr << htons(raddr.sin_port);
|
||||
std::cerr << ") ";
|
||||
printNetBinID(std::cerr, PeerId(), type);
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "NetBinDummy::dummyConnect = true!";
|
||||
std::cerr << std::endl;
|
||||
|
||||
if (type == PQI_CONNECT_TCP)
|
||||
{
|
||||
std::cerr << "NetBinDummy:: Not connecting TCP";
|
||||
std::cerr << std::endl;
|
||||
if (parent())
|
||||
{
|
||||
parent()->notifyEvent(this, CONNECT_FAILED);
|
||||
}
|
||||
}
|
||||
else if (!dummyConnected)
|
||||
{
|
||||
toConnect = true;
|
||||
connectTS = time(NULL) + connectDelta;
|
||||
std::cerr << "NetBinDummy::toConnect = true, connect in: ";
|
||||
std::cerr << connectDelta << " secs";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "NetBinDummy:: Already Connected!";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int NetBinDummy::listen()
|
||||
{
|
||||
std::cerr << "NetBinDummy::connect() ";
|
||||
printNetBinID(std::cerr, PeerId(), type);
|
||||
std::cerr << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int NetBinDummy::stoplistening()
|
||||
{
|
||||
std::cerr << "NetBinDummy::stoplistening() ";
|
||||
printNetBinID(std::cerr, PeerId(), type);
|
||||
std::cerr << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int NetBinDummy::disconnect()
|
||||
{
|
||||
std::cerr << "NetBinDummy::disconnect() ";
|
||||
printNetBinID(std::cerr, PeerId(), type);
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "NetBinDummy::dummyConnect = false!";
|
||||
std::cerr << std::endl;
|
||||
dummyConnected = false;
|
||||
|
||||
if (parent())
|
||||
{
|
||||
parent()->notifyEvent(this, CONNECT_FAILED);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int NetBinDummy::reset()
|
||||
{
|
||||
std::cerr << "NetBinDummy::reset() ";
|
||||
printNetBinID(std::cerr, PeerId(), type);
|
||||
std::cerr << std::endl;
|
||||
|
||||
disconnect();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Bin Interface.
|
||||
int NetBinDummy::tick()
|
||||
{
|
||||
|
||||
if (toConnect)
|
||||
{
|
||||
if (connectTS < time(NULL))
|
||||
{
|
||||
std::cerr << "NetBinDummy::tick() dummyConnected = true ";
|
||||
printNetBinID(std::cerr, PeerId(), type);
|
||||
std::cerr << std::endl;
|
||||
dummyConnected = true;
|
||||
toConnect = false;
|
||||
if (parent())
|
||||
parent()->notifyEvent(this, CONNECT_SUCCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "NetBinDummy::tick() toConnect ";
|
||||
printNetBinID(std::cerr, PeerId(), type);
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NetBinDummy::senddata(void *data, int len)
|
||||
{
|
||||
std::cerr << "NetBinDummy::senddata() ";
|
||||
printNetBinID(std::cerr, PeerId(), type);
|
||||
std::cerr << std::endl;
|
||||
|
||||
if (dummyConnected)
|
||||
return len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NetBinDummy::readdata(void *data, int len)
|
||||
{
|
||||
std::cerr << "NetBinDummy::readdata() ";
|
||||
printNetBinID(std::cerr, PeerId(), type);
|
||||
std::cerr << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NetBinDummy::netstatus()
|
||||
{
|
||||
std::cerr << "NetBinDummy::netstatus() ";
|
||||
printNetBinID(std::cerr, PeerId(), type);
|
||||
std::cerr << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int NetBinDummy::isactive()
|
||||
{
|
||||
std::cerr << "NetBinDummy::isactive() ";
|
||||
printNetBinID(std::cerr, PeerId(), type);
|
||||
if (dummyConnected)
|
||||
std::cerr << " true ";
|
||||
else
|
||||
std::cerr << " false ";
|
||||
std::cerr << std::endl;
|
||||
|
||||
return dummyConnected;
|
||||
}
|
||||
|
||||
bool NetBinDummy::moretoread()
|
||||
{
|
||||
std::cerr << "NetBinDummy::moretoread() ";
|
||||
printNetBinID(std::cerr, PeerId(), type);
|
||||
std::cerr << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetBinDummy::cansend()
|
||||
{
|
||||
std::cerr << "NetBinDummy::cansend() ";
|
||||
printNetBinID(std::cerr, PeerId(), type);
|
||||
std::cerr << std::endl;
|
||||
|
||||
return dummyConnected;
|
||||
}
|
||||
|
||||
std::string NetBinDummy::gethash()
|
||||
{
|
||||
std::cerr << "NetBinDummy::gethash() ";
|
||||
printNetBinID(std::cerr, PeerId(), type);
|
||||
std::cerr << std::endl;
|
||||
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -29,11 +29,12 @@
|
||||
#define PQI_BIN_INTERFACE_HEADER
|
||||
|
||||
#include "pqi/pqi_base.h"
|
||||
#include "pqi/pqihash.h"
|
||||
|
||||
class BinFileInterface: public BinInterface
|
||||
{
|
||||
public:
|
||||
BinFileInterface(char *fname, int flags);
|
||||
BinFileInterface(const char *fname, int flags);
|
||||
virtual ~BinFileInterface();
|
||||
|
||||
virtual int tick() { return 1; }
|
||||
@ -56,11 +57,13 @@ virtual bool moretoread()
|
||||
|
||||
|
||||
virtual bool cansend() { return (bin_flags | BIN_FLAGS_WRITEABLE); }
|
||||
virtual std::string gethash();
|
||||
|
||||
private:
|
||||
int bin_flags;
|
||||
FILE *buf;
|
||||
int size;
|
||||
pqihash *hash;
|
||||
};
|
||||
|
||||
|
||||
@ -93,6 +96,7 @@ virtual bool moretoread()
|
||||
}
|
||||
|
||||
virtual bool cansend() { return (bin_flags | BIN_FLAGS_WRITEABLE); }
|
||||
virtual std::string gethash();
|
||||
|
||||
private:
|
||||
int bin_flags;
|
||||
@ -100,9 +104,42 @@ virtual bool cansend() { return (bin_flags | BIN_FLAGS_WRITEABLE); }
|
||||
int size;
|
||||
int recvsize;
|
||||
int readloc;
|
||||
pqihash *hash;
|
||||
};
|
||||
|
||||
|
||||
class NetBinDummy: public NetBinInterface
|
||||
{
|
||||
public:
|
||||
NetBinDummy(PQInterface *parent, std::string id, uint32_t t);
|
||||
virtual ~NetBinDummy() { return; }
|
||||
|
||||
// Net Interface
|
||||
virtual int connect(struct sockaddr_in raddr);
|
||||
virtual int listen();
|
||||
virtual int stoplistening();
|
||||
virtual int disconnect();
|
||||
virtual int reset();
|
||||
|
||||
// Bin Interface.
|
||||
virtual int tick();
|
||||
|
||||
virtual int senddata(void *data, int len);
|
||||
virtual int readdata(void *data, int len);
|
||||
virtual int netstatus();
|
||||
virtual int isactive();
|
||||
virtual bool moretoread();
|
||||
virtual bool cansend();
|
||||
virtual std::string gethash();
|
||||
|
||||
private:
|
||||
uint32_t type;
|
||||
bool dummyConnected;
|
||||
bool toConnect;
|
||||
uint32_t connectDelta;
|
||||
time_t connectTS;
|
||||
};
|
||||
|
||||
|
||||
#endif // PQI_BINARY_INTERFACES_HEADER
|
||||
|
||||
|
@ -1,610 +0,0 @@
|
||||
/*
|
||||
* "$Id: pqichannel.cc,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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include "pqi/pqichannel.h"
|
||||
|
||||
static const int pqicizone = 449;
|
||||
#include "pqi/pqidebug.h"
|
||||
#include <sstream>
|
||||
|
||||
const int PQChan_MsgType = 0x5601;
|
||||
const int PQChan_NameType = 0x5602;
|
||||
const int PQChan_HashType = 0x5604;
|
||||
const int PQChan_TitleType = 0x5608;
|
||||
const int PQChan_FileType = 0x5610;
|
||||
const int PQChan_SizeType = 0x5620;
|
||||
const int PQChan_ListType = 0x5640;
|
||||
|
||||
|
||||
PQTunnel *createChannelItems(void *d, int n)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqicizone,
|
||||
"createChannelItems()");
|
||||
|
||||
return new PQChanItem();
|
||||
}
|
||||
|
||||
PQChanItem::PQChanItem()
|
||||
:PQTunnel(PQI_TUNNEL_CHANNEL_ITEM_TYPE),
|
||||
certDER(NULL), certType(0), certLen(0), msg(""),
|
||||
signature(NULL), signType(0), signLen(0)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqicizone,
|
||||
"PQChanItem::PQChanItem()");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
PQChanItem::~PQChanItem()
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqicizone,
|
||||
"PQChanItem::~PQChanItem()");
|
||||
|
||||
clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PQChanItem *PQChanItem::clone()
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqicizone,
|
||||
"PQChanItem::clone()");
|
||||
|
||||
PQChanItem *di = new PQChanItem();
|
||||
di -> copy(this);
|
||||
return di;
|
||||
}
|
||||
|
||||
void PQChanItem::copy(const PQChanItem *di)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqicizone,
|
||||
"PQChanItem::copy()");
|
||||
|
||||
PQTunnel::copy(di);
|
||||
|
||||
clear();
|
||||
|
||||
certType = di -> certType;
|
||||
certLen = di -> certLen;
|
||||
|
||||
// allocate memory and copy.
|
||||
if (NULL == (certDER = (unsigned char *) malloc(certLen)))
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqicizone,
|
||||
"PQChanItem::in() Not enough Memory!");
|
||||
return; // cant be us.
|
||||
}
|
||||
|
||||
memcpy(certDER, di -> certDER, certLen);
|
||||
|
||||
msg = di -> msg;
|
||||
|
||||
files = di -> files;
|
||||
|
||||
// only the signature to go!.
|
||||
signType = di -> signType;
|
||||
signLen = di -> signLen;
|
||||
|
||||
// allocate memory and copy.
|
||||
if (NULL == (signature = (unsigned char *) malloc(signLen)))
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqicizone,
|
||||
"PQChanItem::copy() Not enough Memory!");
|
||||
return; // cant be us.
|
||||
}
|
||||
|
||||
memcpy(signature, di -> signature, signLen);
|
||||
}
|
||||
|
||||
// Overloaded from PQTunnel.
|
||||
const int PQChanItem::getSize() const
|
||||
{
|
||||
// 8 bytes for cert + certLen;
|
||||
// 8 bytes for msg + msgLen;
|
||||
// 12 bytes for files + sum(file -> getSize())
|
||||
// 8 bytes for sign + signLen;
|
||||
|
||||
int files_size = 0;
|
||||
FileList::const_iterator it;
|
||||
for(it = files.begin(); it != files.end(); it++)
|
||||
{
|
||||
files_size += it -> getSize();
|
||||
}
|
||||
|
||||
return 8 + certLen + 8 + msg.length() +
|
||||
12 + files_size + 8 + signLen;
|
||||
}
|
||||
|
||||
int PQChanItem::out(void *data, const int size) const
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQChanItem::out() Data: " << data;
|
||||
out << " Size: " << size << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqicizone, out.str());
|
||||
}
|
||||
|
||||
if (size < PQChanItem::getSize())
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqicizone,
|
||||
"PQChanItem::out() Packet Too Small!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// out is easy cos the getSize should be correct.
|
||||
char *dta = (char *) data;
|
||||
|
||||
// first we put down the certificate;
|
||||
((int *) dta)[0] = certType;
|
||||
((int *) dta)[1] = certLen;
|
||||
dta += 8; // 4 bytes per int.
|
||||
memcpy(dta, certDER, certLen);
|
||||
dta += certLen;
|
||||
|
||||
// now the message.
|
||||
((int *) dta)[0] = PQChan_MsgType;
|
||||
((int *) dta)[1] = msg.length();
|
||||
dta += 8; // 4 bytes per int.
|
||||
memcpy(dta, msg.c_str(), msg.length());
|
||||
dta += msg.length();
|
||||
|
||||
// now list counter.
|
||||
((int *) dta)[0] = PQChan_ListType;
|
||||
((int *) dta)[1] = files.size();
|
||||
|
||||
// calc the length.
|
||||
int files_size = 0;
|
||||
FileList::const_iterator it;
|
||||
for(it = files.begin(); it != files.end(); it++)
|
||||
{
|
||||
files_size += it -> getSize();
|
||||
}
|
||||
|
||||
((int *) dta)[2] = files_size;
|
||||
dta += 12; // 4 bytes per int.
|
||||
|
||||
// for each item of the list we need to put the data out.
|
||||
for(it = files.begin(); it != files.end(); it++)
|
||||
{
|
||||
int fsize = it -> getSize();
|
||||
it -> out(dta, fsize);
|
||||
dta += fsize;
|
||||
}
|
||||
|
||||
// finally the signature.
|
||||
((int *) dta)[0] = signType;
|
||||
((int *) dta)[1] = signLen;
|
||||
dta += 8; // 4 bytes per int.
|
||||
memcpy(dta, signature, signLen);
|
||||
|
||||
return PQChanItem::getSize();
|
||||
}
|
||||
|
||||
|
||||
void PQChanItem::clear()
|
||||
{
|
||||
// first reset all our dataspaces.
|
||||
if (certDER != NULL)
|
||||
{
|
||||
free(certDER);
|
||||
certDER = NULL;
|
||||
}
|
||||
certLen = 0;
|
||||
msg.clear();
|
||||
files.clear();
|
||||
if (signature != NULL)
|
||||
{
|
||||
free(signature);
|
||||
signature = NULL;
|
||||
}
|
||||
signLen = 0;
|
||||
}
|
||||
|
||||
|
||||
int PQChanItem::in(const void *data, const int size)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQChanItem::in() Data: " << data;
|
||||
out << " Size: " << size << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqicizone, out.str());
|
||||
}
|
||||
|
||||
clear();
|
||||
|
||||
int i;
|
||||
int basesize = PQChanItem::getSize();
|
||||
if (size < basesize)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::in() Not enough space for Class (Base)!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
|
||||
// now get certLen.
|
||||
char *loc = ((char *) data);
|
||||
certType = ((int *) loc)[0];
|
||||
certLen = ((int *) loc)[1];
|
||||
loc += 8;
|
||||
// check size again.
|
||||
if (size < (basesize = PQChanItem::getSize()))
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::in() Not enough space for Class (Cert)!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
|
||||
// allocate memory and copy.
|
||||
if (NULL == (certDER = (unsigned char *) malloc(certLen)))
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::in() Not enough Memory!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
|
||||
memcpy(certDER, loc, certLen);
|
||||
|
||||
loc += certLen;
|
||||
|
||||
// now get msgSize.
|
||||
if (((int *) loc)[0] != PQChan_MsgType)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::in() Bad Msg Data Type!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
|
||||
int msize = ((int *) loc)[1];
|
||||
loc += 8;
|
||||
|
||||
if (size < basesize + msize)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::in() Not enough space for Class (Msg)!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
for(i = 0; i < msize; i++)
|
||||
{
|
||||
msg += loc[i];
|
||||
}
|
||||
loc += msize;
|
||||
|
||||
// now the files....
|
||||
// get total size... and check.
|
||||
// now list counter.
|
||||
|
||||
// now get msgSize.
|
||||
if (((int *) loc)[0] != PQChan_ListType)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::in() Bad List Data Type!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
|
||||
int fcount = ((int *) loc)[1];
|
||||
int fsize = ((int *) loc)[2];
|
||||
loc += 12;
|
||||
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQChanItem::in() Size before Files: " << PQChanItem::getSize();
|
||||
out << " FileCount: " << fcount;
|
||||
out << " FileSize: " << fsize;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqicizone, out.str());
|
||||
}
|
||||
|
||||
// check the size again.
|
||||
if (size < PQChanItem::getSize() + fsize)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::in() Not enough space for Class (Files)!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
|
||||
// Loop through the the files.
|
||||
int remain_fsize = fsize;
|
||||
for(i = 0; i < fcount; i++)
|
||||
{
|
||||
FileItem file;
|
||||
// loc, and the space left.
|
||||
if (0 >= file.in(loc, remain_fsize))
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQChanItem::in() Not enough space for Class (File2)!";
|
||||
out << std::endl;
|
||||
out << "\tWhen loading File #" << i+1 << " of " << fcount;
|
||||
out << "\tCurrent Loc: " << loc << " Remaining: " << remain_fsize;
|
||||
|
||||
pqioutput(PQL_ALERT, pqicizone, out.str());
|
||||
return -1; // cant be us.
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQChanItem::in() Loaded File #" << i+1;
|
||||
out << " Loc: " << loc << " size: " << file.getSize();
|
||||
pqioutput(PQL_DEBUG_BASIC, pqicizone, out.str());
|
||||
}
|
||||
|
||||
loc += file.getSize();
|
||||
remain_fsize -= file.getSize();
|
||||
|
||||
files.push_back(file);
|
||||
}
|
||||
|
||||
if (remain_fsize != 0)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQChanItem::in() Warning files size incorrect:";
|
||||
out << std::endl;
|
||||
out << "Indicated Size: " << fsize << " Indicated Count:";
|
||||
out << fcount << std::endl;
|
||||
out << "Real Size: " << fsize - remain_fsize;
|
||||
pqioutput(PQL_ALERT, pqicizone, out.str());
|
||||
}
|
||||
|
||||
// only the signature to go!.
|
||||
signType = ((int *) loc)[0];
|
||||
signLen = ((int *) loc)[1];
|
||||
loc += 8;
|
||||
// check size again.
|
||||
if (size != PQChanItem::getSize())
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQChanItem::in() Size of Packet Incorrect!";
|
||||
out << std::endl;
|
||||
out << "getSize(): " << PQChanItem::getSize();
|
||||
out << "data size: " << size;
|
||||
|
||||
pqioutput(PQL_ALERT, pqicizone, out.str());
|
||||
|
||||
return -1; // cant be us.
|
||||
}
|
||||
|
||||
// allocate memory and copy.
|
||||
if (NULL == (signature = (unsigned char *) malloc(signLen)))
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::in() Not enough Memory!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
|
||||
memcpy(signature, loc, signLen);
|
||||
|
||||
loc += signLen;
|
||||
|
||||
return PQChanItem::getSize();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
std::ostream &PQChanItem::print(std::ostream &out)
|
||||
{
|
||||
out << "-------- PQChanItem" << std::endl;
|
||||
PQItem::print(out);
|
||||
|
||||
out << "Cert Type/Len: " << certType << "/";
|
||||
out << certLen << std::endl;
|
||||
out << "Msg: " << msg << std::endl;
|
||||
FileList::iterator it;
|
||||
for(it = files.begin(); it != files.end(); it++)
|
||||
{
|
||||
it -> print(out);
|
||||
}
|
||||
out << "Sign Type/Len: " << signType << "/";
|
||||
out << signLen << std::endl;
|
||||
|
||||
return out << "--------" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
std::ostream &PQChanItem::FileItem::print(std::ostream &out)
|
||||
{
|
||||
out << "-- PQChanItem::FileItem" << std::endl;
|
||||
out << "Name: " << name << std::endl;
|
||||
out << "Hash: " << hash << std::endl;
|
||||
out << "Size: " << size << std::endl;
|
||||
return out << "--" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
// Overloaded from PQTunnel.
|
||||
const int PQChanItem::FileItem::getSize() const
|
||||
{
|
||||
// 8 bytes
|
||||
// 8 bytes file + size;
|
||||
// 8 bytes message + size;
|
||||
// 8 bytes size;
|
||||
|
||||
return 8 + 8 + name.length() + 8 + hash.length() + 8;
|
||||
}
|
||||
|
||||
int PQChanItem::FileItem::out(void *data, const int size) const
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQChanItem::FileItem::out() Data: " << data;
|
||||
out << " Size: " << size << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqicizone, out.str());
|
||||
}
|
||||
|
||||
if (size < PQChanItem::FileItem::getSize())
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqicizone,
|
||||
"PQChanItem::FileItem::out() Packet Too Small!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// out is easy cos the getSize should be correct.
|
||||
char *dta = (char *) data;
|
||||
|
||||
// first we put down the total
|
||||
((int *) dta)[0] = PQChan_FileType;
|
||||
((int *) dta)[1] = PQChanItem::FileItem::getSize();
|
||||
dta += 8; // 4 bytes per int.
|
||||
|
||||
((int *) dta)[0] = PQChan_NameType;
|
||||
((int *) dta)[1] = name.length();
|
||||
dta += 8; // 4 bytes per int.
|
||||
memcpy(dta, name.c_str(), name.length());
|
||||
dta += name.length();
|
||||
|
||||
((int *) dta)[0] = PQChan_HashType;
|
||||
((int *) dta)[1] = hash.length();
|
||||
dta += 8; // 4 bytes per int.
|
||||
memcpy(dta, hash.c_str(), hash.length());
|
||||
dta += hash.length();
|
||||
|
||||
((int *) dta)[0] = PQChan_SizeType;
|
||||
((int *) dta)[1] = this -> size;
|
||||
dta += 8; // 4 bytes per int.
|
||||
|
||||
return PQChanItem::FileItem::getSize();
|
||||
}
|
||||
|
||||
|
||||
void PQChanItem::FileItem::clear()
|
||||
{
|
||||
// first reset all our dataspaces.
|
||||
name.clear();
|
||||
hash.clear();
|
||||
}
|
||||
|
||||
|
||||
int PQChanItem::FileItem::in(const void *data, const int size)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQChanItem::FileItem::in() Data: " << data;
|
||||
out << " Size: " << size << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqicizone, out.str());
|
||||
}
|
||||
|
||||
clear();
|
||||
int i;
|
||||
|
||||
int basesize = PQChanItem::FileItem::getSize();
|
||||
if (size < basesize)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::FileItem::in() No space for Class (Base)!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
|
||||
|
||||
char *loc = ((char *) data);
|
||||
if (((int *) loc)[0] != PQChan_FileType)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::FileItem::in() Bad File Data Type!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
|
||||
int real_size = ((int *) loc)[1];
|
||||
if (size < real_size)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::FileItem::in() No space for Class (TotalSize)!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
loc += 8; // 4 bytes per int.
|
||||
|
||||
// now get name;
|
||||
if (((int *) loc)[0] != PQChan_NameType)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::FileItem::in() Bad Name Data Type!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
|
||||
int msize = ((int *) loc)[1];
|
||||
loc += 8;
|
||||
|
||||
if (real_size < basesize + msize)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::FileItem::in() No space for Class (Name)!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
for(i = 0; i < msize; i++)
|
||||
{
|
||||
name += loc[i];
|
||||
}
|
||||
loc += msize;
|
||||
|
||||
// now get hash;
|
||||
if (((int *) loc)[0] != PQChan_HashType)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::FileItem::in() Bad Hash Data Type!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
|
||||
int hsize = ((int *) loc)[1];
|
||||
loc += 8;
|
||||
|
||||
if (real_size < basesize + msize + hsize)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::FileItem::in() No space for Class (Hash)!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
for(i = 0; i < hsize; i++)
|
||||
{
|
||||
hash += loc[i];
|
||||
}
|
||||
loc += hsize;
|
||||
|
||||
// now get size.
|
||||
if (((int *) loc)[0] != PQChan_SizeType)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::FileItem::in() Bad Size Data Type!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
|
||||
this -> size = ((int *) loc)[1];
|
||||
loc += 8;
|
||||
|
||||
// finally verify that the sizes are correct.
|
||||
if (real_size != PQChanItem::FileItem::getSize())
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqicizone,
|
||||
"PQChanItem::FileItem::in() Size Mismatch!");
|
||||
return -1; // cant be us.
|
||||
}
|
||||
|
||||
return PQChanItem::FileItem::getSize();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* "$Id: pqichannel.h,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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef MRK_PQI_CHANNELITEM_H
|
||||
#define MRK_PQI_CHANNELITEM_H
|
||||
|
||||
#include "pqi/pqitunnel.h"
|
||||
|
||||
#define PQI_TUNNEL_CHANNEL_ITEM_TYPE 162
|
||||
|
||||
PQTunnel *createChannelItems(void *d, int n);
|
||||
|
||||
class PQChanItem: public PQTunnel
|
||||
{
|
||||
protected:
|
||||
//PQChanItem(int st);
|
||||
public:
|
||||
PQChanItem();
|
||||
~PQChanItem();
|
||||
virtual PQChanItem *clone();
|
||||
void copy(const PQChanItem *di);
|
||||
void clear();
|
||||
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);
|
||||
|
||||
|
||||
// So what data do we need.
|
||||
// data load.
|
||||
//
|
||||
// 1) a Message.
|
||||
// 2) a list of filenames/hashs/sizes.
|
||||
//
|
||||
// So you can different types
|
||||
// of channels.
|
||||
//
|
||||
// 1) Clear Text Signed.
|
||||
// -> name
|
||||
// -> public key.
|
||||
// -> data load
|
||||
// -> signature. (of all)
|
||||
//
|
||||
// 2) Encrypted.
|
||||
// -> name
|
||||
// -> public key
|
||||
// -> encrypted data load.
|
||||
// -> signature (of all)
|
||||
//
|
||||
|
||||
class FileItem
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
std::string hash;
|
||||
long size;
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out);
|
||||
|
||||
const int getSize() const;
|
||||
int out(void *data, const int size) const;
|
||||
int in(const void *data, const int size);
|
||||
};
|
||||
|
||||
typedef std::list<FileItem> FileList;
|
||||
|
||||
// Certificate/Key (containing Name)
|
||||
unsigned char *certDER;
|
||||
int certType;
|
||||
int certLen;
|
||||
|
||||
std::string msg;
|
||||
std::string title;
|
||||
FileList files;
|
||||
|
||||
unsigned char *signature;
|
||||
int signType;
|
||||
int signLen;
|
||||
|
||||
bool signValid; // not transmitted.
|
||||
};
|
||||
|
||||
|
||||
#endif // MRK_PQI_CHANNELITEM_H
|
@ -23,27 +23,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef MRK_PQI_HANDLER_HEADER
|
||||
#define MRK_PQI_HANDLER_HEADER
|
||||
|
||||
#include "pqi/pqi.h"
|
||||
#include "pqi/pqisecurity.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 <map>
|
||||
#include <list>
|
||||
|
||||
|
85
libretroshare/src/pqi/pqihash.h
Normal file
85
libretroshare/src/pqi/pqihash.h
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* libretroshare/src/pqi: pqihash.h
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 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 <openssl/sha.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
class pqihash
|
||||
{
|
||||
public:
|
||||
pqihash()
|
||||
{
|
||||
|
||||
sha_hash = new uint8_t[SHA_DIGEST_LENGTH];
|
||||
sha_ctx = new SHA_CTX;
|
||||
SHA1_Init(sha_ctx);
|
||||
doHash = true;
|
||||
}
|
||||
|
||||
void addData(void *data, uint32_t len)
|
||||
{
|
||||
if (doHash)
|
||||
{
|
||||
SHA1_Update(sha_ctx, data, len);
|
||||
}
|
||||
}
|
||||
|
||||
void Complete(std::string &hash)
|
||||
{
|
||||
if (!doHash)
|
||||
{
|
||||
hash = endHash;
|
||||
return;
|
||||
}
|
||||
|
||||
SHA1_Final(sha_hash, sha_ctx);
|
||||
|
||||
std::ostringstream out;
|
||||
for(int i = 0; i < SHA_DIGEST_LENGTH; i++)
|
||||
{
|
||||
out << std::setw(2) << std::setfill('0') << std::hex;
|
||||
out << (unsigned int) (sha_hash[i]);
|
||||
}
|
||||
endHash = out.str();
|
||||
hash = endHash;
|
||||
doHash = false;
|
||||
|
||||
delete []sha_hash;
|
||||
delete sha_ctx;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
bool doHash;
|
||||
std::string endHash;
|
||||
uint8_t *sha_hash;
|
||||
SHA_CTX *sha_ctx;
|
||||
};
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
||||
class Indicator
|
||||
{
|
||||
public:
|
||||
Indicator(int n = 0)
|
||||
Indicator(int n = 1)
|
||||
:num(n), changeFlags(n) {IndicateChanged();}
|
||||
void IndicateChanged()
|
||||
{
|
||||
@ -44,7 +44,7 @@ void IndicateChanged()
|
||||
changeFlags[i]=true;
|
||||
}
|
||||
|
||||
bool Changed(int idx)
|
||||
bool Changed(int idx = 0)
|
||||
{
|
||||
/* catch overflow */
|
||||
if (idx > num - 1)
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* "$Id: pqitunneltst.cc,v 1.3 2007-02-18 21:46:50 rmf24 Exp $"
|
||||
* libretroshare/src/pqi: pqilistener.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
|
||||
@ -23,14 +23,26 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MRK_PQI_GENERIC_LISTEN_HEADER
|
||||
#define MRK_PQI_GENERIC_LISTEN_HEADER
|
||||
|
||||
// operating system specific network header.
|
||||
#include "pqi/pqinetwork.h"
|
||||
|
||||
|
||||
#include "pqi/pqitunneltst.h"
|
||||
|
||||
PQTunnel *createPQTStst(void *d, int n)
|
||||
class pqilistener
|
||||
{
|
||||
return new PQTunnelTst();
|
||||
}
|
||||
public:
|
||||
|
||||
pqilistener() { return; }
|
||||
virtual ~pqilistener() { return; }
|
||||
|
||||
virtual int tick() { return 1; }
|
||||
virtual int status() { return 1; }
|
||||
virtual int setListenAddr(struct sockaddr_in addr) { return 1; }
|
||||
virtual int setuplisten() { return 1; }
|
||||
virtual int resetlisten() { return 1; }
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // MRK_PQI_GENERIC_LISTEN_HEADER
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* "$Id: pqiloopback.cc,v 1.8 2007-02-19 20:08:30 rmf24 Exp $"
|
||||
* libretroshare/src/pqi: pqiloopback.cc
|
||||
*
|
||||
* 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
|
||||
@ -23,33 +23,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include "pqi/pqi.h"
|
||||
#include "pqi/pqiloopback.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 ******************/
|
||||
|
||||
// Test Interface (LoopBack)
|
||||
|
||||
|
||||
pqiloopback::pqiloopback(std::string id)
|
||||
:PQInterface(id)
|
||||
{
|
||||
//std::cerr << "pqiloopback construction()" << std::endl;
|
||||
// rates are irrelevant..... no B/W consumed.
|
||||
setMaxRate(true, 0);
|
||||
setMaxRate(false, 0);
|
||||
setRate(true, 0);
|
||||
@ -65,9 +44,6 @@ pqiloopback::~pqiloopback()
|
||||
|
||||
int pqiloopback::SendItem(RsItem *i)
|
||||
{
|
||||
// contact Id should be correct already!
|
||||
//i -> p = getContact();
|
||||
//i -> flags |= PQI_ITEM_FLAG_LOCAL;
|
||||
objs.push_back(i);
|
||||
return 1;
|
||||
}
|
||||
@ -78,15 +54,12 @@ RsItem * pqiloopback::GetItem()
|
||||
{
|
||||
RsItem *pqi = objs.front();
|
||||
objs.pop_front();
|
||||
// breaks the module, through ssl dependance.
|
||||
// but necessary for running system..
|
||||
//pqi -> p = getSSLRoot() -> getOwnCert();
|
||||
return pqi;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// // PQI interface.
|
||||
// PQI interface.
|
||||
int pqiloopback::tick()
|
||||
{
|
||||
return 0;
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* "$Id: pqiloopback.h,v 1.5 2007-02-19 20:08:30 rmf24 Exp $"
|
||||
* libretroshare/src/pqi: pqiloopback.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
|
||||
@ -23,12 +23,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef MRK_PQI_LOOPBACK_HEADER
|
||||
#define MRK_PQI_LOOPBACK_HEADER
|
||||
|
||||
|
||||
// The standard data types and the search interface.
|
||||
#include "pqi/pqi.h"
|
||||
|
||||
@ -36,9 +33,6 @@
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
// Test Interface (LoopBack)
|
||||
// public interface .... includes the whole p3interface.
|
||||
class pqiloopback: public PQInterface
|
||||
{
|
||||
public:
|
||||
|
@ -1,124 +0,0 @@
|
||||
/*
|
||||
* "$Id: pqimon.cc,v 1.2 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".
|
||||
*
|
||||
*/
|
||||
|
||||
/**************** 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/pqimon.h"
|
||||
|
||||
|
||||
pqimonitor::pqimonitor() { return; }
|
||||
pqimonitor::~pqimonitor() { return; }
|
||||
|
||||
|
||||
int pqimonitor::tick()
|
||||
{
|
||||
|
||||
/* grab the sslroot - and check the state of the peers */
|
||||
sslroot *sslr = getSSLRoot();
|
||||
std::list<cert *> &certlist = sslr->getCertList();
|
||||
std::list<cert *>::iterator it;
|
||||
std::list<pqipeer>::iterator pit;
|
||||
std::list<pqimonclient *>::iterator cit;
|
||||
|
||||
//std::cerr << "pqimonitor::tick() plist:" << plist.size() << " clist:" << certlist.size() << std::endl;
|
||||
|
||||
bool ok = true;
|
||||
if (plist.size() != certlist.size())
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
|
||||
pit = plist.begin();
|
||||
for(it = certlist.begin(); (ok) && (it != certlist.end()); it++, pit++)
|
||||
{
|
||||
certsign sign;
|
||||
if (!sslr->getcertsign(*it, sign))
|
||||
{
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
|
||||
std::string id = convert_to_str(sign);
|
||||
|
||||
if (id != pit->id)
|
||||
{
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
//std::cerr << "pqimonitor::tick() Updating plist" << std::endl;
|
||||
/* copy the list */
|
||||
plist.clear();
|
||||
for(it = certlist.begin(); it != certlist.end(); it++)
|
||||
{
|
||||
/* list */
|
||||
certsign sign;
|
||||
if (!sslr->getcertsign(*it, sign))
|
||||
{
|
||||
std::cerr << "Major Error in pqimonitor!";
|
||||
std::cerr << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pqipeer peer;
|
||||
peer.id = convert_to_str(sign);
|
||||
peer.name = (*it)->Name();
|
||||
if ((*it)->Connected())
|
||||
{
|
||||
peer.state = PQI_PEER_STATE_ONLINE;
|
||||
}
|
||||
else
|
||||
{
|
||||
peer.state = PQI_PEER_STATE_OFFLINE;
|
||||
}
|
||||
plist.push_back(peer);
|
||||
}
|
||||
|
||||
/* now notify clients */
|
||||
for(cit = clients.begin(); cit != clients.end(); cit++)
|
||||
{
|
||||
//std::cerr << "pqimonitor::tick() Calling Client" << std::endl;
|
||||
(*cit)->monUpdate(plist);
|
||||
}
|
||||
}
|
||||
return 0; /* don't make more work for anyone */
|
||||
}
|
||||
|
||||
|
||||
|
83
libretroshare/src/pqi/pqimonitor.cc
Normal file
83
libretroshare/src/pqi/pqimonitor.cc
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* libretroshare/src/pqi: pqimonitor.cc
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2007-2008 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/pqimonitor.h"
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "util/rsprint.h"
|
||||
|
||||
/***** DUMMY Connect CB for testing *****/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
pqiConnectCbDummy::pqiConnectCbDummy()
|
||||
{
|
||||
std::cerr << "pqiConnectCbDummy()" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
pqiConnectCbDummy::~pqiConnectCbDummy()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void pqiConnectCbDummy::peerStatus(std::string id,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||
uint32_t type, uint32_t mode, uint32_t source)
|
||||
{
|
||||
std::cerr << "pqiConnectCbDummy::peerStatus()";
|
||||
std::cerr << " id: " << id;
|
||||
|
||||
std::cerr << " laddr: " << inet_ntoa(laddr.sin_addr);
|
||||
std::cerr << " lport: " << ntohs(laddr.sin_port);
|
||||
std::cerr << " raddr: " << inet_ntoa(raddr.sin_addr);
|
||||
std::cerr << " rport: " << ntohs(raddr.sin_port);
|
||||
|
||||
std::cerr << " type: " << type;
|
||||
std::cerr << " mode: " << mode;
|
||||
std::cerr << " source: " << source;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
void pqiConnectCbDummy::peerConnectRequest(std::string id, uint32_t type)
|
||||
{
|
||||
std::cerr << "pqiConnectCbDummy::peerConnectRequest()";
|
||||
std::cerr << " id: " << id;
|
||||
std::cerr << " type: " << type;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void pqiConnectCbDummy::stunStatus(std::string id, struct sockaddr_in addr, uint32_t flags)
|
||||
{
|
||||
std::cerr << "pqiConnectCbDummy::stunStatus()";
|
||||
std::cerr << " idhash: " << RsUtil::BinToHex(id) << " addr: " << inet_ntoa(addr.sin_addr);
|
||||
std::cerr << " port: " << ntohs(addr.sin_port);
|
||||
std::cerr << " flags: " << flags;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
|
132
libretroshare/src/pqi/pqimonitor.h
Normal file
132
libretroshare/src/pqi/pqimonitor.h
Normal file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* libretroshare/src/pqi: pqimonitor.h
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2007-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_MONITOR_H
|
||||
#define PQI_MONITOR_H
|
||||
|
||||
/**** Rough sketch of a Monitor class
|
||||
* expect it to change significantly
|
||||
*
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
/************** Define Type/Mode/Source ***************/
|
||||
|
||||
|
||||
/* STATE MASK */
|
||||
const uint32_t RS_PEER_STATE_MASK = 0x00ff;
|
||||
const uint32_t RS_PEER_ACTION_MASK = 0xff00;
|
||||
|
||||
/* STATE */
|
||||
const uint32_t RS_PEER_S_FRIEND = 0x0001;
|
||||
const uint32_t RS_PEER_S_ONLINE = 0x0002;
|
||||
const uint32_t RS_PEER_S_CONNECTED = 0x0004; /* heard from recently..*/
|
||||
|
||||
/* ACTIONS */
|
||||
const uint32_t RS_PEER_NEW = 0x0001; /* new Peer */
|
||||
const uint32_t RS_PEER_MOVED = 0x0002; /* moved from F->O or O->F */
|
||||
const uint32_t RS_PEER_CONNECTED = 0x0004;
|
||||
const uint32_t RS_PEER_DISCONNECTED = 0x0008;
|
||||
const uint32_t RS_PEER_CONNECT_REQ = 0x0010;
|
||||
|
||||
/* Stun Status Flags */
|
||||
//const uint32_t RS_STUN_SRC_DHT = 0x0001;
|
||||
//const uint32_t RS_STUN_SRC_PEER = 0x0002;
|
||||
const uint32_t RS_STUN_ONLINE = 0x0010;
|
||||
const uint32_t RS_STUN_FRIEND = 0x0020;
|
||||
|
||||
|
||||
|
||||
#define RS_CONNECT_PASSIVE 1
|
||||
#define RS_CONNECT_ACTIVE 2
|
||||
|
||||
#define RS_CB_DHT 1 /* from dht */
|
||||
#define RS_CB_DISC 2 /* from peers */
|
||||
#define RS_CB_PERSON 3 /* from connection */
|
||||
|
||||
|
||||
class pqipeer
|
||||
{
|
||||
public:
|
||||
std::string id;
|
||||
std::string name;
|
||||
uint32_t state;
|
||||
uint32_t actions;
|
||||
};
|
||||
|
||||
class p3ConnectMgr;
|
||||
|
||||
class pqiMonitor
|
||||
{
|
||||
public:
|
||||
pqiMonitor() :mConnMgr(NULL) { return; }
|
||||
virtual ~pqiMonitor() { return; }
|
||||
|
||||
void setConnectionMgr(p3ConnectMgr *cm) { mConnMgr = cm; }
|
||||
virtual void statusChange(const std::list<pqipeer> &plist) = 0;
|
||||
|
||||
//virtual void peerStatus(std::string id, uint32_t mode) = 0;
|
||||
|
||||
protected:
|
||||
p3ConnectMgr *mConnMgr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class pqiConnectCb
|
||||
{
|
||||
public:
|
||||
virtual ~pqiConnectCb() { return; }
|
||||
virtual void peerStatus(std::string id,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||
uint32_t type, uint32_t mode, uint32_t source) = 0;
|
||||
|
||||
virtual void peerConnectRequest(std::string id, uint32_t type) = 0;
|
||||
|
||||
virtual void stunStatus(std::string id, struct sockaddr_in addr, uint32_t flags) = 0;
|
||||
};
|
||||
|
||||
|
||||
/**** DUMMY CB FOR TESTING (just prints) ****/
|
||||
class pqiConnectCbDummy: public pqiConnectCb
|
||||
{
|
||||
public:
|
||||
pqiConnectCbDummy();
|
||||
virtual ~pqiConnectCbDummy();
|
||||
virtual void peerStatus(std::string id,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||
uint32_t type, uint32_t mode, uint32_t source);
|
||||
|
||||
virtual void peerConnectRequest(std::string id, uint32_t type);
|
||||
|
||||
virtual void stunStatus(std::string id, struct sockaddr_in addr, uint32_t flags);
|
||||
};
|
||||
|
||||
#endif // PQI_MONITOR_H
|
||||
|
@ -436,6 +436,15 @@ in_addr_t pqi_inet_netof(struct in_addr addr)
|
||||
//return abit;
|
||||
}
|
||||
|
||||
int sockaddr_cmp(struct sockaddr_in &addr1, struct sockaddr_in &addr2 )
|
||||
{
|
||||
if (addr1.sin_family != addr2.sin_family)
|
||||
return addr1.sin_family - addr2.sin_family;
|
||||
if (addr1.sin_addr.s_addr != addr2.sin_addr.s_addr)
|
||||
return (addr1.sin_addr.s_addr - addr2.sin_addr.s_addr);
|
||||
if (addr1.sin_port != addr2.sin_port)
|
||||
return (addr1.sin_port - addr2.sin_port);
|
||||
}
|
||||
|
||||
int inaddr_cmp(struct sockaddr_in addr1, struct sockaddr_in addr2 )
|
||||
{
|
||||
@ -660,7 +669,7 @@ bool isSameSubnet(struct in_addr *addr1, struct in_addr *addr2)
|
||||
bool LookupDNSAddr(std::string name, struct sockaddr_in &addr)
|
||||
{
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
char service[100];
|
||||
struct addrinfo hints_st;
|
||||
struct addrinfo *hints = &hints_st;
|
||||
|
@ -102,6 +102,7 @@ extern int errno; /* Define extern errno, to duplicate unix behaviour */
|
||||
std::ostream &showSocketError(std::ostream &out);
|
||||
|
||||
std::string socket_errorType(int err);
|
||||
int sockaddr_cmp(struct sockaddr_in &addr1, struct sockaddr_in &addr2 );
|
||||
int inaddr_cmp(struct sockaddr_in addr1, struct sockaddr_in addr1 );
|
||||
int inaddr_cmp(struct sockaddr_in addr1, unsigned long);
|
||||
|
||||
|
@ -23,41 +23,22 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "pqi/pqi.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "pqi/pqiperson.h"
|
||||
#include "pqi/pqipersongrp.h"
|
||||
|
||||
const int pqipersonzone = 82371;
|
||||
#include "pqi/pqidebug.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
pqiperson::pqiperson(cert *c, std::string id)
|
||||
:PQInterface(id), sslcert(c), active(false), activepqi(NULL),
|
||||
inConnectAttempt(false), waittimes(0)
|
||||
pqiperson::pqiperson(std::string id, pqipersongrp *pg)
|
||||
:PQInterface(id), active(false), activepqi(NULL),
|
||||
inConnectAttempt(false), waittimes(0),
|
||||
pqipg(pg)
|
||||
{
|
||||
sroot = getSSLRoot();
|
||||
|
||||
// check certificate
|
||||
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#if defined(PQI_USE_XPGP)
|
||||
sroot -> validateCertificateXPGP(sslcert);
|
||||
#else /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
sroot -> validateCertificate(sslcert);
|
||||
#endif /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
if (!(sslcert -> Valid()))
|
||||
{
|
||||
std::cerr << "pqiperson::Warning Certificate Not Approved!";
|
||||
std::cerr << " pqiperson will not initialise...." << std::endl;
|
||||
}
|
||||
/* must check id! */
|
||||
|
||||
return;
|
||||
}
|
||||
@ -65,13 +46,13 @@ pqiperson::pqiperson(cert *c, std::string id)
|
||||
pqiperson::~pqiperson()
|
||||
{
|
||||
// clean up the children.
|
||||
std::list<pqiconnect *>::iterator it = kids.begin();
|
||||
for(it = kids.begin(); it != kids.end(); )
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
{
|
||||
pqiconnect *pc = (*it);
|
||||
it = kids.erase(it);
|
||||
pqiconnect *pc = (it->second);
|
||||
delete pc;
|
||||
}
|
||||
kids.clear();
|
||||
}
|
||||
|
||||
|
||||
@ -111,11 +92,6 @@ int pqiperson::status()
|
||||
return -1;
|
||||
}
|
||||
|
||||
cert * pqiperson::getContact()
|
||||
{
|
||||
return sslcert;
|
||||
}
|
||||
|
||||
// tick......
|
||||
int pqiperson::tick()
|
||||
{
|
||||
@ -123,7 +99,7 @@ int pqiperson::tick()
|
||||
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiperson::tick() Cert: " << sslcert -> Name() << " ";
|
||||
out << "pqiperson::tick() Id: " << PeerId() << " ";
|
||||
if (active)
|
||||
out << "***Active***";
|
||||
else
|
||||
@ -140,48 +116,19 @@ int pqiperson::tick()
|
||||
|
||||
|
||||
// tick the children.
|
||||
std::list<pqiconnect *>::iterator it;
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
{
|
||||
if (0 < (*it) -> tick())
|
||||
if (0 < (it->second) -> tick())
|
||||
{
|
||||
activeTick = 1;
|
||||
}
|
||||
out << "\tTicking Child: " << (*it) << std::endl;
|
||||
out << "\tTicking Child: " << (it->first) << std::endl;
|
||||
}
|
||||
|
||||
pqioutput(PQL_DEBUG_ALL, pqipersonzone, out.str());
|
||||
} // end of pqioutput.
|
||||
|
||||
// use cert settings to control everything.
|
||||
if (!active)
|
||||
{
|
||||
if ((sslcert -> WillConnect()) && (!inConnectAttempt))
|
||||
{
|
||||
if (sslcert -> nc_timestamp < time(NULL))
|
||||
{
|
||||
// calc the time til next connect.
|
||||
sslcert -> nc_timestamp = time(NULL) +
|
||||
connectWait();
|
||||
connectattempt(NULL);
|
||||
}
|
||||
}
|
||||
if (sslcert -> Listening())
|
||||
{
|
||||
if (!(sslcert -> WillListen()))
|
||||
{
|
||||
stoplistening();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sslcert -> WillListen())
|
||||
{
|
||||
listen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return activeTick;
|
||||
}
|
||||
|
||||
@ -192,7 +139,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiperson::notifyEvent() Cert: " << sslcert -> Name();
|
||||
out << "pqiperson::notifyEvent() Id: " << PeerId();
|
||||
out << std::endl;
|
||||
out << "Message: " << newState << " from: " << ni << std::endl;
|
||||
|
||||
@ -201,7 +148,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
|
||||
/* find the pqi, */
|
||||
pqiconnect *pqi = NULL;
|
||||
std::list<pqiconnect *>::iterator it;
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
|
||||
/* start again */
|
||||
int i = 0;
|
||||
@ -211,15 +158,15 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
out << "pqiperson::connectattempt() Kid# ";
|
||||
out << i << " of " << kids.size();
|
||||
out << std::endl;
|
||||
out << " pqiconn: " << (*it);
|
||||
out << " ni: " << (*it)->ni;
|
||||
out << " type: " << (it->first);
|
||||
out << " ni: " << (it->second)->ni;
|
||||
out << " in_ni: " << ni;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
|
||||
i++;
|
||||
|
||||
if ((*it)->thisNetInterface(ni))
|
||||
if ((it->second)->thisNetInterface(ni))
|
||||
{
|
||||
pqi = (*it);
|
||||
pqi = (it->second);
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,13 +181,16 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
{
|
||||
case CONNECT_RECEIVED:
|
||||
case CONNECT_SUCCESS:
|
||||
|
||||
/* notify */
|
||||
if (pqipg)
|
||||
pqipg->notifyConnect(PeerId(), true);
|
||||
|
||||
if ((active) && (activepqi != pqi)) // already connected - trouble
|
||||
{
|
||||
pqioutput(PQL_WARNING, pqipersonzone,
|
||||
"CONNECT_SUCCESS+active->trouble: shutdown EXISTING->switch to new one!");
|
||||
|
||||
//pqi -> stoplistening();
|
||||
|
||||
// This is the RESET that's killing the connections.....
|
||||
activepqi -> reset();
|
||||
// this causes a recursive call back into this fn.
|
||||
@ -256,20 +206,20 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
// mark as active.
|
||||
active = true;
|
||||
activepqi = pqi;
|
||||
sslcert -> Connected(true);
|
||||
sroot -> IndicateCertsChanged();
|
||||
|
||||
connectSuccess();
|
||||
|
||||
inConnectAttempt = false;
|
||||
// dont stop listening.
|
||||
//stoplistening();
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case CONNECT_UNREACHABLE:
|
||||
case CONNECT_FIREWALLED:
|
||||
case CONNECT_FAILED:
|
||||
|
||||
/* notify up */
|
||||
if (pqipg)
|
||||
pqipg->notifyConnect(PeerId(), false);
|
||||
|
||||
if (active)
|
||||
{
|
||||
if (activepqi == pqi)
|
||||
@ -278,8 +228,6 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
"CONNECT_FAILED->marking so!");
|
||||
active = false;
|
||||
activepqi = NULL;
|
||||
sslcert -> Connected(false);
|
||||
sroot -> IndicateCertsChanged();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@ -295,7 +243,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
pqioutput(PQL_WARNING, pqipersonzone,
|
||||
"CONNECT_FAILED+NOT active -> try connect again");
|
||||
|
||||
connectattempt(pqi);
|
||||
//connectattempt(pqi);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
@ -311,59 +259,33 @@ int pqiperson::reset()
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiperson::reset() Cert: " << sslcert -> Name();
|
||||
out << "pqiperson::reset() Id: " << PeerId();
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
|
||||
}
|
||||
|
||||
std::list<pqiconnect *>::iterator it;
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
{
|
||||
(*it) -> reset();
|
||||
(it->second) -> reset();
|
||||
}
|
||||
|
||||
activepqi = NULL;
|
||||
active = false;
|
||||
sslcert -> Listening(false);
|
||||
sslcert -> Connected(false);
|
||||
sroot -> IndicateCertsChanged();
|
||||
|
||||
// check auto setting at reset.
|
||||
if (!sslcert -> Manual())
|
||||
autoconnect(true);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqiperson::autoconnect(bool b)
|
||||
int pqiperson::addChildInterface(uint32_t type, pqiconnect *pqi)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiperson::autoconnect() Cert: " << sslcert -> Name();
|
||||
out << " - " << (int) b << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
|
||||
}
|
||||
|
||||
sslcert -> Manual(!b);
|
||||
|
||||
sslcert -> WillConnect(b);
|
||||
sslcert -> WillListen(b);
|
||||
sroot -> IndicateCertsChanged();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int pqiperson::addChildInterface(pqiconnect *pqi)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiperson::addChildInterface() : " << pqi;
|
||||
out << "pqiperson::addChildInterface() : Id " << PeerId() << " " << type;
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
|
||||
}
|
||||
|
||||
kids.push_back(pqi);
|
||||
kids[type] = pqi;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -375,21 +297,19 @@ int pqiperson::listen()
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiperson::listen() Cert: " << sslcert -> Name();
|
||||
out << "pqiperson::listen() Id: " << PeerId();
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
|
||||
}
|
||||
|
||||
if (!active)
|
||||
{
|
||||
std::list<pqiconnect *>::iterator it;
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
{
|
||||
// set them all listening.
|
||||
(*it) -> listen();
|
||||
(it->second) -> listen();
|
||||
}
|
||||
sslcert -> Listening(true);
|
||||
sroot -> IndicateCertsChanged();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -399,114 +319,53 @@ int pqiperson::stoplistening()
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiperson::stoplistening() Cert: " << sslcert -> Name();
|
||||
out << "pqiperson::stoplistening() Id: " << PeerId();
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
|
||||
}
|
||||
|
||||
std::list<pqiconnect *>::iterator it;
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
{
|
||||
// set them all listening.
|
||||
(*it) -> stoplistening();
|
||||
(it->second) -> stoplistening();
|
||||
}
|
||||
sslcert -> Listening(false);
|
||||
sroot -> IndicateCertsChanged();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqiperson::connectattempt(pqiconnect *last)
|
||||
int pqiperson::connect(uint32_t type, struct sockaddr_in raddr)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiperson::connectattempt() Cert: " << sslcert -> Name();
|
||||
out << "pqiperson::connect() Id: " << PeerId();
|
||||
out << " type: " << type;
|
||||
out << " addr: " << inet_ntoa(raddr.sin_addr);
|
||||
out << ":" << ntohs(raddr.sin_port);
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
|
||||
}
|
||||
|
||||
std::list<pqiconnect *>::iterator it = kids.begin();
|
||||
int i = 0;
|
||||
if (last != NULL)
|
||||
{
|
||||
// find the current connection.
|
||||
for(; (it != kids.end()) && ((*it) != last); it++, i++);
|
||||
|
||||
if (it != kids.end())
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiperson::connectattempt() Last Cert#: ";
|
||||
out << i << " of " << kids.size();
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
|
||||
|
||||
|
||||
it++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
// now at the first one to try.
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiperson::connectattempt() Cert: " << sslcert -> Name();
|
||||
out << " Starting Attempts at Interface " << i << " of " << kids.size();
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
|
||||
}
|
||||
|
||||
// try to connect on the next one.
|
||||
for(; (it != kids.end()) && (0 > (*it)->connectattempt()); it++, i++);
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
|
||||
it = kids.find(type);
|
||||
if (it == kids.end())
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiperson::connectattempt() Cert: " << sslcert -> Name();
|
||||
out << " Failed on All Interfaces";
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiperson::connectattempt() Cert: " << sslcert -> Name();
|
||||
out << " attempt on pqiconnect #" << i << " suceeded";
|
||||
out << "pqiperson::connect()";
|
||||
out << " missing pqiconnect";
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
|
||||
}
|
||||
|
||||
(it->second)->connect(raddr);
|
||||
|
||||
// flag if we started a new connectionAttempt.
|
||||
inConnectAttempt = (it != kids.end());
|
||||
inConnectAttempt = true;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// returns (in secs) the time til next connect attempt
|
||||
// this is based on the
|
||||
//
|
||||
#define SEC_PER_LOG_UNIT 600 /* ten minutes? */
|
||||
#define MAX_WAITTIMES 10 /* ten minutes? */
|
||||
|
||||
int pqiperson::connectWait()
|
||||
{
|
||||
int log_weight = (1 << waittimes);
|
||||
// max wait of 2^10 = 1024 * X min (over a month)
|
||||
// 10240 min = 1 day
|
||||
waittimes++;
|
||||
if (waittimes > MAX_WAITTIMES)
|
||||
waittimes = MAX_WAITTIMES;
|
||||
// make it linear instead!.
|
||||
return waittimes * SEC_PER_LOG_UNIT;
|
||||
//return log_weight * SEC_PER_LOG_UNIT;
|
||||
}
|
||||
|
||||
// called to reduce the waittimes, next time.
|
||||
int pqiperson::connectSuccess()
|
||||
{
|
||||
return waittimes = 0;
|
||||
}
|
||||
|
||||
|
||||
float pqiperson::getRate(bool in)
|
||||
{
|
||||
// get the rate from the active one.
|
||||
@ -520,10 +379,10 @@ void pqiperson::setMaxRate(bool in, float val)
|
||||
// set to all of them. (and us)
|
||||
PQInterface::setMaxRate(in, val);
|
||||
// clean up the children.
|
||||
std::list<pqiconnect *>::iterator it = kids.begin();
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
{
|
||||
(*it) -> setMaxRate(in, val);
|
||||
(it->second) -> setMaxRate(in, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,23 +31,9 @@
|
||||
|
||||
#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 <list>
|
||||
|
||||
class pqiperson;
|
||||
class sslroot;
|
||||
|
||||
static const int CONNECT_RECEIVED = 1;
|
||||
static const int CONNECT_SUCCESS = 2;
|
||||
@ -77,7 +63,7 @@ public:
|
||||
virtual ~pqiconnect() { return; }
|
||||
|
||||
// presents a virtual NetInterface -> passes to ni.
|
||||
virtual int connectattempt() { return ni -> connectattempt(); }
|
||||
virtual int connect(struct sockaddr_in raddr) { return ni->connect(raddr); }
|
||||
virtual int listen() { return ni -> listen(); }
|
||||
virtual int stoplistening() { return ni -> stoplistening(); }
|
||||
virtual int reset() { return ni -> reset(); }
|
||||
@ -104,19 +90,20 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
class pqipersongrp;
|
||||
|
||||
class pqiperson: public PQInterface
|
||||
{
|
||||
public:
|
||||
pqiperson(cert *c, std::string id);
|
||||
pqiperson(std::string id, pqipersongrp *ppg);
|
||||
virtual ~pqiperson(); // must clean up children.
|
||||
|
||||
// control of the connection.
|
||||
int reset();
|
||||
int autoconnect(bool);
|
||||
int connect(uint32_t type, struct sockaddr_in raddr);
|
||||
|
||||
// add in connection method.
|
||||
int addChildInterface(pqiconnect *pqi);
|
||||
int addChildInterface(uint32_t type, pqiconnect *pqi);
|
||||
|
||||
// The PQInterface interface.
|
||||
virtual int SendItem(RsItem *);
|
||||
@ -124,7 +111,6 @@ virtual RsItem *GetItem();
|
||||
|
||||
virtual int status();
|
||||
virtual int tick();
|
||||
virtual cert * getContact();
|
||||
|
||||
// overloaded callback function for the child - notify of a change.
|
||||
int notifyEvent(NetInterface *ni, int event);
|
||||
@ -135,23 +121,18 @@ virtual void setMaxRate(bool in, float val);
|
||||
|
||||
private:
|
||||
|
||||
std::list<pqiconnect *> kids;
|
||||
cert *sslcert;
|
||||
std::map<uint32_t, pqiconnect *> kids;
|
||||
bool active;
|
||||
pqiconnect *activepqi;
|
||||
bool inConnectAttempt;
|
||||
int waittimes;
|
||||
|
||||
sslroot *sroot;
|
||||
|
||||
private: /* Helper functions */
|
||||
|
||||
int connectWait();
|
||||
int connectSuccess();
|
||||
int listen();
|
||||
int stoplistening();
|
||||
int connectattempt(pqiconnect *last);
|
||||
|
||||
pqipersongrp *pqipg; /* parent for callback */
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* "$Id: pqipersongrp.cc,v 1.14 2007-02-19 20:08:30 rmf24 Exp $"
|
||||
* libretroshare/src/pqi: pqipersongrp.cc
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
@ -23,22 +23,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include "pqi/pqipersongrp.h"
|
||||
|
||||
#include "pqi/pqissl.h"
|
||||
#include "pqi/pqissllistener.h"
|
||||
|
||||
#ifdef PQI_USE_PROXY
|
||||
#include "pqi/pqiudpproxy.h"
|
||||
#include "pqi/pqissludp.h"
|
||||
#endif
|
||||
|
||||
//#include "pqi/pqitunneltst.h"
|
||||
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/pqidebug.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
const int pqipersongrpzone = 354;
|
||||
@ -101,87 +89,13 @@ int pqipersongrp::tickServiceSend()
|
||||
}
|
||||
|
||||
|
||||
// inits
|
||||
pqipersongrp::pqipersongrp(SecurityPolicy *glob, sslroot *sr, unsigned long flags)
|
||||
:pqihandler(glob), sslr(sr),
|
||||
#ifdef PQI_USE_PROXY
|
||||
p3p(NULL),
|
||||
#endif
|
||||
initFlags(flags)
|
||||
// init
|
||||
pqipersongrp::pqipersongrp(SecurityPolicy *glob, unsigned long flags)
|
||||
:pqihandler(glob), pqil(NULL), config(NULL), initFlags(flags)
|
||||
{
|
||||
// add a p3proxy & p3disc.
|
||||
#ifdef PQI_USE_PROXY
|
||||
p3p = new p3udpproxy(p3d);
|
||||
#endif
|
||||
|
||||
if (!(sr -> active()))
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqipersongrpzone, "sslroot not active... exiting!");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// make listen
|
||||
Person *us = sr -> getOwnCert();
|
||||
if (us != NULL)
|
||||
{
|
||||
if (flags & PQIPERSON_NO_SSLLISTENER)
|
||||
{
|
||||
pqil = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
pqil = new pqissllistener(us -> localaddr);
|
||||
}
|
||||
#ifdef PQI_USE_PROXY
|
||||
pqiudpl = new pqiudplistener((p3udpproxy *) p3p,
|
||||
us -> localaddr);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqipersongrpzone, "No Us! what are we!");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
// now we run through any certificates
|
||||
// already made... and reactivate them.
|
||||
std::list<cert *>::iterator it;
|
||||
std::list<cert *> &clist = sr -> getCertList();
|
||||
for(it = clist.begin(); it != clist.end(); it++)
|
||||
{
|
||||
cert *c = (*it);
|
||||
|
||||
c -> InUse(false);
|
||||
c -> Listening(false);
|
||||
c -> Connected(false);
|
||||
|
||||
// make new
|
||||
if (c -> Accepted())
|
||||
{
|
||||
cert_accept(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// finally lets
|
||||
|
||||
|
||||
// add in a tunneltest.
|
||||
// register the packet creations.
|
||||
//addService(new PQTStst());
|
||||
//registerTunnelType(PQI_TUNNEL_TST_TYPE, createPQTStst);
|
||||
|
||||
|
||||
#ifdef PQI_USE_PROXY
|
||||
addService(p3p);
|
||||
registerTunnelType(PQI_TUNNEL_PROXY_TYPE, createPQTunnelProxy);
|
||||
registerTunnelInitType(PQI_TUNNEL_PROXY_TYPE, createPQTunnelProxyInit);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int pqipersongrp::tick()
|
||||
{
|
||||
/* could limit the ticking of listener / tunnels to 1/sec...
|
||||
@ -192,9 +106,6 @@ int pqipersongrp::tick()
|
||||
{
|
||||
pqil -> tick();
|
||||
}
|
||||
#ifdef PQI_USE_PROXY
|
||||
pqiudpl->tick();
|
||||
#endif
|
||||
int i = 0;
|
||||
|
||||
if (tickServiceSend()) i = 1;
|
||||
@ -206,166 +117,59 @@ int pqipersongrp::tick()
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int pqipersongrp::status()
|
||||
{
|
||||
if (pqil)
|
||||
{
|
||||
pqil -> status();
|
||||
}
|
||||
#ifdef PQI_USE_PROXY
|
||||
//pqiudpl->status();
|
||||
#endif
|
||||
return pqihandler::status();
|
||||
}
|
||||
|
||||
// control the connections.
|
||||
|
||||
int pqipersongrp::cert_accept(cert *a)
|
||||
/* Initialise pqilistener */
|
||||
int pqipersongrp::init_listener()
|
||||
{
|
||||
if (a -> InUse())
|
||||
/* extract our information from the p3ConnectMgr */
|
||||
if (initFlags & PQIPERSON_NO_LISTENER)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone,
|
||||
"pqipersongrp::cert_accept() Cert in Use!");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
{
|
||||
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);
|
||||
|
||||
/* 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);
|
||||
|
||||
#ifdef PQI_USE_PROXY
|
||||
pqiudpproxy *pqipxy = new pqiudpproxy(a, (p3udpproxy *) p3p, NULL);
|
||||
pqissludp *pqius = new pqissludp(a, pqip, pqipxy);
|
||||
pqiconnect *pqiusc = new pqiconnect(pqius);
|
||||
|
||||
// add a ssl + proxy interface.
|
||||
// Add Proxy First.
|
||||
pqip -> addChildInterface(pqiusc);
|
||||
#endif
|
||||
|
||||
a -> InUse(true);
|
||||
a -> Accepted(true);
|
||||
|
||||
|
||||
// setup no behaviour. (no remote address)
|
||||
|
||||
// attach to pqihandler
|
||||
SearchModule *sm = new SearchModule();
|
||||
sm -> peerid = a->PeerId();
|
||||
sm -> pqi = pqip;
|
||||
sm -> sp = secpolicy_create();
|
||||
|
||||
// reset it to start it working.
|
||||
pqis -> reset();
|
||||
|
||||
|
||||
return AddSearchModule(sm);
|
||||
}
|
||||
|
||||
int pqipersongrp::cert_deny(cert *a)
|
||||
{
|
||||
std::map<std::string, 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;
|
||||
pqiperson *p = (pqiperson *) mod -> pqi;
|
||||
if (a->PeerId() == p->PeerId())
|
||||
{
|
||||
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 pqipersongrp::cert_auto(cert *a, bool b)
|
||||
{
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
if (b)
|
||||
{
|
||||
cert_accept(a);
|
||||
// find module.
|
||||
for(it = mods.begin(); it != mods.end();it++)
|
||||
{
|
||||
SearchModule *mod = it -> second;
|
||||
pqiperson *p = (pqiperson *) mod -> pqi;
|
||||
if (a->PeerId() == p->PeerId())
|
||||
{
|
||||
p -> autoconnect(b);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
pqil = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
a -> Manual(true);
|
||||
cert_deny(a);
|
||||
/* extract details from
|
||||
*/
|
||||
peerConnectState state;
|
||||
mConnMgr->getOwnNetStatus(state);
|
||||
|
||||
pqil = createListener(state.localaddr);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int pqipersongrp::restart_listener()
|
||||
{
|
||||
// stop it,
|
||||
// change the address.
|
||||
// restart.
|
||||
cert *own = sslr -> getOwnCert();
|
||||
if (pqil)
|
||||
{
|
||||
peerConnectState state;
|
||||
mConnMgr->getOwnNetStatus(state);
|
||||
|
||||
pqil -> resetlisten();
|
||||
pqil -> setListenAddr(own -> localaddr);
|
||||
pqil -> setListenAddr(state.localaddr);
|
||||
pqil -> setuplisten();
|
||||
}
|
||||
#ifdef PQI_USE_PROXY
|
||||
pqiudpl -> resetlisten();
|
||||
pqiudpl -> setListenAddr(own -> localaddr);
|
||||
pqiudpl -> setuplisten();
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int pqipersongrp::setConfig(p3GeneralConfig *cfg)
|
||||
{
|
||||
config = cfg;
|
||||
}
|
||||
|
||||
static const std::string pqih_ftr("PQIH_FTR");
|
||||
|
||||
int pqipersongrp::save_config()
|
||||
@ -373,15 +177,21 @@ int pqipersongrp::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));
|
||||
if (config)
|
||||
{
|
||||
config -> setSetting(pqih_ftr, std::string(line));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int pqipersongrp::load_config()
|
||||
{
|
||||
std::string line = sslr -> getSetting(pqih_ftr);
|
||||
std::string line;
|
||||
if (config)
|
||||
{
|
||||
line = config -> getSetting(pqih_ftr);
|
||||
}
|
||||
|
||||
float mri, mro, miri, miro;
|
||||
|
||||
if (4 == sscanf(line.c_str(), "%f %f %f %f", &mri, &mro, &miri, &miro))
|
||||
@ -406,3 +216,195 @@ int pqipersongrp::load_config()
|
||||
}
|
||||
|
||||
|
||||
void pqipersongrp::statusChange(const std::list<pqipeer> &plist)
|
||||
{
|
||||
|
||||
/* iterate through, only worry about the friends */
|
||||
std::list<pqipeer>::const_iterator it;
|
||||
for(it = plist.begin(); it != plist.end(); it++)
|
||||
{
|
||||
if (it->state & RS_PEER_S_FRIEND)
|
||||
{
|
||||
/* now handle add/remove */
|
||||
if ((it->actions & RS_PEER_NEW)
|
||||
|| (it->actions & RS_PEER_MOVED))
|
||||
{
|
||||
addPeer(it->id);
|
||||
}
|
||||
|
||||
if (it->actions & RS_PEER_CONNECT_REQ)
|
||||
{
|
||||
connectPeer(it->id);
|
||||
}
|
||||
}
|
||||
else /* Not Friend */
|
||||
{
|
||||
if (it->actions & RS_PEER_MOVED)
|
||||
{
|
||||
removePeer(it->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int pqipersongrp::addPeer(std::string id)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqipersongrp::addPeer() PeerId: " << id;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, out.str());
|
||||
}
|
||||
|
||||
std::cerr << " pqipersongrp::addPeer() id: " << id;
|
||||
std::cerr << std::endl;
|
||||
|
||||
SearchModule *sm = NULL;
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
it = mods.find(id);
|
||||
if (it != mods.end())
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone,
|
||||
"pqipersongrp::addPeer() Peer already in Use!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pqiperson *pqip = createPerson(id, pqil);
|
||||
|
||||
// attach to pqihandler
|
||||
sm = new SearchModule();
|
||||
sm -> peerid = id;
|
||||
sm -> pqi = pqip;
|
||||
sm -> sp = secpolicy_create();
|
||||
|
||||
// reset it to start it working.
|
||||
pqip -> reset();
|
||||
|
||||
return AddSearchModule(sm);
|
||||
}
|
||||
|
||||
|
||||
int pqipersongrp::removePeer(std::string id)
|
||||
{
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
|
||||
std::cerr << " pqipersongrp::removePeer() id: " << id;
|
||||
std::cerr << std::endl;
|
||||
|
||||
it = mods.find(id);
|
||||
if (it != mods.end())
|
||||
{
|
||||
SearchModule *mod = it->second;
|
||||
RemoveSearchModule(mod);
|
||||
secpolicy_delete(mod -> sp);
|
||||
pqiperson *p = (pqiperson *) mod -> pqi;
|
||||
p -> reset();
|
||||
delete p;
|
||||
mods.erase(it);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqipersongrp::connectPeer(std::string id)
|
||||
{
|
||||
/* get status from p3connectMgr */
|
||||
std::cerr << " pqipersongrp::connectPeer() id: " << id << " does nothing yet! ";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
it = mods.find(id);
|
||||
if (it == mods.end())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/* get the connect attempt details from the p3connmgr... */
|
||||
SearchModule *mod = it->second;
|
||||
pqiperson *p = (pqiperson *) mod -> pqi;
|
||||
|
||||
|
||||
/* get address from p3connmgr */
|
||||
if (!mConnMgr)
|
||||
return 0;
|
||||
|
||||
struct sockaddr_in addr;
|
||||
uint32_t type;
|
||||
|
||||
mConnMgr->connectAttempt(id, addr, type);
|
||||
|
||||
uint32_t ptype;
|
||||
if (type & RS_NET_CONN_TCP_ALL)
|
||||
{
|
||||
ptype = PQI_CONNECT_TCP;
|
||||
}
|
||||
else if (type & RS_NET_CONN_UDP_ALL)
|
||||
{
|
||||
ptype = PQI_CONNECT_UDP;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
||||
p->connect(ptype, addr);
|
||||
|
||||
/* */
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool pqipersongrp::notifyConnect(std::string id, bool success)
|
||||
{
|
||||
if (mConnMgr)
|
||||
mConnMgr->connectResult(id, success, 0);
|
||||
|
||||
return (NULL != mConnMgr);
|
||||
}
|
||||
|
||||
/******************************** DUMMY Specific features ***************************/
|
||||
|
||||
#include "pqi/pqibin.h"
|
||||
|
||||
pqilistener * pqipersongrpDummy::createListener(struct sockaddr_in laddr)
|
||||
{
|
||||
pqilistener *listener = new pqilistener();
|
||||
return listener;
|
||||
}
|
||||
|
||||
|
||||
pqiperson * pqipersongrpDummy::createPerson(std::string id, pqilistener *listener)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqipersongrpDummy::createPerson() PeerId: " << id;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, out.str());
|
||||
}
|
||||
|
||||
pqiperson *pqip = new pqiperson(id, this);
|
||||
|
||||
// TCP
|
||||
NetBinDummy *d1 = new NetBinDummy(pqip, id, PQI_CONNECT_TCP);
|
||||
|
||||
RsSerialiser *rss = new RsSerialiser();
|
||||
rss->addSerialType(new RsFileItemSerialiser());
|
||||
rss->addSerialType(new RsCacheItemSerialiser());
|
||||
rss->addSerialType(new RsServiceSerialiser());
|
||||
|
||||
pqiconnect *pqic = new pqiconnect(rss, d1);
|
||||
|
||||
pqip -> addChildInterface(PQI_CONNECT_TCP, pqic);
|
||||
|
||||
// UDP.
|
||||
NetBinDummy *d2 = new NetBinDummy(pqip, id, PQI_CONNECT_UDP);
|
||||
|
||||
RsSerialiser *rss2 = new RsSerialiser();
|
||||
rss2->addSerialType(new RsFileItemSerialiser());
|
||||
rss2->addSerialType(new RsCacheItemSerialiser());
|
||||
rss2->addSerialType(new RsServiceSerialiser());
|
||||
|
||||
pqiconnect *pqic2 = new pqiconnect(rss2, d2);
|
||||
|
||||
pqip -> addChildInterface(PQI_CONNECT_UDP, pqic2);
|
||||
|
||||
return pqip;
|
||||
}
|
||||
|
||||
/******************************** DUMMY Specific features ***************************/
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* "$Id: pqipersongrp.h,v 1.13 2007-02-18 21:46:49 rmf24 Exp $"
|
||||
* libretroshare/src/pqi: pqipersongrp.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,13 +24,15 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef MRK_PQI_PERSON_HANDLER_HEADER
|
||||
#define MRK_PQI_PERSON_HANDLER_HEADER
|
||||
|
||||
#include "pqi/pqihandler.h"
|
||||
#include "pqi/pqiperson.h"
|
||||
#include "pqi/pqilistener.h"
|
||||
#include "pqi/pqiservice.h"
|
||||
#include "pqi/pqimonitor.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
|
||||
|
||||
// So this is a specific implementation
|
||||
@ -40,61 +42,46 @@
|
||||
// as an added bonus, we are going to
|
||||
// make this a pqitunnelserver, to which services can be attached.
|
||||
|
||||
#ifdef PQI_USE_PROXY
|
||||
class p3proxy;
|
||||
class pqiudplistener;
|
||||
#endif
|
||||
|
||||
|
||||
const unsigned long PQIPERSON_NO_SSLLISTENER = 0x0001;
|
||||
const unsigned long PQIPERSON_NO_LISTENER = 0x0001;
|
||||
|
||||
const unsigned long PQIPERSON_ALL_BW_LIMITED = 0x0010;
|
||||
|
||||
#ifdef PQI_USE_DISC
|
||||
class p3disc;
|
||||
#endif
|
||||
|
||||
#ifdef PQI_USE_CHANNELS
|
||||
class p3channel;
|
||||
#endif
|
||||
|
||||
class pqissllistener;
|
||||
|
||||
class pqipersongrp: public pqihandler, public p3ServiceServer
|
||||
class pqipersongrp: public pqihandler, public pqiMonitor, public p3ServiceServer
|
||||
{
|
||||
public:
|
||||
pqipersongrp(SecurityPolicy *, sslroot *sr, unsigned long flags);
|
||||
|
||||
// control the connections.
|
||||
int cert_accept(cert *a);
|
||||
int cert_deny(cert *a);
|
||||
int cert_auto(cert *a, bool b);
|
||||
pqipersongrp(SecurityPolicy *, unsigned long flags);
|
||||
|
||||
/*************************** Setup *************************/
|
||||
/* pqilistener */
|
||||
int init_listener();
|
||||
int restart_listener();
|
||||
|
||||
int setConfig(p3GeneralConfig *cfg);
|
||||
int save_config();
|
||||
int load_config();
|
||||
|
||||
/*************** pqiMonitor callback ***********************/
|
||||
virtual void statusChange(const std::list<pqipeer> &plist);
|
||||
|
||||
/******************* Peer Control **************************/
|
||||
virtual int addPeer(std::string id); /* can be overloaded for testing */
|
||||
int removePeer(std::string id);
|
||||
int connectPeer(std::string id);
|
||||
|
||||
/*** callback from children ****/
|
||||
bool notifyConnect(std::string id, bool success);
|
||||
|
||||
// tick interfaces.
|
||||
virtual int tick();
|
||||
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; }
|
||||
#endif
|
||||
|
||||
#ifdef PQI_USE_CHANNELS
|
||||
p3channel *getP3Channel() { return p3c; }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
/********* FUNCTIONS to OVERLOAD for specialisation ********/
|
||||
virtual pqilistener *createListener(struct sockaddr_in laddr) = 0;
|
||||
virtual pqiperson *createPerson(std::string id, pqilistener *listener) = 0;
|
||||
/********* FUNCTIONS to OVERLOAD for specialisation ********/
|
||||
|
||||
/* Overloaded RsItem Check
|
||||
* checks item->cid vs Person
|
||||
*/
|
||||
@ -106,22 +93,25 @@ virtual int checkOutgoingRsItem(RsItem *item, int global) { return 1; }
|
||||
int tickServiceRecv();
|
||||
int tickServiceSend();
|
||||
|
||||
pqissllistener *pqil;
|
||||
|
||||
sslroot *sslr;
|
||||
|
||||
#ifdef PQI_USE_DISC
|
||||
p3disc *p3d;
|
||||
#endif
|
||||
|
||||
#ifdef PQI_USE_PROXY
|
||||
p3proxy *p3p;
|
||||
pqiudplistener *pqiudpl;
|
||||
#endif
|
||||
#ifdef PQI_USE_CHANNELS
|
||||
p3channel *p3c;
|
||||
#endif
|
||||
pqilistener *pqil;
|
||||
p3GeneralConfig *config;
|
||||
unsigned long initFlags;
|
||||
};
|
||||
|
||||
class pqipersongrpDummy: public pqipersongrp
|
||||
{
|
||||
public:
|
||||
pqipersongrpDummy(SecurityPolicy *pol, unsigned long flags)
|
||||
:pqipersongrp(pol, flags) { return; }
|
||||
|
||||
protected:
|
||||
|
||||
/********* FUNCTIONS to OVERLOAD for specialisation ********/
|
||||
virtual pqilistener *createListener(struct sockaddr_in laddr);
|
||||
virtual pqiperson *createPerson(std::string id, pqilistener *listener);
|
||||
/********* FUNCTIONS to OVERLOAD for specialisation ********/
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // MRK_PQI_PERSON_HANDLER_HEADER
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,376 +0,0 @@
|
||||
/*
|
||||
* "$Id: pqiproxy.h,v 1.7 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_PROXY_HEADER
|
||||
#define MRK_PQI_PROXY_HEADER
|
||||
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
#include "pqi/pqi.h"
|
||||
|
||||
#include "pqi/pqiperson.h"
|
||||
#include "pqi/pqitunnel.h"
|
||||
#include "pqi/pqitunnelproxy.h"
|
||||
|
||||
class cert;
|
||||
|
||||
class pqiproxy;
|
||||
class pqifilter;
|
||||
|
||||
class p3disc;
|
||||
|
||||
// PQItem derived classes.
|
||||
class PQTunnelInit;
|
||||
class PQTunnelProxyInit;
|
||||
|
||||
class PQTunnel;
|
||||
class PQTunnelProxy;
|
||||
|
||||
/*
|
||||
* #ifdef PQI_USE_XPGP
|
||||
* #include "xpgpcert.h"
|
||||
*/
|
||||
|
||||
class p3proxy : public PQTunnelService
|
||||
{
|
||||
public:
|
||||
|
||||
p3proxy(p3disc *p)
|
||||
:PQTunnelService(PQI_TUNNEL_PROXY_TYPE), p3d(p)
|
||||
{
|
||||
sroot = getSSLRoot();
|
||||
return;
|
||||
}
|
||||
|
||||
virtual ~p3proxy() { return; }
|
||||
|
||||
// PQTunnelService Overloading.
|
||||
virtual int receive(PQTunnel *);
|
||||
virtual PQTunnel * send();
|
||||
|
||||
virtual int receive(PQTunnelInit *);
|
||||
virtual PQTunnelInit * sendInit();
|
||||
|
||||
// interface to pqiproxy.
|
||||
int attach(pqiproxy *p, cert *c);
|
||||
int detach(pqiproxy *p, cert *c);
|
||||
|
||||
int listen(pqiproxy *p, cert *c);
|
||||
int stoplistening(pqiproxy *p, cert *c);
|
||||
int stopconnecting(pqiproxy *p, cert *c);
|
||||
|
||||
int reset(pqiproxy *p, cert *c);
|
||||
|
||||
int outgoingpkt(pqiproxy *p, cert *, void *d, int size);
|
||||
int incomingpkt(pqiproxy *p, void *d, int maxsize);
|
||||
|
||||
// overloaded from many sources.
|
||||
virtual int tick();
|
||||
|
||||
int status();
|
||||
|
||||
int connectattempt(pqiproxy*, cert*);
|
||||
int connectattempt();
|
||||
int nextconnectattempt(cert *, cert *);
|
||||
|
||||
protected:
|
||||
|
||||
// Fn to translate the sig to a cert.
|
||||
bool filter(PQTunnelProxy *in);
|
||||
|
||||
cert *findcert(certsign &cs);
|
||||
|
||||
PQTunnelProxyInit *createProxyInit(cert *dest, cert *proxy);
|
||||
PQTunnelProxy *createProxyPkt(cert *dest, cert *proxy, long nextseq,
|
||||
const char *data, int size);
|
||||
|
||||
// Register Connections for which we are the Proxy.
|
||||
// (only channels registered this way can send proxy packets)
|
||||
int registerProxyConnection(cert *src, cert *proxy,
|
||||
cert *dest, PQTunnelProxyInit *pinit);
|
||||
// indicates if a proxy connection has been established.
|
||||
int isConnection(cert *src, cert *dest);
|
||||
|
||||
// Init Proxy Connections.
|
||||
int respondConnect(cert *o, cert *p, PQTunnelProxyInit *in);
|
||||
int completeConnect(cert *o, cert *p, PQTunnelProxyInit *in);
|
||||
int endConnect(cert *o, cert *p, PQTunnelProxyInit *in);
|
||||
|
||||
// process incoming.
|
||||
virtual int processincoming();
|
||||
|
||||
// Overload to provide alternative behaviour.
|
||||
// These fns are called from receive(PQTunnel *);
|
||||
virtual int connectionCompletedAsProxy(cert *n1, cert *n2) { return 1; }
|
||||
virtual int connectionCompletedAsPeer(cert *proxy, cert *peer) { return 1; }
|
||||
|
||||
|
||||
// Overload to provide alternative behaviour.
|
||||
// These fns are called from receive(PQTunnel *);
|
||||
virtual int receiveAsProxy(PQTunnelProxy* pqtp, cert *src, cert *dest);
|
||||
virtual int receiveAsDestination(PQTunnelProxy* pqtp,
|
||||
cert *src, cert *from, cert *dest, pqiproxy *pqip);
|
||||
|
||||
virtual int receiveAsError(PQTunnelProxy* pqtp, cert *src, cert *from, cert *dest);
|
||||
|
||||
// Proxy Control functions.
|
||||
int sendProxyInit(cert *c);
|
||||
|
||||
// Fn to send
|
||||
int sendEndProxyConnectionPkt(cert *other, cert *proxy);
|
||||
|
||||
bool active;
|
||||
|
||||
// the registered proxies.
|
||||
// All of these maps are
|
||||
// indexed by the destination, not the proxy.
|
||||
// which is the second cert is some cases.
|
||||
|
||||
std::map<cert *, pqiproxy *> proxymap;
|
||||
std::list<cert *> listenqueue; // the ones to listen for.
|
||||
std::list<cert *> connectqueue; // the ones to attempt to connect.
|
||||
std::map<cert *, cert *> initmap; // ones we sent init, wait for init.
|
||||
std::map<cert *, cert *> replymap; // ones that need a auth reply.
|
||||
std::map<cert *, cert *> connectionmap;
|
||||
std::map<cert *, cert *> lastproxymap;
|
||||
std::map<cert *, unsigned long> connecttimemap; // timeout map.
|
||||
std::map<cert *, bool> passivemap; // who inited connection.
|
||||
|
||||
// double direction map.
|
||||
//std::map<pqiproxy *, ChanId> outmap;
|
||||
std::map<pqiproxy *, std::list<PQTunnelProxy *> > inqueue;
|
||||
|
||||
// filters. (remove bad packets/cache data).
|
||||
std::list<pqifilter *> filters;
|
||||
|
||||
// Map of the connections we are proxy for.
|
||||
std::map<std::pair<cert *, cert *>, int> proxyconnect;
|
||||
|
||||
p3disc *p3d; // needed to find proxies.
|
||||
sslroot *sroot; // for certificate references.
|
||||
|
||||
// input fn for details.
|
||||
int addOutInitPkt(PQTunnelInit *pkt);
|
||||
|
||||
std::list<PQTunnel *> outPkts;
|
||||
std::list<PQTunnelInit *> outInitPkts;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// pqiconnect, derives from pqistreamer/PQInterface.
|
||||
//
|
||||
// this class needs to provide.
|
||||
// 1) read/write data.
|
||||
// 2) connect functions.
|
||||
|
||||
// base interface for pqiproxy....
|
||||
class pqiproxy
|
||||
{
|
||||
public:
|
||||
pqiproxy(cert *c, p3proxy *l)
|
||||
:sslcert(c), p3p(l) { return; }
|
||||
virtual ~pqiproxy() { return; }
|
||||
|
||||
// The interface to p3proxy.
|
||||
virtual int notifyEvent(int type) = 0;
|
||||
|
||||
// notification from p3proxy.
|
||||
virtual int connected(bool active) = 0;
|
||||
virtual int disconnected() = 0;
|
||||
|
||||
protected:
|
||||
cert *sslcert;
|
||||
p3proxy *p3p;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* use a common peer as a proxy, to pass messages
|
||||
* between proxied peers.
|
||||
*/
|
||||
|
||||
class pqipeerproxy: public pqiproxy, public NetBinInterface
|
||||
{
|
||||
public:
|
||||
pqipeerproxy(cert *c, p3proxy *l, PQInterface *parent);
|
||||
virtual ~pqipeerproxy();
|
||||
|
||||
// Net Interface.
|
||||
virtual int connectattempt();
|
||||
virtual int listen();
|
||||
virtual int stoplistening();
|
||||
virtual int reset();
|
||||
virtual int disconnect();
|
||||
|
||||
// Overloaded from PQInterface
|
||||
virtual int status();
|
||||
virtual int tick();
|
||||
virtual cert * getContact();
|
||||
|
||||
// Bin Interface.
|
||||
virtual int senddata(void*, int);
|
||||
virtual int readdata(void*, int);
|
||||
virtual int netstatus();
|
||||
virtual int isactive();
|
||||
virtual bool moretoread();
|
||||
virtual bool cansend();
|
||||
|
||||
// The interface to p3proxy.
|
||||
virtual int notifyEvent(int type);
|
||||
|
||||
// notification from p3proxy.
|
||||
virtual int connected(bool active);
|
||||
virtual int disconnected();
|
||||
|
||||
protected:
|
||||
|
||||
/* data */
|
||||
//p3proxy *p3p;
|
||||
|
||||
bool active;
|
||||
int connect_mode;
|
||||
|
||||
void *pkt;
|
||||
int maxpktlen;
|
||||
int pktlen;
|
||||
int pktn;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* Documenting the virtual (proxy) pqi interface.
|
||||
*
|
||||
* This is used to create proxy interface
|
||||
* for people behind firewalls.
|
||||
*
|
||||
* There are two options for such an
|
||||
* interface.
|
||||
* 1) Encrypted Tunneling - This has the
|
||||
* the advantage/disadvantage that it
|
||||
* allows multiple layers of proxying,
|
||||
* and very private.
|
||||
*
|
||||
* 2) Open Proxying - This lets people
|
||||
* see the data, and allows restriction to one
|
||||
* layer. This option allow the proxier,
|
||||
* to collect the files passing through.
|
||||
* (benefit for allowing proxying).
|
||||
*
|
||||
* As this option will less impact on the
|
||||
* persons bandwidth, and give them some
|
||||
* benefit, it'll be implemented first.
|
||||
*
|
||||
* The data will be saved in a cache,
|
||||
* with a first in, first out policy,
|
||||
*
|
||||
* maybe show a window of cached files,
|
||||
* and allow the user to save any from
|
||||
* a list.
|
||||
*
|
||||
* So to do this we need
|
||||
* i) a cache system.
|
||||
* ii) extra message types to indicate
|
||||
* proxied files, and searches etc.
|
||||
* iii) a proxy server, to handle proxy messages.
|
||||
*
|
||||
* actually, this class will need to
|
||||
*
|
||||
* a proxy interface in someway or another.
|
||||
*
|
||||
*
|
||||
* P1 PROXY P2
|
||||
* requests a
|
||||
* proxy interface.
|
||||
* --------->
|
||||
* end attempt <----- IF Not
|
||||
* Available.
|
||||
*
|
||||
* else ---------------> Check for proxy/person auth
|
||||
* end attempt <------ cancel ------- If Not Auth.
|
||||
*
|
||||
* else, if allowed.
|
||||
* build proxy server.
|
||||
* Build proxy <------ setup ---------- send okay
|
||||
* server connection.
|
||||
*
|
||||
* pqissl.
|
||||
* -> proxy interface.
|
||||
* Send()
|
||||
* return proxymsg locally
|
||||
* pulled by proxy server.
|
||||
*
|
||||
* ps -> send proxy msg
|
||||
* to correct pqissl.
|
||||
* ----------> popped out to
|
||||
* the proxy server.
|
||||
* if file cache.
|
||||
* redirect ------> recieved by pqissl.
|
||||
* pulled by proxy server.
|
||||
*
|
||||
* proxy server
|
||||
*
|
||||
* all proxied information is
|
||||
* going to be signed/or encrypted.
|
||||
*
|
||||
* very simple - that is the only
|
||||
* necessary change.
|
||||
*
|
||||
* proxy msg.
|
||||
* ---------------------
|
||||
* type : init
|
||||
* end
|
||||
* msg (signed)
|
||||
* tunnelled (includes init of ssl.)
|
||||
* dest cert signature:
|
||||
*
|
||||
* encryption/signature mode.
|
||||
*
|
||||
* signature len:
|
||||
* signature:
|
||||
*
|
||||
* data len:
|
||||
* data
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* is this the right place to add it?
|
||||
* or is pqistreamer the answer.
|
||||
*
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -49,13 +49,10 @@
|
||||
|
||||
|
||||
#define WAITING_NOT 0
|
||||
#define WAITING_PROXY_CONNECT 1
|
||||
#define WAITING_LOCAL_ADDR 2
|
||||
#define WAITING_REMOTE_ADDR 3
|
||||
#define WAITING_SOCK_CONNECT 4
|
||||
#define WAITING_SSL_CONNECTION 5
|
||||
#define WAITING_SSL_AUTHORISE 6
|
||||
#define WAITING_FAIL_INTERFACE 7
|
||||
#define WAITING_SOCK_CONNECT 1
|
||||
#define WAITING_SSL_CONNECTION 2
|
||||
#define WAITING_SSL_AUTHORISE 3
|
||||
#define WAITING_FAIL_INTERFACE 4
|
||||
|
||||
|
||||
#define PQISSL_PASSIVE 0x00
|
||||
@ -93,63 +90,14 @@ class cert;
|
||||
|
||||
class pqissllistener;
|
||||
|
||||
#if 0 /* REMOVING pqissllistener */
|
||||
|
||||
class pqissllistener
|
||||
{
|
||||
public:
|
||||
|
||||
pqissllistener(struct sockaddr_in addr);
|
||||
|
||||
int addlistenaddr(cert *c, pqissl *acc);
|
||||
int removeListenPort(cert *c);
|
||||
|
||||
int setListenAddr(struct sockaddr_in addr);
|
||||
int setuplisten();
|
||||
int resetlisten();
|
||||
|
||||
int acceptconnection();
|
||||
int continueaccepts();
|
||||
int continueSSL(SSL *ssl, bool);
|
||||
int continueSocket(int fd, bool);
|
||||
|
||||
//int connectCertExchange(cert *);
|
||||
//
|
||||
|
||||
|
||||
int tick();
|
||||
int status();
|
||||
|
||||
private:
|
||||
|
||||
// fn to get cert, anyway
|
||||
int Extract_Failed_SSL_Certificate(SSL *ssl, struct sockaddr_in *inaddr);
|
||||
|
||||
struct sockaddr_in raddr;
|
||||
struct sockaddr_in laddr;
|
||||
socklen_t addrlen;
|
||||
|
||||
bool active;
|
||||
int lsock;
|
||||
cert *localcert;
|
||||
std::map<cert *, pqissl *> listenaddr;
|
||||
std::list<SSL *> incoming_ssl;
|
||||
std::list<int> incoming_skts;
|
||||
|
||||
sslroot *sslccr;
|
||||
};
|
||||
|
||||
|
||||
#endif /* removing pqisllistener */
|
||||
|
||||
class pqissl: public NetBinInterface
|
||||
{
|
||||
public:
|
||||
pqissl(cert *c, pqissllistener *l, PQInterface *parent);
|
||||
pqissl(pqissllistener *l, PQInterface *parent);
|
||||
virtual ~pqissl();
|
||||
|
||||
// NetInterface
|
||||
virtual int connectattempt();
|
||||
virtual int connect(struct sockaddr_in raddr);
|
||||
virtual int listen();
|
||||
virtual int stoplistening();
|
||||
virtual int reset();
|
||||
@ -165,6 +113,7 @@ virtual int netstatus();
|
||||
virtual int isactive();
|
||||
virtual bool moretoread();
|
||||
virtual bool cansend();
|
||||
virtual std::string gethash(); /* not used here */
|
||||
virtual bool bandwidthLimited();
|
||||
|
||||
protected:
|
||||
@ -177,14 +126,9 @@ protected:
|
||||
int ConnectAttempt();
|
||||
int waiting;
|
||||
|
||||
// These first five fns are overloaded for udp/etc connections.
|
||||
virtual int Reattempt_Connection();
|
||||
virtual int Request_Proxy_Connection();
|
||||
virtual int Check_Proxy_Connection();
|
||||
virtual int Request_Local_Address();
|
||||
virtual int Determine_Local_Address();
|
||||
virtual int Determine_Remote_Address();
|
||||
virtual int Failed_Connection();
|
||||
|
||||
// These two fns are overloaded for udp/etc connections.
|
||||
virtual int Initiate_Connection();
|
||||
virtual int Basic_Connection_Complete();
|
||||
|
||||
@ -223,14 +167,9 @@ virtual int net_internal_fcntl_nonblock(int fd) { return unix_fcntl_nonblock(fd)
|
||||
SSL *ssl_connection;
|
||||
int sockfd;
|
||||
|
||||
cert *sslcert;
|
||||
sslroot *sslccr;
|
||||
|
||||
pqissllistener *pqil;
|
||||
|
||||
struct sockaddr_in remote_addr;
|
||||
|
||||
|
||||
void *readpkt;
|
||||
int pktlen;
|
||||
|
||||
|
@ -503,19 +503,18 @@ pqissllistener::~pqissllistener()
|
||||
return;
|
||||
}
|
||||
|
||||
int pqissllistener::addlistenaddr(cert *c, pqissl *acc)
|
||||
int pqissllistener::addlistenaddr(std::string id, pqissl *acc)
|
||||
{
|
||||
std::map<cert *, pqissl *>::iterator it;
|
||||
std::map<std::string, pqissl *>::iterator it;
|
||||
|
||||
std::ostringstream out;
|
||||
|
||||
out << "Adding to Cert Listening Addresses:" << std::endl;
|
||||
sslccr -> printCertificate(c, out);
|
||||
out << "Adding to Cert Listening Addresses Id: " << id << std::endl;
|
||||
out << "Current Certs:" << std::endl;
|
||||
for(it = listenaddr.begin(); it != listenaddr.end(); it++)
|
||||
{
|
||||
sslccr -> printCertificate(it -> first, out);
|
||||
if (sslccr -> compareCerts(c, it -> first) == 0)
|
||||
out << id << std::endl;
|
||||
if (it -> first == id)
|
||||
{
|
||||
out << "pqissllistener::addlistenaddr()";
|
||||
out << "Already listening for Certificate!";
|
||||
@ -530,20 +529,20 @@ int pqissllistener::addlistenaddr(cert *c, pqissl *acc)
|
||||
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str());
|
||||
|
||||
// not there can accept it!
|
||||
listenaddr[c] = acc;
|
||||
listenaddr[id] = acc;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqissllistener::removeListenPort(cert *c)
|
||||
int pqissllistener::removeListenPort(std::string id)
|
||||
{
|
||||
// check where the connection is coming from.
|
||||
// if in list of acceptable addresses,
|
||||
//
|
||||
// check if in list.
|
||||
std::map<cert *, pqissl *>::iterator it;
|
||||
std::map<std::string, pqissl *>::iterator it;
|
||||
for(it = listenaddr.begin();it!=listenaddr.end();it++)
|
||||
{
|
||||
if (sslccr -> compareCerts(it -> first, c) == 0)
|
||||
if (it->first == id)
|
||||
{
|
||||
listenaddr.erase(it);
|
||||
|
||||
@ -564,14 +563,14 @@ int pqissllistener::status()
|
||||
{
|
||||
pqissllistenbase::status();
|
||||
// print certificates we are listening for.
|
||||
std::map<cert *, pqissl *>::iterator it;
|
||||
std::map<std::string, pqissl *>::iterator it;
|
||||
|
||||
std::ostringstream out;
|
||||
out << "pqissllistener::status(): ";
|
||||
out << " Listening (" << ntohs(laddr.sin_port) << ") for Certs:" << std::endl;
|
||||
for(it = listenaddr.begin(); it != listenaddr.end(); it++)
|
||||
{
|
||||
sslccr -> printCertificate(it -> first, out);
|
||||
out << it -> first << std::endl;
|
||||
}
|
||||
pqioutput(PQL_DEBUG_ALL, pqissllistenzone, out.str());
|
||||
|
||||
@ -612,7 +611,7 @@ int pqissllistener::completeConnection(int fd, SSL *ssl, struct sockaddr_in &rem
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
bool found = false;
|
||||
std::map<cert *, pqissl *>::iterator it;
|
||||
std::map<std::string, pqissl *>::iterator it;
|
||||
|
||||
// Let connected one through as well! if ((npc == NULL) || (npc -> Connected()))
|
||||
if (npc == NULL)
|
||||
@ -633,8 +632,8 @@ int pqissllistener::completeConnection(int fd, SSL *ssl, struct sockaddr_in &rem
|
||||
// check if cert is in our list.....
|
||||
for(it = listenaddr.begin();(found!=true) && (it!=listenaddr.end());)
|
||||
{
|
||||
out << "\tagainst: " << it->first->Name() << std::endl;
|
||||
if (sslccr -> compareCerts(it -> first, npc) == 0)
|
||||
out << "\tagainst: " << it->first << std::endl;
|
||||
if (it -> first == npc->PeerId())
|
||||
{
|
||||
out << "\t\tMatch!";
|
||||
found = true;
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <map>
|
||||
|
||||
#include "pqi/pqi_base.h"
|
||||
#include "pqi/pqilistener.h"
|
||||
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#if defined(PQI_USE_XPGP)
|
||||
@ -53,23 +54,29 @@
|
||||
class pqissl;
|
||||
class cert;
|
||||
|
||||
class pqissllistenbase
|
||||
class pqissllistenbase: public pqilistener
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
pqissllistenbase(struct sockaddr_in addr);
|
||||
virtual ~pqissllistenbase();
|
||||
|
||||
int setListenAddr(struct sockaddr_in addr);
|
||||
int setuplisten();
|
||||
int resetlisten();
|
||||
/*************************************/
|
||||
/* LISTENER INTERFACE **/
|
||||
|
||||
virtual int tick();
|
||||
virtual int status();
|
||||
virtual int setListenAddr(struct sockaddr_in addr);
|
||||
virtual int setuplisten();
|
||||
virtual int resetlisten();
|
||||
|
||||
/*************************************/
|
||||
|
||||
int acceptconnection();
|
||||
int continueaccepts();
|
||||
int continueSSL(SSL *ssl, struct sockaddr_in remote_addr, bool);
|
||||
|
||||
virtual int tick();
|
||||
virtual int status();
|
||||
|
||||
virtual int completeConnection(int sockfd, SSL *in_connection, struct sockaddr_in &raddr) = 0;
|
||||
|
||||
@ -100,8 +107,8 @@ class pqissllistener: public pqissllistenbase
|
||||
pqissllistener(struct sockaddr_in addr);
|
||||
virtual ~pqissllistener();
|
||||
|
||||
int addlistenaddr(cert *c, pqissl *acc);
|
||||
int removeListenPort(cert *c);
|
||||
int addlistenaddr(std::string id, pqissl *acc);
|
||||
int removeListenPort(std::string id);
|
||||
|
||||
//virtual int tick();
|
||||
virtual int status();
|
||||
@ -110,7 +117,7 @@ virtual int completeConnection(int sockfd, SSL *in_connection, struct sockaddr_i
|
||||
|
||||
private:
|
||||
|
||||
std::map<cert *, pqissl *> listenaddr;
|
||||
std::map<std::string, pqissl *> listenaddr;
|
||||
};
|
||||
|
||||
|
||||
|
95
libretroshare/src/pqi/pqisslpersongrp.cc
Normal file
95
libretroshare/src/pqi/pqisslpersongrp.cc
Normal file
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* libretroshare/src/pqi: pqisslpersongrp.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/pqisslpersongrp.h"
|
||||
#include "pqi/pqidebug.h"
|
||||
#include <sstream>
|
||||
|
||||
const int pqipersongrpzone = 354;
|
||||
|
||||
/********************************** SSL Specific features ***************************/
|
||||
|
||||
#include "pqi/pqissl.h"
|
||||
#include "pqi/pqissllistener.h"
|
||||
|
||||
#ifdef PQI_USE_PROXY
|
||||
#include "pqi/pqissludp.h"
|
||||
#endif
|
||||
|
||||
pqilistener * pqisslpersongrp::createListener(struct sockaddr_in laddr)
|
||||
{
|
||||
pqilistener *listener = new pqissllistener(laddr);
|
||||
return listener;
|
||||
}
|
||||
|
||||
pqiperson * pqisslpersongrp::createPerson(std::string id, pqilistener *listener)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqipersongrp::createPerson() PeerId: " << id;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, out.str());
|
||||
}
|
||||
|
||||
pqiperson *pqip = new pqiperson(id, this);
|
||||
pqissl *pqis = new pqissl((pqissllistener *) listener, pqip);
|
||||
|
||||
/* 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(PQI_CONNECT_TCP, pqisc);
|
||||
|
||||
#ifdef PQI_USE_PROXY
|
||||
pqissludp *pqius = new pqissludp(pqip);
|
||||
|
||||
RsSerialiser *rss2 = new RsSerialiser();
|
||||
rss2->addSerialType(new RsFileItemSerialiser());
|
||||
rss2->addSerialType(new RsCacheItemSerialiser());
|
||||
rss2->addSerialType(new RsServiceSerialiser());
|
||||
|
||||
pqiconnect *pqiusc = new pqiconnect(rss2, pqius);
|
||||
|
||||
// add a ssl + proxy interface.
|
||||
// Add Proxy First.
|
||||
pqip -> addChildInterface(PQI_CONNECT_UDP, pqiusc);
|
||||
#endif
|
||||
|
||||
return pqip;
|
||||
}
|
||||
|
||||
|
||||
/********************************** SSL Specific features ***************************/
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* "$Id: pqibin.h,v 1.2 2007-02-18 21:46:49 rmf24 Exp $"
|
||||
* libretroshare/src/pqi: pqisslpersongrp.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
|
||||
@ -23,50 +23,26 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PQI_MONITOR_HEADER
|
||||
#define PQI_MONITOR_HEADER
|
||||
|
||||
/**** Rough sketch of a Monitor class
|
||||
* expect it to change significantly
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
const uint32_t PQI_PEER_STATE_OFFLINE = 0;
|
||||
const uint32_t PQI_PEER_STATE_ONLINE = 1;
|
||||
#ifndef MRK_PQI_SSL_PERSON_HANDLER_HEADER
|
||||
#define MRK_PQI_SSL_PERSON_HANDLER_HEADER
|
||||
|
||||
class pqipeer
|
||||
#include "pqi/pqipersongrp.h"
|
||||
|
||||
class pqisslpersongrp: public pqipersongrp
|
||||
{
|
||||
public:
|
||||
std::string id;
|
||||
std::string name;
|
||||
int state;
|
||||
};
|
||||
pqisslpersongrp(SecurityPolicy *pol, unsigned long flags)
|
||||
:pqipersongrp(pol, flags) { return; }
|
||||
|
||||
class pqimonclient
|
||||
{
|
||||
public:
|
||||
protected:
|
||||
|
||||
pqimonclient() { return; }
|
||||
virtual ~pqimonclient() { return; }
|
||||
|
||||
virtual void monUpdate(const std::list<pqipeer> &plist) = 0;
|
||||
/********* FUNCTIONS to OVERLOAD for specialisation ********/
|
||||
virtual pqilistener *createListener(struct sockaddr_in laddr);
|
||||
virtual pqiperson *createPerson(std::string id, pqilistener *listener);
|
||||
/********* FUNCTIONS to OVERLOAD for specialisation ********/
|
||||
};
|
||||
|
||||
|
||||
class pqimonitor
|
||||
{
|
||||
public:
|
||||
pqimonitor();
|
||||
~pqimonitor();
|
||||
int tick();
|
||||
int addClient(pqimonclient *cli) { clients.push_back(cli); return 1; }
|
||||
|
||||
private:
|
||||
std::list<pqimonclient *> clients;
|
||||
std::list<pqipeer> plist;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#endif // MRK_PQI_SSL_PERSON_HANDLER_HEADER
|
File diff suppressed because it is too large
Load Diff
@ -38,12 +38,6 @@
|
||||
|
||||
#include "pqi/pqissl.h"
|
||||
|
||||
// function for discovering certificates.
|
||||
//int connectForExchange(struct sockaddr_in addr);
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
/* So pqissludp is the special firewall breaking protocol.
|
||||
* This class will implement the basics of streaming
|
||||
* ssl over udp using a tcponudp library....
|
||||
@ -51,59 +45,8 @@
|
||||
*/
|
||||
|
||||
class pqissludp;
|
||||
class pqiudpproxy;
|
||||
class p3udpproxy;
|
||||
class cert;
|
||||
|
||||
/* no such thing as a listener .... actually each one
|
||||
* can receive connections..... its the stateless you see!.
|
||||
*
|
||||
* so pqiudplistener
|
||||
*
|
||||
* will be the support udp listener for proxy connections.
|
||||
* this will be used by the p3proxy for external addresses.
|
||||
*/
|
||||
|
||||
class pqiudplistener
|
||||
{
|
||||
public:
|
||||
|
||||
pqiudplistener(p3udpproxy *p, struct sockaddr_in addr);
|
||||
|
||||
int resetlisten();
|
||||
int setListenAddr(struct sockaddr_in addr);
|
||||
int setuplisten();
|
||||
|
||||
int tick(); /* does below */
|
||||
int status();
|
||||
|
||||
int recvfrom(void *data, int *size, struct sockaddr_in &addr);
|
||||
int reply(void *data, int size, struct sockaddr_in &addr);
|
||||
|
||||
private:
|
||||
int serverStun();
|
||||
bool response(void *data, int size, struct sockaddr_in &addr);
|
||||
int checkExtAddr(struct sockaddr_in &src_addr,
|
||||
void *data, int size, struct sockaddr_in &ext_addr);
|
||||
|
||||
bool generate_stun_pkt(void *stun_pkt, int *len);
|
||||
void *generate_stun_reply(struct sockaddr_in *stun_addr, int *len);
|
||||
|
||||
p3udpproxy *p3u;
|
||||
|
||||
int sockfd;
|
||||
struct sockaddr_in laddr;
|
||||
bool active;
|
||||
|
||||
int laststun, firstattempt, lastattempt;
|
||||
|
||||
/* last stun packet sent out */
|
||||
struct sockaddr_in stun_addr;
|
||||
void *stunpkt;
|
||||
int stunpktlen;
|
||||
};
|
||||
|
||||
|
||||
/* This provides a NetBinInterface, which is
|
||||
* primarily inherited from pqissl.
|
||||
* fns declared here are different -> all others are identical.
|
||||
@ -112,7 +55,7 @@ void *generate_stun_reply(struct sockaddr_in *stun_addr, int *len);
|
||||
class pqissludp: public pqissl
|
||||
{
|
||||
public:
|
||||
pqissludp(cert *c, PQInterface *parent, pqiudpproxy *prxy);
|
||||
pqissludp(PQInterface *parent);
|
||||
virtual ~pqissludp();
|
||||
|
||||
// NetInterface.
|
||||
@ -130,24 +73,13 @@ virtual bool cansend();
|
||||
virtual bool bandwidthLimited() { return true; }
|
||||
|
||||
// pqissludp specific.
|
||||
// These three functions must
|
||||
// be called to initiate a connection;
|
||||
|
||||
int attach(sockaddr_in&);
|
||||
// stun packet handling.
|
||||
void *generate_stun_pkt(struct sockaddr_in *stun_addr, int *len);
|
||||
int getStunReturnedAddr(void *pkt, int len, struct sockaddr_in *stun_addr);
|
||||
// called to initiate a connection;
|
||||
int attach();
|
||||
|
||||
protected:
|
||||
|
||||
virtual int Request_Proxy_Connection();// Overloaded -> all 7.
|
||||
virtual int Check_Proxy_Connection();
|
||||
virtual int Request_Local_Address();
|
||||
virtual int Determine_Local_Address();
|
||||
virtual int Determine_Remote_Address();
|
||||
virtual int Initiate_Connection();
|
||||
virtual int Basic_Connection_Complete();
|
||||
virtual int Reattempt_Connection();
|
||||
|
||||
//protected internal fns that are overloaded for udp case.
|
||||
virtual int net_internal_close(int fd);
|
||||
@ -157,16 +89,7 @@ virtual int net_internal_fcntl_nonblock(int fd);
|
||||
private:
|
||||
|
||||
BIO *tou_bio; // specific to ssludp.
|
||||
pqiudpproxy *udpproxy;
|
||||
|
||||
// are these needed at all??
|
||||
struct sockaddr_in local_addr; // ssludp
|
||||
struct sockaddr_in firewall_addr; // ssludp
|
||||
|
||||
|
||||
struct sockaddr_in stun_addr; //pqissl.
|
||||
int stun_timeout;
|
||||
int stun_attempts;
|
||||
int remote_timeout;
|
||||
int proxy_timeout;
|
||||
int udp_connect_timeout;
|
||||
|
@ -1,264 +0,0 @@
|
||||
/*
|
||||
* "$Id: pqistunner.cc,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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "pqi/pqistunner.h"
|
||||
#include "tcponudp/tou.h"
|
||||
|
||||
#include "pqi/pqidebug.h"
|
||||
#include <sstream>
|
||||
|
||||
const int pqistunzone = 13754;
|
||||
|
||||
|
||||
pqistunner::pqistunner(struct sockaddr_in addr)
|
||||
:sockfd(-1), active(false)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqistunzone,
|
||||
"pqistunner::pqistunner()");
|
||||
|
||||
setListenAddr(addr);
|
||||
setuplisten();
|
||||
|
||||
stunpkt = malloc(1024); /* 20 = size of a stun request */
|
||||
stunpktlen = 1024;
|
||||
}
|
||||
|
||||
|
||||
int pqistunner::setListenAddr(struct sockaddr_in addr)
|
||||
{
|
||||
laddr = addr;
|
||||
// increment the port by 1. (can't open on same)
|
||||
laddr.sin_port = htons(ntohs(laddr.sin_port) + 1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqistunner::resetlisten()
|
||||
{
|
||||
if (sockfd > -1)
|
||||
{
|
||||
/* close it down */
|
||||
std::ostringstream out;
|
||||
out << "pqistunner::resetlisten() Closed stun port";
|
||||
pqioutput(PQL_ALERT, pqistunzone, out.str());
|
||||
|
||||
tou_close(sockfd);
|
||||
sockfd = -1;
|
||||
}
|
||||
active = false;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqistunner::setuplisten()
|
||||
{
|
||||
sockfd = tou_socket(0,0,0);
|
||||
if (0 == tou_bind(sockfd, (struct sockaddr *) &laddr, sizeof(laddr)))
|
||||
{
|
||||
active = true;
|
||||
std::ostringstream out;
|
||||
out << "pqistunner::setuplisten() Attached to Listen Address: ";
|
||||
out << inet_ntoa(laddr.sin_addr) << ":" << ntohs(laddr.sin_port);
|
||||
pqioutput(PQL_ALERT, pqistunzone, out.str());
|
||||
}
|
||||
else
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqistunzone, "pqistunner::setuplisten Failed!");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqistunner::stun(struct sockaddr_in stun_addr)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqistunzone, "pqistunner::stun()");
|
||||
|
||||
/* send out a stun packet -> save in the local variable */
|
||||
if (!active)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqistunzone, "pqistunner::stun() Not Active!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tmplen = stunpktlen;
|
||||
bool done = generate_stun_pkt(stunpkt, &tmplen);
|
||||
if (!done)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqistunzone, "pqistunner::stun() Failed!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* increment the port +1 */
|
||||
stun_addr.sin_port = htons(ntohs(stun_addr.sin_port) + 1);
|
||||
/* and send it off */
|
||||
int sentlen = tou_sendto(sockfd, stunpkt, stunpktlen, 0,
|
||||
(const struct sockaddr *) &stun_addr, sizeof(stun_addr));
|
||||
|
||||
std::ostringstream out;
|
||||
out << "pqistunner::stun() Sent Stun Packet(" << sentlen << ") from:";
|
||||
out << inet_ntoa(laddr.sin_addr) << ":" << ntohs(laddr.sin_port);
|
||||
out << " to:";
|
||||
out << inet_ntoa(stun_addr.sin_addr) << ":" << ntohs(stun_addr.sin_port);
|
||||
pqioutput(PQL_ALERT, pqistunzone, out.str());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool pqistunner::response(void *stun_pkt, int size, struct sockaddr_in &addr)
|
||||
{
|
||||
/* check what type it is */
|
||||
if (size < 28)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((uint16_t *) stun_pkt)[0] != 0x0101)
|
||||
{
|
||||
/* not a response */
|
||||
return false;
|
||||
}
|
||||
|
||||
/* iterate through the packet */
|
||||
/* for now assume the address follows the header directly */
|
||||
/* all stay in netbyteorder! */
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = ((uint32_t *) stun_pkt)[6];
|
||||
addr.sin_port = ((uint16_t *) stun_pkt)[11];
|
||||
|
||||
|
||||
std::ostringstream out;
|
||||
out << "pqistunner::response() Recvd a Stun Response, ext_addr: ";
|
||||
out << inet_ntoa(addr.sin_addr) << ":" << ntohs(addr.sin_port);
|
||||
pqioutput(PQL_ALERT, pqistunzone, out.str());
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/************************** Basic Functionality ******************/
|
||||
int pqistunner::recvfrom(void *data, int *size, struct sockaddr_in &addr)
|
||||
{
|
||||
if (!active)
|
||||
{
|
||||
pqioutput(PQL_ALERT, pqistunzone, "pqistunner::recvfrom() Not Active!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check the socket */
|
||||
socklen_t addrlen = sizeof(addr);
|
||||
|
||||
int rsize = tou_recvfrom(sockfd, data, *size, 0, (struct sockaddr *) &addr, &addrlen);
|
||||
if (rsize > 0)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqistunner::recvfrom() Recvd a Pkt on: ";
|
||||
out << inet_ntoa(laddr.sin_addr) << ":" << ntohs(laddr.sin_port);
|
||||
out << " from: ";
|
||||
out << inet_ntoa(addr.sin_addr) << ":" << ntohs(addr.sin_port);
|
||||
pqioutput(PQL_ALERT, pqistunzone, out.str());
|
||||
|
||||
*size = rsize;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pqistunner::reply(void *data, int size, struct sockaddr_in &addr)
|
||||
{
|
||||
/* so we design a new packet with the external address in it */
|
||||
int pktlen = 0;
|
||||
void *pkt = generate_stun_reply(&addr, &pktlen);
|
||||
|
||||
/* and send it off */
|
||||
int sentlen = tou_sendto(sockfd, pkt, pktlen, 0,
|
||||
(const struct sockaddr *) &addr, sizeof(addr));
|
||||
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqistunner::reply() Replying from: ";
|
||||
out << inet_ntoa(laddr.sin_addr) << ":" << ntohs(laddr.sin_port);
|
||||
out << " to: ";
|
||||
out << inet_ntoa(addr.sin_addr) << ":" << ntohs(addr.sin_port);
|
||||
pqioutput(PQL_ALERT, pqistunzone, out.str());
|
||||
}
|
||||
|
||||
free(pkt);
|
||||
|
||||
/* display status */
|
||||
|
||||
return sentlen;
|
||||
}
|
||||
|
||||
bool pqistunner::generate_stun_pkt(void *stun_pkt, int *len)
|
||||
{
|
||||
if (*len < 20)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* just the header */
|
||||
((uint16_t *) stun_pkt)[0] = 0x0001;
|
||||
((uint16_t *) stun_pkt)[1] = 0x0020; /* only header */
|
||||
/* transaction id - should be random */
|
||||
((uint32_t *) stun_pkt)[1] = 0x0020;
|
||||
((uint32_t *) stun_pkt)[2] = 0x0121;
|
||||
((uint32_t *) stun_pkt)[3] = 0x0111;
|
||||
((uint32_t *) stun_pkt)[4] = 0x1010;
|
||||
*len = 20;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void *pqistunner::generate_stun_reply(struct sockaddr_in *stun_addr, int *len)
|
||||
{
|
||||
/* just the header */
|
||||
void *stun_pkt = malloc(28);
|
||||
((uint16_t *) stun_pkt)[0] = 0x0101;
|
||||
((uint16_t *) stun_pkt)[1] = 0x0028; /* only header + 8 byte addr */
|
||||
/* transaction id - should be random */
|
||||
((uint32_t *) stun_pkt)[1] = 0x0020;
|
||||
((uint32_t *) stun_pkt)[2] = 0x0121;
|
||||
((uint32_t *) stun_pkt)[3] = 0x0111;
|
||||
((uint32_t *) stun_pkt)[4] = 0x1010;
|
||||
/* now add address
|
||||
* 0 1 2 3
|
||||
* <INET> <port>
|
||||
* <inet address>
|
||||
*/
|
||||
|
||||
((uint32_t *) stun_pkt)[6] = stun_addr->sin_addr.s_addr;
|
||||
((uint16_t *) stun_pkt)[11] = stun_addr->sin_port;
|
||||
|
||||
*len = 28;
|
||||
return stun_pkt;
|
||||
}
|
||||
|
||||
|
@ -1,403 +0,0 @@
|
||||
/*
|
||||
* "$Id: pqitunnel.cc,v 1.4 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/pqitunnel.h"
|
||||
|
||||
const int pqitunnelzone = 60478;
|
||||
#include "pqi/pqidebug.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
PQTunnel::PQTunnel(int st)
|
||||
:PQItem(PQI_ITEM_TYPE_TUNNELITEM, st)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTunnel::PQTunnel() Creation...");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PQTunnel::~PQTunnel()
|
||||
{
|
||||
}
|
||||
|
||||
// This is commented out - because
|
||||
// it should never be cloned at this level!
|
||||
//
|
||||
//PQTunnel *PQTunnel::clone()
|
||||
//{
|
||||
// pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
// "PQTunnel::clone");
|
||||
//
|
||||
// PQTunnel *t = new PQTunnel(subtype);
|
||||
// t -> copy(this);
|
||||
// return t;
|
||||
//}
|
||||
|
||||
void PQTunnel::copy(const PQTunnel *src)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTunnel::copy() : Only the Base!");
|
||||
PQItem::copy(src);
|
||||
}
|
||||
|
||||
std::ostream &PQTunnel::print(std::ostream &out)
|
||||
{
|
||||
out << "-------- PQTunnel";
|
||||
PQItem::print(out);
|
||||
|
||||
out << "PQTunnel size:" << getSize();
|
||||
out << "--------" << std::endl;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
//const int PQTunnel::getSize() const
|
||||
//{
|
||||
// return size;
|
||||
//}
|
||||
//
|
||||
//const void *PQTunnel::getData() const
|
||||
//{
|
||||
// return data;
|
||||
//}
|
||||
//
|
||||
//int PQTunnel::out(void *dta, const int n) const
|
||||
//{
|
||||
// pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
// "PQTunnel::out()");
|
||||
//
|
||||
// if ((dta == NULL) || (data == NULL))
|
||||
// {
|
||||
// return -1;
|
||||
// }
|
||||
// if (size == 0)
|
||||
// {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// if (n < size)
|
||||
// return -1;
|
||||
// memcpy(dta, data, size);
|
||||
// return size;
|
||||
//}
|
||||
//
|
||||
//int PQTunnel::in(const void *dta, const int n)
|
||||
//{
|
||||
// pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
// "PQTunnel::in()");
|
||||
//
|
||||
// if (data)
|
||||
// {
|
||||
// if (n != size)
|
||||
// {
|
||||
// free(data);
|
||||
// data = malloc(n);
|
||||
// size = n;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// data = malloc(n);
|
||||
// size = n;
|
||||
// }
|
||||
//
|
||||
// memcpy(data, dta, size);
|
||||
// return 1;
|
||||
//}
|
||||
|
||||
PQTunnelInit::PQTunnelInit(int st)
|
||||
:PQItem(PQI_ITEM_TYPE_TUNNELINITITEM, st), mode(Request)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTunnelInit::PQTunnelInit()");
|
||||
return;
|
||||
}
|
||||
|
||||
PQTunnelInit::~PQTunnelInit()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
PQTunnelInit *PQTunnelInit::clone()
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTunnelInit::clone()");
|
||||
|
||||
PQTunnelInit *ni = new PQTunnelInit(subtype);
|
||||
ni -> copy(this);
|
||||
return ni;
|
||||
}
|
||||
|
||||
void PQTunnelInit::copy(const PQTunnelInit *item)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTunnelInit::copy()");
|
||||
|
||||
PQItem::copy(item);
|
||||
|
||||
mode = item -> mode;
|
||||
}
|
||||
|
||||
std::ostream &PQTunnelInit::print(std::ostream &out)
|
||||
{
|
||||
out << "---- ---- PQTunnelInit" << std::endl;
|
||||
PQItem::print(out);
|
||||
out << "mode: ";
|
||||
switch(mode)
|
||||
{
|
||||
case Request:
|
||||
out << "Request" << std::endl;
|
||||
break;
|
||||
case Connect:
|
||||
out << "Connect" << std::endl;
|
||||
break;
|
||||
case End:
|
||||
out << "End" << std::endl;
|
||||
break;
|
||||
default:
|
||||
out << "Unknown" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
out << "---- ----" << std::endl;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
const int PQTunnelInit::getSize() const
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
int PQTunnelInit::out(void *data, const int size) const
|
||||
{
|
||||
if (size < PQTunnelInit::getSize())
|
||||
return -1;
|
||||
((int *) data)[0] = (int) mode;
|
||||
return PQTunnelInit::getSize();
|
||||
}
|
||||
|
||||
|
||||
int PQTunnelInit::in(const void *data, const int size)
|
||||
{
|
||||
if (size < PQTunnelInit::getSize())
|
||||
return -1;
|
||||
mode = (InitMsg) ((int *) data)[0];
|
||||
return PQTunnelInit::getSize();
|
||||
}
|
||||
|
||||
PQTunnelServer::PQTunnelServer()
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTunnelServer::PQTunnelServer()");
|
||||
|
||||
rrit = services.begin();
|
||||
return;
|
||||
}
|
||||
|
||||
int PQTunnelServer::addService(PQTunnelService *ts)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTunnelServer::addService()");
|
||||
|
||||
std::map<int, PQTunnelService *>::iterator it;
|
||||
it = services.find(ts -> getSubType());
|
||||
if (it != services.end())
|
||||
{
|
||||
// it exists already!
|
||||
return -1;
|
||||
}
|
||||
|
||||
services[ts -> getSubType()] = ts;
|
||||
rrit = services.begin();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int PQTunnelServer::incoming(PQItem *item)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTunnelServer::incoming()");
|
||||
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQTunnelServer::incoming() Service: ";
|
||||
out << item -> subtype << std::endl;
|
||||
out << "Item:" << std::endl;
|
||||
item -> print(out);
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone, out.str());
|
||||
}
|
||||
|
||||
std::map<int, PQTunnelService *>::iterator it;
|
||||
it = services.find(item -> subtype);
|
||||
if (it == services.end())
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTunnelServer::incoming() Service: No Service - deleting");
|
||||
|
||||
// delete it.
|
||||
delete item;
|
||||
|
||||
// it exists already!
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch(item -> type)
|
||||
{
|
||||
case PQI_ITEM_TYPE_TUNNELITEM:
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQTunnelServer::incoming() Sending to";
|
||||
out << it -> second << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone, out.str());
|
||||
|
||||
return (it->second) -> receive((PQTunnel *) item);
|
||||
}
|
||||
break;
|
||||
case PQI_ITEM_TYPE_TUNNELINITITEM:
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQTunnelServer::incoming() Sending to";
|
||||
out << it -> second << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone, out.str());
|
||||
|
||||
return (it->second) -> receive((PQTunnelInit *) item);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
delete item;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PQItem *PQTunnelServer::outgoing()
|
||||
{
|
||||
pqioutput(PQL_DEBUG_ALL, pqitunnelzone,
|
||||
"PQTunnelServer::outgoing()");
|
||||
|
||||
if (rrit != services.end())
|
||||
{
|
||||
rrit++;
|
||||
}
|
||||
else
|
||||
{
|
||||
rrit = services.begin();
|
||||
}
|
||||
|
||||
std::map<int, PQTunnelService *>::iterator sit = rrit;
|
||||
// run to the end.
|
||||
PQItem *item;
|
||||
|
||||
// run through to the end,
|
||||
for(;rrit != services.end();rrit++)
|
||||
{
|
||||
// send out init items first.
|
||||
if (NULL != (item = (rrit -> second) -> sendInit()))
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQTunnelServer::outgoing() Got InitItem From:";
|
||||
out << rrit -> second << std::endl;
|
||||
|
||||
item -> print(out);
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone, out.str());
|
||||
return item;
|
||||
}
|
||||
if (NULL != (item = (rrit -> second) -> send()))
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQTunnelServer::outgoing() Got Item From:";
|
||||
out << rrit -> second << std::endl;
|
||||
|
||||
item -> print(out);
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone, out.str());
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
// from the beginning to where we started.
|
||||
for(rrit = services.begin();rrit != sit; rrit++)
|
||||
{
|
||||
if (NULL != (item = (rrit -> second) -> sendInit()))
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQTunnelServer::outgoing() Got InitItem From:";
|
||||
out << rrit -> second << std::endl;
|
||||
|
||||
item -> print(out);
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone, out.str());
|
||||
return item;
|
||||
}
|
||||
if (NULL != (item = (rrit -> second) -> send()))
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQTunnelServer::outgoing() Got Item From:";
|
||||
out << rrit -> second << std::endl;
|
||||
|
||||
item -> print(out);
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone, out.str());
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int PQTunnelServer::tick()
|
||||
{
|
||||
pqioutput(PQL_DEBUG_ALL, pqitunnelzone,
|
||||
"PQTunnelServer::tick()");
|
||||
|
||||
std::map<int, PQTunnelService *>::iterator it;
|
||||
|
||||
// from the beginning to where we started.
|
||||
for(it = services.begin();it != services.end(); it++)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "PQTunnelServer::service id:" << it -> first;
|
||||
out << " -> Service: " << it -> second;
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_ALL, pqitunnelzone, out.str());
|
||||
|
||||
// now we should actually tick the service.
|
||||
(it -> second) -> tick();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,168 +0,0 @@
|
||||
/*
|
||||
* "$Id: pqitunnel.h,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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef PQI_TUNNEL_HEADER
|
||||
#define PQI_TUNNEL_HEADER
|
||||
|
||||
#include "pqi/pqi_base.h"
|
||||
|
||||
// PQI Tunnel, this is a raw tunnel of data.
|
||||
// The bottom layer on which other 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
|
||||
//
|
||||
|
||||
class PQTunnel: public PQItem
|
||||
{
|
||||
// private copy constructor... prevent copying...
|
||||
PQTunnel(const PQTunnel &) {return; }
|
||||
protected:
|
||||
PQTunnel(int st); // initialise with subtypes.
|
||||
public:
|
||||
virtual ~PQTunnel();
|
||||
|
||||
// copy functions.
|
||||
//virtual PQTunnel *clone() = 0;
|
||||
void copy(const PQTunnel *src);
|
||||
|
||||
// These will be made pure virtual.
|
||||
virtual const int getSize() const { return 0; }
|
||||
virtual int out(void *data, const int size) const { return 0;}
|
||||
virtual int in(const void *data, const int size) { return 0;}
|
||||
// an overloaded
|
||||
// fn that will
|
||||
// mean the building
|
||||
// fns will be attached.
|
||||
// to the class. and
|
||||
// dont have to
|
||||
|
||||
virtual std::ostream &print(std::ostream &out);
|
||||
|
||||
// int size;
|
||||
// void *data;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class PQTunnelInit: public PQItem
|
||||
{
|
||||
// private copy constructor... prevent copying...
|
||||
PQTunnelInit(const PQTunnelInit &) {return; }
|
||||
protected:
|
||||
PQTunnelInit(int st); // initialise with subtypes.
|
||||
public:
|
||||
virtual ~PQTunnelInit();
|
||||
|
||||
// copy functions.
|
||||
virtual PQTunnelInit *clone();
|
||||
void copy(const PQTunnelInit *src);
|
||||
|
||||
std::ostream &print(std::ostream &out);
|
||||
|
||||
// These are overloaded from PQTunnelInit.
|
||||
// these should be able to construct + destruct
|
||||
// the whole packet from here.
|
||||
virtual const int getSize() const;
|
||||
virtual int out(void *data, const int size) const; // write
|
||||
virtual int in(const void *data, const int size); // read,
|
||||
|
||||
enum InitMsg { Request, Connect, End };
|
||||
InitMsg mode;
|
||||
};
|
||||
|
||||
|
||||
class PQTunnelService
|
||||
{
|
||||
protected:
|
||||
|
||||
PQTunnelService(int s) // our type of packets.
|
||||
:subtype(s) { return; }
|
||||
|
||||
virtual ~PQTunnelService() { return; }
|
||||
|
||||
public:
|
||||
//
|
||||
virtual int receive(PQTunnel *) = 0;
|
||||
virtual PQTunnel * send() = 0;
|
||||
|
||||
virtual int receive(PQTunnelInit *) = 0;
|
||||
virtual PQTunnelInit * sendInit() = 0;
|
||||
|
||||
int getSubType() { return subtype; }
|
||||
|
||||
virtual int tick() { return 1; }
|
||||
|
||||
private:
|
||||
int subtype;
|
||||
};
|
||||
|
||||
#include <map>
|
||||
|
||||
|
||||
class PQTunnelServer
|
||||
{
|
||||
public:
|
||||
PQTunnelServer();
|
||||
|
||||
int addService(PQTunnelService *);
|
||||
|
||||
int incoming(PQItem *);
|
||||
PQItem *outgoing();
|
||||
|
||||
int tick();
|
||||
|
||||
private:
|
||||
|
||||
std::map<int, PQTunnelService *> services;
|
||||
std::map<int, PQTunnelService *>::iterator rrit;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // PQI_TUNNEL_HEADER
|
@ -1,389 +0,0 @@
|
||||
/*
|
||||
* "$Id: pqitunnelproxy.cc,v 1.4 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/pqitunnelproxy.h"
|
||||
|
||||
PQTunnel *createPQTunnelProxy(void *d, int n)
|
||||
{
|
||||
return new PQTunnelProxy();
|
||||
}
|
||||
|
||||
|
||||
PQTunnelInit *createPQTunnelProxyInit(void *d, int n)
|
||||
{
|
||||
return new PQTunnelProxyInit();
|
||||
}
|
||||
|
||||
|
||||
PQTunnelProxy::PQTunnelProxy()
|
||||
:PQTunnel(PQI_TUNNEL_PROXY_TYPE), seq(0), size(0), data(NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PQTunnelProxy::~PQTunnelProxy()
|
||||
{
|
||||
if (data)
|
||||
free(data);
|
||||
}
|
||||
|
||||
|
||||
// copy functions.
|
||||
PQTunnelProxy *PQTunnelProxy::clone()
|
||||
{
|
||||
PQTunnelProxy *item = new PQTunnelProxy();
|
||||
item -> copy(this);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PQTunnelProxy::copy(const PQTunnelProxy *item)
|
||||
{
|
||||
// copy parents.
|
||||
PQTunnel::copy(item);
|
||||
|
||||
if (data)
|
||||
free(data);
|
||||
size = 0;
|
||||
size = item -> PQTunnelProxy::getSize() - PQTunnelProxy::getSize();
|
||||
data = malloc(size);
|
||||
|
||||
seq = item -> seq;
|
||||
src = item -> src;
|
||||
dest = item -> dest;
|
||||
//proxy = item -> proxy;
|
||||
|
||||
memcpy(data, item -> data, size);
|
||||
memcpy(sign, item -> sign, PQI_TUNNEL_SIGN_SIZE);
|
||||
}
|
||||
|
||||
|
||||
int PQTunnelProxy::out(void *dta, const int n) const
|
||||
{
|
||||
//std::cerr << "PQTunnelProxy::out()" << std::endl;
|
||||
if (n < PQTunnelProxy::getSize())
|
||||
{
|
||||
std::cerr << "PQTunnelProxy::out() Failed 1" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (PQTunnel::getSize() != PQTunnel::out(dta, n))
|
||||
{
|
||||
std::cerr << "PQTunnelProxy::out() Failed 2" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n < PQTunnelProxy::getSize())
|
||||
return -1;
|
||||
char *ptr = (char *) dta;
|
||||
ptr += PQTunnel::getSize();
|
||||
|
||||
|
||||
memcpy(ptr, &seq, 4);
|
||||
ptr += 4;
|
||||
memcpy(ptr, src.data, CERTSIGNLEN);
|
||||
ptr += CERTSIGNLEN;
|
||||
memcpy(ptr, dest.data, CERTSIGNLEN);
|
||||
ptr += CERTSIGNLEN;
|
||||
|
||||
memcpy(ptr, data, size);
|
||||
ptr += size;
|
||||
|
||||
memcpy(ptr, sign, PQI_TUNNEL_SIGN_SIZE);
|
||||
ptr += PQI_TUNNEL_SIGN_SIZE;
|
||||
|
||||
return PQTunnelProxy::getSize();
|
||||
}
|
||||
|
||||
// The Size
|
||||
int PQTunnelProxy::in(const void *dta, const int n)
|
||||
{
|
||||
//std::cerr << "PQTunnelProxy::in()" << std::endl;
|
||||
|
||||
if ((dta == NULL) || (n < PQTunnelProxy::getSize()))
|
||||
{
|
||||
std::cerr << "PQTunnelProxy::in() Failed 1" << std::endl;
|
||||
if (dta == NULL)
|
||||
std::cerr << "PQTunnelProxy::in() dta==NULL" << std::endl;
|
||||
std::cerr << "PQTunnelProxy::in() is? n: " << n << " < ";
|
||||
std::cerr << PQTunnelProxy::getSize() << std::endl;
|
||||
if (n < PQTunnelProxy::getSize())
|
||||
std::cerr << "PQTunnelProxy::in() not Enough Space" << std::endl;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (PQTunnel::getSize() != PQTunnel::in(dta, n))
|
||||
{
|
||||
std::cerr << "PQTunnelProxy::in() Failed 2" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// range check size.
|
||||
if (data)
|
||||
{
|
||||
if (n != PQTunnelProxy::getSize())
|
||||
{
|
||||
free(data);
|
||||
size = 0;
|
||||
size = n - PQTunnelProxy::getSize();
|
||||
data = malloc(size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size = 0;
|
||||
size = n - PQTunnelProxy::getSize();
|
||||
data = malloc(size);
|
||||
}
|
||||
|
||||
char *ptr = (char *) dta;
|
||||
ptr += PQTunnel::getSize();
|
||||
|
||||
memcpy(&seq, ptr, 4);
|
||||
ptr += 4;
|
||||
memcpy(src.data, ptr, CERTSIGNLEN);
|
||||
ptr += CERTSIGNLEN;
|
||||
memcpy(dest.data, ptr, CERTSIGNLEN);
|
||||
ptr += CERTSIGNLEN;
|
||||
|
||||
memcpy(data, ptr, size);
|
||||
ptr += size;
|
||||
|
||||
memcpy(sign, ptr, PQI_TUNNEL_SIGN_SIZE);
|
||||
ptr += PQI_TUNNEL_SIGN_SIZE;
|
||||
|
||||
return PQTunnelProxy::getSize();
|
||||
}
|
||||
|
||||
const int PQTunnelProxy::getSize() const
|
||||
{
|
||||
//std::cerr << "PQTunnelProxy::getSize()" << std::endl;
|
||||
return PQTunnel::getSize() + sizeof(long) +
|
||||
CERTSIGNLEN * 2 +
|
||||
+ size + PQI_TUNNEL_SIGN_SIZE;
|
||||
}
|
||||
|
||||
|
||||
#include "pqipacket.h"
|
||||
|
||||
std::ostream &PQTunnelProxy::print(std::ostream &out)
|
||||
{
|
||||
out << "-------- PQTunnelProxy" << std::endl;
|
||||
PQItem::print(out);
|
||||
|
||||
out << "-------- -------- Tunnelling" << std::endl;
|
||||
PQItem *pkt = NULL;
|
||||
if ((data == NULL) || (size == 0))
|
||||
{
|
||||
out << "NULL Pkt" << std::endl;
|
||||
}
|
||||
else if (pqipkt_check(data, size))
|
||||
{
|
||||
pkt = pqipkt_create(data);
|
||||
}
|
||||
|
||||
if (pkt == NULL)
|
||||
{
|
||||
out << "Unknown Packet Type" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
pkt -> print(out);
|
||||
delete pkt;
|
||||
}
|
||||
out << "-------- -------- " << std::endl;
|
||||
return out << "-------- PQTunnelProxy" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PQTunnelProxyInit::PQTunnelProxyInit()
|
||||
:PQTunnelInit(PQI_TUNNEL_PROXY_TYPE), seq(0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PQTunnelProxyInit::~PQTunnelProxyInit()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PQTunnelProxyInit *PQTunnelProxyInit::clone()
|
||||
{
|
||||
PQTunnelProxyInit *ni = new PQTunnelProxyInit();
|
||||
ni -> copy(this);
|
||||
return ni;
|
||||
}
|
||||
|
||||
void PQTunnelProxyInit::copy(const PQTunnelProxyInit *item)
|
||||
{
|
||||
PQTunnelInit::copy(item);
|
||||
|
||||
mode = item -> mode;
|
||||
seq = item -> seq;
|
||||
src = item -> src;
|
||||
dest = item -> dest;
|
||||
proxy = item -> proxy;
|
||||
memcpy(challenge, item -> challenge, CERTSIGNLEN);
|
||||
memcpy(sign, item -> sign, PQI_TUNNEL_SIGN_SIZE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::ostream &PQTunnelProxyInit::print(std::ostream &out)
|
||||
{
|
||||
out << "-----------------PQTunnelProxyInit" << std::endl;
|
||||
PQTunnelInit::print(out);
|
||||
out << "Mode: " << mode << std::endl;
|
||||
out << "Seq: " << seq << std::endl;
|
||||
|
||||
out << std::hex;
|
||||
out << "Src: ";
|
||||
int i;
|
||||
for(i = 0; i < CERTSIGNLEN; i++)
|
||||
{
|
||||
out << ":" << (unsigned int) src.data[i];
|
||||
}
|
||||
out << std::endl;
|
||||
|
||||
out << "Proxy: ";
|
||||
for(i = 0; i < CERTSIGNLEN; i++)
|
||||
{
|
||||
out << ":" << (unsigned int) proxy.data[i];
|
||||
}
|
||||
out << std::endl;
|
||||
|
||||
out << "Dest: ";
|
||||
for(i = 0; i < CERTSIGNLEN; i++)
|
||||
{
|
||||
out << ":" << (unsigned int) dest.data[i];
|
||||
}
|
||||
out << std::endl;
|
||||
out << std::dec;
|
||||
|
||||
out << "-----------------PQTunnelProxyInit" << std::endl;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
int PQTunnelProxyInit::out(void *dta, const int n) const
|
||||
{
|
||||
//std::cerr << "PQTunnelProxyInit::out()" << std::endl;
|
||||
if (n < PQTunnelProxyInit::getSize())
|
||||
{
|
||||
std::cerr << "PQTunnelProxyInit::out() Failed 1" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (PQTunnelInit::getSize() != PQTunnelInit::out(dta, n))
|
||||
{
|
||||
std::cerr << "PQTunnelProxyInit::out() Failed 2" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
char *ptr = (char *) dta;
|
||||
ptr += PQTunnelInit::getSize();
|
||||
|
||||
memcpy(ptr, &seq, 4);
|
||||
ptr += 4;
|
||||
memcpy(ptr, &mode, 4);
|
||||
ptr += 4;
|
||||
memcpy(ptr, src.data, CERTSIGNLEN);
|
||||
ptr += CERTSIGNLEN;
|
||||
memcpy(ptr, proxy.data, CERTSIGNLEN);
|
||||
ptr += CERTSIGNLEN;
|
||||
memcpy(ptr, dest.data, CERTSIGNLEN);
|
||||
ptr += CERTSIGNLEN;
|
||||
|
||||
memcpy(ptr, challenge, PQI_PROXY_CHALLENGE_SIZE);
|
||||
ptr += PQI_PROXY_CHALLENGE_SIZE;
|
||||
|
||||
memcpy(ptr, sign, PQI_TUNNEL_SIGN_SIZE);
|
||||
ptr += PQI_TUNNEL_SIGN_SIZE;
|
||||
|
||||
return PQTunnelProxyInit::getSize();
|
||||
}
|
||||
|
||||
|
||||
int PQTunnelProxyInit::in(const void *dta, const int n)
|
||||
{
|
||||
//std::cerr << "PQTunnelProxyInit::in()" << std::endl;
|
||||
|
||||
if ((dta == NULL) || (n < PQTunnelProxyInit::getSize()))
|
||||
{
|
||||
std::cerr << "PQTunnelProxyInit::in() Failed 1" << std::endl;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (PQTunnelInit::getSize() != PQTunnelInit::in(dta, n))
|
||||
{
|
||||
std::cerr << "PQTunnelProxyInit::in() Failed 2" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *ptr = (char *) dta;
|
||||
ptr += PQTunnelInit::getSize();
|
||||
|
||||
memcpy(&seq, ptr, 4);
|
||||
ptr += 4;
|
||||
memcpy(&mode, ptr, 4);
|
||||
ptr += 4;
|
||||
memcpy(src.data, ptr, CERTSIGNLEN);
|
||||
ptr += CERTSIGNLEN;
|
||||
memcpy(proxy.data, ptr, CERTSIGNLEN);
|
||||
ptr += CERTSIGNLEN;
|
||||
memcpy(dest.data, ptr, CERTSIGNLEN);
|
||||
ptr += CERTSIGNLEN;
|
||||
|
||||
memcpy(challenge, ptr, PQI_PROXY_CHALLENGE_SIZE);
|
||||
ptr += PQI_PROXY_CHALLENGE_SIZE;
|
||||
|
||||
memcpy(sign, ptr, PQI_TUNNEL_SIGN_SIZE);
|
||||
ptr += PQI_TUNNEL_SIGN_SIZE;
|
||||
|
||||
return PQTunnelProxyInit::getSize();
|
||||
}
|
||||
|
||||
|
||||
|
||||
const int PQTunnelProxyInit::getSize() const
|
||||
{
|
||||
//std::cerr << "PQTunnelProxyInit::getSize()" << std::endl;
|
||||
|
||||
return PQTunnelInit::getSize() +
|
||||
2 * sizeof(long) +
|
||||
3 * CERTSIGNLEN +
|
||||
PQI_PROXY_CHALLENGE_SIZE +
|
||||
PQI_TUNNEL_SIGN_SIZE;
|
||||
}
|
||||
|
@ -1,120 +0,0 @@
|
||||
/*
|
||||
* "$Id: pqitunnelproxy.h,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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef PQI_TUNNEL_PROXY_HEADER
|
||||
#define PQI_TUNNEL_PROXY_HEADER
|
||||
|
||||
#include "pqi/pqitunnel.h"
|
||||
|
||||
#define PQI_TUNNEL_PROXY_TYPE 0x0024
|
||||
|
||||
#define PQI_TUNNEL_SIGN_SIZE 256
|
||||
#define PQI_TUNNEL_SHRT_SIGN_SIZE 16
|
||||
#define PQI_PROXY_CHALLENGE_SIZE 1024
|
||||
|
||||
// mode types...
|
||||
#define PQI_TI_REQUEST 0x01
|
||||
#define PQI_TI_CONNECT 0x02
|
||||
#define PQI_TI_END 0x03
|
||||
|
||||
PQTunnel *createPQTunnelProxy(void *d, int n);
|
||||
PQTunnelInit *createPQTunnelProxyInit(void *d, int n);
|
||||
// defined at the end of header.
|
||||
|
||||
class PQTunnelProxyInit: public PQTunnelInit
|
||||
{
|
||||
// private copy constructor... prevent copying...
|
||||
PQTunnelProxyInit(const PQTunnelProxyInit &)
|
||||
:PQTunnelInit(PQI_TUNNEL_PROXY_TYPE)
|
||||
{return; }
|
||||
|
||||
public:
|
||||
PQTunnelProxyInit();
|
||||
virtual ~PQTunnelProxyInit();
|
||||
|
||||
// copy functions.
|
||||
virtual PQTunnelProxyInit *clone();
|
||||
void copy(const PQTunnelProxyInit *src);
|
||||
|
||||
// These are overloaded from PQTunnelInit.
|
||||
virtual const int getSize() const;
|
||||
virtual int out(void *data, const int size) const; // write
|
||||
virtual int in(const void *data, const int size); // read,
|
||||
|
||||
std::ostream &print(std::ostream &out);
|
||||
|
||||
long seq;
|
||||
|
||||
int mode;
|
||||
|
||||
// source
|
||||
certsign src;
|
||||
certsign proxy;
|
||||
certsign dest;
|
||||
|
||||
unsigned char challenge[PQI_PROXY_CHALLENGE_SIZE];
|
||||
unsigned char sign[PQI_TUNNEL_SIGN_SIZE];
|
||||
|
||||
};
|
||||
|
||||
// Data Via Proxy.
|
||||
|
||||
class PQTunnelProxy: public PQTunnel
|
||||
{
|
||||
// private copy constructor... prevent copying...
|
||||
PQTunnelProxy(const PQTunnelProxy &)
|
||||
:PQTunnel(PQI_TUNNEL_PROXY_TYPE)
|
||||
{return; }
|
||||
|
||||
public:
|
||||
PQTunnelProxy();
|
||||
virtual ~PQTunnelProxy();
|
||||
|
||||
// copy functions.
|
||||
virtual PQTunnelProxy *clone();
|
||||
void copy(const PQTunnelProxy *src);
|
||||
|
||||
virtual const int getSize() const;
|
||||
virtual int out(void *data, const int size) const; // write
|
||||
virtual int in(const void *data, const int size); // read,
|
||||
|
||||
std::ostream &print(std::ostream &out);
|
||||
|
||||
//private:
|
||||
// full redefinition of the data space.
|
||||
|
||||
long seq;
|
||||
|
||||
certsign src, dest;
|
||||
|
||||
int size;
|
||||
void *data;
|
||||
|
||||
unsigned char sign[PQI_TUNNEL_SIGN_SIZE];
|
||||
};
|
||||
|
||||
#endif // PQI_TUNNEL_HEADER
|
@ -1,162 +0,0 @@
|
||||
/*
|
||||
* "$Id: pqitunnelproxyudp.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/pqitunnelproxyudp.h"
|
||||
|
||||
PQProxyUdp::PQProxyUdp()
|
||||
:type(0), ksize(0), key(NULL), connectMode(0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PQProxyUdp::PQProxyUdp(void *data, int n)
|
||||
:ksize(0), key(NULL), connectMode(0)
|
||||
{
|
||||
in(data, n);
|
||||
}
|
||||
|
||||
// construct from info.
|
||||
PQProxyUdp::PQProxyUdp(struct sockaddr_in *proxyaddr, void *ikey, int n)
|
||||
:type(PQI_TPUDP_TYPE_1), paddr(*proxyaddr), ksize(n), key(NULL),
|
||||
connectMode(0)
|
||||
|
||||
{
|
||||
key = malloc(ksize);
|
||||
memcpy(key, ikey, ksize);
|
||||
}
|
||||
|
||||
PQProxyUdp::PQProxyUdp(struct sockaddr_in *neighaddr,
|
||||
struct sockaddr_in *peeraddr, int cMode)
|
||||
:type(PQI_TPUDP_TYPE_2),
|
||||
naddr(*neighaddr),
|
||||
paddr(*peeraddr),
|
||||
ksize(0), key(NULL), connectMode(cMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PQProxyUdp::~PQProxyUdp()
|
||||
{
|
||||
if (key)
|
||||
{
|
||||
ksize = 0;
|
||||
free(key);
|
||||
}
|
||||
}
|
||||
|
||||
const int PQProxyUdp::getSize() const
|
||||
{
|
||||
return sizeof(int) + 2 * sizeof(struct sockaddr_in)
|
||||
+ sizeof(int) + ksize;
|
||||
}
|
||||
|
||||
int PQProxyUdp::out(void *dta, const int n) const // write
|
||||
{
|
||||
if (n < getSize())
|
||||
return -1;
|
||||
|
||||
char *loc = (char *) dta; // so we can count bytes
|
||||
int cs = sizeof(int);
|
||||
memcpy(loc, &type, cs);
|
||||
loc += cs;
|
||||
cs = sizeof(struct sockaddr_in);
|
||||
memcpy(loc, &naddr, cs);
|
||||
loc += cs;
|
||||
memcpy(loc, &paddr, cs);
|
||||
loc += cs;
|
||||
|
||||
/* add in ConnectMode */
|
||||
cs = sizeof(int);
|
||||
memcpy(loc, &connectMode, cs);
|
||||
loc += cs;
|
||||
|
||||
if (ksize)
|
||||
{
|
||||
memcpy(loc, key, ksize);
|
||||
}
|
||||
loc += ksize;
|
||||
|
||||
return getSize();
|
||||
}
|
||||
|
||||
int PQProxyUdp::in(const void *dta, const int n) // read,
|
||||
{
|
||||
if (key)
|
||||
{
|
||||
ksize = 0;
|
||||
free(key);
|
||||
key = NULL;
|
||||
}
|
||||
|
||||
if (n < getSize()) /* smaller than min ksize */
|
||||
{
|
||||
std::cerr << "PQTunnelProxy::in() Failed (n < getSize())" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *loc = (char *) dta;
|
||||
int cs = sizeof(int);
|
||||
memcpy(&type, loc, cs);
|
||||
loc += cs;
|
||||
cs = sizeof(struct sockaddr_in);
|
||||
memcpy(&naddr, loc, cs);
|
||||
loc += cs;
|
||||
memcpy(&paddr, loc, cs);
|
||||
loc += cs;
|
||||
|
||||
/* get in ConnectMode */
|
||||
cs = sizeof(int);
|
||||
memcpy(&connectMode,loc, cs);
|
||||
loc += cs;
|
||||
|
||||
ksize = 0;
|
||||
ksize = n - getSize();
|
||||
if (ksize)
|
||||
{
|
||||
key = malloc(ksize);
|
||||
memcpy(key, loc, ksize);
|
||||
}
|
||||
return getSize(); /* should be equal to n */
|
||||
}
|
||||
|
||||
|
||||
std::ostream &PQProxyUdp::print(std::ostream &out)
|
||||
{
|
||||
out << "-------- PQProxyUdp" << std::endl;
|
||||
out << "Type: " << type << std::endl;
|
||||
out << "naddr: " << inet_ntoa(naddr.sin_addr) << ":";
|
||||
out << ntohs(naddr.sin_port) << std::endl;
|
||||
out << "paddr: " << inet_ntoa(paddr.sin_addr) << ":";
|
||||
out << ntohs(paddr.sin_port) << std::endl;
|
||||
out << "ConnectMode: " << connectMode << std::endl;
|
||||
out << "KeySize: " << ksize << std::endl;
|
||||
return out << "-------- PQProxyUdp" << std::endl;
|
||||
}
|
||||
|
||||
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* "$Id: pqitunnelproxyudp.h,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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef PQI_TUNNEL_PROXY_UDP_HEADER
|
||||
#define PQI_TUNNEL_PROXY_UDP_HEADER
|
||||
|
||||
#include "pqi/pqitunnel.h"
|
||||
|
||||
#define PQI_TPUDP_TYPE_1 0x0001
|
||||
#define PQI_TPUDP_TYPE_2 0x0002
|
||||
|
||||
class PQProxyUdp
|
||||
{
|
||||
public:
|
||||
// construct from data.
|
||||
PQProxyUdp(void *data, int size);
|
||||
PQProxyUdp();
|
||||
|
||||
// construct from info.
|
||||
PQProxyUdp(struct sockaddr_in *proxyaddr, void *key, int size);
|
||||
PQProxyUdp(struct sockaddr_in *neighaddr,
|
||||
struct sockaddr_in *peeraddr, int cMode);
|
||||
|
||||
virtual ~PQProxyUdp();
|
||||
|
||||
// no copy functions.
|
||||
|
||||
virtual const int getSize() const;
|
||||
virtual int out(void *data, const int size) const; // write
|
||||
virtual int in(const void *data, const int size); // read,
|
||||
|
||||
std::ostream &print(std::ostream &out);
|
||||
|
||||
int type;
|
||||
struct sockaddr_in naddr, paddr;
|
||||
int ksize;
|
||||
void *key;
|
||||
int connectMode;
|
||||
};
|
||||
|
||||
#endif // PQI_TUNNEL_PROXY_UDP_HEADER
|
@ -1,146 +0,0 @@
|
||||
/*
|
||||
* "$Id: pqitunneltst.h,v 1.4 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 PQI_TUNNEL_TST_HEADER
|
||||
#define PQI_TUNNEL_TST_HEADER
|
||||
|
||||
#include "pqi/pqitunnel.h"
|
||||
|
||||
#define PQI_TUNNEL_TST_TYPE 0x0265
|
||||
|
||||
|
||||
#define pqitunnelzone 71849
|
||||
#include "pqi/pqidebug.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
PQTunnel *createPQTStst(void *d, int n);
|
||||
|
||||
|
||||
class PQTunnelTst: public PQTunnel
|
||||
{
|
||||
public:
|
||||
PQTunnelTst()
|
||||
:PQTunnel(PQI_TUNNEL_TST_TYPE)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTunnelTst::PQTunnelTst()");
|
||||
return;
|
||||
}
|
||||
|
||||
virtual ~PQTunnelTst()
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTunnelTst::~PQTunnelTst()");
|
||||
return;
|
||||
}
|
||||
|
||||
virtual PQTunnelTst *clone()
|
||||
{
|
||||
PQTunnelTst *pqt = new PQTunnelTst();
|
||||
// getData() no longer exists.
|
||||
//pqt -> in(getData(), getSize());
|
||||
return pqt;
|
||||
}
|
||||
|
||||
|
||||
virtual std::ostream &print(std::ostream &out)
|
||||
{
|
||||
out << "----------------" << std::endl;
|
||||
out << "PQTunnelTst" << std::endl;
|
||||
// getData() no longer exists.
|
||||
// out << "Msg:" << (char *) getData() << std::endl;
|
||||
PQTunnel::print(out);
|
||||
out << "----------------" << std::endl;
|
||||
return out;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class PQTStst: public PQTunnelService
|
||||
{
|
||||
public:
|
||||
PQTStst() :PQTunnelService(PQI_TUNNEL_TST_TYPE)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTStst::PQTStst()");
|
||||
|
||||
ts = time(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
int receive(PQTunnel *item)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTStst::receive()");
|
||||
|
||||
PQTunnelTst *tst = (PQTunnelTst *) item;
|
||||
std::cerr << "PQTStst::receive()...." << std::endl;
|
||||
tst -> print(std::cerr);
|
||||
delete item;
|
||||
return 1;
|
||||
}
|
||||
|
||||
PQTunnel *send()
|
||||
{
|
||||
if (time(NULL) - ts > 100.0 * rand()/(RAND_MAX + 1.0) )
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTStst::send() Sending Test Packet!");
|
||||
// make an item.
|
||||
PQTunnelTst *tst = new PQTunnelTst();
|
||||
std::string msg = "Hello";
|
||||
tst -> in(msg.c_str(), msg.length());
|
||||
ts = time(NULL);
|
||||
return tst;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int receive(PQTunnelInit *item)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTStst::receive() Cleaning PQTunnelInit");
|
||||
delete item;
|
||||
return 1;
|
||||
}
|
||||
|
||||
PQTunnelInit *sendInit()
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqitunnelzone,
|
||||
"PQTStst::sendInit() returning NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
long ts;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // PQI_TUNNEL_TST_HEADER
|
@ -1,859 +0,0 @@
|
||||
/*
|
||||
* "$Id: pqiudpproxy.cc,v 1.7 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/pqiudpproxy.h"
|
||||
#include "pqi/pqitunnelproxyudp.h"
|
||||
#include "pqi/pqissludp.h"
|
||||
#include "pqi/p3disc.h"
|
||||
|
||||
#include <sstream>
|
||||
#include "pqi/pqidebug.h"
|
||||
|
||||
#include "tcponudp/tou.h"
|
||||
|
||||
const int pqiudpproxyzone = 6846;
|
||||
|
||||
class udpAddrPair
|
||||
{
|
||||
public:
|
||||
udpAddrPair(cert *n1, cert *n2, int fd);
|
||||
~udpAddrPair();
|
||||
|
||||
int match(cert *src, cert *peer, struct sockaddr_in &addr);
|
||||
bool bothMatched();
|
||||
|
||||
cert *cert1, *cert2;
|
||||
int m1count, m2count;
|
||||
bool matched1, matched2;
|
||||
struct sockaddr_in addr1, addr2;
|
||||
char *key1, *key2;
|
||||
int keysize1, keysize2;
|
||||
int sockfd;
|
||||
};
|
||||
|
||||
|
||||
udpAddrPair:: udpAddrPair(cert *n1, cert *n2, int fd)
|
||||
:cert1(n1), cert2(n2),
|
||||
matched1(false), matched2(false),
|
||||
key1(NULL), key2(NULL),
|
||||
keysize1(0), keysize2(0), sockfd(fd)
|
||||
{
|
||||
|
||||
/* choose a random number 20 - 100 */
|
||||
keysize1 = 20 + (int) (80.0 * (rand() / (RAND_MAX + 1.0)));
|
||||
keysize2 = 20 + (int) (80.0 * (rand() / (RAND_MAX + 1.0)));
|
||||
int i;
|
||||
|
||||
/* generate keys */
|
||||
key1 = (char *) malloc(keysize1);
|
||||
key2 = (char *) malloc(keysize2);
|
||||
for(i = 0; i < keysize1; i++)
|
||||
{
|
||||
key1[i] = (char) (256.0 * (rand() / (RAND_MAX + 1.0)));
|
||||
}
|
||||
for(i = 0; i < keysize2; i++)
|
||||
{
|
||||
key2[i] = (char) (256.0 * (rand() / (RAND_MAX + 1.0)));
|
||||
}
|
||||
/* done! */
|
||||
}
|
||||
|
||||
udpAddrPair::~udpAddrPair()
|
||||
{
|
||||
free(key1);
|
||||
free(key2);
|
||||
}
|
||||
|
||||
int udpAddrPair::match(cert *src, cert *peer, struct sockaddr_in &addr)
|
||||
{
|
||||
if ((src == cert1) && (peer == cert2))
|
||||
{
|
||||
/* matched 1 */
|
||||
matched1 = true;
|
||||
m1count++;
|
||||
addr1 = addr;
|
||||
|
||||
std::ostringstream out;
|
||||
out << "udpAddrPair::match() Matched Cert 1" << std::endl;
|
||||
out << "FROM: " << inet_ntoa(addr.sin_addr) << ":";
|
||||
out << ntohs(addr.sin_port) << " count: " << m1count;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
if ((src == cert2) && (peer == cert1 ))
|
||||
{
|
||||
matched2 = true;
|
||||
m2count++;
|
||||
addr2 = addr;
|
||||
|
||||
std::ostringstream out;
|
||||
out << "udpAddrPair::match() Matched Key 2" << std::endl;
|
||||
out << "FROM: " << inet_ntoa(addr.sin_addr) << ":";
|
||||
out << ntohs(addr.sin_port) << " count: " << m1count;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
return true;
|
||||
}
|
||||
|
||||
pqioutput(PQL_DEBUG_ALL, pqiudpproxyzone, "not matched");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool udpAddrPair::bothMatched()
|
||||
{
|
||||
return (matched1 && matched2);
|
||||
}
|
||||
|
||||
|
||||
p3udpproxy::p3udpproxy(p3disc *p)
|
||||
:p3proxy(p)
|
||||
{
|
||||
/* if we have a udp_server,
|
||||
* setup a listener.
|
||||
*/
|
||||
|
||||
/* check that the sslcert flags are good. */
|
||||
//if ((sslcert->isFirewalled() && sslcert->isForwarded() ||
|
||||
// (!(sslcert->isFirewalled())))
|
||||
{
|
||||
/* then check address */
|
||||
/* attempt to setup a udp port to listen...
|
||||
*/
|
||||
struct sockaddr_in *addr = &(getSSLRoot()->getOwnCert()->localaddr);
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::p3udpproxy()";
|
||||
out << " Creating a UDP Listening port:";
|
||||
out << inet_ntoa(addr->sin_addr) << ":" << ntohs(addr->sin_port);
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
|
||||
int sockfd = tou_socket(0,0,0);
|
||||
tou_bind(sockfd, (struct sockaddr *) addr,
|
||||
sizeof(struct sockaddr_in));
|
||||
|
||||
tou_listen(sockfd, 1);
|
||||
tou_extaddr(sockfd, (struct sockaddr *) addr,
|
||||
sizeof(struct sockaddr_in));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
p3udpproxy::~p3udpproxy()
|
||||
{
|
||||
/* should clean up! */
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// PQTunnelService Overloading.
|
||||
//
|
||||
// Major overloaded function.
|
||||
//
|
||||
// The receive function now has two distinct roles.
|
||||
// 1) Proxy role: receive Ext Addresses (in an established connection)
|
||||
// -> when multiple recieved, return address pair to initiate
|
||||
// -> transaction.
|
||||
//
|
||||
// The generic (p3proxy) recieve should split the
|
||||
// packet depending on if we are proxy, or end destination.
|
||||
//
|
||||
// expects to recieve
|
||||
// 1) if we are the proxy ... add address to the
|
||||
// waiting pairs.
|
||||
//
|
||||
// if have both -> respond.
|
||||
//
|
||||
// 2) if receive as destination, and they've
|
||||
// sent the addr pair, then we can
|
||||
// commence the connection.
|
||||
|
||||
|
||||
/* only two types of packets are expected over the
|
||||
* proxy connection......
|
||||
* 1) ProxyAddress + Key.
|
||||
* 2) discovered addresses.
|
||||
*
|
||||
* This information comes from the Proxy for us.
|
||||
* and is encapsulated in a PQProxyUdp packet.
|
||||
*/
|
||||
|
||||
int p3udpproxy::receiveAsProxy(PQTunnelProxy* pqtp, cert *src, cert *dest)
|
||||
{
|
||||
/* if connected (checked already!) */
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::receiveAsProxy()";
|
||||
out << " Received PQTunnel Packet! - Yet to do anything!" << std::endl;
|
||||
pqtp -> print(out);
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
|
||||
/* add to waiting */
|
||||
PQProxyUdp udppkt;
|
||||
if (pqtp->size != udppkt.in(pqtp->data, pqtp->size))
|
||||
{
|
||||
delete pqtp;
|
||||
pqioutput(PQL_WARNING, pqiudpproxyzone,
|
||||
"PQTunnel is Not a PQProxyUdp Pkt...Deleting");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((cert *) pqtp->p != src)
|
||||
{
|
||||
// error
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::receiveAsProxy() ERROR pqtp->p != src";
|
||||
pqioutput(PQL_ALERT, pqiudpproxyzone, out.str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// order very important.... packet from src, for connection to dest!.
|
||||
checkUdpPacket(&udppkt, src, dest);
|
||||
|
||||
/* cleanup */
|
||||
delete pqtp;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int p3udpproxy::receiveAsError(PQTunnelProxy* pqtp, cert *src, cert *from, cert *dest)
|
||||
{
|
||||
/* don't do much */
|
||||
return 1;
|
||||
}
|
||||
|
||||
int p3udpproxy::receiveAsDestination(PQTunnelProxy* pqtp, cert *src, cert *from, cert *dest, pqiproxy *pqip)
|
||||
|
||||
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::receiveAsDestination(";
|
||||
out << src -> Name();
|
||||
out << " -> " << from -> Name();
|
||||
out << " -> " << dest -> Name() << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
|
||||
PQProxyUdp udppkt;
|
||||
if (pqtp->size != udppkt.in(pqtp->data, pqtp->size))
|
||||
{
|
||||
delete pqtp;
|
||||
pqioutput(PQL_WARNING, pqiudpproxyzone,
|
||||
"PQTunnel is Not a PQProxyUdp Pkt...Deleting");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// inform the pqiudpproxy
|
||||
pqiudpproxy *udpproxy = dynamic_cast<pqiudpproxy *>(pqip);
|
||||
if (udpproxy == NULL)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiproxy -> NOT a pqiudpproxy....Trouble";
|
||||
pqioutput(PQL_WARNING, pqiudpproxyzone, out.str());
|
||||
|
||||
// mismatch reject.
|
||||
delete pqtp;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (udppkt.type != PQI_TPUDP_TYPE_2)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone,
|
||||
"Unknown Proxy Packet");
|
||||
delete pqtp;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone,
|
||||
"Packet -> Discovered Address");
|
||||
udpproxy->discoveredaddresses(&(udppkt.naddr), &(udppkt.paddr),
|
||||
udppkt.connectMode);
|
||||
|
||||
/* we have now completed that proxy connection.
|
||||
* shut it down
|
||||
*/
|
||||
|
||||
delete pqtp;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* This is called by the pqiudpproxy, when an address should
|
||||
* be transmitted.....
|
||||
*/
|
||||
|
||||
int p3udpproxy::sendExternalAddress(pqiudpproxy *pqip,
|
||||
struct sockaddr_in &ext_addr)
|
||||
{
|
||||
// first find the certs.
|
||||
cert *dest = pqip -> getContact();
|
||||
cert *own = sroot -> getOwnCert();
|
||||
|
||||
std::map<cert *, cert *>::iterator it;
|
||||
it = connectionmap.find(dest);
|
||||
/* check certs for basic safety */
|
||||
if (it == connectionmap.end())
|
||||
{
|
||||
/* cannot */
|
||||
return -1;
|
||||
}
|
||||
cert *prxy = it -> second;
|
||||
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::sendExternalAddress():";
|
||||
out << " & " << inet_ntoa(ext_addr.sin_addr);
|
||||
out << ":" << ntohs(ext_addr.sin_port);
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
|
||||
PQProxyUdp *udppkt = new PQProxyUdp(&ext_addr, &ext_addr, sizeof(ext_addr));
|
||||
|
||||
/* now pack them in PQTunnelProxy pkts */
|
||||
PQTunnelProxy *tp1 = createProxyUdpPkt(dest, prxy, own, udppkt);
|
||||
delete udppkt;
|
||||
|
||||
/* send them off */
|
||||
outPkts.push_back(tp1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int p3udpproxy::connectionCompletedAsProxy(cert *n1, cert *n2)
|
||||
{
|
||||
/* As the proxy, we do nothing at the completion of the connection
|
||||
* except wait for the two external addresses to be forwarded to us
|
||||
* (this is handled in receiveAsProxy()).
|
||||
*/
|
||||
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::completeConnectAsProxy()";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
|
||||
/* generate keys */
|
||||
udpAddrPair *uc = new udpAddrPair(n1, n2, 1); /* sockfd - legacy = 1? */
|
||||
|
||||
/* save keys in list */
|
||||
keysWaiting.push_back(uc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int p3udpproxy::checkUdpPacket(PQProxyUdp *pkt, cert *src, cert *dest)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::checkUdpPacket()";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
|
||||
/* only if we are the proxy */
|
||||
struct sockaddr_in ext_addr = pkt->paddr;
|
||||
|
||||
/* the packet should just contain the key */
|
||||
std::list<udpAddrPair *>::iterator it;
|
||||
for(it = keysWaiting.begin(); it != keysWaiting.end(); it++)
|
||||
{
|
||||
if ((*it) -> match(src, dest, ext_addr))
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::checkUdpPacket() Matched Key!";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// only way to continue loop!
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*it) -> bothMatched())
|
||||
{
|
||||
udpAddrPair *uc = (*it);
|
||||
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::checkUdpPacket() Both Keys Matched!";
|
||||
out << "p3udpproxy::checkUdpPacket() Sending addresses: ";
|
||||
out << inet_ntoa(uc->addr1.sin_addr) << ":";
|
||||
out << ntohs(uc->addr1.sin_port);
|
||||
out << " & " << inet_ntoa(uc->addr2.sin_addr);
|
||||
out << ":" << ntohs(uc->addr2.sin_port);
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
|
||||
|
||||
/* remove packet, and send addresses to both!
|
||||
* Arbitarily decide which is active (one with addr1)
|
||||
*/
|
||||
PQProxyUdp *p1 = new PQProxyUdp(
|
||||
&(uc->addr1), &(uc->addr2), 1);
|
||||
PQProxyUdp *p2 = new PQProxyUdp(
|
||||
&(uc->addr2), &(uc->addr1), 0);
|
||||
|
||||
|
||||
/* now pack them in PQTunnelProxy pkts */
|
||||
PQTunnelProxy *tp1 = createProxyUdpPkt(uc->cert1, NULL, uc->cert2, p1);
|
||||
PQTunnelProxy *tp2 = createProxyUdpPkt(uc->cert2, NULL, uc->cert1, p2);
|
||||
|
||||
delete p1;
|
||||
delete p2;
|
||||
|
||||
/* send them off */
|
||||
outPkts.push_back(tp1);
|
||||
outPkts.push_back(tp2);
|
||||
|
||||
/* remove */
|
||||
it = keysWaiting.erase(it);
|
||||
|
||||
}
|
||||
/* if we matched -> then good! */
|
||||
return 1;
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::checkUdpPacket() FAILED to Match Incoming UdpPkt";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int p3udpproxy::reset(pqiproxy *p, cert *c)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::reset()";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
// restart.
|
||||
// remove from keysWaiting ???
|
||||
return p3proxy::reset(p,c);
|
||||
}
|
||||
|
||||
|
||||
int p3udpproxy::outgoingpkt(pqiproxy *p, cert *c, void *d, int size)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::outgoingpkt() For: " << c -> Name();
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
/* fails in udpproxy */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int p3udpproxy::incomingpkt(pqiproxy *p, void *d, int maxsize)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::incomingpkt()";
|
||||
pqioutput(PQL_DEBUG_ALL, pqiudpproxyzone, out.str());
|
||||
}
|
||||
/* fails in udpproxy */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int p3udpproxy::status()
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::status()";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
p3proxy::status();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int p3udpproxy::processincoming()
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::processincoming()";
|
||||
pqioutput(PQL_DEBUG_ALL, pqiudpproxyzone, out.str());
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* this is only called by the proxy */
|
||||
PQTunnelProxy *p3udpproxy::createProxyUdpPkt(cert *dest, cert *prxy, cert *src, PQProxyUdp *uap)
|
||||
{
|
||||
PQTunnelProxy *pi = new PQTunnelProxy();
|
||||
cert *o = sroot -> getOwnCert();
|
||||
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3udpproxy::createProxyUdpPkt()" << std::endl;
|
||||
out << "Dest: " << dest -> Name() << std::endl;
|
||||
if (!prxy)
|
||||
{
|
||||
out << "Proxy: US!" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
out << "Proxy: " << prxy -> Name() << std::endl;
|
||||
}
|
||||
out << "Src: " << src -> Name() << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
|
||||
// Fill in Details....
|
||||
// only src = peer to fill in .
|
||||
if (!sroot -> getcertsign(src, pi -> src))
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3proxy::createProxyPkt()";
|
||||
out << " Error: Failed to Get Signature 1...";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
|
||||
delete pi;
|
||||
return NULL;
|
||||
}
|
||||
if (!sroot -> getcertsign(dest, pi -> dest))
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "p3proxy::createProxyPkt()";
|
||||
out << " Error: Failed to Get Signature 2...";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
|
||||
delete pi;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// initialise packets.
|
||||
pi -> sid = 0; // doesn't matter.
|
||||
pi -> seq = 0;
|
||||
|
||||
/* HACK HERE */
|
||||
if (prxy == NULL) /* then we are the proxy */
|
||||
{
|
||||
/* send on */
|
||||
pi -> cid = dest -> cid; // destination.
|
||||
pi -> p = o; // from us;
|
||||
}
|
||||
else
|
||||
{
|
||||
pi -> cid = prxy -> cid; // send to proxy.
|
||||
pi -> p = o; // from us;
|
||||
}
|
||||
|
||||
|
||||
// ProxyInit Details.
|
||||
pi -> size = uap -> getSize();
|
||||
pi -> data = malloc(pi->size);
|
||||
uap->out(pi->data, pi->size);
|
||||
// Sign Packet.
|
||||
|
||||
return pi;
|
||||
}
|
||||
|
||||
|
||||
/************************ PQI PROXY *************************/
|
||||
|
||||
#define PUP_CLOSED 0
|
||||
#define PUP_WAITING_PROXY 1
|
||||
#define PUP_PROXY_CONNECT 2
|
||||
#define PUP_WAITING_DISC 3
|
||||
#define PUP_WAITING_UDP 4
|
||||
#define PUP_WAITING_SSL 5
|
||||
#define PUP_CONNECTED 6
|
||||
|
||||
pqiudpproxy::pqiudpproxy(cert *c, p3udpproxy *l, PQInterface *p)
|
||||
:pqipeerproxy(c, l, p), state(PUP_CLOSED)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiudpproxy::pqiudpproxy()";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
pqiudpproxy::~pqiudpproxy()
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiudpproxy::~pqiudpproxy()";
|
||||
//pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
pqioutput(PQL_ALERT, pqiudpproxyzone, out.str());
|
||||
}
|
||||
state = PUP_CLOSED;
|
||||
return;
|
||||
}
|
||||
|
||||
// pqiconnect Interface.
|
||||
int pqiudpproxy::connectattempt() // as pqiproxy/
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiudpproxy::connectattempt()";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
state = PUP_WAITING_PROXY;
|
||||
return pqipeerproxy::connectattempt();
|
||||
}
|
||||
|
||||
|
||||
int pqiudpproxy::listen()
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiudpproxy::listen()";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
state = PUP_WAITING_PROXY;
|
||||
return pqipeerproxy::listen();
|
||||
}
|
||||
|
||||
|
||||
int pqiudpproxy::stoplistening()
|
||||
{
|
||||
//state = PUP_WAITING_PROXY;
|
||||
return pqipeerproxy::stoplistening();
|
||||
}
|
||||
|
||||
int pqiudpproxy::disconnected()
|
||||
{
|
||||
pqipeerproxy::disconnected();
|
||||
state = PUP_CLOSED;
|
||||
reset();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* pqiproxy interface */
|
||||
int pqiudpproxy::connected(bool act)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiudpproxy::connected() - Set State!";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
state = PUP_PROXY_CONNECT;
|
||||
return pqipeerproxy::connected(act);
|
||||
}
|
||||
|
||||
// called by the p3udpproxy .... means attempt failed....
|
||||
int pqiudpproxy::disconnect()
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiudpproxy::disconnect()";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
/* if we haven't got remote address yet! */
|
||||
if (state < PUP_WAITING_SSL)
|
||||
{
|
||||
disconnected();
|
||||
}
|
||||
/* else is okay */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int pqiudpproxy::reset()
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiudpproxy::reset()";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
pqipeerproxy::reset();
|
||||
state = PUP_CLOSED;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Overloaded from PQInterface
|
||||
int pqiudpproxy::status()
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiudpproxy::status() state = " << state;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
pqipeerproxy::status();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int pqiudpproxy::tick()
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiudpproxy::tick()";
|
||||
pqioutput(PQL_DEBUG_ALL, pqiudpproxyzone, out.str());
|
||||
}
|
||||
|
||||
if (state == PUP_CLOSED) /* silent state */
|
||||
{
|
||||
|
||||
}
|
||||
else if (state == PUP_WAITING_PROXY) /* just started connection */
|
||||
{
|
||||
//state = PUP_WAITING_DISC;
|
||||
}
|
||||
else if (state == PUP_PROXY_CONNECT)
|
||||
{
|
||||
//state = PUP_WAITING_DISC;
|
||||
}
|
||||
else if (state == PUP_WAITING_DISC)
|
||||
{
|
||||
//state = PUP_WAITING_DISC;
|
||||
}
|
||||
else if (state == PUP_WAITING_SSL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
pqipeerproxy::tick();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqiudpproxy::notifyEvent(int type)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiudpproxy::notifyEvent(" << type << ")";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiudpproxyzone, out.str());
|
||||
}
|
||||
return pqipeerproxy::notifyEvent(type);
|
||||
}
|
||||
|
||||
|
||||
int p3udpproxy::requestStunServer(struct sockaddr_in &addr)
|
||||
{
|
||||
if (potentials.size() == 0)
|
||||
{
|
||||
potentials = p3d -> requestStunServers();
|
||||
}
|
||||
|
||||
if (potentials.size() > 0)
|
||||
{
|
||||
/* pop the first one off and return it */
|
||||
addr = potentials.front();
|
||||
potentials.pop_front();
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The pqissludp interface is below, in order of execution
|
||||
*/
|
||||
|
||||
bool pqiudpproxy::isConnected(int &mode)
|
||||
{
|
||||
if (isactive())
|
||||
{
|
||||
mode = connect_mode;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool pqiudpproxy::hasFailed()
|
||||
{
|
||||
return (state == PUP_CLOSED);
|
||||
}
|
||||
|
||||
int pqiudpproxy::requestStunServer(struct sockaddr_in &addr)
|
||||
{
|
||||
return ((p3udpproxy *) p3p) -> requestStunServer(addr);
|
||||
}
|
||||
|
||||
// notification from pqissludp.
|
||||
bool pqiudpproxy::sendExternalAddress(struct sockaddr_in &ext_addr)
|
||||
{
|
||||
return ((p3udpproxy *) p3p) ->
|
||||
sendExternalAddress(this, ext_addr);
|
||||
}
|
||||
|
||||
//
|
||||
int pqiudpproxy::discoveredaddresses(struct sockaddr_in *our_addr,
|
||||
struct sockaddr_in *peer, int cMode)
|
||||
{
|
||||
/* we have our own address!, and peers address */
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqiudpproxy::discoveredaddresses() Connect";
|
||||
out << std::endl;
|
||||
out << "Our Address: " << inet_ntoa(our_addr->sin_addr) << ":";
|
||||
out << ntohs(our_addr->sin_port);
|
||||
out << std::endl;
|
||||
out << " Peers Address: " << inet_ntoa(peer->sin_addr) << ":";
|
||||
out << ntohs(peer->sin_port);
|
||||
|
||||
pqioutput(PQL_ALERT, pqiudpproxyzone, out.str());
|
||||
}
|
||||
|
||||
remote_addr = *peer;
|
||||
if (cMode)
|
||||
{
|
||||
connectMode = 1; /* active */
|
||||
}
|
||||
else
|
||||
{
|
||||
connectMode = 0; /* passive */
|
||||
}
|
||||
state = PUP_WAITING_UDP;
|
||||
|
||||
// shutdown the proxy Connection.
|
||||
// by calling the pqipeerproxy::reset().
|
||||
pqipeerproxy::reset();
|
||||
|
||||
pqioutput(PQL_ALERT, pqiudpproxyzone,
|
||||
"sent pqipeerproxy::reset() should shutdown proxy connect");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// poll by pqissludp for state completion.
|
||||
bool pqiudpproxy::gotRemoteAddress(struct sockaddr_in &raddr, int &cMode)
|
||||
{
|
||||
if (state == PUP_WAITING_UDP)
|
||||
{
|
||||
raddr = remote_addr;
|
||||
cMode = connectMode;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,287 +0,0 @@
|
||||
/*
|
||||
* "$Id: pqiudpproxy.h,v 1.6 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_UDP_PROXY_HEADER
|
||||
#define MRK_PQI_UDP_PROXY_HEADER
|
||||
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
#include "pqi/pqiproxy.h"
|
||||
|
||||
class pqiudpproxy;
|
||||
class udpAddrPair;
|
||||
class pqissludp;
|
||||
class PQProxyUdp;
|
||||
|
||||
class p3udpproxy: public p3proxy
|
||||
{
|
||||
public:
|
||||
p3udpproxy(p3disc *p);
|
||||
virtual ~p3udpproxy();
|
||||
|
||||
// New udp functions.
|
||||
// this first one will be called from
|
||||
// inside p3proxy, at the appropriate time.
|
||||
int checkUdpPacket(PQProxyUdp *, cert *src, cert *peer);
|
||||
|
||||
|
||||
// PQTunnelService Overloading. (none)
|
||||
// Overloaded from p3proxy.
|
||||
// receive now plays role of
|
||||
// collecting address packets.
|
||||
|
||||
// interface to pqiproxy.
|
||||
//int attach(pqiproxy *p, cert *c);
|
||||
//int detach(pqiproxy *p, cert *c);
|
||||
|
||||
//int listen(pqiproxy *p, cert *c);
|
||||
//int stoplistening(pqiproxy *p, cert *c);
|
||||
|
||||
int reset(pqiproxy *p, cert *c);
|
||||
|
||||
virtual int outgoingpkt(pqiproxy *p, cert *, void *d, int size);
|
||||
virtual int incomingpkt(pqiproxy *p, void *d, int maxsize);
|
||||
|
||||
int requestStunServer(struct sockaddr_in &addr);
|
||||
int sendExternalAddress(pqiudpproxy *pqip,
|
||||
struct sockaddr_in &ext_addr);
|
||||
|
||||
|
||||
// overloaded from many sources.
|
||||
//virtual int tick();
|
||||
|
||||
int status();
|
||||
|
||||
//int connectattempt(pqiproxy*, cert*);
|
||||
//int connectattempt();
|
||||
//int nextconnectattempt(cert *, cert *);
|
||||
|
||||
protected: /* interface not clean enough for private */
|
||||
|
||||
// overload connection Completion.
|
||||
virtual int connectionCompletedAsProxy(cert*, cert*);
|
||||
//virtual int connectionCompletedAsPeer(cert*, cert*);
|
||||
|
||||
// overload receiving Tunnel Data.
|
||||
virtual int receiveAsProxy(PQTunnelProxy *pqtp, cert *src, cert *dest);
|
||||
virtual int receiveAsDestination(PQTunnelProxy *pqtp,
|
||||
cert *src, cert *from, cert *dest, pqiproxy *pqip);
|
||||
virtual int receiveAsError(PQTunnelProxy *pqtp, cert *src, cert *from, cert *dest);
|
||||
|
||||
virtual int processincoming();
|
||||
|
||||
|
||||
PQTunnelProxy *createProxyUdpPkt(cert *dest, cert *prxy, cert *src, PQProxyUdp *uap);
|
||||
|
||||
std::list<udpAddrPair *> keysWaiting;
|
||||
std::list<struct sockaddr_in> potentials; // stun addresses.
|
||||
};
|
||||
|
||||
|
||||
// pqiconnect, derives from pqistreamer/PQInterface.
|
||||
//
|
||||
// pqiproxy provide.
|
||||
// 1) read/write data.
|
||||
// 2) connect functions.
|
||||
//
|
||||
// pqiudpproxy provides the
|
||||
// linking, and redirects
|
||||
// the sending the udpssl layer below.
|
||||
//
|
||||
// small extensions to the pqiproxy interface
|
||||
// are required.
|
||||
|
||||
class pqiudpproxy: public pqipeerproxy
|
||||
{
|
||||
public:
|
||||
pqiudpproxy(cert *c, p3udpproxy *l, PQInterface *parent);
|
||||
virtual ~pqiudpproxy();
|
||||
|
||||
// Net Interface.
|
||||
virtual int connectattempt();
|
||||
virtual int listen();
|
||||
virtual int stoplistening();
|
||||
virtual int reset();
|
||||
virtual int disconnect();
|
||||
|
||||
// PQInterface
|
||||
virtual int tick();
|
||||
virtual int status();
|
||||
|
||||
// Bin Interface disabled.
|
||||
virtual int senddata(void*, int) { return 0; }
|
||||
virtual int readdata(void*, int) { return 0; }
|
||||
virtual int netstatus() { return 0; }
|
||||
//virtual int isactive(); -> same as peer.
|
||||
virtual bool moretoread() { return false; }
|
||||
|
||||
// The interface to p3proxy.
|
||||
virtual int notifyEvent(int type);
|
||||
// unneeded notification.
|
||||
|
||||
// notification from p3proxy.
|
||||
virtual int connected(bool active);
|
||||
virtual int disconnected();
|
||||
|
||||
// Below is the pqissludp interface to us.
|
||||
// in order of execution.....
|
||||
|
||||
// poll by pqissludp for state completion.
|
||||
bool isConnected(int &mode);
|
||||
bool hasFailed();
|
||||
|
||||
// requests from pqissludp layer.
|
||||
int requestStunServer(struct sockaddr_in &addr);
|
||||
// notification from pqissludp.
|
||||
bool sendExternalAddress(struct sockaddr_in &ext_addr);
|
||||
|
||||
// notification of external address exchange!
|
||||
virtual int discoveredaddresses(struct sockaddr_in *our_addr,
|
||||
struct sockaddr_in *peer, int cMode);
|
||||
|
||||
// poll by pqissludp for state completion.
|
||||
bool gotRemoteAddress(struct sockaddr_in &remote_addr, int &cMode);
|
||||
|
||||
private:
|
||||
int state;
|
||||
struct sockaddr_in ext_addr;
|
||||
struct sockaddr_in remote_addr;
|
||||
int connectMode; /* sent with the remote addresses */
|
||||
};
|
||||
|
||||
/* Documenting the virtual (proxy) pqi interface.
|
||||
*
|
||||
* This is used to create proxy interface
|
||||
* for people behind firewalls.
|
||||
*
|
||||
* P1 PROXY P2
|
||||
* requests a
|
||||
* proxy interface.
|
||||
* --------->
|
||||
* end attempt <----- IF Not
|
||||
* Available.
|
||||
*
|
||||
* else ---------------> Check for proxy/person auth
|
||||
* end attempt <------ cancel ------- If Not Auth.
|
||||
*
|
||||
* else, if allowed.
|
||||
* build proxy server.
|
||||
* Build proxy <------ setup ---------- send okay
|
||||
* server connection.
|
||||
*
|
||||
* Determine Local
|
||||
* External Addr
|
||||
* Determine Local
|
||||
* External Addr
|
||||
*
|
||||
* send ext addr ------->
|
||||
* collect addresses.
|
||||
* <---------- send ext addr ------->
|
||||
* complete proxy part.
|
||||
* <-------- send addresses ------->
|
||||
*
|
||||
*
|
||||
* Initiate Udp Connection. --------------------> Initiate Udp Connection.
|
||||
* <--------------------------------
|
||||
*
|
||||
*
|
||||
* So the initial stuff is the same.....
|
||||
* but there is no pipe at the end
|
||||
* just the exchange of addresses.
|
||||
*
|
||||
* there is a udp listener on the same address
|
||||
* as the ssllistener (just udp). This port
|
||||
* will be used by the stunServer, and will supply
|
||||
* external addresses to clients that request them.
|
||||
*
|
||||
*
|
||||
* Order of udp connection:
|
||||
* (1) establish a proxy connection.
|
||||
* (2) determine external address.
|
||||
* (3) send external address to proxy.
|
||||
* (4) recieve address pair
|
||||
* (5) initiate a udp connection.
|
||||
*
|
||||
* Each udpproxy must stun to get their connection addr.
|
||||
* this might end up with lots of stuns?
|
||||
* does that matter?
|
||||
*
|
||||
* pqissl.
|
||||
* -> proxy interface.
|
||||
* Send()
|
||||
* return proxymsg locally
|
||||
* pulled by proxy server.
|
||||
*
|
||||
* ps -> send proxy msg
|
||||
* to correct pqissl.
|
||||
* ----------> popped out to
|
||||
* the proxy server.
|
||||
* if file cache.
|
||||
* redirect ------> recieved by pqissl.
|
||||
* pulled by proxy server.
|
||||
*
|
||||
* proxy server
|
||||
*
|
||||
* all proxied information is
|
||||
* going to be signed/or encrypted.
|
||||
*
|
||||
* very simple - that is the only
|
||||
* necessary change.
|
||||
*
|
||||
* proxy msg.
|
||||
* ---------------------
|
||||
* type : init
|
||||
* end
|
||||
* msg (signed)
|
||||
* tunnelled (includes init of ssl.)
|
||||
* dest cert signature:
|
||||
*
|
||||
* encryption/signature mode.
|
||||
*
|
||||
* signature len:
|
||||
* signature:
|
||||
*
|
||||
* data len:
|
||||
* data
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* is this the right place to add it?
|
||||
* or is pqistreamer the answer.
|
||||
*
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
@ -1,16 +0,0 @@
|
||||
|
||||
#include "pqi/pqinetwork.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
addr.sin_port = htons(1101);
|
||||
|
||||
LookupDNSAddr("www.google.com", addr);
|
||||
LookupDNSAddr("10.0.0.19", addr);
|
||||
LookupDNSAddr("localhost", addr);
|
||||
LookupDNSAddr("nameless", addr);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,100 +0,0 @@
|
||||
|
||||
#include "pqi/pqipacket.h"
|
||||
#include "pqi/pqi.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
int checkMsg(PQItem *item);
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
MsgItem *item = new MsgItem();
|
||||
|
||||
item -> sendTime = 0x10203040;
|
||||
item -> msg = "asdfghjklwertyuisdfghjkasdfghewrtyefrghfghdfghjklghjkdfghjdfghjdfghjdfghjdghjsdghdfghjdfghdfghdfghjdfghdfghjdfghjfghjdfghjdfghjfghjfghjfghjdfghj";
|
||||
item -> msg += " asdfghjklwertyuisdfghjkasdfghewrtyefrghfghdfghjklghjkdfghjdfghjdfghjdfghjdghjsdghdfghjdfghdfghdfghjdfghdfghjdfghjfghjdfghjdfghjfghjfghjfghjdfghj";
|
||||
item -> msg += " asdfghjklwertyuisdfghjkasdfghewrtyefrghfghdfghjklghjkdfghjdfghjdfghjdfghjdghjsdghdfghjdfghdfghdfghjdfghdfghjdfghjfghjdfghjdfghjfghjfghjfghjdfghj";
|
||||
|
||||
MsgFileItem mfi;
|
||||
mfi.name = "A";
|
||||
mfi.hash = "B";
|
||||
mfi.size = 0xFFFFFFFF;
|
||||
item -> files.push_back(mfi);
|
||||
|
||||
mfi.name = "safjhlsafhlsa kfjdhlsa kjfh klsajhf lkjsahflkjhsafkljhsafkjhsafjkhsakfjhksjfhkla sjhf klsjhf kl";
|
||||
mfi.hash = "ia dfjsakfjhsalkfjhlsajkfhlhjksf ljksafhlkjsahflkjsahfl kjsahfl jkhsafl kjhsafkl jhsa fkljh ";
|
||||
mfi.size = 0xFFFFFFFF;
|
||||
item -> files.push_back(mfi);
|
||||
|
||||
item -> title = "sadf";
|
||||
item -> header = "To you from me";
|
||||
|
||||
|
||||
/* fill it up with rubbish */
|
||||
checkMsg(item);
|
||||
|
||||
ChatItem *item2 = new ChatItem();
|
||||
item2 -> msg = "A Short Message";
|
||||
checkMsg(item2);
|
||||
|
||||
ChatItem *item3 = new ChatItem();
|
||||
item3 -> msg = "asdfjkhfjhl sajkfhjksahfkl jahs fjklhsakfj hsajk fh klajs hfklja hsfjkhsa kf hksjdfhksajhf klsajhfkl jhdsafkl jhsklfj hksfjh lksajf klsjhfkjsaf sah f;lksahfk; jshfl kjsahfl; kjhsa flkjhsal kfjh s;akfjhsakfjh ljksl kjsahf ;jksal;sajkfhowiher ;oi28y540832qy5h4rlkjqwhrp928y52hrl;kwajhr2098y54 25hujh 32u5h3 285y 319485yh 315jh3 1495y 13295y15ui1 h51o h51ou5A Short Message";
|
||||
checkMsg(item3);
|
||||
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int checkMsg(PQItem *item)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
std::cerr << "Input MsgItem: " << std::endl;
|
||||
item -> print(std::cerr);
|
||||
|
||||
/* stream it */
|
||||
std::cerr << "Streaming..." << std::endl;
|
||||
|
||||
void *pkt = pqipkt_makepkt(item);
|
||||
|
||||
if (!pkt)
|
||||
{
|
||||
std::cerr << "Pkt creation failed!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* print out packet */
|
||||
int size = pqipkt_rawlen(pkt);
|
||||
|
||||
std::cerr << "Pkt Dump(" << size << ")" << std::endl;
|
||||
std::ostringstream out;
|
||||
for(i = 0; i < size;)
|
||||
{
|
||||
for(j = 0; (i + j < size) && (j < 8); j++)
|
||||
{
|
||||
unsigned char n = ((unsigned char *) pkt)[i+j];
|
||||
out << std::setw(2) << std::hex << (unsigned int) n << ":";
|
||||
}
|
||||
i += j;
|
||||
out << std::endl;
|
||||
}
|
||||
std::cerr << out.str();
|
||||
|
||||
/* stream back */
|
||||
PQItem *i2 = pqipkt_create(pkt);
|
||||
|
||||
std::cerr << "Output MsgItem: " << std::endl;
|
||||
i2 -> print(std::cerr);
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1932,6 +1932,19 @@ bool certsign::operator==(const certsign &ref) const
|
||||
|
||||
|
||||
/* Fns for relating cert signatures to structures */
|
||||
cert *sslroot::findPeerId(std::string id)
|
||||
{
|
||||
certsign sign;
|
||||
if (!convert_to_certsign(id, sign))
|
||||
{
|
||||
pqioutput(PQL_WARNING, pqisslrootzone,
|
||||
"sslroot::findPeerId() ERROR: Failed to Convert to certsign");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return findcertsign(sign);
|
||||
}
|
||||
|
||||
cert *sslroot::findcertsign(certsign &sign)
|
||||
{
|
||||
std::map<certsign, cert *>::iterator it;
|
||||
|
@ -181,6 +181,7 @@ void setSetting(std::string opt, std::string val);
|
||||
|
||||
|
||||
/* Fns for relating cert signatures to structures */
|
||||
cert *findPeerId(std::string id);
|
||||
cert *findcertsign(certsign &sign);
|
||||
int getcertsign(cert *c, certsign &sign);
|
||||
int addtosignmap(cert *);
|
||||
|
Loading…
Reference in New Issue
Block a user