Changes required to get Retroshare V0.4 working under windows.

Most of these changes relate to:
 (1) rand() is different 
 (2) sleep() don't exist on Windows.
 (3) networking headers are different - these need to be cleaned up in general.
 (4) disabled tests that won't compile on Windows.

Will probably have to rollback some of these changes for Unix later.





git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@372 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-03-03 14:41:15 +00:00
parent 9e954e9c0f
commit 9bdd44d0f5
29 changed files with 218 additions and 86 deletions

View file

@ -17,16 +17,16 @@ all: librs tests
#dhttest is OLD
dhttest: $(OBJ) dhttest.o
$(CC) $(CFLAGS) -o dhttest $(OBJ) dhttest.o $(RSLIBS)
$(CC) $(CFLAGS) -o dhttest $(OBJ) dhttest.o $(LIBS)
odhtpost_test: $(OBJ) odhtpost_test.o
$(CC) $(CFLAGS) -o odhtpost_test $(OBJ) odhtpost_test.o $(RSLIBS)
$(CC) $(CFLAGS) -o odhtpost_test $(OBJ) odhtpost_test.o $(LIBS)
odhtstr_test: $(OBJ) odhtstr_test.o
$(CC) $(CFLAGS) -o odhtstr_test $(OBJ) odhtstr_test.o $(RSLIBS)
$(CC) $(CFLAGS) -o odhtstr_test $(OBJ) odhtstr_test.o $(LIBS)
odhtmgr_test: $(OBJ) odhtmgr_test.o
$(CC) $(CFLAGS) -o odhtmgr_test $(OBJ) odhtmgr_test.o $(RSLIBS)
$(CC) $(CFLAGS) -o odhtmgr_test $(OBJ) odhtmgr_test.o $(LIBS)
# Extra Rule...
.c.o:

View file

@ -27,17 +27,18 @@
/***** Test for the new DHT system *****/
#include "pqi/p3dhtmgr.h"
#include "pqi/pqimonitor.h"
#include "dht/opendhtmgr.h"
#include "util/rsnet.h"
#include "util/rsthreads.h"
#include "util/rsprint.h"
#include "pqi/p3dhtmgr.h"
#include "pqi/pqimonitor.h"
#include "dht/opendhtmgr.h"
#include <iostream>
#include <sstream>
#include <unistd.h>
void usage(char *name)
{
@ -87,7 +88,14 @@ int main(int argc, char **argv)
dhtTester.start();
/* wait for a little before switching on */
sleep(1);
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS
sleep(1);
#else
Sleep(1000);
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
std::cerr << "Switching on DhtTester()" << std::endl;
dhtTester.setDhtOn(true);
@ -104,7 +112,13 @@ int main(int argc, char **argv)
while(1)
{
std::cerr << "Main waiting..." << std::endl;
sleep(3);
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS
sleep(3);
#else
Sleep(3000);
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
if (!haveOwnAddress)
{

View file

@ -48,7 +48,13 @@ int main()
dht.publishKey(key, value, ttl);
sleep(10);
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS
sleep(10);
#else
Sleep(10000);
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
std::list<std::string> values;
dht.searchKey(key, values);

View file

@ -29,15 +29,17 @@
#include <fstream>
#include <sstream>
#include <sys/time.h>
#include <time.h>
#include "util/rsnet.h"
#include "util/rsprint.h"
const std::string openDHT_Client = "Retroshare V0.4";
const std::string openDHT_Agent = "RS-HTTP-V0.4";
#define MAX_DHT_PEER_FAILS 5
#define MAX_DHT_TOTAL_FAILS 5
#define MAX_DHT_ATTEMPTS 5
#define MAX_DHT_PEER_FAILS 2 /* then discard */
#define MAX_DHT_TOTAL_FAILS 10 /* in a row -> think we're not connected! */
#define MAX_DHT_ATTEMPTS 10 /* attempts per search/publish */
#define MIN_DHT_SERVERS 5
#define OPENDHT_DEBUG 1
@ -174,6 +176,16 @@ bool OpenDHTClient::getServer(std::string &host, uint16_t &port, struct sockaddr
/* randomly choose one */
dhtMutex.lock(); /**** LOCK ****/
#ifndef WINDOWS_SYS
#else
/* WINDOWS don't randomise properly so we'll do it ourselves...
*/
uint32_t randomize = timeGetTime();
srand(randomize);
#endif
uint32_t len = mServers.size();
uint32_t rnd = len * (rand() / (RAND_MAX + 1.0));
@ -334,6 +346,11 @@ bool OpenDHTClient::publishKey(std::string key, std::string value, uint32_t ttl)
bool OpenDHTClient::searchKey(std::string key, std::list<std::string> &values)
{
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_searchKey() key: 0x" << RsUtil::BinToHex(key);
std::cerr << std::endl;
#endif
/* create request */
std::string getmsg = createOpenDHT_get(key, 1024, openDHT_Client);
std::string response;
@ -510,7 +527,13 @@ bool OpenDHTClient::openDHT_sendMessage(std::string msg, std::string &response)
std::cerr << std::endl;
/* now wait for the response */
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS
sleep(1);
#else
Sleep(1000);
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
int recvsize = 51200; /* 50kb */
char *inbuf = (char *) malloc(recvsize);
@ -520,7 +543,6 @@ bool OpenDHTClient::openDHT_sendMessage(std::string msg, std::string &response)
std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " Recvd Chunk:" << size;
std::cerr << std::endl;
idx += size;
}
@ -531,12 +553,16 @@ bool OpenDHTClient::openDHT_sendMessage(std::string msg, std::string &response)
free(inbuf);
/* print it out */
std::cerr << "HTTP What We Sent ***************" << std::endl;
std::cerr << putheader;
std::cerr << msg;
std::cerr << std::endl;
std::cerr << "HTTP response *******************" << std::endl;
std::cerr << response;
std::cerr << std::endl;
std::cerr << "HTTP response *******************" << std::endl;
close(sockfd);
unix_close(sockfd);
return true;
}
@ -607,7 +633,13 @@ bool OpenDHTClient::openDHT_getDHTList(std::string &response)
std::cerr << std::endl;
/* now wait for the response */
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS
sleep(1);
#else
Sleep(1000);
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
int recvsize = 51200; /* 50kb */
char *inbuf = (char *) malloc(recvsize);
@ -617,7 +649,6 @@ bool OpenDHTClient::openDHT_getDHTList(std::string &response)
std::cerr << "OpenDHTClient::openDHT_getDHTList()";
std::cerr << " Recvd Chunk:" << size;
std::cerr << std::endl;
idx += size;
}
@ -633,7 +664,7 @@ bool OpenDHTClient::openDHT_getDHTList(std::string &response)
std::cerr << std::endl;
std::cerr << "HTTP response *******************" << std::endl;
close(sockfd);
unix_close(sockfd);
return true;
}

View file

@ -62,6 +62,8 @@ extern "C" void* doDhtPublish(void* p)
delete data;
pthread_exit(NULL);
return NULL;
}
@ -71,6 +73,8 @@ extern "C" void* doDhtSearch(void* p)
if ((!data) || (!data->mgr) || (!data->client))
{
pthread_exit(NULL);
return NULL;
}
/* search it! */
@ -88,6 +92,8 @@ extern "C" void* doDhtSearch(void* p)
delete data;
pthread_exit(NULL);
return NULL;
}