mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Lossless UDP tests fixed.
This commit is contained in:
parent
619ecb0bb3
commit
d62b91f3ac
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#define PORT 33446
|
#define PORT 33446
|
||||||
|
|
||||||
void printpacket(char * data, uint32_t length, IP_Port ip_port)
|
void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length);
|
printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length);
|
||||||
|
@ -104,13 +104,13 @@ void printconnection(int connection_id)
|
||||||
void Lossless_UDP()
|
void Lossless_UDP()
|
||||||
{
|
{
|
||||||
IP_Port ip_port;
|
IP_Port ip_port;
|
||||||
char data[MAX_UDP_PACKET_SIZE];
|
uint8_t data[MAX_UDP_PACKET_SIZE];
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
while(receivepacket(&ip_port, data, &length) != -1)
|
while(receivepacket(&ip_port, data, &length) != -1)
|
||||||
{
|
{
|
||||||
printf("packet with length: %u\n", length);
|
printf("packet with length: %u\n", length);
|
||||||
if(rand() % 3 != 1)//add packet loss
|
//if(rand() % 3 != 1)//add packet loss
|
||||||
{
|
// {
|
||||||
if(LosslessUDP_handlepacket(data, length, ip_port))
|
if(LosslessUDP_handlepacket(data, length, ip_port))
|
||||||
{
|
{
|
||||||
printpacket(data, length, ip_port);
|
printpacket(data, length, ip_port);
|
||||||
|
@ -118,9 +118,9 @@ void Lossless_UDP()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//printconnection(0);
|
//printconnection(0);
|
||||||
printf("Received handled packet with length: %u\n", length);
|
printf("Received handled packet with length: %u\n", length);
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
doLossless_UDP();
|
doLossless_UDP();
|
||||||
|
@ -136,7 +136,7 @@ int main(int argc, char *argv[])
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
char buffer[128];
|
uint8_t buffer[512];
|
||||||
int read;
|
int read;
|
||||||
|
|
||||||
FILE *file = fopen(argv[3], "rb");
|
FILE *file = fopen(argv[3], "rb");
|
||||||
|
@ -175,7 +175,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
|
|
||||||
//read first part of file
|
//read first part of file
|
||||||
read = fread(buffer, 1, 128, file);
|
read = fread(buffer, 1, 512, file);
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
@ -187,7 +187,7 @@ int main(int argc, char *argv[])
|
||||||
if(write_packet(connection, buffer, read))
|
if(write_packet(connection, buffer, read))
|
||||||
{
|
{
|
||||||
//printf("Wrote data.\n");
|
//printf("Wrote data.\n");
|
||||||
read = fread(buffer, 1, 128, file);
|
read = fread(buffer, 1, 512, file);
|
||||||
|
|
||||||
}
|
}
|
||||||
//printf("%u\n", sendqueue(connection));
|
//printf("%u\n", sendqueue(connection));
|
||||||
|
@ -205,7 +205,7 @@ int main(int argc, char *argv[])
|
||||||
printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer));
|
printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
c_sleep(1);
|
//c_sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#define PORT 33445
|
#define PORT 33445
|
||||||
|
|
||||||
void printpacket(char * data, uint32_t length, IP_Port ip_port)
|
void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length);
|
printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length);
|
||||||
|
@ -100,12 +100,12 @@ void printconnection(int connection_id)
|
||||||
void Lossless_UDP()
|
void Lossless_UDP()
|
||||||
{
|
{
|
||||||
IP_Port ip_port;
|
IP_Port ip_port;
|
||||||
char data[MAX_UDP_PACKET_SIZE];
|
uint8_t data[MAX_UDP_PACKET_SIZE];
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
while(receivepacket(&ip_port, data, &length) != -1)
|
while(receivepacket(&ip_port, data, &length) != -1)
|
||||||
{
|
{
|
||||||
if(rand() % 3 != 1)//add packet loss
|
//if(rand() % 3 != 1)//add packet loss
|
||||||
{
|
//{
|
||||||
if(LosslessUDP_handlepacket(data, length, ip_port))
|
if(LosslessUDP_handlepacket(data, length, ip_port))
|
||||||
{
|
{
|
||||||
printpacket(data, length, ip_port);
|
printpacket(data, length, ip_port);
|
||||||
|
@ -113,9 +113,9 @@ void Lossless_UDP()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//printconnection(0);
|
//printconnection(0);
|
||||||
// printf("Received handled packet with length: %u\n", length);
|
printf("Received handled packet with length: %u\n", length);
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
doLossless_UDP();
|
doLossless_UDP();
|
||||||
|
@ -131,7 +131,7 @@ int main(int argc, char *argv[])
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
char buffer[128];
|
uint8_t buffer[512];
|
||||||
int read;
|
int read;
|
||||||
|
|
||||||
FILE *file = fopen(argv[1], "wb");
|
FILE *file = fopen(argv[1], "wb");
|
||||||
|
@ -173,6 +173,7 @@ int main(int argc, char *argv[])
|
||||||
Lossless_UDP();
|
Lossless_UDP();
|
||||||
if(is_connected(connection) >= 2)
|
if(is_connected(connection) >= 2)
|
||||||
{
|
{
|
||||||
|
kill_connection_in(connection, 3000000);
|
||||||
read = read_packet(connection, buffer);
|
read = read_packet(connection, buffer);
|
||||||
if(read != 0)
|
if(read != 0)
|
||||||
{
|
{
|
||||||
|
@ -183,7 +184,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
if(is_connected(connection) == 4)
|
||||||
{
|
{
|
||||||
printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer));
|
printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer));
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user