mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Compiled for windows and fixed stuff accordingly.
This commit is contained in:
parent
1e17492b78
commit
ccb270add2
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -33,11 +33,15 @@
|
|||
#include <time.h>
|
||||
|
||||
|
||||
|
||||
#ifdef WIN32 //Put win32 includes here
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
|
||||
//we use libsodium (Portable version of NaCl) because stock NaCl doesn't compile on windows.
|
||||
#include <sodium.h>
|
||||
|
||||
#else //Linux includes
|
||||
|
||||
#include <fcntl.h>
|
||||
|
@ -45,6 +49,12 @@
|
|||
#include <netinet/in.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
//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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user