summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-06-26 07:40:07 -0400
committerirungentoo <irungentoo@gmail.com>2013-06-26 07:40:07 -0400
commitd1837342e027d4587221f7a68b387d14f39cdd59 (patch)
tree292b4ae5575247a40c83ae30cb97f75ec551a46a /core
parent68d2995bce43bc1f52ac25ca52e0897baef8d111 (diff)
Couple fixes.
Diffstat (limited to 'core')
-rw-r--r--core/DHT.c30
-rw-r--r--core/DHT.h4
2 files changed, 16 insertions, 18 deletions
diff --git a/core/DHT.c b/core/DHT.c
index 2b9d7157..a8142974 100644
--- a/core/DHT.c
+++ b/core/DHT.c
@@ -214,7 +214,7 @@ int replace_bad(Client_data * list, uint32_t length, char * client_id, IP_Port i
214 214
215} 215}
216 216
217//replace the first good node further to the comp_client_id than that of the client_id 217//replace the first good node that is further to the comp_client_id than that of the client_id in the list
218int replace_good(Client_data * list, uint32_t length, char * client_id, IP_Port ip_port, char * comp_client_id) 218int replace_good(Client_data * list, uint32_t length, char * client_id, IP_Port ip_port, char * comp_client_id)
219{ 219{
220 uint32_t i; 220 uint32_t i;
@@ -266,7 +266,7 @@ void addto_lists(IP_Port ip_port, char * client_id)
266 266
267 267
268//ping timeout in seconds 268//ping timeout in seconds
269#define PING_TIMEOUT 10 269#define PING_TIMEOUT 5
270//check if we are currently pinging an ip_port and/or a ping_id 270//check if we are currently pinging an ip_port and/or a ping_id
271//Variables with values of zero will not be checked. 271//Variables with values of zero will not be checked.
272//if we are already, return 1 272//if we are already, return 1
@@ -282,24 +282,23 @@ int is_pinging(IP_Port ip_port, uint32_t ping_id)
282 { 282 {
283 if((pings[i].timestamp + PING_TIMEOUT) > temp_time) 283 if((pings[i].timestamp + PING_TIMEOUT) > temp_time)
284 { 284 {
285 pinging = 0;
285 if(ip_port.ip.i != 0) 286 if(ip_port.ip.i != 0)
286 { 287 {
287 pinging = 0;
288 if(pings[i].ip_port.ip.i == ip_port.ip.i && 288 if(pings[i].ip_port.ip.i == ip_port.ip.i &&
289 pings[i].ip_port.port == ip_port.port) 289 pings[i].ip_port.port == ip_port.port)
290 { 290 {
291 pinging = 1; 291 pinging++;
292 } 292 }
293 } 293 }
294 if(ping_id != 0) 294 if(ping_id != 0)
295 { 295 {
296 pinging = 0;
297 if(pings[i].ping_id == ping_id) 296 if(pings[i].ping_id == ping_id)
298 { 297 {
299 pinging = 1; 298 pinging++;
300 } 299 }
301 } 300 }
302 if(pinging == 1) 301 if(pinging == (ping_id != 0) + (ip_port.ip.i != 0))
303 { 302 {
304 return 1; 303 return 1;
305 } 304 }
@@ -323,24 +322,23 @@ int is_gettingnodes(IP_Port ip_port, uint32_t ping_id)
323 { 322 {
324 if((send_nodes[i].timestamp + PING_TIMEOUT) > temp_time) 323 if((send_nodes[i].timestamp + PING_TIMEOUT) > temp_time)
325 { 324 {
325 pinging = 0;
326 if(ip_port.ip.i != 0) 326 if(ip_port.ip.i != 0)
327 { 327 {
328 pinging = 0;
329 if(send_nodes[i].ip_port.ip.i == ip_port.ip.i && 328 if(send_nodes[i].ip_port.ip.i == ip_port.ip.i &&
330 send_nodes[i].ip_port.port == ip_port.port) 329 send_nodes[i].ip_port.port == ip_port.port)
331 { 330 {
332 pinging = 1; 331 pinging++;
333 } 332 }
334 } 333 }
335 if(ping_id != 0) 334 if(ping_id != 0)
336 { 335 {
337 pinging = 0;
338 if(send_nodes[i].ping_id == ping_id) 336 if(send_nodes[i].ping_id == ping_id)
339 { 337 {
340 pinging = 1; 338 pinging++;
341 } 339 }
342 } 340 }
343 if(pinging == 1) 341 if(pinging == (ping_id != 0) + (ip_port.ip.i != 0))
344 { 342 {
345 return 1; 343 return 1;
346 } 344 }
@@ -407,7 +405,7 @@ int add_gettingnodes(IP_Port ip_port)
407 405
408 406
409//send a ping request 407//send a ping request
410//Ping request only works if there is none hos been sent to that ip/port in the last 5 seconds. 408//Ping request only works if none has been sent to that ip/port in the last 5 seconds.
411int pingreq(IP_Port ip_port) 409int pingreq(IP_Port ip_port)
412{ 410{
413 if(is_pinging(ip_port, 0)) 411 if(is_pinging(ip_port, 0))
@@ -474,7 +472,7 @@ int getnodes(IP_Port ip_port, char * client_id)
474//send a send nodes response 472//send a send nodes response
475int sendnodes(IP_Port ip_port, char * client_id, uint32_t ping_id) 473int sendnodes(IP_Port ip_port, char * client_id, uint32_t ping_id)
476{ 474{
477 char data[5 + (CLIENT_ID_SIZE + sizeof(IP_Port))*MAX_SENT_NODES]; 475 char data[5 + CLIENT_ID_SIZE + (CLIENT_ID_SIZE + sizeof(IP_Port))*MAX_SENT_NODES];
478 Node_format nodes_list[MAX_SENT_NODES]; 476 Node_format nodes_list[MAX_SENT_NODES];
479 477
480 int num_nodes = get_close_nodes(client_id, nodes_list); 478 int num_nodes = get_close_nodes(client_id, nodes_list);
@@ -703,7 +701,7 @@ int DHT_recvpacket(char * packet, uint32_t length, IP_Port source)
703//Ping each client in the "friends" list every 60 seconds. 701//Ping each client in the "friends" list every 60 seconds.
704//Send a get nodes request every 20 seconds to a random good node for each "friend" in our "friends" list. 702//Send a get nodes request every 20 seconds to a random good node for each "friend" in our "friends" list.
705 703
706uint32_t friend_lastgetnode[MAX_FRIENDS]; 704static uint32_t friend_lastgetnode[MAX_FRIENDS];
707 705
708 706
709void doFriends() 707void doFriends()
@@ -742,7 +740,7 @@ void doFriends()
742 } 740 }
743} 741}
744 742
745uint32_t close_lastgetnodes; 743static uint32_t close_lastgetnodes;
746 744
747//Ping each client in the close nodes list every 60 seconds. 745//Ping each client in the close nodes list every 60 seconds.
748//Send a get nodes request every 20 seconds to a random good node int the list. 746//Send a get nodes request every 20 seconds to a random good node int the list.
diff --git a/core/DHT.h b/core/DHT.h
index 094c7e65..c35b17d5 100644
--- a/core/DHT.h
+++ b/core/DHT.h
@@ -117,8 +117,8 @@ IP_Port getfriendip(char * client_id);
117void doDHT(); 117void doDHT();
118 118
119//if we recieve a DHT packet we call this function so it can be handled. 119//if we recieve a DHT packet we call this function so it can be handled.
120//Return 0 if packet is handled correctly or if the packet was shit. 120//Return 0 if packet is handled correctly.
121//return 1 if it didn't handle the packet. 121//return 1 if it didn't handle the packet or if the packet was shit.
122int DHT_recvpacket(char * packet, uint32_t length, IP_Port source); 122int DHT_recvpacket(char * packet, uint32_t length, IP_Port source);
123 123
124//Use this function to bootstrap the client 124//Use this function to bootstrap the client