mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
Addition of libbitdht.
============================================================ This is intended to be a completely independent library from RS, (hosted at sf.net/projects/bitdht) hence is being commited at the top level. As initial further development / testing will be driven by RS integration it is being added to the RS repository. Equally important is ensuring that RS can compile without requiring aux libraries. Once libbitdht is further developed, this section of the repository is expected to be removed... But that will not be for a while, I expect. drbob. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3276 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
9b72977bba
commit
c415bb6158
56 changed files with 11344 additions and 0 deletions
80
libbitdht/src/tests/Makefile
Normal file
80
libbitdht/src/tests/Makefile
Normal file
|
@ -0,0 +1,80 @@
|
|||
|
||||
LIB_TOP_DIR = ..
|
||||
TEST_TOP_DIR = $(LIB_TOP_DIR)/tests
|
||||
|
||||
##### Define any flags that are needed for this section #######
|
||||
###############################################################
|
||||
|
||||
###############################################################
|
||||
include $(TEST_TOP_DIR)/scripts/config.mk
|
||||
###############################################################
|
||||
|
||||
# Generic Test Harnesses.
|
||||
TESTOBJ = bdmetric_test.o bdmsgs_test.o bdnode_test.o bdspace_test.o
|
||||
TESTOBJ += bdmgr_multitest.o bdnode_multitest1.o bdquery_test.o bdstore_test.o
|
||||
TESTOBJ += bdmidids_test.o bdnode_test2.o bdspace_test2.o
|
||||
#TESTOBJ += bencode_test.o bdudp_test.o
|
||||
|
||||
TESTS = bdmetric_test bdmsgs_test bdnode_test bdspace_test
|
||||
TESTS += bdmgr_multitest bdnode_multitest1 bdquery_test bdstore_test
|
||||
TESTS += bdmidids_test bdnode_test2 bdspace_test2
|
||||
#TESTS += bencode_test bdudp_test
|
||||
|
||||
MANUAL_TESTS =
|
||||
|
||||
all: tests $(MANUAL_TESTS)
|
||||
|
||||
bdmsgs_test: bdmsgs_test.o
|
||||
$(CC) $(CFLAGS) -o bdmsgs_test bdmsgs_test.o $(LIBS)
|
||||
|
||||
bdmetric_test: bdmetric_test.o
|
||||
$(CC) $(CFLAGS) -o bdmetric_test bdmetric_test.o $(LIBS)
|
||||
|
||||
bdquery_test: bdquery_test.o
|
||||
$(CC) $(CFLAGS) -o bdquery_test bdquery_test.o $(LIBS)
|
||||
|
||||
bdspace_test: bdspace_test.o
|
||||
$(CC) $(CFLAGS) -o bdspace_test bdspace_test.o $(LIBS)
|
||||
|
||||
bdspace_test2: bdspace_test2.o
|
||||
$(CC) $(CFLAGS) -o bdspace_test2 bdspace_test2.o $(LIBS)
|
||||
|
||||
bdnode_test: bdnode_test.o
|
||||
$(CC) $(CFLAGS) -o bdnode_test bdnode_test.o $(LIBS)
|
||||
|
||||
bdnode_test2: bdnode_test2.o
|
||||
$(CC) $(CFLAGS) -o bdnode_test2 bdnode_test2.o $(LIBS)
|
||||
|
||||
bdmidids_test: bdmidids_test.o
|
||||
$(CC) $(CFLAGS) -o bdmidids_test bdmidids_test.o $(LIBS)
|
||||
|
||||
|
||||
bdnode_multitest1: bdnode_multitest1.o
|
||||
$(CC) $(CFLAGS) -o bdnode_multitest1 bdnode_multitest1.o $(LIBS)
|
||||
|
||||
bdmgr_multitest: bdmgr_multitest.o
|
||||
$(CC) $(CFLAGS) -o bdmgr_multitest bdmgr_multitest.o $(LIBS)
|
||||
|
||||
|
||||
bdstore_test: bdstore_test.o
|
||||
$(CC) $(CFLAGS) -o bdstore_test bdstore_test.o $(LIBS)
|
||||
|
||||
bdudp_test: bdudp_test.o
|
||||
$(CC) $(CFLAGS) -o bdudp_test bdudp_test.o $(LIBS)
|
||||
|
||||
udpbitdht_nettest: udpbitdht_nettest.o
|
||||
$(CC) $(CFLAGS) -o udpbitdht_test udpbitdht_test.o $(LIBS)
|
||||
|
||||
bencode_test: bencode_test.o
|
||||
$(CC) $(CFLAGS) -o bencode_test bencode_test.o $(LIBS)
|
||||
|
||||
|
||||
clobber: remove_extra_files
|
||||
|
||||
remove_extra_files:
|
||||
-$(RM) $(MANUAL_TESTS)
|
||||
|
||||
###############################################################
|
||||
include $(TEST_TOP_DIR)/scripts/rules.mk
|
||||
###############################################################
|
||||
|
166
libbitdht/src/tests/bdmetric_test.cc
Normal file
166
libbitdht/src/tests/bdmetric_test.cc
Normal file
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* bitdht/bdmetric_test.cc
|
||||
*
|
||||
* BitDHT: An Flexible DHT library.
|
||||
*
|
||||
* Copyright 2010 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "bitdht@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "bitdht/bdpeer.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
/* create some ids */
|
||||
bdId id1;
|
||||
bdId id2;
|
||||
bdId id3;
|
||||
bdId id4;
|
||||
bdId id5;
|
||||
bdId id6;
|
||||
|
||||
bdStdRandomId(&id1);
|
||||
bdStdRandomId(&id2);
|
||||
bdStdRandomId(&id3);
|
||||
bdStdRandomId(&id4);
|
||||
bdStdRandomId(&id5);
|
||||
bdStdRandomId(&id6);
|
||||
|
||||
fprintf(stderr, "id1:");
|
||||
bdStdPrintId(std::cerr,&id1);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
fprintf(stderr, "id2:");
|
||||
bdStdPrintId(std::cerr,&id2);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
fprintf(stderr, "id3:");
|
||||
bdStdPrintId(std::cerr,&id3);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
fprintf(stderr, "id4:");
|
||||
bdStdPrintId(std::cerr,&id4);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
fprintf(stderr, "id5:");
|
||||
bdStdPrintId(std::cerr,&id5);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
fprintf(stderr, "id6:");
|
||||
bdStdPrintId(std::cerr,&id6);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
/* now do the sums */
|
||||
bdMetric met;
|
||||
bdMetric met2;
|
||||
int bdist = 0;
|
||||
bdStdDistance(&(id1.id), &(id2.id), &met);
|
||||
|
||||
fprintf(stderr, "1^2:");
|
||||
bdStdPrintNodeId(std::cerr,&met);
|
||||
fprintf(stderr, "\n");
|
||||
bdist = bdStdBucketDistance(&met);
|
||||
fprintf(stderr, " bucket: %d\n", bdist);
|
||||
|
||||
bdStdDistance(&(id1.id), &(id3.id), &met2);
|
||||
bdist = bdStdBucketDistance(&met2);
|
||||
|
||||
fprintf(stderr, "1^3:");
|
||||
bdStdPrintNodeId(std::cerr,&met2);
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, " bucket: %d\n", bdist);
|
||||
|
||||
int c1 = met < met2;
|
||||
int c2 = met2 < met;
|
||||
|
||||
fprintf(stderr, "1^2<1^3? : %d 1^3<1^2?: %d\n", c1, c2);
|
||||
|
||||
|
||||
bdStdDistance(&(id1.id), &(id4.id), &met2);
|
||||
bdist = bdStdBucketDistance(&met2);
|
||||
|
||||
fprintf(stderr, "1^4:");
|
||||
bdStdPrintNodeId(std::cerr,&met2);
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, " bucket: %d\n", bdist);
|
||||
|
||||
c1 = met < met2;
|
||||
c2 = met2 < met;
|
||||
|
||||
fprintf(stderr, "1^2<1^4? : %d 1^4<1^2?: %d\n", c1, c2);
|
||||
|
||||
bdStdDistance(&(id1.id), &(id5.id), &met);
|
||||
bdist = bdStdBucketDistance(&met);
|
||||
|
||||
fprintf(stderr, "1^5:");
|
||||
bdStdPrintNodeId(std::cerr,&met);
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, " bucket: %d\n", bdist);
|
||||
|
||||
bdStdDistance(&(id1.id), &(id6.id), &met);
|
||||
bdist = bdStdBucketDistance(&met);
|
||||
|
||||
fprintf(stderr, "1^6:");
|
||||
bdStdPrintNodeId(std::cerr,&met);
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, " bucket: %d\n", bdist);
|
||||
|
||||
bdStdDistance(&(id2.id), &(id3.id), &met);
|
||||
bdist = bdStdBucketDistance(&met);
|
||||
|
||||
fprintf(stderr, "2^3:");
|
||||
bdStdPrintNodeId(std::cerr,&met);
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, " bucket: %d\n", bdist);
|
||||
|
||||
|
||||
fprintf(stderr, "id1:");
|
||||
bdStdPrintId(std::cerr,&id1);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
fprintf(stderr, "id2:");
|
||||
bdStdPrintId(std::cerr,&id2);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
fprintf(stderr, "id3:");
|
||||
bdStdPrintId(std::cerr,&id3);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
fprintf(stderr, "id4:");
|
||||
bdStdPrintId(std::cerr,&id4);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
fprintf(stderr, "id5:");
|
||||
bdStdPrintId(std::cerr,&id5);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
fprintf(stderr, "id6:");
|
||||
bdStdPrintId(std::cerr,&id6);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
185
libbitdht/src/tests/bdmgr_multitest.cc
Normal file
185
libbitdht/src/tests/bdmgr_multitest.cc
Normal file
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
* bitdht/bdmgr_multitest.cc
|
||||
*
|
||||
* BitDHT: An Flexible DHT library.
|
||||
*
|
||||
* Copyright 2010 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "bitdht@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "bitdht/bdmanager.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
#include "udp/udplayer.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/**********************************************************************************
|
||||
* tests of multi bdnodes all connected together.
|
||||
* in these cases, the networking step is shortcut and the ip addresses ignored.
|
||||
* instead the port number is used as an index to peers.
|
||||
*
|
||||
* test1()
|
||||
* Small cross seeding, and static list of peers.
|
||||
* Set it going - and see what happens.
|
||||
*/
|
||||
|
||||
std::map<bdId, bdNodeManager *> nodes;
|
||||
std::map<struct sockaddr_in, bdId> addrIdx;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
time_t sim_time = 600;
|
||||
time_t starttime = time(NULL);
|
||||
int n_nodes = 1000;
|
||||
std::map<bdId, bdNodeManager *>::iterator it;
|
||||
std::map<bdId, bdNodeManager *>::iterator nit;
|
||||
std::map<struct sockaddr_in, bdId>::iterator ait;
|
||||
|
||||
int i, j;
|
||||
|
||||
bdDhtFunctions *fns = new bdStdDht();
|
||||
|
||||
std::cerr << "bdmgr_multitest() Setting up Nodes" << std::endl;
|
||||
/* setup nodes */
|
||||
for(i = 0; i < n_nodes; i++)
|
||||
{
|
||||
bdId id;
|
||||
|
||||
bdStdRandomId(&id);
|
||||
|
||||
//id.addr.sin_port = htons(i);
|
||||
//((uint32_t *) (id.id.data))[0] = i * 16 * 16; /* force this so the sort order is maintained! */
|
||||
std::cerr << "bdmgr_multitest() Id: ";
|
||||
fns->bdPrintId(std::cerr, &id);
|
||||
std::cerr << std::endl;
|
||||
|
||||
bdNodeManager *mgr = new bdNodeManager(&(id.id), "bdTEST", "", fns);
|
||||
|
||||
/* Store in nodes */
|
||||
nodes[id] = mgr;
|
||||
/* Store in indices */
|
||||
addrIdx[id.addr] = id;
|
||||
|
||||
}
|
||||
|
||||
std::cerr << "bdmgr_multitest() Cross Seeding" << std::endl;
|
||||
/* do a little cross seeding */
|
||||
for(nit = nodes.begin(); nit != nodes.end(); nit++)
|
||||
{
|
||||
for(j = 0; j < 2; j++)
|
||||
{
|
||||
int peeridx = rand() % n_nodes;
|
||||
for(i = 0, it = nodes.begin();
|
||||
(i < peeridx) && (it != nodes.end()); i++, it++)
|
||||
{
|
||||
/* empty */
|
||||
}
|
||||
if (it != nodes.end())
|
||||
{
|
||||
nit->second->addPotentialPeer((bdId *) &(it->first));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ready to run */
|
||||
|
||||
std::cerr << "bdmgr_multitest() Simulation Time....." << std::endl;
|
||||
i = 0;
|
||||
while(time(NULL) < starttime + sim_time)
|
||||
{
|
||||
i++;
|
||||
std::cerr << "bdmgr_multitest() Iteration: " << i << std::endl;
|
||||
|
||||
for(it = nodes.begin(), j = 0; it != nodes.end(); it++, j++)
|
||||
{
|
||||
/* extract messages to go -> and deliver */
|
||||
#define MAX_MSG_SIZE 10240
|
||||
struct sockaddr_in addr;
|
||||
char data[MAX_MSG_SIZE];
|
||||
int len = MAX_MSG_SIZE;
|
||||
|
||||
while(it->second->outgoingMsg(&addr, data, &len))
|
||||
{
|
||||
std::cerr << "bdmgr_multitest() Msg from Peer: " << j;
|
||||
|
||||
/* find the peer */
|
||||
ait = addrIdx.find(addr);
|
||||
nit = nodes.end();
|
||||
if (ait != addrIdx.end())
|
||||
{
|
||||
nit = nodes.find(ait->second);
|
||||
std::cerr << " For: ";
|
||||
fns->bdPrintId(std::cerr, &(nit->first));
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << " For Unknown Destination";
|
||||
std::cerr << std::endl;
|
||||
|
||||
}
|
||||
|
||||
if (nit != nodes.end())
|
||||
{
|
||||
/* set from address */
|
||||
nit->second->incomingMsg( (sockaddr_in *) &(it->first.addr), data, len);
|
||||
}
|
||||
/* reset message size */
|
||||
len = MAX_MSG_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
for(it = nodes.begin(), j = 0; it != nodes.end(); it++, j++)
|
||||
{
|
||||
/* tick */
|
||||
std::cerr << "bdmgr_multitest() Ticking peer: " << j << std::endl;
|
||||
it->second->iteration();
|
||||
}
|
||||
|
||||
|
||||
/* have a rest */
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
std::cerr << "bdmgr_multitest() Displying States"<< std::endl;
|
||||
for(it = nodes.begin(), j = 0; it != nodes.end(); it++, j++)
|
||||
{
|
||||
/* tick */
|
||||
std::cerr << "bdmgr_multitest() Peer State: " << j << std::endl;
|
||||
it->second->printState();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
96
libbitdht/src/tests/bdmidids_test.cc
Normal file
96
libbitdht/src/tests/bdmidids_test.cc
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* bitdht/bdmidids_test.cc
|
||||
*
|
||||
* BitDHT: An Flexible DHT library.
|
||||
*
|
||||
* Copyright 2010 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "bitdht@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "bitdht/bdpeer.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
/* Do this multiple times */
|
||||
int i, j;
|
||||
|
||||
std::cerr << "Test Mid Peer Intersection....." << std::endl;
|
||||
for(i = 0; i < 10; i++)
|
||||
{
|
||||
bdNodeId targetId;
|
||||
bdNodeId peerId;
|
||||
|
||||
bdStdRandomNodeId(&targetId);
|
||||
bdStdRandomNodeId(&peerId);
|
||||
|
||||
std::cerr << "-------------------------------------------------" << std::endl;
|
||||
|
||||
for(j = 0; j < 10; j++)
|
||||
{
|
||||
|
||||
bdNodeId midId;
|
||||
|
||||
bdStdRandomMidId(&targetId, &peerId, &midId);
|
||||
|
||||
bdMetric TPmetric;
|
||||
bdMetric TMmetric;
|
||||
bdMetric PMmetric;
|
||||
|
||||
bdStdDistance(&targetId, &peerId, &TPmetric);
|
||||
bdStdDistance(&targetId, &midId, &TMmetric);
|
||||
bdStdDistance(&peerId, &midId, &PMmetric);
|
||||
|
||||
int TPdist = bdStdBucketDistance(&TPmetric);
|
||||
int TMdist = bdStdBucketDistance(&TMmetric);
|
||||
int PMdist = bdStdBucketDistance(&PMmetric);
|
||||
|
||||
std::cerr << "Target: ";
|
||||
bdStdPrintNodeId(std::cerr,&targetId);
|
||||
std::cerr << " Peer: ";
|
||||
bdStdPrintNodeId(std::cerr,&peerId);
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "\tTarget ^ Peer: ";
|
||||
bdStdPrintNodeId(std::cerr,&TPmetric);
|
||||
std::cerr << " Bucket: " << TPdist;
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "\tTarget ^ Mid: ";
|
||||
bdStdPrintNodeId(std::cerr,&TMmetric);
|
||||
std::cerr << " Bucket: " << TMdist;
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "\tPeer ^ Mid: ";
|
||||
bdStdPrintNodeId(std::cerr,&PMmetric);
|
||||
std::cerr << " Bucket: " << PMdist;
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* now save mid to peer... and repeat */
|
||||
peerId = midId;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
102
libbitdht/src/tests/bdmsgs_test.cc
Normal file
102
libbitdht/src/tests/bdmsgs_test.cc
Normal file
|
@ -0,0 +1,102 @@
|
|||
|
||||
/*
|
||||
* bitdht/bdmsgs_test.cc
|
||||
*
|
||||
* BitDHT: An Flexible DHT library.
|
||||
*
|
||||
* Copyright 2010 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "bitdht@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "bitdht/bdmsgs.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
#include <string.h>
|
||||
|
||||
/*******************************************************************
|
||||
* Test of bencode message creation functions in bdmsgs.cc
|
||||
*
|
||||
* Create a couple of each type.
|
||||
*/
|
||||
|
||||
#define MAX_MESSAGE_LEN 10240
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/***** create messages *****/
|
||||
char msg[MAX_MESSAGE_LEN];
|
||||
int avail = MAX_MESSAGE_LEN -1;
|
||||
|
||||
bdToken tid;
|
||||
bdToken vid;
|
||||
bdToken token;
|
||||
|
||||
|
||||
bdNodeId ownId;
|
||||
bdNodeId peerId;
|
||||
bdNodeId target;
|
||||
bdNodeId info_hash;
|
||||
|
||||
bdStdRandomNodeId(&ownId);
|
||||
bdStdRandomNodeId(&peerId);
|
||||
bdStdRandomNodeId(&target);
|
||||
bdStdRandomNodeId(&info_hash);
|
||||
|
||||
std::list<bdId> nodes;
|
||||
std::list<std::string> values;
|
||||
|
||||
/* setup tokens */
|
||||
strncpy((char*)tid.data, "tid", 4);
|
||||
strncpy((char*)vid.data, "RS50", 5);
|
||||
strncpy((char*)token.data, "ToKEn", 6);
|
||||
|
||||
tid.len = 3;
|
||||
vid.len = 4;
|
||||
token.len = 5;
|
||||
|
||||
/* setup lists */
|
||||
for(int i = 0; i < 8; i++)
|
||||
{
|
||||
bdId rndId;
|
||||
bdStdRandomId(&rndId);
|
||||
|
||||
nodes.push_back(rndId);
|
||||
values.push_back("values");
|
||||
}
|
||||
|
||||
uint32_t port = 1234;
|
||||
|
||||
bitdht_create_ping_msg(&tid, &ownId, msg, avail);
|
||||
bitdht_response_ping_msg(&tid, &ownId, &vid, msg, avail);
|
||||
|
||||
bitdht_find_node_msg(&tid, &ownId, &target, msg, avail);
|
||||
bitdht_resp_node_msg(&tid, &ownId, nodes, msg, avail);
|
||||
|
||||
bitdht_get_peers_msg(&tid, &ownId, &info_hash, msg, avail);
|
||||
bitdht_peers_reply_hash_msg(&tid, &ownId, &token, values, msg, avail);
|
||||
bitdht_peers_reply_closest_msg(&tid, &ownId, &token, nodes, msg, avail);
|
||||
|
||||
bitdht_announce_peers_msg(&tid, &ownId, &info_hash, port, &token, msg, avail);
|
||||
bitdht_reply_announce_msg(&tid, &ownId, msg, avail);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
184
libbitdht/src/tests/bdnode_multitest1.cc
Normal file
184
libbitdht/src/tests/bdnode_multitest1.cc
Normal file
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
* bitdht/bdnode_multitest1.cc
|
||||
*
|
||||
* BitDHT: An Flexible DHT library.
|
||||
*
|
||||
* Copyright 2010 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "bitdht@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "bitdht/bdnode.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/**********************************************************************************
|
||||
* tests of multi bdnodes all connected together.
|
||||
* in these cases, the networking step is shortcut and the ip addresses ignored.
|
||||
* instead the port number is used as an index to peers.
|
||||
*
|
||||
* test1()
|
||||
* Small cross seeding, and static list of peers.
|
||||
* Set it going - and see what happens.
|
||||
*/
|
||||
|
||||
std::map<bdId, bdNode *> nodes;
|
||||
std::map<uint16_t, bdId> portIdx;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
time_t sim_time = 60;
|
||||
time_t starttime = time(NULL);
|
||||
int n_nodes = 10;
|
||||
std::map<bdId, bdNode *>::iterator it;
|
||||
std::map<bdId, bdNode *>::iterator nit;
|
||||
std::map<uint16_t, bdId>::iterator pit;
|
||||
|
||||
int i, j;
|
||||
|
||||
bdDhtFunctions *fns = new bdStdDht();
|
||||
|
||||
std::cerr << "bdnode_multitest1() Setting up Nodes" << std::endl;
|
||||
/* setup nodes */
|
||||
for(i = 0; i < n_nodes; i++)
|
||||
{
|
||||
bdId id;
|
||||
|
||||
bdStdRandomId(&id);
|
||||
|
||||
id.addr.sin_port = htons(i);
|
||||
((uint32_t *) (id.id.data))[0] = i * 16 * 16; /* force this so the sort order is maintained! */
|
||||
std::cerr << "bdnode_multitest1() Id: ";
|
||||
fns->bdPrintId(std::cerr, &id);
|
||||
std::cerr << std::endl;
|
||||
|
||||
bdNode *node = new bdNode(&(id.id), "bdTEST", "", fns);
|
||||
|
||||
/* Store in nodes */
|
||||
nodes[id] = node;
|
||||
/* Store in indices */
|
||||
portIdx[i] = id;
|
||||
|
||||
}
|
||||
|
||||
std::cerr << "bdnode_multitest1() Cross Seeding" << std::endl;
|
||||
/* do a little cross seeding */
|
||||
for(i = 0; i < n_nodes; i++)
|
||||
{
|
||||
bdId nid = portIdx[i];
|
||||
bdNode *node = nodes[nid];
|
||||
|
||||
for(j = 0; j < 5; j++)
|
||||
{
|
||||
int peeridx = rand() % n_nodes;
|
||||
|
||||
bdId pid = portIdx[peeridx];
|
||||
node->addPotentialPeer(&pid);
|
||||
}
|
||||
}
|
||||
|
||||
/* ready to run */
|
||||
|
||||
std::cerr << "bdnode_multitest1() Simulation Time....." << std::endl;
|
||||
i = 0;
|
||||
while(time(NULL) < starttime + sim_time)
|
||||
{
|
||||
i++;
|
||||
std::cerr << "bdnode_multitest1() Iteration: " << i << std::endl;
|
||||
|
||||
for(it = nodes.begin(), j = 0; it != nodes.end(); it++, j++)
|
||||
{
|
||||
/* extract messages to go -> and deliver */
|
||||
#define MAX_MSG_SIZE 10240
|
||||
struct sockaddr_in addr;
|
||||
char data[MAX_MSG_SIZE];
|
||||
int len = MAX_MSG_SIZE;
|
||||
|
||||
while(it->second->outgoingMsg(&addr, data, &len))
|
||||
{
|
||||
std::cerr << "bdnode_multitest1() Msg from Peer: " << j;
|
||||
|
||||
/* find the peer */
|
||||
int peeridx = htons(addr.sin_port);
|
||||
pit = portIdx.find(peeridx);
|
||||
nit = nodes.end();
|
||||
if (pit != portIdx.end())
|
||||
{
|
||||
nit = nodes.find(pit->second);
|
||||
std::cerr << " For: ";
|
||||
fns->bdPrintId(std::cerr, &(nit->first));
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << " For Unknown Destination";
|
||||
std::cerr << std::endl;
|
||||
|
||||
}
|
||||
|
||||
if (nit != nodes.end())
|
||||
{
|
||||
/* set from address */
|
||||
nit->second->incomingMsg( (sockaddr_in *) &(it->first.addr), data, len);
|
||||
}
|
||||
/* reset message size */
|
||||
len = MAX_MSG_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
for(it = nodes.begin(), j = 0; it != nodes.end(); it++, j++)
|
||||
{
|
||||
/* tick */
|
||||
std::cerr << "bdnode_multitest1() Ticking peer: " << j << std::endl;
|
||||
it->second->iteration();
|
||||
}
|
||||
|
||||
if (i % 5 == 0)
|
||||
{
|
||||
std::cerr << "bdnode_multitest1() Displying States"<< std::endl;
|
||||
for(it = nodes.begin(), j = 0; it != nodes.end(); it++, j++)
|
||||
{
|
||||
/* tick */
|
||||
std::cerr << "bdnode_multitest1() Peer State: " << j << std::endl;
|
||||
it->second->printState();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* have a rest */
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
89
libbitdht/src/tests/bdnode_test.cc
Normal file
89
libbitdht/src/tests/bdnode_test.cc
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* bitdht/bdnode_test.cc
|
||||
*
|
||||
* BitDHT: An Flexible DHT library.
|
||||
*
|
||||
* Copyright 2010 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "bitdht@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "bitdht/bdpeer.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
#include "bitdht/bdquery.h"
|
||||
#include "bitdht/bdnode.h"
|
||||
|
||||
#define N_PEERS_TO_ADD_INIT 10
|
||||
#define N_PEERS_TO_ADD 11
|
||||
#define N_PEERS_TO_START 10
|
||||
#define N_PEERS_TO_PRINT 1
|
||||
#define N_QUERIES 2
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
/* create some ids */
|
||||
bdDhtFunctions *fns = new bdStdDht();
|
||||
|
||||
bdNodeId ownId;
|
||||
bdStdRandomNodeId(&ownId);
|
||||
|
||||
bdNode node(&ownId, "bdTEST","./dht.log", fns);
|
||||
|
||||
int i = 0;
|
||||
for (i = 0; i < N_PEERS_TO_ADD_INIT; i++)
|
||||
{
|
||||
bdId tmpId;
|
||||
bdStdRandomId(&tmpId);
|
||||
|
||||
node.addPeer(&tmpId, 0);
|
||||
}
|
||||
|
||||
node.printState();
|
||||
|
||||
|
||||
for(i = 0; i < N_QUERIES; i++)
|
||||
{
|
||||
/* create a query */
|
||||
bdNodeId queryId;
|
||||
bdStdRandomNodeId(&queryId);
|
||||
|
||||
node.addQuery(&queryId, 0);
|
||||
}
|
||||
|
||||
node.printState();
|
||||
|
||||
for (i = 0; i < N_PEERS_TO_ADD; i++)
|
||||
{
|
||||
bdId tmpId;
|
||||
bdStdRandomId(&tmpId);
|
||||
|
||||
node.addPeer(&tmpId, 0);
|
||||
|
||||
if (i % N_PEERS_TO_PRINT == 0)
|
||||
{
|
||||
node.printState();
|
||||
node.iteration();
|
||||
sleep(5);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
56
libbitdht/src/tests/bdnode_test2.cc
Normal file
56
libbitdht/src/tests/bdnode_test2.cc
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* bitdht/bdnode_test2.cc
|
||||
*
|
||||
* BitDHT: An Flexible DHT library.
|
||||
*
|
||||
* Copyright 2010 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "bitdht@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "bitdht/bdpeer.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
#include "bitdht/bdquery.h"
|
||||
#include "bitdht/bdnode.h"
|
||||
|
||||
#define N_PEERS_TO_ADD_INIT 10
|
||||
#define N_PEERS_TO_ADD 11
|
||||
#define N_PEERS_TO_START 10
|
||||
#define N_PEERS_TO_PRINT 1
|
||||
#define N_QUERIES 2
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
/* create some ids */
|
||||
bdNodeId ownId;
|
||||
bdStdRandomNodeId(&ownId);
|
||||
bdDhtFunctions *fns = new bdStdDht();
|
||||
|
||||
bdNode node(&ownId, "bdTEST", "./dht.log", fns);
|
||||
|
||||
while(1)
|
||||
{
|
||||
node.iteration();
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
83
libbitdht/src/tests/bdquery_test.cc
Normal file
83
libbitdht/src/tests/bdquery_test.cc
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* bitdht/bdquery_test.cc
|
||||
*
|
||||
* BitDHT: An Flexible DHT library.
|
||||
*
|
||||
* Copyright 2010 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "bitdht@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "bitdht/bdpeer.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
#include "bitdht/bdquery.h"
|
||||
|
||||
#define N_PEERS_TO_ADD 10000
|
||||
#define N_PEERS_TO_PRINT 1000
|
||||
#define N_PEERS_TO_START 10
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
/* create some ids */
|
||||
bdNodeId ownId;
|
||||
bdStdRandomNodeId(&ownId);
|
||||
|
||||
bdDhtFunctions *fns = new bdStdDht();
|
||||
|
||||
bdSpace space(&ownId, fns);
|
||||
int i = 0;
|
||||
for (i = 0; i < N_PEERS_TO_ADD; i++)
|
||||
{
|
||||
bdId tmpId;
|
||||
bdStdRandomId(&tmpId);
|
||||
|
||||
space.add_peer(&tmpId, 0);
|
||||
}
|
||||
|
||||
space.printDHT();
|
||||
|
||||
/* create a query */
|
||||
bdId queryId;
|
||||
bdStdRandomId(&queryId);
|
||||
|
||||
|
||||
|
||||
std::list<bdId> startList;
|
||||
std::multimap<bdMetric, bdId> nearest;
|
||||
std::multimap<bdMetric, bdId>::iterator it;
|
||||
|
||||
space.find_nearest_nodes(&(queryId.id), N_PEERS_TO_START, startList, nearest);
|
||||
|
||||
for(it = nearest.begin(); it != nearest.end(); it++)
|
||||
{
|
||||
startList.push_back(it->second);
|
||||
}
|
||||
|
||||
bdQuery query(&(queryId.id), startList, BITDHT_QFLAGS_DISGUISE, fns);
|
||||
|
||||
/* */
|
||||
|
||||
query.printQuery();
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
60
libbitdht/src/tests/bdspace_test.cc
Normal file
60
libbitdht/src/tests/bdspace_test.cc
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* bitdht/bdspace_test.cc
|
||||
*
|
||||
* BitDHT: An Flexible DHT library.
|
||||
*
|
||||
* Copyright 2010 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "bitdht@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "bitdht/bdpeer.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
|
||||
#define N_PEERS_TO_ADD 10000
|
||||
#define N_PEERS_TO_PRINT 1000
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
/* create some ids */
|
||||
bdNodeId ownId;
|
||||
bdStdRandomNodeId(&ownId);
|
||||
bdDhtFunctions *fns = new bdStdDht();
|
||||
|
||||
bdSpace space(&ownId, fns);
|
||||
int i = 0;
|
||||
for (i = 0; i < N_PEERS_TO_ADD; i++)
|
||||
{
|
||||
bdId tmpId;
|
||||
bdStdRandomId(&tmpId);
|
||||
|
||||
space.add_peer(&tmpId, 0);
|
||||
|
||||
if (i % N_PEERS_TO_PRINT == 0)
|
||||
{
|
||||
space.printDHT();
|
||||
}
|
||||
}
|
||||
space.printDHT();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
68
libbitdht/src/tests/bdspace_test2.cc
Normal file
68
libbitdht/src/tests/bdspace_test2.cc
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* bitdht/bdspace_test2.cc
|
||||
*
|
||||
* BitDHT: An Flexible DHT library.
|
||||
*
|
||||
* Copyright 2010 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "bitdht@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "bitdht/bdpeer.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
|
||||
#define N_PEERS_TO_ADD 10000
|
||||
#define N_PEERS_TO_TEST 100
|
||||
#define N_PEERS_TO_FIND 10
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
/* create some ids */
|
||||
bdNodeId ownId;
|
||||
bdStdRandomNodeId(&ownId);
|
||||
bdDhtFunctions *fns = new bdStdDht();
|
||||
|
||||
bdSpace space(&ownId, fns);
|
||||
int i = 0;
|
||||
for (i = 0; i < N_PEERS_TO_ADD; i++)
|
||||
{
|
||||
bdId tmpId;
|
||||
bdStdRandomId(&tmpId);
|
||||
space.add_peer(&tmpId, 0);
|
||||
}
|
||||
|
||||
space.printDHT();
|
||||
|
||||
|
||||
/* now generate random id's and test closeness */
|
||||
for(i = 0; i < N_PEERS_TO_TEST; i++)
|
||||
{
|
||||
bdId tmpId;
|
||||
bdStdRandomId(&tmpId);
|
||||
std::list<bdId> list1;
|
||||
std::multimap<bdMetric, bdId> list2;
|
||||
|
||||
space.find_nearest_nodes(&(tmpId.id), N_PEERS_TO_FIND, list1, list2);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
47
libbitdht/src/tests/bdstore_test.cc
Normal file
47
libbitdht/src/tests/bdstore_test.cc
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* bitdht/bdstore_test.cc
|
||||
*
|
||||
* BitDHT: An Flexible DHT library.
|
||||
*
|
||||
* Copyright 2010 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "bitdht@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "bitdht/bdstore.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* load store */
|
||||
if (argc < 2)
|
||||
{
|
||||
fprintf(stderr, "Missing Store File\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
bdDhtFunctions *fns = new bdStdDht();
|
||||
bdStore store(argv[1], fns);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
66
libbitdht/src/tests/bdudp_test.cc
Normal file
66
libbitdht/src/tests/bdudp_test.cc
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* bitdht/bdudp_test.cc
|
||||
*
|
||||
* BitDHT: An Flexible DHT library.
|
||||
*
|
||||
* Copyright 2010 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "bitdht@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "bitdht/bdpeer.h"
|
||||
#include "bitdht/bdquery.h"
|
||||
#include "udp/udpbitdht.h"
|
||||
|
||||
#define N_PEERS_TO_ADD 10000
|
||||
#define N_PEERS_TO_PRINT 1000
|
||||
#define N_PEERS_TO_START 10
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
/* create some ids */
|
||||
bdId ownId;
|
||||
bdRandomId(&ownId);
|
||||
|
||||
|
||||
struct sockaddr_in local;
|
||||
local.sin_addr.s_addr = 0;
|
||||
local.sin_port = htons(7812);
|
||||
std::string bootstrapfile = "dht.log";
|
||||
|
||||
bdId bid;
|
||||
|
||||
bid.addr = local;
|
||||
bid.id = ownId.id;
|
||||
|
||||
UdpBitDht ubd(local, 0, &bid, bootstrapfile);
|
||||
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
ubd.tick();
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
182
libbitdht/src/tests/bencode_test.cc
Normal file
182
libbitdht/src/tests/bencode_test.cc
Normal file
|
@ -0,0 +1,182 @@
|
|||
/*
|
||||
* bitdht/bencode_test.cc
|
||||
*
|
||||
* BitDHT: An Flexible DHT library.
|
||||
*
|
||||
* Copyright 2010 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "bitdht@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "bitdht/bencode.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
char msg[100];
|
||||
|
||||
msg[0] = 'd';
|
||||
msg[1] = '1';
|
||||
msg[2] = ':';
|
||||
msg[3] = 't';
|
||||
msg[4] = 'L';
|
||||
msg[5] = 'b';
|
||||
msg[6] = 'U';
|
||||
msg[7] = 0xd9;
|
||||
msg[8] = 0xfa;
|
||||
msg[9] = 0xff;
|
||||
msg[10] = 0xff;
|
||||
msg[11] = 0xff;
|
||||
msg[12] = 0xff;
|
||||
msg[13] = '\n';
|
||||
msg[14] = 'H';
|
||||
msg[15] = '#';
|
||||
msg[16] = '#';
|
||||
msg[17] = '#';
|
||||
msg[18] = '#';
|
||||
msg[19] = '#';
|
||||
msg[20] = '#';
|
||||
msg[21] = '#';
|
||||
|
||||
be_node *n = be_decoden(msg, 16);
|
||||
|
||||
if (n)
|
||||
{
|
||||
be_dump(n);
|
||||
be_free(n);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "didn't crash!\n");
|
||||
}
|
||||
|
||||
msg[0] = 'd';
|
||||
msg[1] = '1';
|
||||
msg[2] = ':';
|
||||
msg[3] = 'a';
|
||||
msg[4] = 'L';
|
||||
msg[5] = 0x8d;
|
||||
msg[6] = 0xd6;
|
||||
msg[7] = '\r';
|
||||
msg[8] = 0x9d;
|
||||
msg[9] = ';';
|
||||
msg[10] = 0xff;
|
||||
msg[11] = 0xff;
|
||||
msg[12] = 0xff;
|
||||
msg[13] = 0xff;
|
||||
msg[14] = 'H';
|
||||
msg[15] = '#';
|
||||
msg[16] = '#';
|
||||
msg[17] = '#';
|
||||
msg[18] = '#';
|
||||
msg[19] = '#';
|
||||
msg[20] = '#';
|
||||
msg[21] = '#';
|
||||
|
||||
n = be_decoden(msg, 14);
|
||||
|
||||
if (n)
|
||||
{
|
||||
be_dump(n);
|
||||
be_free(n);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "didn't crash!\n");
|
||||
}
|
||||
|
||||
msg[0] = 'd';
|
||||
msg[1] = '1';
|
||||
msg[2] = ':';
|
||||
msg[3] = 't';
|
||||
msg[4] = '4';
|
||||
msg[5] = ':';
|
||||
msg[6] = 'a';
|
||||
msg[7] = 'b';
|
||||
msg[8] = 'c';
|
||||
msg[9] = 'd';
|
||||
msg[10] = '1';
|
||||
msg[11] = ':';
|
||||
msg[12] = 'y';
|
||||
msg[13] = '1';
|
||||
msg[14] = ':';
|
||||
msg[15] = 'r';
|
||||
msg[16] = '1';
|
||||
msg[17] = ':';
|
||||
msg[18] = 'r';
|
||||
msg[19] = 'd';
|
||||
msg[20] = '2';
|
||||
msg[21] = ':';
|
||||
msg[22] = 'i';
|
||||
msg[23] = 'd';
|
||||
msg[24] = '2';
|
||||
msg[25] = '0';
|
||||
msg[26] = ':';
|
||||
msg[27] = '1';
|
||||
msg[28] = '2';
|
||||
msg[29] = '3';
|
||||
msg[30] = '4';
|
||||
msg[31] = '5';
|
||||
msg[32] = '6';
|
||||
msg[33] = '7';
|
||||
msg[34] = '8';
|
||||
msg[35] = '9';
|
||||
msg[36] = '0';
|
||||
msg[37] = 'a';
|
||||
msg[38] = 'b';
|
||||
msg[39] = 'c';
|
||||
msg[40] = 'd';
|
||||
msg[41] = 'e';
|
||||
msg[42] = 'f';
|
||||
msg[43] = 'g';
|
||||
msg[44] = 'h';
|
||||
msg[45] = 'i';
|
||||
msg[46] = '.';
|
||||
msg[47] = '5';
|
||||
msg[48] = ':';
|
||||
msg[49] = 'n';
|
||||
msg[50] = 'o';
|
||||
msg[51] = 'd';
|
||||
msg[52] = 'e';
|
||||
msg[53] = 's';
|
||||
msg[54] = '2';
|
||||
msg[55] = '0';
|
||||
msg[56] = '8';
|
||||
msg[57] = ':';
|
||||
msg[58] = '\0';
|
||||
msg[59] = '\0';
|
||||
msg[60] = '\0';
|
||||
|
||||
n = be_decoden(msg, 58);
|
||||
|
||||
if (n)
|
||||
{
|
||||
be_dump(n);
|
||||
be_free(n);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "didn't crash!\n");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
19
libbitdht/src/tests/scripts/checks.mk
Normal file
19
libbitdht/src/tests/scripts/checks.mk
Normal file
|
@ -0,0 +1,19 @@
|
|||
#Basic checks
|
||||
|
||||
ifndef TEST_TOP_DIR
|
||||
dummy:
|
||||
echo "TEST_TOP_DIR is not defined in your makefile"
|
||||
endif
|
||||
|
||||
ifneq ($(OS),Linux)
|
||||
ifneq ($(OS),MacOSX)
|
||||
ifndef PTHREADS_DIR
|
||||
dummy:
|
||||
echo "you must define PTHREADS_DIR before you can compile"
|
||||
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
|
118
libbitdht/src/tests/scripts/config-cygwin.mk
Normal file
118
libbitdht/src/tests/scripts/config-cygwin.mk
Normal file
|
@ -0,0 +1,118 @@
|
|||
ifneq ($(OS),Cygwin)
|
||||
dummy:
|
||||
echo "ERROR Cygwin configuration file included, but (OS != Cygwin)
|
||||
|
||||
endif
|
||||
|
||||
############ LINUX CONFIGURATION ########################
|
||||
|
||||
# flags for components....
|
||||
PQI_USE_XPGP = 1
|
||||
#PQI_USE_PROXY = 1
|
||||
#PQI_USE_CHANNELS = 1
|
||||
#USE_FILELOOK = 1
|
||||
|
||||
###########################################################################
|
||||
|
||||
#### DrBobs Versions.... Please Don't Delete.
|
||||
### Comment out if needed.
|
||||
ALT_SRC_ROOT=/cygdrive/c/home/rmfern/prog/MinGW
|
||||
SRC_ROOT=../../../..
|
||||
|
||||
PTHREADS_DIR=$(ALT_SRC_ROOT)/pthreads/pthreads.2
|
||||
|
||||
###################
|
||||
|
||||
#ALT_SRC_ROOT=/cygdrive/c/RetroShareBuild/src
|
||||
#SRC_ROOT=/cygdrive/c/RetroShareBuild/src
|
||||
|
||||
#PTHREADS_DIR=$(ALT_SRC_ROOT)/pthreads-w32-2-8-0-release
|
||||
|
||||
###################
|
||||
|
||||
ZLIB_DIR=$(ALT_SRC_ROOT)/zlib-1.2.3
|
||||
|
||||
SSL_DIR=$(SRC_ROOT)/openssl-0.9.7g-xpgp-0.1c
|
||||
UPNPC_DIR=$(SRC_ROOT)/miniupnpc-1.0
|
||||
|
||||
include $(RS_TOP_DIR)/scripts/checks.mk
|
||||
|
||||
############ ENFORCE DIRECTORY NAMING ########################
|
||||
|
||||
CC = g++
|
||||
RM = /bin/rm
|
||||
RANLIB = ranlib
|
||||
LIBDIR = $(RS_TOP_DIR)/lib
|
||||
LIBRS = $(LIBDIR)/libretroshare.a
|
||||
|
||||
# Unix: Linux/Cygwin
|
||||
INCLUDE = -I $(RS_TOP_DIR)
|
||||
|
||||
ifdef PQI_DEBUG
|
||||
CFLAGS = -Wall -g $(INCLUDE)
|
||||
else
|
||||
CFLAGS = -Wall -O2 $(INCLUDE)
|
||||
endif
|
||||
|
||||
ifdef PQI_USE_XPGP
|
||||
INCLUDE += -I $(SSL_DIR)/include
|
||||
endif
|
||||
|
||||
ifdef PQI_USE_XPGP
|
||||
CFLAGS += -DPQI_USE_XPGP
|
||||
endif
|
||||
|
||||
ifdef PQI_USE_PROXY
|
||||
CFLAGS += -DPQI_USE_PROXY
|
||||
endif
|
||||
|
||||
ifdef PQI_USE_CHANNELS
|
||||
CFLAGS += -DPQI_USE_CHANNELS
|
||||
endif
|
||||
|
||||
ifdef USE_FILELOOK
|
||||
CFLAGS += -DUSE_FILELOOK
|
||||
endif
|
||||
|
||||
|
||||
RSCFLAGS = -Wall -g $(INCLUDE)
|
||||
|
||||
#########################################################################
|
||||
# OS Compile Options
|
||||
#########################################################################
|
||||
|
||||
# For the SSL BIO compilation. (Copied from OpenSSL compilation flags)
|
||||
BIOCC = gcc
|
||||
|
||||
# Cygwin - ?same? as Linux flags
|
||||
BIOCFLAGS = -I $(SSL_DIR)/include -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_NO_KRB5 -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -DSHA1_ASM -DMD5_ASM -DRMD160_ASM
|
||||
|
||||
#########################################################################
|
||||
# OS specific Linking.
|
||||
#########################################################################
|
||||
|
||||
# for static pthread libs....
|
||||
WININC += -DPTW32_STATIC_LIB
|
||||
WININC += -mno-cygwin -mwindows -fno-exceptions
|
||||
WININC += -DWINDOWS_SYS
|
||||
|
||||
WINLIB = -lws2_32 -luuid -lole32 -liphlpapi
|
||||
WINLIB += -lcrypt32 -lwinmm
|
||||
|
||||
CFLAGS += -I$(PTHREADS_DIR) $(WININC)
|
||||
CFLAGS += -I$(ZLIB_DIR)
|
||||
|
||||
LIBS = -L$(LIBDIR) -lretroshare
|
||||
ifdef PQI_USE_XPGP
|
||||
LIBS += -L$(SSL_DIR)
|
||||
endif
|
||||
|
||||
LIBS += -lssl -lcrypto
|
||||
LIBS += -L$(UPNPC_DIR) -lminiupnpc
|
||||
LIBS += -L$(ZLIB_DIR) -lz
|
||||
LIBS += -L$(PTHREADS_DIR) -lpthreadGC2d
|
||||
LIBS += $(WINLIB)
|
||||
|
||||
RSCFLAGS += $(WININC)
|
||||
|
||||
|
41
libbitdht/src/tests/scripts/config-linux.mk
Normal file
41
libbitdht/src/tests/scripts/config-linux.mk
Normal file
|
@ -0,0 +1,41 @@
|
|||
|
||||
ifneq ($(OS),Linux)
|
||||
dummy:
|
||||
echo "ERROR Linux configuration file included, but (OS != Linux)
|
||||
|
||||
endif
|
||||
|
||||
############ LINUX CONFIGURATION ########################
|
||||
|
||||
include $(TEST_TOP_DIR)/scripts/checks.mk
|
||||
|
||||
############ ENFORCE DIRECTORY NAMING ########################
|
||||
|
||||
CC = g++
|
||||
RM = /bin/rm
|
||||
RANLIB = ranlib
|
||||
LIBDIR = $(LIB_TOP_DIR)/lib
|
||||
LIBRS = $(LIBDIR)/libretroshare.a
|
||||
|
||||
# Unix: Linux/Cygwin
|
||||
INCLUDE = -I $(LIB_TOP_DIR)
|
||||
CFLAGS = -Wall -g $(INCLUDE)
|
||||
CFLAGS += ${DEFINES} -D BE_DEBUG
|
||||
|
||||
#########################################################################
|
||||
# OS Compile Options
|
||||
#########################################################################
|
||||
|
||||
#########################################################################
|
||||
# OS specific Linking.
|
||||
#########################################################################
|
||||
|
||||
LIBS = -L$(LIBDIR) -lbitdht
|
||||
LIBS += -lpthread
|
||||
#LIBS += $(XLIB) -ldl -lz
|
||||
#LIBS += -lupnp
|
||||
#LIBS += -lgpgme
|
||||
#
|
||||
#RSLIBS = $(LIBS)
|
||||
|
||||
|
152
libbitdht/src/tests/scripts/config-macosx.mk
Normal file
152
libbitdht/src/tests/scripts/config-macosx.mk
Normal file
|
@ -0,0 +1,152 @@
|
|||
|
||||
ifneq ($(OS),MacOSX)
|
||||
dummy:
|
||||
echo "ERROR MacOSX configuration file included, but (OS != MacOSX)
|
||||
|
||||
endif
|
||||
|
||||
############ LINUX CONFIGURATION ########################
|
||||
|
||||
|
||||
# FLAGS to decide if we want i386 Build or ppc Build
|
||||
#
|
||||
#
|
||||
|
||||
# PPC is default
|
||||
# Could define both for combined compilation...
|
||||
# except might not work for bio_tou.c file!
|
||||
#
|
||||
# MAC_I386_BUILD = 1
|
||||
# MAC_PPC_BUILD = 1
|
||||
|
||||
#MAC_I386_BUILD = 1
|
||||
#MAC_PPC_BUILD = 1
|
||||
|
||||
ifndef MAC_I386_BUILD
|
||||
MAC_PPC_BUILD = 1
|
||||
endif
|
||||
|
||||
# flags for components....
|
||||
#PQI_USE_SSLONLY = 1
|
||||
#PQI_USE_XPGP = 1
|
||||
|
||||
#PQI_USE_PROXY = 1
|
||||
#PQI_USE_CHANNELS = 1
|
||||
#USE_FILELOOK = 1
|
||||
|
||||
SSL_DIR=../../../../../src/openssl-0.9.7g-xpgp-0.1c
|
||||
UPNPC_DIR=../../../../../src/miniupnpc-1.0
|
||||
|
||||
include $(RS_TOP_DIR)/scripts/checks.mk
|
||||
|
||||
############ ENFORCE DIRECTORY NAMING ########################
|
||||
|
||||
CC = g++
|
||||
RM = /bin/rm
|
||||
|
||||
RANLIB = ranlib
|
||||
|
||||
# Dummy ranlib -> can't do it until afterwards with universal binaries.
|
||||
# RANLIB = ls -l
|
||||
|
||||
LIBDIR = $(RS_TOP_DIR)/lib
|
||||
LIBRS = $(LIBDIR)/libretroshare.a
|
||||
|
||||
OPT_DIR = /opt/local
|
||||
OPT_INCLUDE = $(OPT_DIR)/include
|
||||
OPT_LIBS = $(OPT_DIR)/lib
|
||||
|
||||
INCLUDE = -I $(RS_TOP_DIR) -I $(OPT_INCLUDE)
|
||||
#CFLAGS = -Wall -O3
|
||||
CFLAGS = -Wall -g
|
||||
|
||||
# Flags for architecture builds.
|
||||
ifdef MAC_I386_BUILD
|
||||
CFLAGS += -arch i386
|
||||
endif
|
||||
|
||||
ifdef MAC_PPC_BUILD
|
||||
CFLAGS += -arch ppc
|
||||
endif
|
||||
|
||||
CFLAGS += $(INCLUDE)
|
||||
|
||||
# This Line is for Universal BUILD for 10.4 + 10.5
|
||||
# (but unlikely to work unless Qt Libraries are build properly)
|
||||
# CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk
|
||||
|
||||
ifdef PQI_USE_XPGP
|
||||
INCLUDE += -I $(SSL_DIR)/include
|
||||
CFLAGS += -DPQI_USE_XPGP
|
||||
endif
|
||||
|
||||
ifdef PQI_USE_SSLONLY
|
||||
CFLAGS += -DPQI_USE_SSLONLY
|
||||
endif
|
||||
|
||||
ifdef PQI_USE_PROXY
|
||||
CFLAGS += -DPQI_USE_PROXY
|
||||
endif
|
||||
|
||||
ifdef PQI_USE_CHANNELS
|
||||
CFLAGS += -DPQI_USE_CHANNELS
|
||||
endif
|
||||
|
||||
ifdef USE_FILELOOK
|
||||
CFLAGS += -DUSE_FILELOOK
|
||||
endif
|
||||
|
||||
|
||||
# RSCFLAGS = -Wall -O3 $(INCLUDE)
|
||||
|
||||
#########################################################################
|
||||
# OS Compile Options
|
||||
#########################################################################
|
||||
|
||||
# For the SSL BIO compilation. (Copied from OpenSSL compilation flags)
|
||||
BIOCC = gcc
|
||||
|
||||
|
||||
# Flags for architecture builds.
|
||||
ifdef MAC_I386_BUILD
|
||||
BIOCFLAGS = -arch i386 -I $(SSL_DIR)/include -DOPENSSL_SYSNAME_MACOSX -DOPENSSL_THREADS -D_REENTRANT -DOPENSSL_NO_KRB5 -O3 -fomit-frame-pointer -fno-common
|
||||
endif
|
||||
|
||||
ifdef MAC_PPC_BUILD
|
||||
BIOCFLAGS = -arch ppc -I $(SSL_DIR)/include -DOPENSSL_SYSNAME_MACOSX -DOPENSSL_THREADS -D_REENTRANT -DOPENSSL_NO_KRB5 -O3 -fomit-frame-pointer -fno-common -DB_ENDIAN
|
||||
endif
|
||||
|
||||
|
||||
|
||||
# MacOSX flags
|
||||
# BIOCFLAGS = -I $(SSL_DIR)/include -DOPENSSL_SYSNAME_MACOSX -DOPENSSL_THREADS -D_REENTRANT -DOPENSSL_NO_KRB5 -O3 -fomit-frame-pointer -fno-common -DB_ENDIAN
|
||||
|
||||
# This is for the Universal Build...
|
||||
# but is unlikely to work... as options are PPC specific....
|
||||
#
|
||||
# BIOCFLAGS = -arch ppc -arch i386 -I $(SSL_DIR)/include -DOPENSSL_SYSNAME_MACOSX -DOPENSSL_THREADS -D_REENTRANT -DOPENSSL_NO_KRB5 -O3 -fomit-frame-pointer -fno-common -DB_ENDIAN
|
||||
|
||||
|
||||
#########################################################################
|
||||
# OS specific Linking.
|
||||
#########################################################################
|
||||
|
||||
LIBS = -Wl,-search_paths_first
|
||||
|
||||
# for Univeral BUILD
|
||||
# LIBS += -arch ppc -arch i386
|
||||
# LIBS += -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386
|
||||
|
||||
LIBS += -L$(LIBDIR) -lretroshare
|
||||
ifdef PQI_USE_XPGP
|
||||
LIBS += -L$(SSL_DIR)
|
||||
endif
|
||||
LIBS += -lssl -lcrypto -lpthread
|
||||
LIBS += -L$(OPT_LIBS)
|
||||
LIBS += -lgpgme -lgpg-error
|
||||
LIBS += -L$(UPNPC_DIR) -lminiupnpc
|
||||
LIBS += $(XLIB) -ldl -lz
|
||||
|
||||
RSLIBS = $(LIBS)
|
||||
|
||||
|
138
libbitdht/src/tests/scripts/config-mingw.mk
Normal file
138
libbitdht/src/tests/scripts/config-mingw.mk
Normal file
|
@ -0,0 +1,138 @@
|
|||
#ifneq ($(OS),"Win ")
|
||||
#dummy:
|
||||
# echo "ERROR OS = $(OS)"
|
||||
# echo "ERROR MinGW configuration file included, but (OS != Win)
|
||||
#
|
||||
#endif
|
||||
|
||||
############ LINUX CONFIGURATION ########################
|
||||
|
||||
# flags for components....
|
||||
#PQI_USE_XPGP = 1
|
||||
#PQI_USE_PROXY = 1
|
||||
#PQI_USE_CHANNELS = 1
|
||||
#USE_FILELOOK = 1
|
||||
|
||||
###########################################################################
|
||||
|
||||
#### DrBobs Versions.... Please Don't Delete.
|
||||
### Comment out if needed.
|
||||
SRC_ROOT_PKG=/home/Mark/prog/retroshare/package/rs-win-v0.5.0/src
|
||||
SRC_ROOT_GPG=/local
|
||||
|
||||
#ALT_SRC_ROOT=/cygdrive/c/home/rmfern/prog/MinGW
|
||||
#SRC_ROOT=../../../..
|
||||
|
||||
PTHREADS_DIR=$(SRC_ROOT_PKG)/pthreads-w32-2-8-0/Pre-built.2
|
||||
ZLIB_DIR=$(SRC_ROOT_PKG)/zlib-1.2.3
|
||||
SSL_DIR=$(SRC_ROOT_PKG)/openssl-tmp
|
||||
UPNPC_DIR=$(SRC_ROOT_PKG)/miniupnpc-1.3
|
||||
|
||||
###########################################################################
|
||||
|
||||
#### Enable this section for compiling with MSYS/MINGW compile
|
||||
#SRC_ROOT=/home/linux
|
||||
|
||||
#SSL_DIR=$(SRC_ROOT)/OpenSSL
|
||||
#GPGME_DIR=$(SRC_ROOT)/gpgme-1.1.8
|
||||
#GPG_ERROR_DIR=$(SRC_ROOT)/libgpg-error-1.7
|
||||
|
||||
#ZLIB_DIR=$(SRC_ROOT)/zlib-1.2.3
|
||||
#UPNPC_DIR=$(SRC_ROOT)/miniupnpc-1.0
|
||||
#PTHREADS_DIR=$(SRC_ROOT)/pthreads-w32-2-8-0-release
|
||||
|
||||
include $(RS_TOP_DIR)/scripts/checks.mk
|
||||
|
||||
############ ENFORCE DIRECTORY NAMING #######################################
|
||||
|
||||
CC = g++
|
||||
RM = /bin/rm
|
||||
RANLIB = ranlib
|
||||
LIBDIR = $(RS_TOP_DIR)/lib
|
||||
LIBRS = $(LIBDIR)/libretroshare.a
|
||||
|
||||
# Unix: Linux/Cygwin
|
||||
INCLUDE = -I $(RS_TOP_DIR)
|
||||
|
||||
ifdef PQI_DEBUG
|
||||
CFLAGS = -Wall -g $(INCLUDE)
|
||||
else
|
||||
CFLAGS = -Wall -O2 $(INCLUDE)
|
||||
endif
|
||||
|
||||
# These aren't used anymore.... really.
|
||||
ifdef PQI_USE_XPGP
|
||||
CFLAGS += -DPQI_USE_XPGP
|
||||
endif
|
||||
|
||||
ifdef PQI_USE_PROXY
|
||||
CFLAGS += -DPQI_USE_PROXY
|
||||
endif
|
||||
|
||||
ifdef PQI_USE_CHANNELS
|
||||
CFLAGS += -DPQI_USE_CHANNELS
|
||||
endif
|
||||
|
||||
ifdef USE_FILELOOK
|
||||
CFLAGS += -DUSE_FILELOOK
|
||||
endif
|
||||
|
||||
|
||||
# SSL / pthreads / Zlib
|
||||
# included by default for Windows compilation.
|
||||
INCLUDE += -I $(SSL_DIR)/include
|
||||
INCLUDE += -I$(PTHREADS_DIR)
|
||||
INCLUDE += -I$(ZLIB_DIR)
|
||||
|
||||
|
||||
#########################################################################
|
||||
# OS Compile Options
|
||||
#########################################################################
|
||||
|
||||
# For the SSL BIO compilation. (Copied from OpenSSL compilation flags)
|
||||
BIOCC = gcc
|
||||
|
||||
# Cygwin - ?same? as Linux flags
|
||||
BIOCFLAGS = -I $(SSL_DIR)/include -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_NO_KRB5 -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -DSHA1_ASM -DMD5_ASM -DRMD160_ASM
|
||||
BIOCFLAGS += -DWINDOWS_SYS
|
||||
|
||||
#########################################################################
|
||||
# OS specific Linking.
|
||||
#########################################################################
|
||||
|
||||
# for static pthread libs....
|
||||
#WININC += -DPTW32_STATIC_LIB
|
||||
#WININC += -mno-cygwin -mwindows -fno-exceptions
|
||||
|
||||
WININC += -DWINDOWS_SYS
|
||||
|
||||
WINLIB = -lws2_32 -luuid -lole32 -liphlpapi
|
||||
WINLIB += -lcrypt32 -lwinmm
|
||||
|
||||
CFLAGS += -I$(SSL_DIR)/include
|
||||
CFLAGS += -I$(PTHREADS_DIR)/include
|
||||
CFLAGS += -I$(ZLIB_DIR)
|
||||
CFLAGS += -I$(SRC_ROOT_GPG)/include
|
||||
|
||||
### Enable this for GPGME and GPG ERROR dirs
|
||||
#CFLAGS += -I$(GPGME_DIR)/src
|
||||
#CFLAGS += -I$(GPG_ERROR_DIR)/src
|
||||
|
||||
CFLAGS += $(WININC)
|
||||
|
||||
|
||||
|
||||
LIBS = -L$(LIBDIR) -lretroshare
|
||||
|
||||
LIBS += -L$(SSL_DIR)
|
||||
|
||||
LIBS += -lssl -lcrypto
|
||||
LIBS += -L$(UPNPC_DIR) -lminiupnpc
|
||||
LIBS += -L$(ZLIB_DIR) -lz
|
||||
LIBS += -L$(PTHREADS_DIR) -lpthreadGC2d
|
||||
LIBS += $(WINLIB)
|
||||
|
||||
#RSCFLAGS = -Wall -g $(INCLUDE)
|
||||
#RSCFLAGS += $(WININC)
|
||||
|
||||
|
27
libbitdht/src/tests/scripts/config.mk
Normal file
27
libbitdht/src/tests/scripts/config.mk
Normal file
|
@ -0,0 +1,27 @@
|
|||
|
||||
# determine which operating system
|
||||
#
|
||||
###########################################################################
|
||||
#Define OS.
|
||||
#
|
||||
OS = Linux
|
||||
#OS = MacOSX
|
||||
#OS = Cygwin
|
||||
#OS = Win # MinGw.
|
||||
###########################################################################
|
||||
|
||||
ifeq ($(OS),Linux)
|
||||
include $(TEST_TOP_DIR)/scripts/config-linux.mk
|
||||
else
|
||||
ifeq ($(OS),MacOSX)
|
||||
include $(TEST_TOP_DIR)/scripts/config-macosx.mk
|
||||
else
|
||||
ifeq ($(OS),Cygwin)
|
||||
include $(TEST_TOP_DIR)/scripts/config-cygwin.mk
|
||||
else
|
||||
include $(TEST_TOP_DIR)/scripts/config-mingw.mk
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
###########################################################################
|
25
libbitdht/src/tests/scripts/regress.mk
Normal file
25
libbitdht/src/tests/scripts/regress.mk
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
testoutputfiles = $(foreach tt,$(1),$(tt).tstout)
|
||||
|
||||
%.tstout : %.sh
|
||||
-sh ./$< > $@ 2>&1
|
||||
|
||||
%.tstout : %
|
||||
-./$< > $@ 2>&1
|
||||
|
||||
TESTOUT = $(call testoutputfiles,$(TESTS))
|
||||
|
||||
.phony : tests regress retest clobber
|
||||
|
||||
tests: $(TESTS)
|
||||
|
||||
regress: $(TESTOUT)
|
||||
@-echo "--------------- SUCCESS (count):"
|
||||
@-grep -c SUCCESS $(TESTOUT)
|
||||
@-echo "--------------- FAILURE REPORTS:"
|
||||
@-grep FAILURE $(TESTOUT) || echo no failures
|
||||
@-echo "--------------- end"
|
||||
|
||||
retest:
|
||||
-/bin/rm $(TESTOUT)
|
||||
|
19
libbitdht/src/tests/scripts/rules.mk
Normal file
19
libbitdht/src/tests/scripts/rules.mk
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
# defines required / used.
|
||||
#
|
||||
# CFLAGS
|
||||
#
|
||||
#
|
||||
|
||||
.cc.o:
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
clean:
|
||||
-/bin/rm $(EXECOBJ) $(TESTOBJ)
|
||||
|
||||
clobber: clean retest
|
||||
-/bin/rm $(EXEC) $(TESTS)
|
||||
|
||||
|
||||
include $(TEST_TOP_DIR)/scripts/regress.mk
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue