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:
drbob 2008-01-25 06:36:40 +00:00
parent de0ce110b9
commit 6435357c07
63 changed files with 8336 additions and 10839 deletions

View file

@ -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("");
}