summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-03 16:35:44 -0400
committerirungentoo <irungentoo@gmail.com>2013-07-03 16:35:44 -0400
commitccb270add2c3ee1df8301a428e2029939250a9e0 (patch)
treea7cd3f09f16298915dcac03cd66c10dfb6b1bb96
parent1e17492b783cd9ecfea57ef4cd2112c0fa155538 (diff)
Compiled for windows and fixed stuff accordingly.
-rw-r--r--core/Lossless_UDP.c6
-rw-r--r--core/network.c22
-rw-r--r--core/network.h10
-rw-r--r--docs/Lossless_UDP.txt2
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 @@
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
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:
15 Alice puts it in the handshake packet (handshake_id1). 15 Alice puts it in the handshake packet (handshake_id1).
16 Alice starts sending handshake packets to Bob (send 10 packets over 5 seconds if no response connection fails.) 16 Alice starts sending handshake packets to Bob (send 10 packets over 5 seconds if no response connection fails.)
17 Bob receives the packet. 17 Bob receives the packet.
18 Bob copies the handshake packet he got from alice but caternates a random 4 byte number to it (handshake_id2) 18 Bob copies the handshake packet he got from alice but concatenates a random 4 byte number to it (handshake_id2)
19 Alice receives the packet, checks if handshake_id1 matches the one she sent. 19 Alice receives the packet, checks if handshake_id1 matches the one she sent.
20 If it does she starts sending SYNC packets with sent_packetnum = handshake_id2 and recv_packetnum = handshake_id1. 20 If it does she starts sending SYNC packets with sent_packetnum = handshake_id2 and recv_packetnum = handshake_id1.
21 Bob receives the packet, 21 Bob receives the packet,