mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-08 14:42:51 -04:00
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:
parent
3be22536df
commit
62176264d3
5 changed files with 493 additions and 444 deletions
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue