summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJeffail <ash.jeffs@gmail.com>2013-08-02 10:59:09 +0100
committerJeffail <ash.jeffs@gmail.com>2013-08-02 10:59:09 +0100
commit67efb67f963e66412c4aca38debd8c20af9f7ba8 (patch)
tree4d17bb0bfc25976ce79f9e44f1bbee6a9ccd4719 /core
parentbcf36e81151160d6cbe49557169c2ea56284afff (diff)
Refactored DHT.c from end of NAT punching to EOF
Diffstat (limited to 'core')
-rw-r--r--core/DHT.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/core/DHT.c b/core/DHT.c
index 8bc4a8b3..5a362ecc 100644
--- a/core/DHT.c
+++ b/core/DHT.c
@@ -1266,17 +1266,22 @@ void DHT_save(uint8_t * data)
1266} 1266}
1267 1267
1268/* load the DHT from data of size size; 1268/* load the DHT from data of size size;
1269 return -1 if failure 1269 * return -1 if failure
1270 return 0 if success */ 1270 * return 0 if success
1271 */
1271int DHT_load(uint8_t * data, uint32_t size) 1272int DHT_load(uint8_t * data, uint32_t size)
1272{ 1273{
1273 if(size < sizeof(close_clientlist)) 1274 if(size < sizeof(close_clientlist))
1274 return -1; 1275 return -1;
1276
1275 if((size - sizeof(close_clientlist)) % sizeof(Friend) != 0) 1277 if((size - sizeof(close_clientlist)) % sizeof(Friend) != 0)
1276 return -1; 1278 return -1;
1279
1277 uint32_t i, j; 1280 uint32_t i, j;
1278 /* uint32_t temp_time = unix_time(); */
1279 uint16_t temp; 1281 uint16_t temp;
1282 /* uint32_t temp_time = unix_time(); */
1283
1284 Client_data * client;
1280 1285
1281 temp = (size - sizeof(close_clientlist))/sizeof(Friend); 1286 temp = (size - sizeof(close_clientlist))/sizeof(Friend);
1282 1287
@@ -1285,29 +1290,34 @@ int DHT_load(uint8_t * data, uint32_t size)
1285 1290
1286 for(i = 0; i < temp; ++i) { 1291 for(i = 0; i < temp; ++i) {
1287 DHT_addfriend(tempfriends_list[i].client_id); 1292 DHT_addfriend(tempfriends_list[i].client_id);
1288 for(j = 0; j < MAX_FRIEND_CLIENTS; ++j) 1293
1289 if(tempfriends_list[i].client_list[j].timestamp != 0) { 1294 for(j = 0; j < MAX_FRIEND_CLIENTS; ++j) {
1290 getnodes(tempfriends_list[i].client_list[j].ip_port, 1295 client = &tempfriends_list[i].client_list[j];
1291 tempfriends_list[i].client_list[j].client_id, tempfriends_list[i].client_id); 1296 if(client->timestamp != 0)
1292 } 1297 getnodes(client->ip_port, client->client_id, tempfriends_list[i].client_id);
1298 }
1293 } 1299 }
1294 } 1300 }
1295 Client_data * tempclose_clientlist = (Client_data *)data; 1301 Client_data * tempclose_clientlist = (Client_data *)data;
1296 1302
1297 for(i = 0; i < LCLIENT_LIST; ++i) 1303 for(i = 0; i < LCLIENT_LIST; ++i) {
1298 if(tempclose_clientlist[i].timestamp != 0) 1304 if(tempclose_clientlist[i].timestamp != 0)
1299 DHT_bootstrap(tempclose_clientlist[i].ip_port, tempclose_clientlist[i].client_id); 1305 DHT_bootstrap( tempclose_clientlist[i].ip_port,
1306 tempclose_clientlist[i].client_id );
1307 }
1300 return 0; 1308 return 0;
1301} 1309}
1302 1310
1303/* returns 0 if we are not connected to the DHT 1311/* returns 0 if we are not connected to the DHT
1304 returns 1 if we are */ 1312 * returns 1 if we are
1313 */
1305int DHT_isconnected() 1314int DHT_isconnected()
1306{ 1315{
1307 uint32_t i; 1316 uint32_t i, temp_time = unix_time();
1308 uint32_t temp_time = unix_time(); 1317
1309 for(i = 0; i < LCLIENT_LIST; ++i) 1318 for(i = 0; i < LCLIENT_LIST; ++i) {
1310 if(close_clientlist[i].timestamp + BAD_NODE_TIMEOUT > temp_time) 1319 if(close_clientlist[i].timestamp + BAD_NODE_TIMEOUT > temp_time)
1311 return 1; 1320 return 1;
1321 }
1312 return 0; 1322 return 0;
1313} 1323}