* Added history to .pro

* modified nettest to be useful as a test program



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3562 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2010-09-29 20:37:30 +00:00
parent aa46ed0f69
commit 2964533caf
2 changed files with 110 additions and 32 deletions

View File

@ -87,6 +87,7 @@ HEADERS += \
bitdht/bdnode.h \
bitdht/bdmanager.h \
bitdht/bdstddht.h \
bitdht/bdhistory.h \
util/bdnet.h \
util/bdthreads.h \
udp/udplayer.h \
@ -104,6 +105,7 @@ SOURCES += \
bitdht/bdnode.cc \
bitdht/bdmanager.cc \
bitdht/bdstddht.cc \
bitdht/bdhistory.cc \
util/bdnet.cc \
util/bdthreads.cc \
udp/udplayer.cc \

View File

@ -32,63 +32,135 @@
#include <stdlib.h>
/*******************************************************************
* Test of bencode message creation functions in bdmsgs.cc
* DHT test program.
*
*
* Create a couple of each type.
*/
#define MAX_MESSAGE_LEN 10240
int args(char *name)
{
std::cerr << "Usage: " << name;
std::cerr << " -p <port> ";
std::cerr << " -b </path/to/bootfile> ";
std::cerr << " -u <uid> ";
std::cerr << " -r (do random queries) ";
std::cerr << std::endl;
return 1;
}
#define DEF_PORT 7500
#define MIN_DEF_PORT 1001
#define MAX_DEF_PORT 16000
#define DEF_BOOTFILE "bdboot.txt"
int main(int argc, char **argv)
{
/* setup id, and bootstrap file */
if (argc < 2)
int c;
int port = DEF_PORT;
std::string bootfile = DEF_BOOTFILE;
std::string uid;
bool setUid = false;
bool doRandomQueries = false;
srand(time(NULL));
while((c = getopt(argc, argv,"p:b:u:r")) != -1)
{
std::cerr << " Missing port number " << std::endl;
exit(1);
switch (c)
{
case 'p':
{
int tmp_port = atoi(optarg);
if ((tmp_port > MIN_DEF_PORT) && (tmp_port < MAX_DEF_PORT))
{
port = tmp_port;
std::cerr << "Port: " << port;
std::cerr << std::endl;
}
else
{
std::cerr << "Invalid Port";
std::cerr << std::endl;
args(argv[0]);
return 1;
}
}
break;
case 'b':
{
bootfile = optarg;
std::cerr << "Bootfile: " << bootfile;
std::cerr << std::endl;
}
break;
case 'u':
{
setUid = true;
uid = optarg;
std::cerr << "UID: " << uid;
std::cerr << std::endl;
}
break;
case 'r':
{
doRandomQueries = true;
std::cerr << "Doing Random Queries";
std::cerr << std::endl;
}
break;
default:
{
args(argv[0]);
return 1;
}
break;
}
}
int delta = 0;
if (argc < 3)
{
std::cerr << "No Id Delta" << std::endl;
}
else
{
delta = atoi(argv[2]);
}
int port = atoi(argv[1]);
std::cerr << "Using Port: " << port << std::endl;
std::cerr << "Using Delta: " << delta << std::endl;
bdDhtFunctions *fns = new bdStdDht();
bdNodeId id;
/**
memcpy(((char *) id.data), "1234567890abcdefghi", 20);
uint32_t *deltaptr = (uint32_t *) (id.data);
(*deltaptr) += htonl(delta);
**/
/* start off with a random id! */
bdStdRandomNodeId(&id);
if (setUid)
{
int len = uid.size();
if (len > 20)
{
len = 20;
}
for(int i = 0; i < len; i++)
{
id.data[i] = uid[i];
}
}
std::cerr << "Using NodeId: ";
fns->bdPrintNodeId(std::cerr, &id);
std::cerr << std::endl;
std::string bootstrapfile = "bdboot.txt";
/* setup the udp port */
struct sockaddr_in local;
memset(&local, 0, sizeof(local));
local.sin_family = AF_INET;
local.sin_addr.s_addr = 0;
local.sin_port = htons(port);
UdpStack *udpstack = new UdpStack(local);
/* create bitdht component */
std::string dhtVersion = "dbTEST";
UdpBitDht *bitdht = new UdpBitDht(udpstack, &id, dhtVersion, bootstrapfile, fns);
UdpBitDht *bitdht = new UdpBitDht(udpstack, &id, dhtVersion, bootfile, fns);
/* add in the stack */
udpstack->addReceiver(bitdht);
@ -107,21 +179,25 @@ int main(int argc, char **argv)
/* do a couple of random continuous searchs. */
uint32_t mode = BITDHT_QFLAGS_DO_IDLE;
mode = 0;
int count = 0;
while(1)
{
sleep(120);
sleep(60);
if (++count == 2)
{
/* switch to one-shot searchs */
mode = 0;
}
bdNodeId rndId;
bdStdRandomNodeId(&rndId);
bitdht->addFindNode(&rndId, mode);
if (doRandomQueries)
{
bdNodeId rndId;
bdStdRandomNodeId(&rndId);
bitdht->addFindNode(&rndId, mode);
}
}
return 1;