mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Test programs updated. (I'm gonna wait until I finish Lossless_UDP before pushing it.)
This commit is contained in:
parent
fd44c68801
commit
c9d0c208a5
|
@ -88,7 +88,7 @@ Lossless UDP:
|
||||||
[byte with value: 16 (10 in hex)][4 byte (handshake_id1)][4 bytes (handshake_id2)]
|
[byte with value: 16 (10 in hex)][4 byte (handshake_id1)][4 bytes (handshake_id2)]
|
||||||
|
|
||||||
SYNC packets:
|
SYNC packets:
|
||||||
[byte with value: 17 (11 in hex)][byte (type) (00 for keep alive, 01 for request)][byte (counter)][4 byte (recv_packetnum)][4 byte (sent_packetnum)][sequence of requested packet ids[4 bytes each](not present in keep alive)]
|
[byte with value: 17 (11 in hex)][byte (counter)][4 byte (recv_packetnum)][4 byte (sent_packetnum)][sequence of requested packet ids[4 bytes each](not present in keep alive)]
|
||||||
|
|
||||||
|
|
||||||
data packets:
|
data packets:
|
||||||
|
|
|
@ -40,6 +40,64 @@ void printpacket(char * data, uint32_t length, IP_Port ip_port)
|
||||||
printf("\n--------------------END-----------------------------\n\n\n");
|
printf("\n--------------------END-----------------------------\n\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printip(IP_Port ip_port)
|
||||||
|
{
|
||||||
|
printf("\nIP: %u.%u.%u.%u Port: %u",ip_port.ip.c[0],ip_port.ip.c[1],ip_port.ip.c[2],ip_port.ip.c[3],ntohs(ip_port.port));
|
||||||
|
}
|
||||||
|
|
||||||
|
void printpackets(Data test)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
if(test.size == 0)
|
||||||
|
return;
|
||||||
|
printf("SIZE: %u\n", test.size);
|
||||||
|
for(i =0; i < test.size; i++)
|
||||||
|
{
|
||||||
|
printf("%hhX", test.data[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void printconnection(int connection_id)
|
||||||
|
{
|
||||||
|
printf("--------------------BEGIN---------------------\n");
|
||||||
|
IP_Port ip_port = connections[connection_id].ip_port;
|
||||||
|
printf("IP: %u.%u.%u.%u Port: %u\n",ip_port.ip.c[0],ip_port.ip.c[1],ip_port.ip.c[2],ip_port.ip.c[3],ntohs(ip_port.port));
|
||||||
|
printf("status: %u, inbound: %u, SYNC_rate: %u\n", connections[connection_id].status,
|
||||||
|
connections[connection_id].inbound, connections[connection_id].SYNC_rate);
|
||||||
|
printf("data rate: %u, last sync: %llu, last sent: %llu, last recv: %llu \n", connections[connection_id].data_rate,
|
||||||
|
connections[connection_id].last_SYNC, connections[connection_id].last_sent, connections[connection_id].last_recv);
|
||||||
|
int i;
|
||||||
|
for(i =0; i < MAX_QUEUE_NUM; i++)
|
||||||
|
{
|
||||||
|
printf(" %u ",i);
|
||||||
|
printpackets(connections[connection_id].sendbuffer[i]);
|
||||||
|
}
|
||||||
|
for(i =0; i < MAX_QUEUE_NUM; i++)
|
||||||
|
{
|
||||||
|
printf(" %u ",i);
|
||||||
|
printpackets(connections[connection_id].recvbuffer[i]);
|
||||||
|
}
|
||||||
|
Data sendbuffer[MAX_QUEUE_NUM];
|
||||||
|
Data recvbuffer[MAX_QUEUE_NUM];
|
||||||
|
printf("recv_num: %u, recv_sync: %u, sent_packetnum %u, send_packetnum: %u, successful_sent: %u, successful_read: %u\n",
|
||||||
|
connections[connection_id].recv_packetnum,
|
||||||
|
connections[connection_id].recv_packetnum_sync, connections[connection_id].sent_packetnum, connections[connection_id].send_packetnum,
|
||||||
|
connections[connection_id].successful_sent,
|
||||||
|
connections[connection_id].successful_read);
|
||||||
|
|
||||||
|
printf("req packets: \n");
|
||||||
|
for(i = 0; i < MAX_PACKET_NUM; i++)
|
||||||
|
{
|
||||||
|
printf(" %u ", connections[connection_id].req_packets[i]);
|
||||||
|
}
|
||||||
|
printf("\nNumber: %u recv_counter: %u, send_counter: %u\n", connections[connection_id].num_req_paquets,
|
||||||
|
connections[connection_id].recv_counter, connections[connection_id].send_counter);
|
||||||
|
|
||||||
|
printf("--------------------END---------------------\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//recieve packets and send them to the packethandler
|
//recieve packets and send them to the packethandler
|
||||||
//run doLossless_UDP();
|
//run doLossless_UDP();
|
||||||
void Lossless_UDP()
|
void Lossless_UDP()
|
||||||
|
@ -49,14 +107,18 @@ void Lossless_UDP()
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
while(recievepacket(&ip_port, data, &length) != -1)
|
while(recievepacket(&ip_port, data, &length) != -1)
|
||||||
{
|
{
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//printconnection(0);
|
||||||
printf("Received handled packet with length: %u\n", length);
|
printf("Received handled packet with length: %u\n", length);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
doLossless_UDP();
|
doLossless_UDP();
|
||||||
|
@ -85,8 +147,10 @@ int main(int argc, char *argv[])
|
||||||
ip.i = 0;
|
ip.i = 0;
|
||||||
init_networking(ip, PORT);
|
init_networking(ip, PORT);
|
||||||
perror("Initialization");
|
perror("Initialization");
|
||||||
|
IP_Port serverip;
|
||||||
IP_Port serverip = {{{inet_addr(argv[1])}}, htons(atoi(argv[2]))};
|
serverip.ip.i = inet_addr(argv[1]);
|
||||||
|
serverip.port = htons(atoi(argv[2]));
|
||||||
|
printip(serverip);
|
||||||
int connection = new_connection(serverip);
|
int connection = new_connection(serverip);
|
||||||
uint64_t timer = current_time();
|
uint64_t timer = current_time();
|
||||||
while(1)
|
while(1)
|
||||||
|
@ -94,47 +158,50 @@ int main(int argc, char *argv[])
|
||||||
Lossless_UDP();
|
Lossless_UDP();
|
||||||
if(is_connected(connection) == 3)
|
if(is_connected(connection) == 3)
|
||||||
{
|
{
|
||||||
printf("Connecting took: %llu us", (unsigned long long)(current_time() - timer));
|
printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(is_connected(connection) == 0)
|
if(is_connected(connection) == 0)
|
||||||
{
|
{
|
||||||
printf("Connection timeout after: %llu us", (unsigned long long)(current_time() - timer));
|
printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer));
|
||||||
break;
|
return 1;
|
||||||
}
|
}
|
||||||
c_sleep(1);
|
c_sleep(100);
|
||||||
}
|
}
|
||||||
timer = current_time();
|
timer = current_time();
|
||||||
|
|
||||||
|
|
||||||
//read first part of file
|
//read first part of file
|
||||||
read = fread(buffer, 1, 128, file);
|
read = fread(buffer, 1, 1, file);
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
//printconnection(connection);
|
||||||
Lossless_UDP();
|
Lossless_UDP();
|
||||||
|
|
||||||
if(is_connected(connection) == 1)
|
if(is_connected(connection) == 3)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(write_packet(connection, buffer, read))
|
if(write_packet(connection, buffer, read))
|
||||||
{
|
{
|
||||||
read = fread(buffer, 1, 128, file);
|
//printf("Wrote data.\n");
|
||||||
|
read = fread(buffer, 1, 1, file);
|
||||||
}
|
}
|
||||||
if(sendqueue(connection) == 0)
|
if(sendqueue(connection) == 0)
|
||||||
{
|
{
|
||||||
if(read == 0)
|
if(read == 0)
|
||||||
{
|
{
|
||||||
printf("Sent file successfully in: %llu us", (unsigned long long)(current_time() - timer));
|
printf("Sent file successfully in: %llu us\n", (unsigned long long)(current_time() - timer));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Connecting Lost after: %llu us", (unsigned long long)(current_time() - timer));
|
printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer));
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
c_sleep(1);
|
c_sleep(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -40,6 +40,58 @@ void printpacket(char * data, uint32_t length, IP_Port ip_port)
|
||||||
}
|
}
|
||||||
printf("\n--------------------END-----------------------------\n\n\n");
|
printf("\n--------------------END-----------------------------\n\n\n");
|
||||||
}
|
}
|
||||||
|
void printpackets(Data test)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
if(test.size == 0)
|
||||||
|
return;
|
||||||
|
printf("SIZE: %u\n", test.size);
|
||||||
|
for(i =0; i < test.size; i++)
|
||||||
|
{
|
||||||
|
printf("%hhX", test.data[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void printconnection(int connection_id)
|
||||||
|
{
|
||||||
|
printf("--------------------BEGIN---------------------\n");
|
||||||
|
IP_Port ip_port = connections[connection_id].ip_port;
|
||||||
|
printf("IP: %u.%u.%u.%u Port: %u\n",ip_port.ip.c[0],ip_port.ip.c[1],ip_port.ip.c[2],ip_port.ip.c[3],ntohs(ip_port.port));
|
||||||
|
printf("status: %u, inbound: %u, SYNC_rate: %u\n", connections[connection_id].status,
|
||||||
|
connections[connection_id].inbound, connections[connection_id].SYNC_rate);
|
||||||
|
printf("data rate: %u, last sync: %llu, last sent: %llu, last recv: %llu \n", connections[connection_id].data_rate,
|
||||||
|
connections[connection_id].last_SYNC, connections[connection_id].last_sent, connections[connection_id].last_recv);
|
||||||
|
int i;
|
||||||
|
for(i =0; i < MAX_QUEUE_NUM; i++)
|
||||||
|
{
|
||||||
|
printf(" %u ",i);
|
||||||
|
printpackets(connections[connection_id].sendbuffer[i]);
|
||||||
|
}
|
||||||
|
for(i =0; i < MAX_QUEUE_NUM; i++)
|
||||||
|
{
|
||||||
|
printf(" %u ",i);
|
||||||
|
printpackets(connections[connection_id].recvbuffer[i]);
|
||||||
|
}
|
||||||
|
Data sendbuffer[MAX_QUEUE_NUM];
|
||||||
|
Data recvbuffer[MAX_QUEUE_NUM];
|
||||||
|
printf("recv_num: %u, recv_sync: %u, sent_packetnum %u, send_packetnum: %u, successful_sent: %u, successful_read: %u\n",
|
||||||
|
connections[connection_id].recv_packetnum,
|
||||||
|
connections[connection_id].recv_packetnum_sync, connections[connection_id].sent_packetnum, connections[connection_id].send_packetnum,
|
||||||
|
connections[connection_id].successful_sent,
|
||||||
|
connections[connection_id].successful_read);
|
||||||
|
|
||||||
|
printf("req packets: \n");
|
||||||
|
for(i = 0; i < MAX_PACKET_NUM; i++)
|
||||||
|
{
|
||||||
|
printf(" %u ", connections[connection_id].req_packets[i]);
|
||||||
|
}
|
||||||
|
printf("\nNumber: %u recv_counter: %u, send_counter: %u\n", connections[connection_id].num_req_paquets,
|
||||||
|
connections[connection_id].recv_counter, connections[connection_id].send_counter);
|
||||||
|
|
||||||
|
printf("--------------------END---------------------\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//recieve packets and send them to the packethandler
|
//recieve packets and send them to the packethandler
|
||||||
//run doLossless_UDP();
|
//run doLossless_UDP();
|
||||||
|
@ -50,12 +102,14 @@ void Lossless_UDP()
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
while(recievepacket(&ip_port, data, &length) != -1)
|
while(recievepacket(&ip_port, data, &length) != -1)
|
||||||
{
|
{
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// printconnection(0);
|
||||||
printf("Received handled packet with length: %u\n", length);
|
printf("Received handled packet with length: %u\n", length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +130,7 @@ int main(int argc, char *argv[])
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
int read;
|
int read;
|
||||||
|
|
||||||
FILE *file = fopen(argv[3], "rb");
|
FILE *file = fopen(argv[1], "wb");
|
||||||
if ( file==NULL ){return 1;}
|
if ( file==NULL ){return 1;}
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,23 +153,26 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if(is_connected(connection) == 3)
|
if(is_connected(connection) == 3)
|
||||||
{
|
{
|
||||||
printf("Recieved the connection.");
|
printf("Recieved the connection.\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
c_sleep(1);
|
c_sleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
timer = current_time();
|
timer = current_time();
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
//printconnection(0);
|
||||||
Lossless_UDP();
|
Lossless_UDP();
|
||||||
if(is_connected(connection) == 1)
|
if(is_connected(connection) == 3)
|
||||||
{
|
{
|
||||||
read = read_packet(connection, buffer);
|
read = read_packet(connection, buffer);
|
||||||
|
|
||||||
if(read != 0)
|
if(read != 0)
|
||||||
{
|
{
|
||||||
|
printf("Recieved data.\n");
|
||||||
if(!fwrite(buffer, read, 1, file))
|
if(!fwrite(buffer, read, 1, file))
|
||||||
{
|
{
|
||||||
printf("file write error\n");
|
printf("file write error\n");
|
||||||
|
@ -124,9 +181,11 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Connecting Lost after: %llu us", (unsigned long long)(current_time() - timer));
|
printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer));
|
||||||
|
fclose(file);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
c_sleep(1);
|
c_sleep(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -14,7 +14,7 @@ sock.bind((UDP_IP, UDP_PORT))
|
||||||
client_id = str(''.join(random.choice("abcdefghijklmnopqrstuvwxyz") for x in range(32)))
|
client_id = str(''.join(random.choice("abcdefghijklmnopqrstuvwxyz") for x in range(32)))
|
||||||
|
|
||||||
print client_id
|
print client_id
|
||||||
|
a = 1;
|
||||||
#send ping request to our DHT on localhost.
|
#send ping request to our DHT on localhost.
|
||||||
sock.sendto("0012345678".decode("hex") + client_id, ('127.0.0.1', 33445))
|
sock.sendto("0012345678".decode("hex") + client_id, ('127.0.0.1', 33445))
|
||||||
|
|
||||||
|
@ -35,3 +35,11 @@ while True:
|
||||||
#127.0.0.1:5000, 127.0.0.1:5001, 127.0.0.1:5002
|
#127.0.0.1:5000, 127.0.0.1:5001, 127.0.0.1:5002
|
||||||
sock.sendto("03".decode('hex') + data[1:5] + client_id + ("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113880000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113890000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F000001138A0000".decode('hex')), addr)
|
sock.sendto("03".decode('hex') + data[1:5] + client_id + ("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113880000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113890000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F000001138A0000".decode('hex')), addr)
|
||||||
|
|
||||||
|
if data[0] == "10".decode('hex'):
|
||||||
|
print "Sending handshake resp"
|
||||||
|
sock.sendto("10".decode('hex') + data[1:5] + client_id[:4], addr)
|
||||||
|
if data[0] == "11".decode('hex'):
|
||||||
|
print "Sending SYNC resp"
|
||||||
|
a+=1
|
||||||
|
sock.sendto("11".decode('hex') + chr(a) + data[1:9], addr)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user