summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Lossless_UDP.c6
-rw-r--r--core/network.c22
-rw-r--r--core/network.h10
3 files changed, 30 insertions, 8 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 @@
40#define CONNEXION_TIMEOUT 10 40#define CONNEXION_TIMEOUT 10
41 41
42//initial amount of sync/hanshake packets to send per second. 42//initial amount of sync/hanshake packets to send per second.
43#define SYNC_RATE 50 43#define SYNC_RATE 10
44 44
45//initial send rate of sync packets when data is being sent/recieved. 45//initial send rate of data.
46#define DATA_SYNC_RATE 200 46#define DATA_SYNC_RATE 30
47 47
48typedef struct 48typedef struct
49{ 49{
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 @@
25#include "network.h" 25#include "network.h"
26 26
27 27
28//returns current time in milliseconds since the epoch. 28//returns current UNIX time in microseconds (us).
29uint64_t current_time() 29uint64_t current_time()
30{ 30{
31 uint64_t time; 31 uint64_t time;
32 #ifdef WIN32 32 #ifdef WIN32
33 //TODO: windows version 33 //This probably works fine
34 FILETIME ft;
35 GetSystemTimeAsFileTime(&ft);
36 time = ft.dwHighDateTime;
37 time <<=32;
38 time |= ft.dwLowDateTime;
39 time -= 116444736000000000UL;
40 return time/10;
34 #else 41 #else
35 struct timeval a; 42 struct timeval a;
36 gettimeofday(&a, NULL); 43 gettimeofday(&a, NULL);
37 time = 1000000UL*a.tv_sec + a.tv_usec; 44 time = 1000000UL*a.tv_sec + a.tv_usec;
38 #endif
39 return time; 45 return time;
46 #endif
47
40 48
41} 49}
42 50
43uint32_t random_int() 51uint32_t random_int()
44{ 52{
45 #ifdef WIN32 53 #ifdef WIN32
46 //TODO replace rand with something cryptograhically secure 54 //NOTE: this function comes from libsodium
47 return rand(); 55 return randombytes_random();
48 #else 56 #else
49 return random(); 57 return random();
50 #endif 58 #endif
@@ -69,7 +77,11 @@ int sendpacket(IP_Port ip_port, char * data, uint32_t length)
69int recievepacket(IP_Port * ip_port, char * data, uint32_t * length) 77int recievepacket(IP_Port * ip_port, char * data, uint32_t * length)
70{ 78{
71 ADDR addr; 79 ADDR addr;
80 #ifdef WIN32
81 int addrlen = sizeof(addr);
82 #else
72 uint32_t addrlen = sizeof(addr); 83 uint32_t addrlen = sizeof(addr);
84 #endif
73 (*(int32_t *)length) = recvfrom(sock, data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen); 85 (*(int32_t *)length) = recvfrom(sock, data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen);
74 if(*(int32_t *)length <= 0) 86 if(*(int32_t *)length <= 0)
75 { 87 {
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 @@
33#include <time.h> 33#include <time.h>
34 34
35 35
36
36#ifdef WIN32 //Put win32 includes here 37#ifdef WIN32 //Put win32 includes here
37 38
38#include <winsock2.h> 39#include <winsock2.h>
39#include <windows.h> 40#include <windows.h>
40 41
42//we use libsodium (Portable version of NaCl) because stock NaCl doesn't compile on windows.
43#include <sodium.h>
44
41#else //Linux includes 45#else //Linux includes
42 46
43#include <fcntl.h> 47#include <fcntl.h>
@@ -45,6 +49,12 @@
45#include <netinet/in.h> 49#include <netinet/in.h>
46#include <errno.h> 50#include <errno.h>
47#include <sys/time.h> 51#include <sys/time.h>
52
53//TODO: Including stuff like this is bad. This needs fixing.
54//We keep support for the original NaCl for now on UNIX like Operating Systems.
55//Commented out for now
56//#include "../nacl/build/Linux/include/amd64/crypto_box.h"
57
48#endif 58#endif
49 59
50#define MAX_UDP_PACKET_SIZE 65507 60#define MAX_UDP_PACKET_SIZE 65507