From 9bdd44d0f555ce8742f602afc4c217009c54fab3 Mon Sep 17 00:00:00 2001 From: drbob Date: Mon, 3 Mar 2008 14:41:15 +0000 Subject: [PATCH] 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 --- libretroshare/src/dbase/cachestrapper.h | 7 +-- libretroshare/src/dbase/fimonitor.h | 2 +- libretroshare/src/dht/Makefile | 8 ++-- libretroshare/src/dht/odhtmgr_test.cc | 24 ++++++++--- libretroshare/src/dht/odhtpost_test.cc | 8 +++- libretroshare/src/dht/opendht.cc | 45 +++++++++++++++++--- libretroshare/src/dht/opendhtmgr.cc | 6 +++ libretroshare/src/pqi/Makefile | 6 ++- libretroshare/src/pqi/conn_test.cc | 12 ++++++ libretroshare/src/pqi/dht_test.cc | 15 +++++++ libretroshare/src/pqi/net_test.cc | 2 +- libretroshare/src/pqi/p3dhtmgr.cc | 12 +++++- libretroshare/src/pqi/pqinetwork.cc | 2 +- libretroshare/src/pqi/pqinetwork.h | 8 ++-- libretroshare/src/pqi/pqissl.cc | 3 +- libretroshare/src/scripts/config-cygwin.mk | 27 ++++++++---- libretroshare/src/scripts/config.mk | 4 +- libretroshare/src/serialiser/rsbaseserial.cc | 1 - libretroshare/src/serialiser/tlvbase_test.cc | 2 +- libretroshare/src/services/p3gamelauncher.cc | 17 +++++++- libretroshare/src/services/p3ranking.cc | 16 ++++++- libretroshare/src/tcponudp/Makefile | 8 ++-- libretroshare/src/tcponudp/tou_net.h | 31 +++----------- libretroshare/src/upnp/Makefile | 2 +- libretroshare/src/upnp/upnphandler.cc | 2 +- libretroshare/src/upnp/upnputil.c | 8 +++- libretroshare/src/util/rsnet.cc | 6 +++ libretroshare/src/util/rsnet.h | 4 +- retroshare-gui/src/RetroShare.pro | 16 ++++--- 29 files changed, 218 insertions(+), 86 deletions(-) diff --git a/libretroshare/src/dbase/cachestrapper.h b/libretroshare/src/dbase/cachestrapper.h index 5fa9cf69f..a3d62c4e7 100644 --- a/libretroshare/src/dbase/cachestrapper.h +++ b/libretroshare/src/dbase/cachestrapper.h @@ -24,11 +24,14 @@ #ifndef MRK_CACHE_STRAPPER_H #define MRK_CACHE_STRAPPER_H +#include "pqi/p3cfgmgr.h" +#include "pqi/pqimonitor.h" +#include "util/rsthreads.h" + #include #include #include #include -#include "util/rsthreads.h" /******************* CacheStrapper and Related Classes ******************* * A generic Cache Update system. @@ -268,8 +271,6 @@ class CachePair bool operator<(const CachePair &a, const CachePair &b); -#include "pqi/pqimonitor.h" -#include "pqi/p3cfgmgr.h" class p3AuthMgr; diff --git a/libretroshare/src/dbase/fimonitor.h b/libretroshare/src/dbase/fimonitor.h index 4d97afe06..8d1aaf1b0 100644 --- a/libretroshare/src/dbase/fimonitor.h +++ b/libretroshare/src/dbase/fimonitor.h @@ -24,8 +24,8 @@ #ifndef FILE_INDEX_MONITOR_H #define FILE_INDEX_MONITOR_H -#include "dbase/findex.h" #include "dbase/cachestrapper.h" +#include "dbase/findex.h" #include "util/rsthreads.h" /****************************************************************************************** diff --git a/libretroshare/src/dht/Makefile b/libretroshare/src/dht/Makefile index dd5b52e3d..09d825e1d 100644 --- a/libretroshare/src/dht/Makefile +++ b/libretroshare/src/dht/Makefile @@ -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: diff --git a/libretroshare/src/dht/odhtmgr_test.cc b/libretroshare/src/dht/odhtmgr_test.cc index 66a11ddeb..a10af8acb 100644 --- a/libretroshare/src/dht/odhtmgr_test.cc +++ b/libretroshare/src/dht/odhtmgr_test.cc @@ -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 #include +#include 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) { diff --git a/libretroshare/src/dht/odhtpost_test.cc b/libretroshare/src/dht/odhtpost_test.cc index 359545d4a..fba186668 100644 --- a/libretroshare/src/dht/odhtpost_test.cc +++ b/libretroshare/src/dht/odhtpost_test.cc @@ -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 values; dht.searchKey(key, values); diff --git a/libretroshare/src/dht/opendht.cc b/libretroshare/src/dht/opendht.cc index ca3185d26..40484ef21 100644 --- a/libretroshare/src/dht/opendht.cc +++ b/libretroshare/src/dht/opendht.cc @@ -29,15 +29,17 @@ #include #include +#include +#include #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 &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; } diff --git a/libretroshare/src/dht/opendhtmgr.cc b/libretroshare/src/dht/opendhtmgr.cc index 16f697839..6db3a8d99 100644 --- a/libretroshare/src/dht/opendhtmgr.cc +++ b/libretroshare/src/dht/opendhtmgr.cc @@ -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; } diff --git a/libretroshare/src/pqi/Makefile b/libretroshare/src/pqi/Makefile index e062da9a1..d031824eb 100644 --- a/libretroshare/src/pqi/Makefile +++ b/libretroshare/src/pqi/Makefile @@ -31,9 +31,11 @@ RSOBJ = $(BASE_OBJ) $(LOOP_OBJ) \ $(UDP_OBJ) \ $(GRP_OBJ) -TESTOBJ = net_test.o dht_test.o conn_test.o +TESTOBJ = net_test.o dht_test.o +#conn_test.o -TESTS = net_test dht_test conn_test +TESTS = net_test dht_test +#conn_test all: librs tests diff --git a/libretroshare/src/pqi/conn_test.cc b/libretroshare/src/pqi/conn_test.cc index 542a82a28..7ca8043a4 100644 --- a/libretroshare/src/pqi/conn_test.cc +++ b/libretroshare/src/pqi/conn_test.cc @@ -302,7 +302,13 @@ int main() dhtTester.start(); /* wait for a little before switching on */ +/********************************** 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); @@ -310,7 +316,13 @@ int main() /* wait loop */ while(1) { +/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ +#ifndef WINDOWS_SYS sleep(1); +#else + Sleep(1000); +#endif +/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ connMgr.tick(); pqipg->tick(); diff --git a/libretroshare/src/pqi/dht_test.cc b/libretroshare/src/pqi/dht_test.cc index 450ee545f..370a3b1c9 100644 --- a/libretroshare/src/pqi/dht_test.cc +++ b/libretroshare/src/pqi/dht_test.cc @@ -3,6 +3,8 @@ /***** Test for the new DHT system *****/ +#include "pqi/pqinetwork.h" + #include "util/rsnet.h" #include "util/rsthreads.h" #include "util/rsprint.h" @@ -218,7 +220,13 @@ int main() dhtTester.start(); /* wait for a little before switching on */ +/********************************** 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); @@ -234,7 +242,14 @@ int main() while(1) { std::cerr << "Main waiting..." << std::endl; +/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ +#ifndef WINDOWS_SYS sleep(3); +#else + Sleep(3000); +#endif +/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ + /* handle async search */ frmMtx.lock(); /* LOCK TEST FRAMEWORK MUTEX */ diff --git a/libretroshare/src/pqi/net_test.cc b/libretroshare/src/pqi/net_test.cc index 4634d6549..8842c330a 100644 --- a/libretroshare/src/pqi/net_test.cc +++ b/libretroshare/src/pqi/net_test.cc @@ -29,8 +29,8 @@ * */ -#include "util/rsnet.h" #include "pqi/pqinetwork.h" +#include "util/rsnet.h" #include #include diff --git a/libretroshare/src/pqi/p3dhtmgr.cc b/libretroshare/src/pqi/p3dhtmgr.cc index d62a421b3..2b192716c 100644 --- a/libretroshare/src/pqi/p3dhtmgr.cc +++ b/libretroshare/src/pqi/p3dhtmgr.cc @@ -457,8 +457,14 @@ void p3DhtMgr::run() break; /* speed up config modifications */ } - +/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ +#ifndef WINDOWS_SYS sleep(waittime); +#else + Sleep(1000 * waittime); +#endif +/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ + } } } @@ -1148,6 +1154,10 @@ bool p3DhtMgr::resultDHT(std::string key, std::string value) * */ +#ifdef DHT_DEBUG + std::cerr << "p3DhtMgr::resultDHT() key: " << key << " value: " << value << std::endl; +#endif + /* variables for dhtResult() call */ struct sockaddr_in laddr; struct sockaddr_in raddr; diff --git a/libretroshare/src/pqi/pqinetwork.cc b/libretroshare/src/pqi/pqinetwork.cc index f9218be2a..7ac2439a2 100644 --- a/libretroshare/src/pqi/pqinetwork.cc +++ b/libretroshare/src/pqi/pqinetwork.cc @@ -354,7 +354,7 @@ in_addr_t inet_netof(struct in_addr addr) // This returns in Host Byte Order. (as the man page says) // Again, to be consistent with Linux. -in_addr_t inet_network(char *inet_name) +in_addr_t inet_network(const char *inet_name) { struct in_addr addr; if (inet_aton(inet_name, &addr)) diff --git a/libretroshare/src/pqi/pqinetwork.h b/libretroshare/src/pqi/pqinetwork.h index 252bd800b..9a997add5 100644 --- a/libretroshare/src/pqi/pqinetwork.h +++ b/libretroshare/src/pqi/pqinetwork.h @@ -28,6 +28,7 @@ #ifndef MRK_PQI_NETWORKING_HEADER #define MRK_PQI_NETWORKING_HEADER + /********************************** WINDOWS/UNIX SPECIFIC PART ******************/ #ifndef WINDOWS_SYS @@ -47,20 +48,21 @@ /* This defines the platform to be WinXP or later... * and is needed for getaddrinfo.... (not used anymore) * -#define _WIN32_WINNT 0x0501 */ +#define _WIN32_WINNT 0x0501 +#include "util/rsnet.h" /* more generic networking header */ #include #include typedef int socklen_t; -typedef unsigned long in_addr_t; +//typedef unsigned long in_addr_t; // Some Network functions that are missing from windows. in_addr_t inet_netof(struct in_addr addr); -in_addr_t inet_network(char *inet_name); +in_addr_t inet_network(const char *inet_name); int inet_aton(const char *name, struct in_addr *addr); extern int errno; /* Define extern errno, to duplicate unix behaviour */ diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index e6fd439c3..0f9a38b9b 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -26,11 +26,12 @@ -#include "util/rsnet.h" #include "pqi/pqissl.h" #include "pqi/pqinetwork.h" +#include "util/rsnet.h" + #include #include diff --git a/libretroshare/src/scripts/config-cygwin.mk b/libretroshare/src/scripts/config-cygwin.mk index 800ca0fb8..ca9a36d87 100644 --- a/libretroshare/src/scripts/config-cygwin.mk +++ b/libretroshare/src/scripts/config-cygwin.mk @@ -34,7 +34,12 @@ LIBRS = $(LIBDIR)/libretroshare.a # Unix: Linux/Cygwin INCLUDE = -I $(RS_TOP_DIR) -I$(KADC_DIR) -CFLAGS = -Wall -g $(INCLUDE) + +ifdef PQI_DEBUG + CFLAGS = -Wall -g $(INCLUDE) +else + CFLAGS = -Wall -O2 $(INCLUDE) +endif ifdef PQI_USE_XPGP INCLUDE += -I $(SSL_DIR)/include @@ -59,6 +64,16 @@ 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. ######################################################################### @@ -69,7 +84,7 @@ WININC += -mno-cygwin -mwindows -fno-exceptions WININC += -DWINDOWS_SYS WINLIB = -lws2_32 -luuid -lole32 -liphlpapi -WINLIB += -lcrypt32 +WINLIB += -lcrypt32 -lwinmm CFLAGS += -I$(PTHREADS_DIR) $(WININC) CFLAGS += -I$(ZLIB_DIR) @@ -83,12 +98,8 @@ LIBS += -lssl -lcrypto LIBS += -L$(KADC_DIR) -lKadC LIBS += -L$(UPNPC_DIR) -lminiupnpc LIBS += -L$(ZLIB_DIR) -lz - -RSLIBS += $(LIBS) -RSLIBS += -L$(PTHREADS_DIR) -lpthreadGC2d - -RSLIBS += $(WINLIB) -LIBS += $(WINLIB) +LIBS += -L$(PTHREADS_DIR) -lpthreadGC2d +LIBS += $(WINLIB) RSCFLAGS += $(WININC) diff --git a/libretroshare/src/scripts/config.mk b/libretroshare/src/scripts/config.mk index 9f22fa363..49cae3dd2 100644 --- a/libretroshare/src/scripts/config.mk +++ b/libretroshare/src/scripts/config.mk @@ -4,9 +4,9 @@ ########################################################################### #Define OS. # -OS = Linux +#OS = Linux #OS = MacOSX -#OS = Cygwin +OS = Cygwin #OS = Win # MinGw. ########################################################################### diff --git a/libretroshare/src/serialiser/rsbaseserial.cc b/libretroshare/src/serialiser/rsbaseserial.cc index c568e2006..0b02ac8bc 100644 --- a/libretroshare/src/serialiser/rsbaseserial.cc +++ b/libretroshare/src/serialiser/rsbaseserial.cc @@ -24,7 +24,6 @@ * */ -#include #include "serialiser/rsbaseserial.h" #include "util/rsnet.h" diff --git a/libretroshare/src/serialiser/tlvbase_test.cc b/libretroshare/src/serialiser/tlvbase_test.cc index 5d61364fd..a1b7efeb4 100644 --- a/libretroshare/src/serialiser/tlvbase_test.cc +++ b/libretroshare/src/serialiser/tlvbase_test.cc @@ -29,10 +29,10 @@ #include #include -#include #include "serialiser/rstlvbase.h" #include "util/utest.h" +#include "util/rsnet.h" INITTEST(); diff --git a/libretroshare/src/services/p3gamelauncher.cc b/libretroshare/src/services/p3gamelauncher.cc index 2a872ff41..977fae293 100644 --- a/libretroshare/src/services/p3gamelauncher.cc +++ b/libretroshare/src/services/p3gamelauncher.cc @@ -27,6 +27,7 @@ #include "services/p3gameservice.h" #include "pqi/pqidebug.h" #include +#include /* global variable for GUI */ RsGameLauncher *rsGameLauncher = NULL; @@ -131,13 +132,27 @@ std::string generateRandomGameId() { std::ostringstream out; out << std::hex; - +/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ +#ifndef WINDOWS_SYS /* 4 bytes per random number: 4 x 4 = 16 bytes */ for(int i = 0; i < 4; i++) { + out << std::setw(8) << std::setfill('0'); uint32_t rint = random(); out << rint; } +#else + srand(time(NULL)); + /* 2 bytes per random number: 8 x 2 = 16 bytes */ + for(int i = 0; i < 8; i++) + { + out << std::setw(4) << std::setfill('0'); + uint16_t rint = rand(); /* only gives 16 bits */ + out << rint; + } +#endif +/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ + return out.str(); } diff --git a/libretroshare/src/services/p3ranking.cc b/libretroshare/src/services/p3ranking.cc index 672d55d07..3a2b05784 100644 --- a/libretroshare/src/services/p3ranking.cc +++ b/libretroshare/src/services/p3ranking.cc @@ -25,6 +25,7 @@ #include "serialiser/rsrankitems.h" #include "services/p3ranking.h" +#include #include "pqi/pqibin.h" #include "pqi/p3authmgr.h" @@ -823,13 +824,26 @@ std::string generateRandomLinkId() { std::ostringstream out; out << std::hex; - +/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ +#ifndef WINDOWS_SYS /* 4 bytes per random number: 4 x 4 = 16 bytes */ for(int i = 0; i < 4; i++) { + out << std::setw(8) << std::setfill('0'); uint32_t rint = random(); out << rint; } +#else + srand(time(NULL)); + /* 2 bytes per random number: 8 x 2 = 16 bytes */ + for(int i = 0; i < 8; i++) + { + out << std::setw(4) << std::setfill('0'); + uint16_t rint = rand(); /* only gives 16 bits */ + out << rint; + } +#endif +/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ return out.str(); } diff --git a/libretroshare/src/tcponudp/Makefile b/libretroshare/src/tcponudp/Makefile index efea248ec..0326a7a20 100644 --- a/libretroshare/src/tcponudp/Makefile +++ b/libretroshare/src/tcponudp/Makefile @@ -15,12 +15,12 @@ RSOBJ += tcppacket.o tcpstream.o tou.o $(BIOOBJ) EXECS = librs udpsock_test udpsort_test udp_server #test_tou pair_tou reset_tou internal_tou largefile_tou -TESTOBJ = udpsock_test.o udpsort_test.o udp_server.o test_tou.o -TESTOBJ += pair_tou.o reset_tou.o largefile_tou.o +#TESTOBJ = udpsock_test.o udpsort_test.o udp_server.o test_tou.o +#TESTOBJ += pair_tou.o reset_tou.o largefile_tou.o #internal_tou.o -TESTS = udpsock_test udpsort_test udp_server test_tou -TESTS += pair_tou reset_tou largefile_tou +#TESTS = udpsock_test udpsort_test udp_server test_tou +#TESTS += pair_tou reset_tou largefile_tou #internal_tou all: librs tests diff --git a/libretroshare/src/tcponudp/tou_net.h b/libretroshare/src/tcponudp/tou_net.h index 39c02e24f..f852aa4bc 100644 --- a/libretroshare/src/tcponudp/tou_net.h +++ b/libretroshare/src/tcponudp/tou_net.h @@ -28,6 +28,11 @@ #ifndef TOU_UNIVERSAL_NETWORK_HEADER #define TOU_UNIVERSAL_NETWORK_HEADER +/* Some Types need to be defined before the interface can be declared + */ + +#include "util/rsnet.h" + /* C Interface */ #ifdef __cplusplus extern "C" { @@ -58,32 +63,6 @@ extern "C" { * int tounet_checkTTL(); a check if we can modify the ttl */ -/* Some Types need to be defined before the interface can be declared - */ -/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ -#ifndef WINDOWS_SYS - -#include -#include - -#include -#include - -#include -#include - -#else - -#include -#include - -#include /* for ssize_t */ -typedef int socklen_t; -typedef unsigned long in_addr_t; - -#endif -/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ - /* the universal interface */ int tounet_errno(); /* for internal networking errors */ diff --git a/libretroshare/src/upnp/Makefile b/libretroshare/src/upnp/Makefile index 47a9b5069..d579a2273 100644 --- a/libretroshare/src/upnp/Makefile +++ b/libretroshare/src/upnp/Makefile @@ -20,7 +20,7 @@ TESTS = upnptest all: librs tests upnptest: $(OBJ) upnptest.o - $(CC) $(CFLAGS) -o upnptest $(OBJ) upnptest.o $(RSLIBS) + $(CC) $(CFLAGS) -o upnptest $(OBJ) upnptest.o $(LIBS) ############################################################### include $(RS_TOP_DIR)/scripts/rules.mk diff --git a/libretroshare/src/upnp/upnphandler.cc b/libretroshare/src/upnp/upnphandler.cc index 0a628c292..945c3ea49 100644 --- a/libretroshare/src/upnp/upnphandler.cc +++ b/libretroshare/src/upnp/upnphandler.cc @@ -10,8 +10,8 @@ extern "C" { #endif /* This stuff is actually C */ -#include "upnp/upnputil.h" #include "upnp/upnphandler.h" +#include "upnp/upnputil.h" class uPnPConfigData { diff --git a/libretroshare/src/upnp/upnputil.c b/libretroshare/src/upnp/upnputil.c index 0d2437362..bd72375f2 100644 --- a/libretroshare/src/upnp/upnputil.c +++ b/libretroshare/src/upnp/upnputil.c @@ -138,9 +138,13 @@ bool SetRedirectAndTest(struct UPNPUrls * urls, printf("ExternalIPAddress = %s\n", externalIPAddress); else printf("GetExternalIPAddress failed.\n"); - + +// Unix at the moment! +// r = UPNP_AddPortMapping(urls->controlURL, data->servicetype, +// eport, iport, iaddr, 0, leaseDuration, proto); + r = UPNP_AddPortMapping(urls->controlURL, data->servicetype, - eport, iport, iaddr, 0, leaseDuration, proto); + eport, iport, iaddr, 0, proto); if(r==0) { printf("AddPortMapping(%s, %s, %s) failed\n", eport, iport, iaddr); diff --git a/libretroshare/src/util/rsnet.cc b/libretroshare/src/util/rsnet.cc index 60d426409..d53d9120a 100644 --- a/libretroshare/src/util/rsnet.cc +++ b/libretroshare/src/util/rsnet.cc @@ -26,6 +26,12 @@ #include "util/rsnet.h" #include +/* enforce LITTLE_ENDIAN on Windows */ +#ifdef WINDOWS_SYS + #define BYTE_ORDER 1234 + #define LITTLE_ENDIAN 1234 + #define BIG_ENDIAN 4321 +#endif uint64_t ntohll(uint64_t x) { diff --git a/libretroshare/src/util/rsnet.h b/libretroshare/src/util/rsnet.h index e56513aa1..47430ccbe 100644 --- a/libretroshare/src/util/rsnet.h +++ b/libretroshare/src/util/rsnet.h @@ -45,9 +45,11 @@ #include #include /* for ssize_t */ -typedef uint32_t socklen_t; +//typedef uint32_t socklen_t; typedef uint32_t in_addr_t; +int inet_aton(const char *name, struct in_addr *addr); + #endif /********************************** WINDOWS/UNIX SPECIFIC PART ******************/ diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 768ef6c63..aed02fd40 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -1,10 +1,11 @@ ###################################################################### # Automatically generated by qmake (2.00a) Fr 18. Aug 22:48:56 2006 -###################################################################### -OBJECTS_DIR = temp/obj -RCC_DIR = temp/qrc -UI_DIR = temp/ui -MOC_DIR = temp/moc +####################################################################### +#OBJECTS_DIR = temp/obj +#RCC_DIR = temp/qrc +#UI_DIR = temp/ui +#MOC_DIR = temp/moc + CONFIG += qt release QT += network xml TEMPLATE = app @@ -313,8 +314,9 @@ win32 { RC_FILE = gui/images/retroshare_win.rc - "LIBS += -L"../../winlibs" -lretroshare -lssl -lcrypto -lpthreadGC2d -lKadC -lminiupnpc -lz -lws2_32 -luuid -lole32 -liphlpapi -lcrypt32-cygwin -lskin -lqcheckers -lsmplayer -lgdi32 - CONFIG += qt release" + LIBS += -L"../../../../lib" -lretroshare -lssl -lcrypto -lpthreadGC2d -lKadC -lminiupnpc -lz + LIBS += -lqcheckers -lsmplayer + LIBS += -lws2_32 -luuid -lole32 -liphlpapi -lcrypt32-cygwin -gdi32 LIBS += -lole32 }