From ccb270add2c3ee1df8301a428e2029939250a9e0 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 3 Jul 2013 16:35:44 -0400 Subject: Compiled for windows and fixed stuff accordingly. --- core/Lossless_UDP.c | 6 +++--- core/network.c | 22 +++++++++++++++++----- core/network.h | 10 ++++++++++ docs/Lossless_UDP.txt | 2 +- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/core/Lossless_UDP.c b/core/Lossless_UDP.c index 7513e5b4..bcbfb18a 100644 --- a/core/Lossless_UDP.c +++ b/core/Lossless_UDP.c @@ -40,10 +40,10 @@ #define CONNEXION_TIMEOUT 10 //initial amount of sync/hanshake packets to send per second. -#define SYNC_RATE 50 +#define SYNC_RATE 10 -//initial send rate of sync packets when data is being sent/recieved. -#define DATA_SYNC_RATE 200 +//initial send rate of data. +#define DATA_SYNC_RATE 30 typedef struct { diff --git a/core/network.c b/core/network.c index 35257d54..601066cd 100644 --- a/core/network.c +++ b/core/network.c @@ -25,26 +25,34 @@ #include "network.h" -//returns current time in milliseconds since the epoch. +//returns current UNIX time in microseconds (us). uint64_t current_time() { uint64_t time; #ifdef WIN32 - //TODO: windows version + //This probably works fine + FILETIME ft; + GetSystemTimeAsFileTime(&ft); + time = ft.dwHighDateTime; + time <<=32; + time |= ft.dwLowDateTime; + time -= 116444736000000000UL; + return time/10; #else struct timeval a; gettimeofday(&a, NULL); time = 1000000UL*a.tv_sec + a.tv_usec; - #endif return time; + #endif + } uint32_t random_int() { #ifdef WIN32 - //TODO replace rand with something cryptograhically secure - return rand(); + //NOTE: this function comes from libsodium + return randombytes_random(); #else return random(); #endif @@ -69,7 +77,11 @@ int sendpacket(IP_Port ip_port, char * data, uint32_t length) int recievepacket(IP_Port * ip_port, char * data, uint32_t * length) { ADDR addr; + #ifdef WIN32 + int addrlen = sizeof(addr); + #else uint32_t addrlen = sizeof(addr); + #endif (*(int32_t *)length) = recvfrom(sock, data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen); if(*(int32_t *)length <= 0) { diff --git a/core/network.h b/core/network.h index f84ceccb..c8fdce5c 100644 --- a/core/network.h +++ b/core/network.h @@ -33,11 +33,15 @@ #include + #ifdef WIN32 //Put win32 includes here #include #include +//we use libsodium (Portable version of NaCl) because stock NaCl doesn't compile on windows. +#include + #else //Linux includes #include @@ -45,6 +49,12 @@ #include #include #include + +//TODO: Including stuff like this is bad. This needs fixing. +//We keep support for the original NaCl for now on UNIX like Operating Systems. +//Commented out for now +//#include "../nacl/build/Linux/include/amd64/crypto_box.h" + #endif #define MAX_UDP_PACKET_SIZE 65507 diff --git a/docs/Lossless_UDP.txt b/docs/Lossless_UDP.txt index 7886bf5d..bbfd2ad1 100644 --- a/docs/Lossless_UDP.txt +++ b/docs/Lossless_UDP.txt @@ -15,7 +15,7 @@ Lossless UDP: Alice puts it in the handshake packet (handshake_id1). Alice starts sending handshake packets to Bob (send 10 packets over 5 seconds if no response connection fails.) Bob receives the packet. - Bob copies the handshake packet he got from alice but caternates a random 4 byte number to it (handshake_id2) + Bob copies the handshake packet he got from alice but concatenates a random 4 byte number to it (handshake_id2) Alice receives the packet, checks if handshake_id1 matches the one she sent. If it does she starts sending SYNC packets with sent_packetnum = handshake_id2 and recv_packetnum = handshake_id1. Bob receives the packet, -- cgit v1.2.3