Merge pull request #57 from Martijnvdc/patch-2

Patch 2
This commit is contained in:
irungentoo 2013-07-19 10:54:42 -07:00
commit ac6003e932
2 changed files with 30 additions and 30 deletions

View File

@ -103,7 +103,7 @@ static Connection connections[MAX_CONNECTIONS];
int getconnection_id(IP_Port ip_port)
{
uint32_t i;
for(i = 0; i < MAX_CONNECTIONS; i++ )
for(i = 0; i < MAX_CONNECTIONS; ++i)
{
if(connections[i].ip_port.ip.i == ip_port.ip.i &&
connections[i].ip_port.port == ip_port.port && connections[i].status > 0)
@ -124,7 +124,7 @@ static uint32_t randtable[6][256];
uint32_t handshake_id(IP_Port source)
{
uint32_t id = 0, i;
for(i = 0; i < 6; i++)
for(i = 0; i < 6; ++i)
{
if(randtable[i][((uint8_t *)&source)[i]] == 0)
{
@ -159,7 +159,7 @@ int new_connection(IP_Port ip_port)
return connect;
}
uint32_t i;
for(i = 0; i < MAX_CONNECTIONS; i++)
for(i = 0; i < MAX_CONNECTIONS; ++i)
{
if(connections[i].status == 0)
{
@ -195,7 +195,7 @@ int new_inconnection(IP_Port ip_port)
return -1;
}
uint32_t i;
for(i = 0; i < MAX_CONNECTIONS; i++)
for(i = 0; i < MAX_CONNECTIONS; ++i)
{
if(connections[i].status == 0)
{
@ -223,7 +223,7 @@ int new_inconnection(IP_Port ip_port)
int incoming_connection()
{
uint32_t i;
for(i = 0; i < MAX_CONNECTIONS; i++)
for(i = 0; i < MAX_CONNECTIONS; ++i)
{
if(connections[i].inbound == 2)
{
@ -323,7 +323,7 @@ int read_packet(int connection_id, uint8_t * data)
uint16_t index = connections[connection_id].successful_read % MAX_QUEUE_NUM;
uint16_t size = connections[connection_id].recvbuffer[index].size;
memcpy(data, connections[connection_id].recvbuffer[index].data, size);
connections[connection_id].successful_read++;
++connections[connection_id].successful_read;
connections[connection_id].recvbuffer[index].size = 0;
return size;
}
@ -372,7 +372,7 @@ uint32_t missing_packets(int connection_id, uint32_t * requested)
{
temp = htonl(i);
memcpy(requested + number, &temp, 4);
number++;
++number;
}
}
if(number == 0)
@ -556,7 +556,7 @@ int handle_SYNC2(int connection_id, uint8_t counter, uint32_t recv_packetnum, ui
{
connections[connection_id].status = 3;
connections[connection_id].recv_counter = counter;
connections[connection_id].send_counter++;
++connections[connection_id].send_counter;
send_SYNC(connection_id);
return 0;
}
@ -579,8 +579,8 @@ int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, ui
connections[connection_id].successful_sent = recv_packetnum;
connections[connection_id].last_recvSYNC = current_time();
connections[connection_id].recv_counter = counter;
connections[connection_id].send_counter++;
for(i = 0; i < number; i++)
++connections[connection_id].send_counter;
for(i = 0; i < number; ++i)
{
temp = ntohl(req_packets[i]);
memcpy(connections[connection_id].req_packets + i, &temp, 4 * number);
@ -641,7 +641,7 @@ int add_recv(int connection_id, uint32_t data_num, uint8_t * data, uint16_t size
uint32_t i;
uint32_t maxnum = connections[connection_id].successful_read + BUFFER_PACKET_NUM;
uint32_t sent_packet = data_num - connections[connection_id].osent_packetnum;
for(i = connections[connection_id].recv_packetnum; i != maxnum; i++)
for(i = connections[connection_id].recv_packetnum; i != maxnum; ++i)
{
if(i == data_num)
{
@ -655,7 +655,7 @@ int add_recv(int connection_id, uint32_t data_num, uint8_t * data, uint16_t size
break;
}
}
for(i = connections[connection_id].recv_packetnum; i != maxnum; i++)
for(i = connections[connection_id].recv_packetnum; i != maxnum; ++i)
{
if(connections[connection_id].recvbuffer[i % MAX_QUEUE_NUM].size != 0)
{
@ -729,7 +729,7 @@ void doNew()
{
uint32_t i;
uint64_t temp_time = current_time();
for(i = 0; i < MAX_CONNECTIONS; i++)
for(i = 0; i < MAX_CONNECTIONS; ++i)
{
if(connections[i].status == 1)
{
@ -758,7 +758,7 @@ void doSYNC()
{
uint32_t i;
uint64_t temp_time = current_time();
for(i = 0; i < MAX_CONNECTIONS; i++)
for(i = 0; i < MAX_CONNECTIONS; ++i)
{
if(connections[i].status == 2 || connections[i].status == 3)
{
@ -776,7 +776,7 @@ void doData()
uint32_t i;
uint64_t j;
uint64_t temp_time = current_time();
for(i = 0; i < MAX_CONNECTIONS; i++)
for(i = 0; i < MAX_CONNECTIONS; ++i)
{
if(connections[i].status == 3 && sendqueue(i) != 0)
{
@ -801,7 +801,7 @@ void adjustRates()
{
uint32_t i;
uint64_t temp_time = current_time();
for(i = 0; i < MAX_CONNECTIONS; i++)
for(i = 0; i < MAX_CONNECTIONS; ++i)
{
if(connections[i].status == 3)
{
@ -834,4 +834,4 @@ void doLossless_UDP()
adjustRates();
}
}

View File

@ -128,9 +128,9 @@ int decrypt_data(uint8_t * public_key, uint8_t * secret_key, uint8_t * nonce,
void increment_nonce(uint8_t * nonce)
{
uint32_t i;
for(i = 0; i < crypto_box_NONCEBYTES; i++)
for(i = 0; i < crypto_box_NONCEBYTES; ++i)
{
nonce[i]++;
++nonce[i];
if(nonce[i] != 0)
{
break;
@ -143,7 +143,7 @@ void increment_nonce(uint8_t * nonce)
void random_nonce(uint8_t * nonce)
{
uint32_t i;
for(i = 0; i < crypto_box_NONCEBYTES; i++)
for(i = 0; i < crypto_box_NONCEBYTES; ++i)
{
nonce[i] = random_int() % 256;
}
@ -228,7 +228,7 @@ int send_friendrequest(uint8_t * public_key, IP_Port ip_port, uint8_t * data, ui
return -1;
}
uint32_t i;
for(i = 0; i < MAX_FRIEND_REQUESTS; i++)
for(i = 0; i < MAX_FRIEND_REQUESTS; ++i)
{
if(outbound_friendrequests[i] == -1)
{
@ -365,7 +365,7 @@ int handle_cryptohandshake(uint8_t * public_key, uint8_t * secret_nonce,
int handle_friendrequest(uint8_t * public_key, uint8_t * data)
{
uint32_t i;
for(i = 0; i < MAX_INCOMING; i++)
for(i = 0; i < MAX_INCOMING; ++i)
{
if(incoming_connections[i] != -1)
{
@ -403,7 +403,7 @@ int handle_friendrequest(uint8_t * public_key, uint8_t * data)
int getcryptconnection_id(uint8_t * public_key)
{
uint32_t i;
for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++)
for(i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i)
{
if(crypto_connections[i].status > 0)
{
@ -432,7 +432,7 @@ int crypto_connect(uint8_t * public_key, IP_Port ip_port)
return -1;
}
}
for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++)
for(i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i)
{
if(crypto_connections[i].status == 0)
{
@ -469,7 +469,7 @@ int crypto_connect(uint8_t * public_key, IP_Port ip_port)
int crypto_inbound(uint8_t * public_key, uint8_t * secret_nonce, uint8_t * session_key)
{
uint32_t i;
for(i = 0; i < MAX_INCOMING; i++)
for(i = 0; i < MAX_INCOMING; ++i)
{
if(incoming_connections[i] != -1)
{
@ -530,7 +530,7 @@ int accept_crypto_inbound(int connection_id, uint8_t * public_key, uint8_t * sec
{
return -1;
}*/
for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++)
for(i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i)
{
if(crypto_connections[i].status == 0)
{
@ -603,7 +603,7 @@ void load_keys(uint8_t * keys)
int new_incoming(int id)
{
uint32_t i;
for(i = 0; i < MAX_INCOMING; i++)
for(i = 0; i < MAX_INCOMING; ++i)
{
if(incoming_connections[i] == -1)
{
@ -633,7 +633,7 @@ static void handle_incomings()
static void receive_crypto()
{
uint32_t i;
for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++)
for(i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i)
{
if(crypto_connections[i].status == 1)
{
@ -717,7 +717,7 @@ void initNetCrypto()
memset(outbound_friendrequests, -1 ,sizeof(outbound_friendrequests));
memset(incoming_connections, -1 ,sizeof(incoming_connections));
uint32_t i;
for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++)
for(i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i)
{
crypto_connections[i].number = ~0;
}
@ -726,7 +726,7 @@ void initNetCrypto()
static void killTimedout()
{
uint32_t i;
for(i = 0; i < MAX_CRYPTO_CONNECTIONS; i++)
for(i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i)
{
if(crypto_connections[i].status != 0 && is_connected(crypto_connections[i].number) == 4)
{