mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-03 22:55:04 -04:00
Merged branch v0.5-gxs-b1 into trunk (from -r 5351 -> 5995)
This brings a huge amount of goodness into the trunk, but there is still a big chunk todo before it can be released. * GXS Backend. * GXS Services: - Identities. - Circles - Photos - Wiki - GxsForums - Posted. * SSH no-gui server. See branch commits for more info. To switch on GXS stuff, enable CONFIG += gxs in both libretroshare.pro and retroshare-gui.pro git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5996 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
commit
069b72e0b2
549 changed files with 111171 additions and 25579 deletions
|
@ -6,11 +6,11 @@ LIBS = -L../lib -lbitdht -lpthread
|
|||
|
||||
|
||||
|
||||
EXEC : bdexample
|
||||
EXEC : bssdht
|
||||
|
||||
EGOBJ = bdhandler.o bdexample.o
|
||||
EGOBJ = bdhandler.o bssdht.o bootstrap_fn.o
|
||||
|
||||
bdexample: $(EGOBJ)
|
||||
$(CXX) $(CXXFLAGS) -o bdexample $(EGOBJ) $(LIBS)
|
||||
bssdht: $(EGOBJ)
|
||||
$(CXX) $(CXXFLAGS) -o bssdht $(EGOBJ) $(LIBS)
|
||||
|
||||
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
|
||||
|
||||
#include "bitdht/bdiface.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
#include "bdhandler.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
/* startup dht : with a random id! */
|
||||
bdNodeId ownId;
|
||||
bdStdRandomNodeId(&ownId);
|
||||
|
||||
uint16_t port = 6775;
|
||||
std::string appId = "exId";
|
||||
std::string bootstrapfile = "bdboot.txt";
|
||||
|
||||
BitDhtHandler dht(&ownId, port, appId, bootstrapfile);
|
||||
|
||||
/* run your program */
|
||||
while(1)
|
||||
{
|
||||
bdNodeId searchId;
|
||||
bdStdRandomNodeId(&searchId);
|
||||
|
||||
dht.FindNode(&searchId);
|
||||
|
||||
sleep(180);
|
||||
|
||||
dht.DropNode(&searchId);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -29,8 +29,24 @@
|
|||
#include <bitdht/bdstddht.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "bdhandler.h"
|
||||
|
||||
|
||||
/****
|
||||
* This example bitdht app is designed to perform a single shot DHT search.
|
||||
* Ww want to minimise the dht work, and number of UDP packets sent.
|
||||
*
|
||||
* This means we need to add:
|
||||
* - don't search for App network. (libbitdht option)
|
||||
* - don't bother filling up Space. (libbitdht option)
|
||||
* - Programmatically add bootstrap peers. (libbitdht option)
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* This is a conversion callback class
|
||||
*/
|
||||
|
||||
|
@ -111,6 +127,11 @@ BitDhtHandler::BitDhtHandler(bdNodeId *ownId, uint16_t port, std::string appId,
|
|||
|
||||
mUdpBitDht->start(); /* starts up the bitdht thread */
|
||||
|
||||
/* setup best mode for quick search */
|
||||
uint32_t dhtFlags = BITDHT_MODE_TRAFFIC_MED | BITDHT_MODE_RELAYSERVERS_IGNORED;
|
||||
mUdpBitDht->setDhtMode(dhtFlags);
|
||||
mUdpBitDht->setAttachMode(false);
|
||||
|
||||
/* switch on the dht too */
|
||||
mUdpBitDht->startDht();
|
||||
}
|
||||
|
@ -163,8 +184,19 @@ bool BitDhtHandler::FindNode(bdNodeId *peerId)
|
|||
bdStdPrintNodeId(std::cerr, peerId);
|
||||
std::cerr << ")" << std::endl;
|
||||
|
||||
|
||||
BssResult res;
|
||||
res.id.id = *peerId;
|
||||
res.mode = BSS_SINGLE_SHOT;
|
||||
res.status = 0;
|
||||
|
||||
{
|
||||
bdStackMutex stack(resultsMtx); /********** MUTEX LOCKED *************/
|
||||
mSearchNodes[*peerId] = res;
|
||||
}
|
||||
|
||||
/* add in peer */
|
||||
mUdpBitDht->addFindNode(peerId, BITDHT_QFLAGS_DO_IDLE);
|
||||
mUdpBitDht->addFindNode(peerId, BITDHT_QFLAGS_DISGUISE);
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
@ -179,10 +211,50 @@ bool BitDhtHandler::DropNode(bdNodeId *peerId)
|
|||
/* remove in peer */
|
||||
mUdpBitDht->removeFindNode(peerId);
|
||||
|
||||
bdStackMutex stack(resultsMtx); /********** MUTEX LOCKED *************/
|
||||
|
||||
/* find the node from our list */
|
||||
std::map<bdNodeId, BssResult>::iterator it;
|
||||
it = mSearchNodes.find(*peerId);
|
||||
if (it != mSearchNodes.end())
|
||||
{
|
||||
std::cerr << "BitDhtHandler::DropNode() Found NodeId, removing";
|
||||
std::cerr << std::endl;
|
||||
|
||||
mSearchNodes.erase(it);
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
bool BitDhtHandler::SearchResult(bdId *id, uint32_t &status)
|
||||
{
|
||||
bdStackMutex stack(resultsMtx); /********** MUTEX LOCKED *************/
|
||||
|
||||
/* find the node from our list */
|
||||
std::map<bdNodeId, BssResult>::iterator it;
|
||||
it = mSearchNodes.find(id->id);
|
||||
if (it != mSearchNodes.end())
|
||||
{
|
||||
if (it->second.status != 0)
|
||||
{
|
||||
std::cerr << "BitDhtHandler::SearchResults() Found Results";
|
||||
std::cerr << std::endl;
|
||||
status = it->second.status;
|
||||
*id = it->second.id;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << "BitDhtHandler::SearchResults() No Results Yet";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cerr << "BitDhtHandler::SearchResults() ERROR: No Search Entry";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/********************** Callback Functions **************************/
|
||||
|
||||
|
@ -204,6 +276,20 @@ int BitDhtHandler::PeerCallback(const bdId *id, uint32_t status)
|
|||
bdStdPrintId(std::cerr, id);
|
||||
std::cerr << std::endl;
|
||||
|
||||
bdStackMutex stack(resultsMtx); /********** MUTEX LOCKED *************/
|
||||
|
||||
/* find the node from our list */
|
||||
std::map<bdNodeId, BssResult>::iterator it;
|
||||
it = mSearchNodes.find(id->id);
|
||||
if (it == mSearchNodes.end())
|
||||
{
|
||||
std::cerr << "BitDhtHandler::PeerCallback() Unknown NodeId !!! ";
|
||||
std::cerr << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
it->second.status = status;
|
||||
|
||||
bool connect = false;
|
||||
switch(status)
|
||||
{
|
||||
|
@ -212,6 +298,7 @@ int BitDhtHandler::PeerCallback(const bdId *id, uint32_t status)
|
|||
std::cerr << "BitDhtHandler::PeerCallback() QUERY FAILURE ... do nothin ";
|
||||
std::cerr << std::endl;
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case BITDHT_MGR_QUERY_PEER_OFFLINE:
|
||||
|
@ -225,19 +312,19 @@ int BitDhtHandler::PeerCallback(const bdId *id, uint32_t status)
|
|||
case BITDHT_MGR_QUERY_PEER_UNREACHABLE:
|
||||
/* do nothing */
|
||||
|
||||
std::cerr << "BitDhtHandler::PeerCallback() QUERY PEER UNREACHABLE ... flag? / do nothin ";
|
||||
std::cerr << "BitDhtHandler::PeerCallback() QUERY PEER UNREACHABLE ... saving address ";
|
||||
std::cerr << std::endl;
|
||||
|
||||
it->second.id = *id;
|
||||
|
||||
break;
|
||||
|
||||
case BITDHT_MGR_QUERY_PEER_ONLINE:
|
||||
/* do something */
|
||||
|
||||
std::cerr << "BitDhtHandler::PeerCallback() QUERY PEER ONLINE ... try udp connection";
|
||||
std::cerr << "BitDhtHandler::PeerCallback() QUERY PEER ONLINE ... saving address";
|
||||
std::cerr << std::endl;
|
||||
|
||||
connect = true;
|
||||
it->second.id = *id;
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
|
|
|
@ -37,6 +37,18 @@
|
|||
/*** This class can be overloaded to use the XXXXCallback() Functions *****/
|
||||
class BitDhtIntCallback;
|
||||
|
||||
|
||||
class BssResult
|
||||
{
|
||||
public:
|
||||
bdId id;
|
||||
uint32_t mode; // single shot
|
||||
uint32_t status; // SEARCHING, FAILURE, FOUND, MULTIPLE HITS.
|
||||
};
|
||||
|
||||
#define BSS_SINGLE_SHOT 0x0001
|
||||
|
||||
|
||||
class BitDhtHandler
|
||||
{
|
||||
|
||||
|
@ -58,12 +70,17 @@ virtual int NodeCallback(const bdId *id, uint32_t peerflags);
|
|||
virtual int PeerCallback(const bdId *id, uint32_t status);
|
||||
virtual int ValueCallback(const bdNodeId *id, std::string key, uint32_t status);
|
||||
|
||||
bool SearchResult(bdId *id, uint32_t &status);
|
||||
|
||||
private:
|
||||
|
||||
/* real DHT classes */
|
||||
UdpStack *mStack;
|
||||
UdpBitDht *mUdpBitDht;
|
||||
|
||||
bdMutex resultsMtx; /* for all class data (below) */
|
||||
|
||||
std::map<bdNodeId, BssResult> mSearchNodes;
|
||||
};
|
||||
|
||||
|
||||
|
|
60
libbitdht/src/example/bootstrap_fn.cc
Normal file
60
libbitdht/src/example/bootstrap_fn.cc
Normal file
|
@ -0,0 +1,60 @@
|
|||
|
||||
|
||||
#include "bitdht/bdiface.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
#include "bdhandler.h"
|
||||
|
||||
#include "bootstrap_fn.h"
|
||||
|
||||
bool bdSingleShotFindPeer(const std::string bootstrapfile, const std::string peerId, std::string &peer_ip, uint16_t &peer_port)
|
||||
{
|
||||
/* startup dht : with a random id! */
|
||||
bdNodeId ownId;
|
||||
bdStdRandomNodeId(&ownId);
|
||||
|
||||
uint16_t port = 6775;
|
||||
std::string appId = "bsId";
|
||||
BitDhtHandler dht(&ownId, port, appId, bootstrapfile);
|
||||
|
||||
/* install search node */
|
||||
bdNodeId searchId;
|
||||
bdStdRandomNodeId(&searchId);
|
||||
|
||||
std::cerr << "bssdht: searching for Id: ";
|
||||
bdStdPrintNodeId(std::cerr, &searchId);
|
||||
std::cerr << std::endl;
|
||||
|
||||
dht.FindNode(&searchId);
|
||||
|
||||
/* run your program */
|
||||
bdId resultId;
|
||||
uint32_t status;
|
||||
|
||||
resultId.id = searchId;
|
||||
|
||||
while(false == dht.SearchResult(&resultId, status))
|
||||
{
|
||||
sleep(10);
|
||||
}
|
||||
|
||||
std::cerr << "bdSingleShotFindPeer(): Found Result:" << std::endl;
|
||||
|
||||
std::cerr << "\tId: ";
|
||||
bdStdPrintId(std::cerr, &resultId);
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "\tstatus: " << status;
|
||||
std::cerr << std::endl;
|
||||
|
||||
dht.shutdown();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
17
libbitdht/src/example/bootstrap_fn.h
Normal file
17
libbitdht/src/example/bootstrap_fn.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
|
||||
#include <string>
|
||||
#include <inttypes.h>
|
||||
|
||||
|
||||
/* NOTE. At the moment only the bootstrapfile is actually used.
|
||||
* peerId is ignored (a random peerId is searched for). ip & port are not filled in either.
|
||||
*
|
||||
* This is mainly to finish testing.
|
||||
*
|
||||
* Once the best form of the return functions is decided (ipv4 structure, or strings).
|
||||
* this can be finished off.
|
||||
*
|
||||
*/
|
||||
|
||||
bool bdSingleShotFindPeer(const std::string bootstrapfile, const std::string peerId, std::string &ip, uint16_t &port);
|
||||
|
31
libbitdht/src/example/bssdht.cc
Normal file
31
libbitdht/src/example/bssdht.cc
Normal file
|
@ -0,0 +1,31 @@
|
|||
|
||||
#include "bootstrap_fn.h"
|
||||
#include <iostream>
|
||||
#include <inttypes.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
std::string bootstrapfile = "bdboot.txt";
|
||||
std::string peerId;
|
||||
std::string ip;
|
||||
uint16_t port;
|
||||
|
||||
std::cerr << "bssdht: starting up";
|
||||
std::cerr << std::endl;
|
||||
|
||||
bdSingleShotFindPeer(bootstrapfile, peerId, ip, port);
|
||||
|
||||
std::cerr << "bssdht: finished";
|
||||
std::cerr << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue