mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-18 10:58:43 -04:00
added config target for turtle hoping, pushed router dev a little further.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1074 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
32c12542dc
commit
8d08034380
3 changed files with 187 additions and 313 deletions
|
@ -25,7 +25,7 @@ win32-x-g++ {
|
||||||
QMAKE_CXXFLAGS *= -Wmissing-include-dirs
|
QMAKE_CXXFLAGS *= -Wmissing-include-dirs
|
||||||
QMAKE_CC = i586-mingw32msvc-g++
|
QMAKE_CC = i586-mingw32msvc-g++
|
||||||
QMAKE_LIB = i586-mingw32msvc-ar
|
QMAKE_LIB = i586-mingw32msvc-ar
|
||||||
DEFINES *= STATICLIB
|
DEFINES *= STATICLIB WIN32
|
||||||
|
|
||||||
INCLUDEPATH *= /usr/i586-mingw32msvc/include ${HOME}/.wine/drive_c/pthreads/include/
|
INCLUDEPATH *= /usr/i586-mingw32msvc/include ${HOME}/.wine/drive_c/pthreads/include/
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,8 @@ win32 {
|
||||||
|
|
||||||
DEFINES *= PQI_USE_XPGP MINIUPNPC_VERSION=10
|
DEFINES *= PQI_USE_XPGP MINIUPNPC_VERSION=10
|
||||||
|
|
||||||
SSL_DIR = ../../../../openssl-0.9.7g-xpgp-0.1c
|
SSL_DIR=../../../../src/openssl-0.9.7g-xpgp-0.1c
|
||||||
UPNPC_DIR = ../../../../miniupnpc-1.0
|
UPNPC_DIR=../../../../src/miniupnpc-1.0
|
||||||
|
|
||||||
INCLUDEPATH += . $${SSL_DIR}/include $${UPNPC_DIR}
|
INCLUDEPATH += . $${SSL_DIR}/include $${UPNPC_DIR}
|
||||||
|
|
||||||
|
@ -315,3 +315,13 @@ SOURCES = \
|
||||||
util/rsnet.cc \
|
util/rsnet.cc \
|
||||||
util/rsprint.cc \
|
util/rsprint.cc \
|
||||||
util/rsthreads.cc
|
util/rsthreads.cc
|
||||||
|
|
||||||
|
# To compile for turtle hopping. I'm using this flag to avoid conflict while developping.
|
||||||
|
# Just do a
|
||||||
|
# qmake CONFIG=turtle
|
||||||
|
|
||||||
|
turtle {
|
||||||
|
SOURCES += services/p3turtle.cc
|
||||||
|
HEADERS += services/p3turtle.h
|
||||||
|
DEFINES *= TURTLE_HOPPING
|
||||||
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
/*
|
/*
|
||||||
* libretroshare/src/services: p3disc.cc
|
* libretroshare/src/services: p3turtle.cc
|
||||||
*
|
*
|
||||||
* Services for RetroShare.
|
* Services for RetroShare.
|
||||||
*
|
*
|
||||||
* Copyright 2004-2008 by Robert Fernie.
|
* Copyright 2009 by Cyril Soler
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
@ -19,17 +19,17 @@
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
* USA.
|
* USA.
|
||||||
*
|
*
|
||||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
* Please report all bugs and problems to "csoler@users.sourceforge.net".
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "rsiface/rsiface.h"
|
#include "rsiface/rsiface.h"
|
||||||
#include "rsiface/rspeers.h"
|
#include "rsiface/rspeers.h"
|
||||||
#include "services/p3disc.h"
|
|
||||||
|
|
||||||
#include "pqi/p3authmgr.h"
|
#include "pqi/p3authmgr.h"
|
||||||
#include "pqi/p3connmgr.h"
|
#include "pqi/p3connmgr.h"
|
||||||
|
#include "p3turtle.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -48,9 +48,7 @@ const uint8_t RS_TURTLE_SUBTYPE_SEARCH_RESULT = 0x02;
|
||||||
|
|
||||||
/* DISC FLAGS */
|
/* DISC FLAGS */
|
||||||
|
|
||||||
/*****
|
#define P3TURTLE_DEBUG 1
|
||||||
* #define P3DISC_DEBUG 1
|
|
||||||
****/
|
|
||||||
|
|
||||||
/*********** NOTE ***************
|
/*********** NOTE ***************
|
||||||
*
|
*
|
||||||
|
@ -64,7 +62,7 @@ const uint8_t RS_TURTLE_SUBTYPE_SEARCH_RESULT = 0x02;
|
||||||
|
|
||||||
p3turtle::p3turtle(p3AuthMgr *am, p3ConnectMgr *cm) :p3Service(RS_SERVICE_TYPE_TURTLE), mAuthMgr(am), mConnMgr(cm)
|
p3turtle::p3turtle(p3AuthMgr *am, p3ConnectMgr *cm) :p3Service(RS_SERVICE_TYPE_TURTLE), mAuthMgr(am), mConnMgr(cm)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
addSerialType(new RsTurtleSerialiser());
|
addSerialType(new RsTurtleSerialiser());
|
||||||
}
|
}
|
||||||
|
@ -74,20 +72,51 @@ int p3turtle::tick()
|
||||||
handleIncoming(); // handle incoming packets
|
handleIncoming(); // handle incoming packets
|
||||||
handleOutgoing(); // handle outgoing packets
|
handleOutgoing(); // handle outgoing packets
|
||||||
|
|
||||||
|
// Clean every 10 sec.
|
||||||
|
time_t now = time(NULL) ;
|
||||||
|
|
||||||
|
if(now > 10+_last_clean_time)
|
||||||
|
{
|
||||||
autoclean() ; // clean old/unused tunnels and search requests.
|
autoclean() ; // clean old/unused tunnels and search requests.
|
||||||
|
_last_clean_time = now ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int p3turtle::autoclean()
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
|
// look for tunnels and stored temportary info that have not been used for a while.
|
||||||
|
}
|
||||||
|
|
||||||
|
TurtleRequestId p3turtle::performSearch(const std::string& string_to_match)
|
||||||
|
{
|
||||||
|
// generate a new search id.
|
||||||
|
|
||||||
|
TurtleRequestId = generateRandomRequestId() ;
|
||||||
|
|
||||||
|
// form a request packet
|
||||||
|
//
|
||||||
|
RsTurtleSearchRequestItem *item = new RsTurtleSearchRequestItem ;
|
||||||
|
|
||||||
|
item->match_string = string_to_match ;
|
||||||
|
item->request_id = TurtleRequestId ;
|
||||||
|
item->depth = 0 ;
|
||||||
|
|
||||||
|
// send it
|
||||||
|
|
||||||
|
handleSearchRequest(item) ;
|
||||||
|
|
||||||
|
delete item ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int p3turtle::handleIncoming()
|
int p3turtle::handleIncoming()
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_TURTLE
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << "p3turtle::handleIncoming()";
|
std::cerr << "p3turtle::handleIncoming()";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{
|
|
||||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
|
||||||
}
|
|
||||||
|
|
||||||
int nhandled = 0;
|
int nhandled = 0;
|
||||||
// While messages read
|
// While messages read
|
||||||
//
|
//
|
||||||
|
@ -115,25 +144,39 @@ int p3turtle::handleIncoming()
|
||||||
return nhandled;
|
return nhandled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3turtle::handleSearchRequest(const RsSearchRequestItem *item)
|
void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
|
||||||
{
|
{
|
||||||
// take a look at the item:
|
// take a look at the item:
|
||||||
// - If the item destimation is
|
// - If the item destimation is
|
||||||
|
|
||||||
|
#ifdef P3TURTLE_DEBUG
|
||||||
|
std::cerr << "Received search request: " << std::endl ;
|
||||||
|
item->print() ;
|
||||||
|
#endif
|
||||||
// If the item contains an already handled search request, give up. This
|
// If the item contains an already handled search request, give up. This
|
||||||
// happens when the same search request gets relayed by different peers
|
// happens when the same search request gets relayed by different peers
|
||||||
//
|
//
|
||||||
if(requests_origins.find(item->request_id) != requests_origins.end())
|
if(requests_origins.find(item->request_id) != requests_origins.end())
|
||||||
|
{
|
||||||
|
#ifdef P3TURTLE_DEBUG
|
||||||
|
std::cerr << " This is a bouncing request. Ignoring and deleting it." << std::endl ;
|
||||||
|
#endif
|
||||||
return ;
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
// This is a new request. Let's add it to the request map, and forward it to
|
// This is a new request. Let's add it to the request map, and forward it to
|
||||||
// open peers.
|
// open peers.
|
||||||
|
|
||||||
requests_origins[item->request_id] = item->peerId() ;
|
requests_origins[item->request_id] = item->peerId() ;
|
||||||
|
|
||||||
// Perform local search. If something found, forward the search result back.
|
// If it's not for us, perform a local search. If something found, forward the search result back.
|
||||||
|
|
||||||
std::map<FileHash,FileName> result ;
|
if(item->peerId() != own_peer_id)
|
||||||
|
{
|
||||||
|
#ifdef P3TURTLE_DEBUG
|
||||||
|
std::cerr << " Request not from us. Performing local search" << std::endl ;
|
||||||
|
#endif
|
||||||
|
std::map<TurtleFileHash,FileName> result ;
|
||||||
performLocalSearch(item->match_string,result) ;
|
performLocalSearch(item->match_string,result) ;
|
||||||
|
|
||||||
if(!result.empty())
|
if(!result.empty())
|
||||||
|
@ -143,20 +186,32 @@ void p3turtle::handleSearchRequest(const RsSearchRequestItem *item)
|
||||||
// forward item back
|
// forward item back
|
||||||
RsTurtleSearchResultItem *res_item = new RsTurtleSearchResultItem ;
|
RsTurtleSearchResultItem *res_item = new RsTurtleSearchResultItem ;
|
||||||
|
|
||||||
|
// perhaps we should chop search results items into several items of finite size ?
|
||||||
res_item->depth = 0 ;
|
res_item->depth = 0 ;
|
||||||
res_item->result = result ;
|
res_item->result = result ;
|
||||||
res_item->request_id = item->request_id ;
|
res_item->request_id = item->request_id ;
|
||||||
res_item->peer_id = item->peer_id ; // send back to the same guy
|
res_item->peer_id = item->peer_id ; // send back to the same guy
|
||||||
|
|
||||||
|
#ifdef P3TURTLE_DEBUG
|
||||||
|
std::cerr << " " << result.size() << " matches found. Sending back to origin." << std::endl ;
|
||||||
|
#endif
|
||||||
sendItem(res_item) ;
|
sendItem(res_item) ;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If search depth not too large, also forward this search request to all other peers.
|
// If search depth not too large, also forward this search request to all other peers.
|
||||||
//
|
//
|
||||||
if(item->depth < TURTLE_MAX_SEARCH_DEPTH)
|
if(item->depth < TURTLE_MAX_SEARCH_DEPTH)
|
||||||
for(std::map<>::const_iterator it(openned_peers.begin());it!=openned_peers.end();++it)
|
{
|
||||||
|
std::list<std::string> onlineIds ;
|
||||||
|
mConnMgr->getOnlineList(onlineIds);
|
||||||
|
|
||||||
|
for(std::map<>::const_iterator it(inlineIds.begin());it!=inlineIds.end();++it)
|
||||||
if(*it != item->peerId())
|
if(*it != item->peerId())
|
||||||
{
|
{
|
||||||
|
#ifdef P3TURTLE_DEBUG
|
||||||
|
std::cerr << " Forwarding request to peer = " << *it << std::endl ;
|
||||||
|
#endif
|
||||||
// Copy current item and modify it.
|
// Copy current item and modify it.
|
||||||
RsTurtleSearchRequestItem *fwd_item = new RsTurtleSearchRequestItem(item) ;
|
RsTurtleSearchRequestItem *fwd_item = new RsTurtleSearchRequestItem(item) ;
|
||||||
|
|
||||||
|
@ -166,13 +221,21 @@ void p3turtle::handleSearchRequest(const RsSearchRequestItem *item)
|
||||||
sendItem(fwd_item) ;
|
sendItem(fwd_item) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef P3TURTLE_DEBUG
|
||||||
|
else
|
||||||
|
std::cout << " Dropping this item, as search depth is " << item->depth << std::endl ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void p3turtle::handleSearchResult(const RsSearchResultItem *item)
|
void p3turtle::handleSearchResult(const RsTurtleSearchResultItem *item)
|
||||||
{
|
{
|
||||||
// Find who actually sent the corresponding request.
|
// Find who actually sent the corresponding request.
|
||||||
//
|
//
|
||||||
std::map<TurtleRequestId,TurtlePeerId>::const_iterator it = requests_origins.find(item->request_id) ;
|
std::map<TurtleRequestId,TurtlePeerId>::const_iterator it = requests_origins.find(item->request_id) ;
|
||||||
|
#ifdef P3TURTLE_DEBUG
|
||||||
|
std::cerr << "Received search result:" << std::endl ;
|
||||||
|
item->print() ;
|
||||||
|
#endif
|
||||||
if(it == requests_origins.end())
|
if(it == requests_origins.end())
|
||||||
{
|
{
|
||||||
// This is an error: how could we receive a search result corresponding to a search item we
|
// This is an error: how could we receive a search result corresponding to a search item we
|
||||||
|
@ -189,7 +252,10 @@ void p3turtle::handleSearchResult(const RsSearchResultItem *item)
|
||||||
returnSearchResult(item) ; // Yes, so send upward.
|
returnSearchResult(item) ; // Yes, so send upward.
|
||||||
else
|
else
|
||||||
{ // Nope, so forward it back.
|
{ // Nope, so forward it back.
|
||||||
RsSearchResultItem *fwd_item = new RsSearchResultItem(item) ; // copy the item
|
#ifdef P3TURTLE_DEBUG
|
||||||
|
std::cerr << " Forwarding result back to " << it->second << std::endl;
|
||||||
|
#endif
|
||||||
|
RsTurtleSearchResultItem *fwd_item = new RsTurtleSearchResultItem(item) ; // copy the item
|
||||||
|
|
||||||
++(fwd_item->depth) ; // increase depth
|
++(fwd_item->depth) ; // increase depth
|
||||||
|
|
||||||
|
@ -201,9 +267,41 @@ void p3turtle::handleSearchResult(const RsSearchResultItem *item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RsTurtleSearchRequestItem::print() const
|
||||||
|
{
|
||||||
|
std::cout << "Search request:" << std::endl ;
|
||||||
|
|
||||||
|
std::cout << " match string: \"" << match_string << "\"" << std::endl ;
|
||||||
|
std::cout << " Req. Id: " << request_id << std::endl ;
|
||||||
|
std::cout << " Depth : " << depth << std::endl ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsTurtleSearchResultItem::print() const
|
||||||
|
{
|
||||||
|
std::cout << "Search result:" << std::endl ;
|
||||||
|
|
||||||
|
std::cout << " Peer id: " << peer_id << std::endl ;
|
||||||
|
std::cout << " Depth : " << depth << std::endl ;
|
||||||
|
std::cout << " Req. Id: " << request_id << std::endl ;
|
||||||
|
std::cout << " Files:" << std::endl ;
|
||||||
|
|
||||||
|
for(std::map<TurtleFileHash,FileName>::const_iterator it(result.begin());it!=result.end();++it)
|
||||||
|
std::cout << " " << it->first << " " << it->Second << std::endl ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3turtle::returnSearchResult(RsTurtleSearchResultItem *item)
|
||||||
|
{
|
||||||
|
// just cout for now, but it should be notified to the gui
|
||||||
|
|
||||||
|
std::cerr << "Received result for search request: " << std::endl ;
|
||||||
|
item->print() ;
|
||||||
|
}
|
||||||
|
|
||||||
/************* from pqiMonitor *******************/
|
/************* from pqiMonitor *******************/
|
||||||
void p3turtle::statusChange(const std::list<pqipeer> &plist)
|
void p3turtle::statusChange(const std::list<pqipeer> &plist)
|
||||||
{
|
{
|
||||||
|
// Do we shutdown tunnels whne peers are down, or automatically find a new tunnel ?
|
||||||
|
// I'll see that later...
|
||||||
#ifdef TO_DO
|
#ifdef TO_DO
|
||||||
/* get a list of all online peers */
|
/* get a list of all online peers */
|
||||||
std::list<std::string> onlineIds;
|
std::list<std::string> onlineIds;
|
||||||
|
@ -223,273 +321,3 @@ void p3turtle::statusChange(const std::list<pqipeer> &plist)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef A_VIRER
|
|
||||||
|
|
||||||
void p3disc::respondToPeer(std::string id)
|
|
||||||
{
|
|
||||||
/* get a peer lists */
|
|
||||||
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::cerr << "p3disc::respondToPeer() id: " << id;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::list<std::string> friendIds;
|
|
||||||
std::list<std::string> onlineIds;
|
|
||||||
std::list<std::string>::iterator it;
|
|
||||||
|
|
||||||
mConnMgr->getFriendList(friendIds);
|
|
||||||
mConnMgr->getOnlineList(onlineIds);
|
|
||||||
|
|
||||||
/* Check that they have DISC on */
|
|
||||||
{
|
|
||||||
/* get details */
|
|
||||||
peerConnectState detail;
|
|
||||||
if (!mConnMgr->getFriendNetStatus(id, detail))
|
|
||||||
{
|
|
||||||
/* major error! */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (detail.visState & RS_VIS_STATE_NODISC)
|
|
||||||
{
|
|
||||||
/* don't have DISC enabled */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* send them a list of all friend's details */
|
|
||||||
for(it = friendIds.begin(); it != friendIds.end(); it++)
|
|
||||||
{
|
|
||||||
/* get details */
|
|
||||||
peerConnectState detail;
|
|
||||||
if (!mConnMgr->getFriendNetStatus(*it, detail))
|
|
||||||
{
|
|
||||||
/* major error! */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(detail.visState & RS_VIS_STATE_NODISC))
|
|
||||||
{
|
|
||||||
sendPeerDetails(id, *it); /* (dest (to), source (cert)) */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* send their details to all online peers */
|
|
||||||
for(it = onlineIds.begin(); it != onlineIds.end(); it++)
|
|
||||||
{
|
|
||||||
peerConnectState detail;
|
|
||||||
if (!mConnMgr->getFriendNetStatus(*it, detail))
|
|
||||||
{
|
|
||||||
/* major error! */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(detail.visState & RS_VIS_STATE_NODISC))
|
|
||||||
{
|
|
||||||
sendPeerDetails(*it, id); /* (dest (to), source (cert)) */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************************/
|
|
||||||
/* Output Network Msgs */
|
|
||||||
/*************************************************************************************/
|
|
||||||
void p3disc::sendOwnDetails(std::string to)
|
|
||||||
{
|
|
||||||
/* setup:
|
|
||||||
* IP local / external
|
|
||||||
* availability (TCP LOCAL / EXT, UDP ...)
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Then send message.
|
|
||||||
{
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::ostringstream out;
|
|
||||||
out << "p3disc::sendOwnDetails()";
|
|
||||||
out << "Constructing a RsDiscItem Message!" << std::endl;
|
|
||||||
out << "Sending to: " << to;
|
|
||||||
std::cerr << out.str() << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct a message
|
|
||||||
RsDiscItem *di = new RsDiscItem();
|
|
||||||
|
|
||||||
/* components:
|
|
||||||
* laddr
|
|
||||||
* saddr
|
|
||||||
* contact_tf
|
|
||||||
* discFlags
|
|
||||||
*/
|
|
||||||
|
|
||||||
peerConnectState detail;
|
|
||||||
if (!mConnMgr->getOwnNetStatus(detail))
|
|
||||||
{
|
|
||||||
/* major error! */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fill the message
|
|
||||||
di -> PeerId(to);
|
|
||||||
di -> laddr = detail.localaddr;
|
|
||||||
di -> saddr = detail.serveraddr;
|
|
||||||
di -> contact_tf = 0;
|
|
||||||
|
|
||||||
/* construct disc flags */
|
|
||||||
di -> discFlags = 0;
|
|
||||||
if (!(detail.visState & RS_VIS_STATE_NODISC))
|
|
||||||
{
|
|
||||||
di->discFlags |= P3DISC_FLAGS_USE_DISC;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(detail.visState & RS_VIS_STATE_NODHT))
|
|
||||||
{
|
|
||||||
di->discFlags |= P3DISC_FLAGS_USE_DHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((detail.netMode & RS_NET_MODE_EXT) ||
|
|
||||||
(detail.netMode & RS_NET_MODE_UPNP))
|
|
||||||
{
|
|
||||||
di->discFlags |= P3DISC_FLAGS_EXTERNAL_ADDR;
|
|
||||||
}
|
|
||||||
else if (detail.netMode & RS_NET_MODE_UDP)
|
|
||||||
{
|
|
||||||
di->discFlags |= P3DISC_FLAGS_STABLE_UDP;
|
|
||||||
}
|
|
||||||
|
|
||||||
di->discFlags |= P3DISC_FLAGS_OWN_DETAILS;
|
|
||||||
|
|
||||||
/* send msg */
|
|
||||||
sendItem(di);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (dest (to), source (cert)) */
|
|
||||||
void p3disc::sendPeerDetails(std::string to, std::string about)
|
|
||||||
{
|
|
||||||
/* setup:
|
|
||||||
* Certificate.
|
|
||||||
* IP local / external
|
|
||||||
* availability ...
|
|
||||||
* last connect (0) if online.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* send it off */
|
|
||||||
{
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::ostringstream out;
|
|
||||||
out << "p3disc::sendPeerDetails()";
|
|
||||||
out << " Sending details of: " << about;
|
|
||||||
out << " to: " << to << std::endl;
|
|
||||||
std::cerr << out.str() << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
peerConnectState detail;
|
|
||||||
if (!mConnMgr->getFriendNetStatus(about, detail))
|
|
||||||
{
|
|
||||||
/* major error! */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct a message
|
|
||||||
RsDiscReply *di = new RsDiscReply();
|
|
||||||
|
|
||||||
// Fill the message
|
|
||||||
// Set Target as input cert.
|
|
||||||
di -> PeerId(to);
|
|
||||||
di -> aboutId = about;
|
|
||||||
|
|
||||||
// set the server address.
|
|
||||||
di -> laddr = detail.localaddr;
|
|
||||||
di -> saddr = detail.serveraddr;
|
|
||||||
|
|
||||||
if (detail.state & RS_PEER_S_CONNECTED)
|
|
||||||
{
|
|
||||||
di -> contact_tf = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
di -> contact_tf = convertTDeltaToTRange(time(NULL) - detail.lastcontact);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* construct disc flags */
|
|
||||||
di->discFlags = 0;
|
|
||||||
|
|
||||||
/* NOTE we should not be sending packet if NODISC is set....
|
|
||||||
* checked elsewhere... so don't check.
|
|
||||||
*/
|
|
||||||
di->discFlags |= P3DISC_FLAGS_USE_DISC;
|
|
||||||
|
|
||||||
if (!(detail.visState & RS_VIS_STATE_NODHT))
|
|
||||||
{
|
|
||||||
di->discFlags |= P3DISC_FLAGS_USE_DHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (detail.netMode & RS_NET_MODE_EXT)
|
|
||||||
{
|
|
||||||
di->discFlags |= P3DISC_FLAGS_EXTERNAL_ADDR;
|
|
||||||
}
|
|
||||||
else if (detail.netMode & RS_NET_MODE_UDP)
|
|
||||||
{
|
|
||||||
di->discFlags |= P3DISC_FLAGS_STABLE_UDP;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (detail.state & RS_PEER_S_CONNECTED)
|
|
||||||
{
|
|
||||||
di->discFlags |= P3DISC_FLAGS_PEER_ONLINE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add 3rd party trust info
|
|
||||||
// We look at peers that trust 'to', by looking into 'to''s tigners list. The problem is that
|
|
||||||
// signers are accessible through their names instead of their id, so there is ambiguity if too peers
|
|
||||||
// have the same names. @DrBob: that would be cool to save signers using their ids...
|
|
||||||
//
|
|
||||||
RsPeerDetails pd ;
|
|
||||||
std::string name = rsPeers->getPeerName(about) ;
|
|
||||||
if(rsPeers->getPeerDetails(to,pd))
|
|
||||||
for(std::list<std::string>::const_iterator it(pd.signers.begin());it!=pd.signers.end();++it)
|
|
||||||
if(*it == name)
|
|
||||||
{
|
|
||||||
di->discFlags |= P3DISC_FLAGS_PEER_TRUSTS_ME;
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::cerr << " Peer " << about << "(" << name << ")" << " is trusting " << to << ", sending info." << std::endl ;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t certLen = 0;
|
|
||||||
|
|
||||||
unsigned char **binptr = (unsigned char **) &(di -> certDER.bin_data);
|
|
||||||
|
|
||||||
mAuthMgr->SaveCertificateToBinary(about, binptr, &certLen);
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::cerr << "Saved certificate to binary in p3discReply. Length=" << certLen << std::endl ;
|
|
||||||
#endif
|
|
||||||
if (certLen > 0)
|
|
||||||
{
|
|
||||||
di -> certDER.bin_len = certLen;
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::cerr << "Cert Encoded(" << certLen << ")" << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::cerr << "Failed to Encode Cert" << std::endl;
|
|
||||||
#endif
|
|
||||||
di -> certDER.bin_len = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send off message
|
|
||||||
sendItem(di);
|
|
||||||
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::cerr << "Sent DI Message" << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -57,14 +57,17 @@ class p3ConnectMgr;
|
||||||
|
|
||||||
typedef uint32_t TurtleRequestId ;
|
typedef uint32_t TurtleRequestId ;
|
||||||
typedef std::string TurtlePeerId ;
|
typedef std::string TurtlePeerId ;
|
||||||
|
typedef std::string TurtleFileHash ;
|
||||||
|
typedef std::string TurtleFileName ;
|
||||||
|
|
||||||
class RsTurtleItem: public RsItem
|
class RsTurtleItem: public RsItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void serialize(void *& data,uint32_t& size) {} // isn't it better that items can (de)serialize themselves ?
|
virtual bool serialize(void *data,uint32_t& size) = 0 ; // isn't it better that items can (de)serialize themselves ?
|
||||||
virtual void deserialize(const void *data,uint32_t size) {}
|
virtual RsItem *deserialize(const void *data,uint32_t size) = 0 ;
|
||||||
|
virtual uint32_t serial_size() const = 0 ;
|
||||||
|
|
||||||
virtual int size() const ;
|
virtual void print() const = 0 ;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsTurtleSearchResultItem: public RsTurtleItem
|
class RsTurtleSearchResultItem: public RsTurtleItem
|
||||||
|
@ -75,9 +78,13 @@ class RsTurtleSearchResultItem: public RsTurtleItem
|
||||||
|
|
||||||
TurtleRequestId request_id ; // randomly generated request id.
|
TurtleRequestId request_id ; // randomly generated request id.
|
||||||
|
|
||||||
std::map<FileHash,FileName> result ;
|
std::map<TurtleFileHash,TurtleFileName> result ;
|
||||||
// uint8_t hash[20] ; // sha1 hash of the file found
|
virtual void print() const ;
|
||||||
// std::string filename ; // name of the file found
|
|
||||||
|
protected:
|
||||||
|
virtual bool serialize(void *data,uint32_t& size) ;
|
||||||
|
virtual RsItem *deserialize(const void *data,uint32_t size) ;
|
||||||
|
virtual uint32_t serial_size() const ;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsTurtleSearchRequestItem: public RsTurtleItem
|
class RsTurtleSearchRequestItem: public RsTurtleItem
|
||||||
|
@ -86,6 +93,31 @@ class RsTurtleSearchRequestItem: public RsTurtleItem
|
||||||
std::string match_string ; // string to match
|
std::string match_string ; // string to match
|
||||||
uint32_t request_id ; // randomly generated request id.
|
uint32_t request_id ; // randomly generated request id.
|
||||||
uint16_t depth ; // Used for limiting search depth.
|
uint16_t depth ; // Used for limiting search depth.
|
||||||
|
|
||||||
|
virtual void print() const = 0 ;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool serialize(void *data,uint32_t& size) ;
|
||||||
|
virtual RsItem *deserialize(const void *data,uint32_t size) ;
|
||||||
|
virtual uint32_t serial_size() const ;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Class responsible for serializing/deserializing all turtle items.
|
||||||
|
//
|
||||||
|
class RsTurtleSerialiser: public RsSerialType
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RsTurtleSerialiser() : RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_TURTLE) {}
|
||||||
|
|
||||||
|
virtual uint32_t size (RsItem *item)
|
||||||
|
{
|
||||||
|
return static_cast<RsTurtleItem *>(item)->serial_size() ;
|
||||||
|
}
|
||||||
|
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
|
||||||
|
{
|
||||||
|
return static_cast<RsTurtleItem *>(item)->serialize(data,*size) ;
|
||||||
|
}
|
||||||
|
virtual RsItem * deserialise (void *data, uint32_t *size) ;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TurtleTunnel
|
class TurtleTunnel
|
||||||
|
@ -121,18 +153,22 @@ class p3turtle: public p3Service, public pqiMonitor
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline uint32_t generateRandomRequestId() const { return lrand48() ; }
|
inline uint32_t generateRandomRequestId() const { return lrand48() ; }
|
||||||
|
void autoclean() ;
|
||||||
|
|
||||||
/* Network Input */
|
/* Network Input */
|
||||||
int handleIncoming();
|
int handleIncoming();
|
||||||
|
int handleOutgoing();
|
||||||
|
|
||||||
void recvSearchRequest(RsTurtleSearchRequestItem *item);
|
void handleSearchRequest(RsTurtleSearchRequestItem *item);
|
||||||
|
|
||||||
std::map<TurtleRequestId,TurtlePeerId> request_origins ; // keeps trace of who emmitted a given request
|
std::map<TurtleRequestId,TurtlePeerId> request_origins ; // keeps trace of who emmitted a given request
|
||||||
std::map<FileHash,TurtleTunnel> file_tunnels ; // stores adequate tunnels for each file hash.
|
std::map<TurtleFileHash,TurtleTunnel> file_tunnels ; // stores adequate tunnels for each file hash.
|
||||||
|
|
||||||
p3AuthMgr *mAuthMgr;
|
p3AuthMgr *mAuthMgr;
|
||||||
p3ConnectMgr *mConnMgr;
|
p3ConnectMgr *mConnMgr;
|
||||||
|
|
||||||
|
time_t _last_clean_time ;
|
||||||
|
|
||||||
/* data */
|
/* data */
|
||||||
RsMutex mTurtleMtx;
|
RsMutex mTurtleMtx;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue