added single function to call dht, with thread cleanup.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5954 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-12-09 13:19:28 +00:00
parent 3be22536df
commit 62176264d3
5 changed files with 493 additions and 444 deletions

View file

@ -1,50 +1,22 @@
#include "bitdht/bdiface.h"
#include "bitdht/bdstddht.h"
#include "bdhandler.h"
#include "bootstrap_fn.h"
#include <iostream>
#include <inttypes.h>
int main(int argc, char **argv)
{
/* startup dht : with a random id! */
bdNodeId ownId;
bdStdRandomNodeId(&ownId);
uint16_t port = 6775;
std::string appId = "bsId";
std::string bootstrapfile = "bdboot.txt";
BitDhtHandler dht(&ownId, port, appId, bootstrapfile);
/* install search node */
bdNodeId searchId;
bdStdRandomNodeId(&searchId);
std::cerr << "bssdht: searching for Id: ";
bdStdPrintNodeId(std::cerr, &searchId);
std::string peerId;
std::string ip;
uint16_t port;
std::cerr << "bssdht: starting up";
std::cerr << std::endl;
dht.FindNode(&searchId);
bdSingleShotFindPeer(bootstrapfile, peerId, ip, port);
/* run your program */
bdId resultId;
uint32_t status;
resultId.id = searchId;
while(false == dht.SearchResult(&resultId, status))
{
sleep(10);
}
std::cerr << "bssdht: Found Result:" << std::endl;
std::cerr << "\tId: ";
bdStdPrintId(std::cerr, &resultId);
std::cerr << std::endl;
std::cerr << "\tstatus: " << status;
std::cerr << "bssdht: finished";
std::cerr << std::endl;
return 1;