diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-05-01 11:27:51 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-05-01 11:27:51 +0000 |
commit | c1eec384277b32b187683165825d7522a94f327e (patch) | |
tree | 1be610c111da6e00bb08f1822b54c503734d0fbc /src/dht | |
parent | 48d9e46f09ea04e6c29acfa2a56c2ed336cdf380 (diff) | |
download | gnunet-c1eec384277b32b187683165825d7522a94f327e.tar.gz gnunet-c1eec384277b32b187683165825d7522a94f327e.zip |
-handle response message
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-wdht_neighbours.c | 80 |
1 files changed, 61 insertions, 19 deletions
diff --git a/src/dht/gnunet-service-wdht_neighbours.c b/src/dht/gnunet-service-wdht_neighbours.c index fe764dc3e..944145b24 100644 --- a/src/dht/gnunet-service-wdht_neighbours.c +++ b/src/dht/gnunet-service-wdht_neighbours.c | |||
@@ -21,6 +21,11 @@ | |||
21 | * @file dht/gnunet-service-wdht_neighbours.c | 21 | * @file dht/gnunet-service-wdht_neighbours.c |
22 | * @brief GNUnet DHT service's finger and friend table management code | 22 | * @brief GNUnet DHT service's finger and friend table management code |
23 | * @author Supriti Singh | 23 | * @author Supriti Singh |
24 | * @author Christian Grothoff | ||
25 | * @author Arthur Dewarumez | ||
26 | * | ||
27 | * TODO: | ||
28 | * - initiate finding of successors | ||
24 | */ | 29 | */ |
25 | #include "platform.h" | 30 | #include "platform.h" |
26 | #include "gnunet_util_lib.h" | 31 | #include "gnunet_util_lib.h" |
@@ -352,12 +357,6 @@ struct FindSuccessorMessage | |||
352 | uint32_t reserved GNUNET_PACKED; | 357 | uint32_t reserved GNUNET_PACKED; |
353 | 358 | ||
354 | /** | 359 | /** |
355 | * Unique (random) identifier this peer will use to | ||
356 | * identify the finger (in future messages). | ||
357 | */ | ||
358 | struct GNUNET_HashCode trail_id; | ||
359 | |||
360 | /** | ||
361 | * Key for which we would like close values returned. | 360 | * Key for which we would like close values returned. |
362 | * identify the finger (in future messages). | 361 | * identify the finger (in future messages). |
363 | */ | 362 | */ |
@@ -1252,8 +1251,7 @@ handle_dht_p2p_random_walk (void *cls, | |||
1252 | 1251 | ||
1253 | 1252 | ||
1254 | /** | 1253 | /** |
1255 | * Handle a `struct RandomWalkResponseMessage` from a GNUNET_MESSAGE_TYPE_WDHT_RANDOM_WALK_RESPONSE | 1254 | * Handle a `struct RandomWalkResponseMessage`. |
1256 | * message. | ||
1257 | * | 1255 | * |
1258 | * @param cls closure (NULL) | 1256 | * @param cls closure (NULL) |
1259 | * @param peer sender identity | 1257 | * @param peer sender identity |
@@ -1266,8 +1264,55 @@ handle_dht_p2p_random_walk_response (void *cls, | |||
1266 | const struct GNUNET_MessageHeader *message) | 1264 | const struct GNUNET_MessageHeader *message) |
1267 | { | 1265 | { |
1268 | const struct RandomWalkResponseMessage *rwrm; | 1266 | const struct RandomWalkResponseMessage *rwrm; |
1267 | struct Trail *trail; | ||
1268 | struct FriendInfo *pred; | ||
1269 | struct FingerTable *ft; | ||
1270 | struct Finger *finger; | ||
1269 | 1271 | ||
1270 | rwrm = (const struct RandomWalkResponseMessage *) message; | 1272 | rwrm = (const struct RandomWalkResponseMessage *) message; |
1273 | trail = GNUNET_CONTAINER_multihashmap_get (trail_map, | ||
1274 | &rwrm->trail_id); | ||
1275 | if (NULL == trail) | ||
1276 | { | ||
1277 | /* TODO: log/statistics: we didn't find the trail (can happen) */ | ||
1278 | return GNUNET_OK; | ||
1279 | } | ||
1280 | if (NULL != (pred = trail->pred)) | ||
1281 | { | ||
1282 | /* We are not the first hop, keep forwarding */ | ||
1283 | struct GNUNET_MQ_Envelope *env; | ||
1284 | struct RandomWalkResponseMessage *rwrm2; | ||
1285 | |||
1286 | env = GNUNET_MQ_msg (rwrm2, | ||
1287 | GNUNET_MESSAGE_TYPE_WDHT_RANDOM_WALK_RESPONSE); | ||
1288 | rwrm2->reserved = htonl (0); | ||
1289 | rwrm2->location = rwrm->location; | ||
1290 | rwrm2->trail_id = trail->pred_id; | ||
1291 | GNUNET_MQ_send (pred->mq, | ||
1292 | env); | ||
1293 | return GNUNET_OK; | ||
1294 | } | ||
1295 | /* We are the first hop, complete finger */ | ||
1296 | if (NULL == (ft = trail->ft)) | ||
1297 | { | ||
1298 | /* Eh, why did we create the trail if we have no FT? */ | ||
1299 | GNUNET_break (0); | ||
1300 | delete_trail (trail, | ||
1301 | GNUNET_NO, | ||
1302 | GNUNET_YES); | ||
1303 | return GNUNET_OK; | ||
1304 | } | ||
1305 | if (NULL == (finger = ft->fingers[trail->finger_off])) | ||
1306 | { | ||
1307 | /* Eh, finger got deleted, but why not the trail as well? */ | ||
1308 | GNUNET_break (0); | ||
1309 | delete_trail (trail, | ||
1310 | GNUNET_NO, | ||
1311 | GNUNET_YES); | ||
1312 | return GNUNET_OK; | ||
1313 | } | ||
1314 | |||
1315 | |||
1271 | // 1) lookup trail => find Finger entry => fill in 'destination' and mark valid, move to end of sorted array, | 1316 | // 1) lookup trail => find Finger entry => fill in 'destination' and mark valid, move to end of sorted array, |
1272 | //mark unsorted, update links from 'trails' | 1317 | //mark unsorted, update links from 'trails' |
1273 | /* | 1318 | /* |
@@ -1334,14 +1379,12 @@ handle_dht_p2p_successor_find (void *cls, | |||
1334 | { | 1379 | { |
1335 | const struct FindSuccessorMessage *fsm; | 1380 | const struct FindSuccessorMessage *fsm; |
1336 | 1381 | ||
1382 | /* We do not expect to track trails for the forward-direction | ||
1383 | of successor finding... */ | ||
1384 | GNUNET_break_op (0 == trail_path_length); | ||
1337 | fsm = (const struct FindSuccessorMessage *) message; | 1385 | fsm = (const struct FindSuccessorMessage *) message; |
1338 | // locate trail (for sending reply), if not exists, fail nicely. | ||
1339 | // otherwise, go to datacache and return 'top k' elements closest to 'key' | ||
1340 | // as "PUT" messages via the trail (need to extend DB API!) | ||
1341 | #if 0 | ||
1342 | GDS_DATACACHE_get_successors (trail_id, | 1386 | GDS_DATACACHE_get_successors (trail_id, |
1343 | key); | 1387 | &fsm->key); |
1344 | #endif | ||
1345 | return GNUNET_OK; | 1388 | return GNUNET_OK; |
1346 | } | 1389 | } |
1347 | 1390 | ||
@@ -1451,14 +1494,14 @@ handle_dht_p2p_peer_put (void *cls, | |||
1451 | #if 0 | 1494 | #if 0 |
1452 | GDS_DATACACHE_handle_put (expiration_time, | 1495 | GDS_DATACACHE_handle_put (expiration_time, |
1453 | key, | 1496 | key, |
1454 | path_length, path, | 1497 | combined_path_length, combined_path, |
1455 | block_type, | 1498 | block_type, |
1456 | data_size, | 1499 | data_size, |
1457 | data); | 1500 | data); |
1458 | GDS_CLIENTS_process_put (options, | 1501 | GDS_CLIENTS_process_put (options, |
1459 | block_type, | 1502 | block_type, |
1460 | 0, 0, | 1503 | 0, 0, |
1461 | path_length, path, | 1504 | combined_path_length, combined_path, |
1462 | expiration_time, | 1505 | expiration_time, |
1463 | key, | 1506 | key, |
1464 | data, | 1507 | data, |
@@ -1468,8 +1511,6 @@ handle_dht_p2p_peer_put (void *cls, | |||
1468 | } | 1511 | } |
1469 | 1512 | ||
1470 | 1513 | ||
1471 | |||
1472 | |||
1473 | /** | 1514 | /** |
1474 | * Handler for a message we received along some trail. | 1515 | * Handler for a message we received along some trail. |
1475 | * | 1516 | * |
@@ -1534,7 +1575,7 @@ handle_dht_p2p_trail_route (void *cls, | |||
1534 | sizeof (struct FindSuccessorMessage) }, | 1575 | sizeof (struct FindSuccessorMessage) }, |
1535 | { &handle_dht_p2p_peer_get, NULL, | 1576 | { &handle_dht_p2p_peer_get, NULL, |
1536 | GNUNET_MESSAGE_TYPE_WDHT_GET, | 1577 | GNUNET_MESSAGE_TYPE_WDHT_GET, |
1537 | sizeof (struct FindSuccessorMessage) }, | 1578 | 0 }, |
1538 | { &handle_dht_p2p_peer_get_result, NULL, | 1579 | { &handle_dht_p2p_peer_get_result, NULL, |
1539 | GNUNET_MESSAGE_TYPE_WDHT_GET_RESULT, | 1580 | GNUNET_MESSAGE_TYPE_WDHT_GET_RESULT, |
1540 | 0 }, | 1581 | 0 }, |
@@ -1645,6 +1686,7 @@ handle_dht_p2p_trail_route (void *cls, | |||
1645 | 1686 | ||
1646 | /** | 1687 | /** |
1647 | * Initialize neighbours subsystem. | 1688 | * Initialize neighbours subsystem. |
1689 | * | ||
1648 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 1690 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1649 | */ | 1691 | */ |
1650 | int | 1692 | int |