diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-04-30 13:18:09 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-04-30 13:18:09 +0000 |
commit | 3673e64f188aec6506f4112b7a9bc3fa86999b78 (patch) | |
tree | d42bb3eacb08527a0327ece9830a64693412e792 /src/dht | |
parent | 24743e534f57a2f8b867be3a70676dbef60cd60c (diff) | |
download | gnunet-3673e64f188aec6506f4112b7a9bc3fa86999b78.tar.gz gnunet-3673e64f188aec6506f4112b7a9bc3fa86999b78.zip |
-more stuff
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-wdht_datacache.h | 2 | ||||
-rw-r--r-- | src/dht/gnunet-service-wdht_neighbours.c | 313 |
2 files changed, 234 insertions, 81 deletions
diff --git a/src/dht/gnunet-service-wdht_datacache.h b/src/dht/gnunet-service-wdht_datacache.h index f9ea8847d..64b80081e 100644 --- a/src/dht/gnunet-service-wdht_datacache.h +++ b/src/dht/gnunet-service-wdht_datacache.h | |||
@@ -67,6 +67,8 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, | |||
67 | * @param reply_bf where the reply bf is (to be) stored, possibly updated!, can be NULL | 67 | * @param reply_bf where the reply bf is (to be) stored, possibly updated!, can be NULL |
68 | * @param reply_bf_mutator mutation value for @a reply_bf | 68 | * @param reply_bf_mutator mutation value for @a reply_bf |
69 | * @return evaluation result for the local replies | 69 | * @return evaluation result for the local replies |
70 | * | ||
71 | * FIXME: also pass options, so we know to record paths or not... | ||
70 | */ | 72 | */ |
71 | enum GNUNET_BLOCK_EvaluationResult | 73 | enum GNUNET_BLOCK_EvaluationResult |
72 | GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *trail_id, | 74 | GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *trail_id, |
diff --git a/src/dht/gnunet-service-wdht_neighbours.c b/src/dht/gnunet-service-wdht_neighbours.c index eec2df69b..b3a45c44d 100644 --- a/src/dht/gnunet-service-wdht_neighbours.c +++ b/src/dht/gnunet-service-wdht_neighbours.c | |||
@@ -728,6 +728,8 @@ delete_trail (struct Trail *trail, | |||
728 | * @param expiration When will this result expire? | 728 | * @param expiration When will this result expire? |
729 | * @param data Payload to store | 729 | * @param data Payload to store |
730 | * @param data_size Size of the @a data | 730 | * @param data_size Size of the @a data |
731 | * | ||
732 | * FIXME: also pass options, so we know to record paths or not... | ||
731 | */ | 733 | */ |
732 | void | 734 | void |
733 | GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *trail_id, | 735 | GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *trail_id, |
@@ -1162,87 +1164,14 @@ handle_dht_p2p_trail_destroy (void *cls, | |||
1162 | trail = GNUNET_CONTAINER_multihashmap_get (trail_map, | 1164 | trail = GNUNET_CONTAINER_multihashmap_get (trail_map, |
1163 | &tdm->trail_id); | 1165 | &tdm->trail_id); |
1164 | delete_trail (trail, | 1166 | delete_trail (trail, |
1165 | 0 != memcmp (peer, | 1167 | ( (NULL != trail->succ) && |
1166 | &trail->pred_id, | 1168 | (0 == memcmp (peer, |
1167 | sizeof (struct GNUNET_PeerIdentity)), | 1169 | &trail->succ->id, |
1168 | 0 != memcmp (peer, | 1170 | sizeof (struct GNUNET_PeerIdentity))) ), |
1169 | &trail->succ_id, | 1171 | ( (NULL != trail->pred) && |
1170 | sizeof (struct GNUNET_PeerIdentity))); | 1172 | (0 == memcmp (peer, |
1171 | return GNUNET_OK; | 1173 | &trail->pred->id, |
1172 | } | 1174 | sizeof (struct GNUNET_PeerIdentity))) )); |
1173 | |||
1174 | |||
1175 | /** | ||
1176 | * Handler for a message we received along some trail. | ||
1177 | * | ||
1178 | * @param cls closure | ||
1179 | * @param trail_id trail identifier | ||
1180 | * @param message the message we got | ||
1181 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1182 | */ | ||
1183 | typedef int | ||
1184 | (*TrailHandlerCallback)(void *cls, | ||
1185 | const struct GNUNET_HashCode *trail_id, | ||
1186 | const struct GNUNET_MessageHandler *message); | ||
1187 | |||
1188 | |||
1189 | /** | ||
1190 | * Definition of a handler for a message received along some trail. | ||
1191 | */ | ||
1192 | struct TrailHandler | ||
1193 | { | ||
1194 | /** | ||
1195 | * NULL for end-of-list. | ||
1196 | */ | ||
1197 | TrailHandlerCallback callback; | ||
1198 | |||
1199 | /** | ||
1200 | * Closure for @e callback. | ||
1201 | */ | ||
1202 | void *cls; | ||
1203 | |||
1204 | /** | ||
1205 | * Message type this handler addresses. | ||
1206 | */ | ||
1207 | uint16_t message_type; | ||
1208 | |||
1209 | /** | ||
1210 | * Use 0 for variable-size. | ||
1211 | */ | ||
1212 | uint16_t message_size; | ||
1213 | }; | ||
1214 | |||
1215 | |||
1216 | /** | ||
1217 | * Handle a `struct TrailRouteMessage`. | ||
1218 | * | ||
1219 | * @param cls closure (NULL) | ||
1220 | * @param peer sender identity | ||
1221 | * @param message the finger destroy message | ||
1222 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1223 | */ | ||
1224 | static int | ||
1225 | handle_dht_p2p_trail_route (void *cls, | ||
1226 | const struct GNUNET_PeerIdentity *peer, | ||
1227 | const struct GNUNET_MessageHeader *message) | ||
1228 | { | ||
1229 | const struct TrailRouteMessage *trm; | ||
1230 | const void *payload; | ||
1231 | size_t msize; | ||
1232 | unsigned int start_payload; | ||
1233 | |||
1234 | /* msize = ntohs (message->size); */ | ||
1235 | /* if (msize < sizeof (struct TrailRouteMessage)) */ | ||
1236 | /* { */ | ||
1237 | /* GNUNET_break_op (0); */ | ||
1238 | /* return GNUNET_YES; */ | ||
1239 | /* } */ | ||
1240 | |||
1241 | /* trm = (const struct TrailRouteMessage *) message; */ | ||
1242 | /* /\* Retreive payload *\/ */ | ||
1243 | /* start_payload = sizeof (struct PeerGetResultMessage); */ | ||
1244 | /* payload = message[start_payload]; */ | ||
1245 | |||
1246 | return GNUNET_OK; | 1175 | return GNUNET_OK; |
1247 | } | 1176 | } |
1248 | 1177 | ||
@@ -1385,6 +1314,228 @@ handle_dht_p2p_peer_put (void *cls, | |||
1385 | } | 1314 | } |
1386 | 1315 | ||
1387 | 1316 | ||
1317 | |||
1318 | |||
1319 | /** | ||
1320 | * Handler for a message we received along some trail. | ||
1321 | * | ||
1322 | * @param cls closure | ||
1323 | * @param trail_id trail identifier | ||
1324 | * @param message the message we got | ||
1325 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1326 | */ | ||
1327 | typedef int | ||
1328 | (*TrailHandlerCallback)(void *cls, | ||
1329 | const struct GNUNET_HashCode *trail_id, | ||
1330 | const struct GNUNET_MessageHeader *message); | ||
1331 | |||
1332 | |||
1333 | /** | ||
1334 | * Definition of a handler for a message received along some trail. | ||
1335 | */ | ||
1336 | struct TrailHandler | ||
1337 | { | ||
1338 | /** | ||
1339 | * NULL for end-of-list. | ||
1340 | */ | ||
1341 | TrailHandlerCallback callback; | ||
1342 | |||
1343 | /** | ||
1344 | * Closure for @e callback. | ||
1345 | */ | ||
1346 | void *cls; | ||
1347 | |||
1348 | /** | ||
1349 | * Message type this handler addresses. | ||
1350 | */ | ||
1351 | uint16_t message_type; | ||
1352 | |||
1353 | /** | ||
1354 | * Use 0 for variable-size. | ||
1355 | */ | ||
1356 | uint16_t message_size; | ||
1357 | }; | ||
1358 | |||
1359 | |||
1360 | /** | ||
1361 | * Blah. | ||
1362 | */ | ||
1363 | static void | ||
1364 | forward_message_on_trail (struct FriendInfo *next_target, | ||
1365 | const struct GNUNET_HashCode *trail_id, | ||
1366 | int have_path, | ||
1367 | const struct GNUNET_PeerIdentity *predecessor, | ||
1368 | const struct GNUNET_PeerIdentity *path, | ||
1369 | uint16_t path_length, | ||
1370 | const struct GNUNET_MessageHeader *payload) | ||
1371 | { | ||
1372 | struct GNUNET_MQ_Envelope *env; | ||
1373 | struct TrailRouteMessage *trm; | ||
1374 | struct GNUNET_PeerIdentity *new_path; | ||
1375 | unsigned int plen; | ||
1376 | uint16_t payload_len; | ||
1377 | |||
1378 | payload_len = ntohs (payload->size); | ||
1379 | if (have_path) | ||
1380 | { | ||
1381 | plen = path_length + 1; | ||
1382 | if (plen >= (GNUNET_SERVER_MAX_MESSAGE_SIZE | ||
1383 | - payload_len | ||
1384 | - sizeof (struct TrailRouteMessage)) | ||
1385 | / sizeof (struct GNUNET_PeerIdentity)) | ||
1386 | { | ||
1387 | /* Should really not have paths this long... */ | ||
1388 | GNUNET_break_op (0); | ||
1389 | plen = 0; | ||
1390 | have_path = 0; | ||
1391 | } | ||
1392 | } | ||
1393 | else | ||
1394 | { | ||
1395 | GNUNET_break_op (0 == path_length); | ||
1396 | path_length = 0; | ||
1397 | plen = 0; | ||
1398 | } | ||
1399 | env = GNUNET_MQ_msg_extra (trm, | ||
1400 | payload_len + | ||
1401 | plen * sizeof (struct GNUNET_PeerIdentity), | ||
1402 | GNUNET_MESSAGE_TYPE_WDHT_TRAIL_ROUTE); | ||
1403 | trm->record_path = htons (have_path); | ||
1404 | trm->path_length = htons (plen); | ||
1405 | trm->trail_id = *trail_id; | ||
1406 | new_path = (struct GNUNET_PeerIdentity *) &trm[1]; | ||
1407 | if (have_path) | ||
1408 | { | ||
1409 | memcpy (new_path, | ||
1410 | path, | ||
1411 | path_length * sizeof (struct GNUNET_PeerIdentity)); | ||
1412 | new_path[path_length] = *predecessor; | ||
1413 | } | ||
1414 | memcpy (&new_path[plen], | ||
1415 | payload, | ||
1416 | payload_len); | ||
1417 | GNUNET_MQ_send (next_target->mq, | ||
1418 | env); | ||
1419 | } | ||
1420 | |||
1421 | |||
1422 | /** | ||
1423 | * Handle a `struct TrailRouteMessage`. | ||
1424 | * | ||
1425 | * @param cls closure (NULL) | ||
1426 | * @param peer sender identity | ||
1427 | * @param message the finger destroy message | ||
1428 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1429 | */ | ||
1430 | static int | ||
1431 | handle_dht_p2p_trail_route (void *cls, | ||
1432 | const struct GNUNET_PeerIdentity *peer, | ||
1433 | const struct GNUNET_MessageHeader *message) | ||
1434 | { | ||
1435 | static const struct TrailHandler handlers[] = { | ||
1436 | { &handle_dht_p2p_successor_find, NULL, | ||
1437 | GNUNET_MESSAGE_TYPE_WDHT_SUCCESSOR_FIND, | ||
1438 | sizeof (struct FindSuccessorMessage) }, | ||
1439 | { NULL, NULL, 0, 0 } | ||
1440 | }; | ||
1441 | unsigned int i; | ||
1442 | const struct TrailRouteMessage *trm; | ||
1443 | const struct GNUNET_PeerIdentity *path; | ||
1444 | uint16_t path_length; | ||
1445 | const struct GNUNET_MessageHeader *payload; | ||
1446 | const struct TrailHandler *th; | ||
1447 | struct Trail *trail; | ||
1448 | size_t msize; | ||
1449 | |||
1450 | /* Parse and check message is well-formed */ | ||
1451 | msize = ntohs (message->size); | ||
1452 | if (msize < sizeof (struct TrailRouteMessage)) | ||
1453 | { | ||
1454 | GNUNET_break_op (0); | ||
1455 | return GNUNET_YES; | ||
1456 | } | ||
1457 | trm = (const struct TrailRouteMessage *) message; | ||
1458 | path_length = ntohs (trm->path_length); | ||
1459 | if (msize < sizeof (struct TrailRouteMessage) + | ||
1460 | path_length * sizeof (struct GNUNET_PeerIdentity) + | ||
1461 | sizeof (struct GNUNET_MessageHeader) ) | ||
1462 | { | ||
1463 | GNUNET_break_op (0); | ||
1464 | return GNUNET_YES; | ||
1465 | } | ||
1466 | path = (const struct GNUNET_PeerIdentity *) &trm[1]; | ||
1467 | payload = (const struct GNUNET_MessageHeader *) &path[path_length]; | ||
1468 | if (msize != (ntohs (payload->size) + | ||
1469 | sizeof (struct TrailRouteMessage) + | ||
1470 | path_length * sizeof (struct GNUNET_PeerIdentity))) | ||
1471 | { | ||
1472 | GNUNET_break_op (0); | ||
1473 | return GNUNET_YES; | ||
1474 | } | ||
1475 | |||
1476 | /* Is this message for us? */ | ||
1477 | trail = GNUNET_CONTAINER_multihashmap_get (trail_map, | ||
1478 | &trm->trail_id); | ||
1479 | if ( (NULL != trail->pred) && | ||
1480 | (0 == memcmp (peer, | ||
1481 | &trail->pred->id, | ||
1482 | sizeof (struct GNUNET_PeerIdentity))) ) | ||
1483 | { | ||
1484 | /* forward to 'successor' */ | ||
1485 | if (NULL != trail->succ) | ||
1486 | { | ||
1487 | forward_message_on_trail (trail->succ, | ||
1488 | &trail->succ_id, | ||
1489 | ntohs (trm->record_path), | ||
1490 | peer, | ||
1491 | path, | ||
1492 | path_length, | ||
1493 | payload); | ||
1494 | return GNUNET_OK; | ||
1495 | } | ||
1496 | } | ||
1497 | else | ||
1498 | { | ||
1499 | /* forward to 'predecessor' */ | ||
1500 | GNUNET_break_op ( (NULL != trail->succ) && | ||
1501 | (0 == memcmp (peer, | ||
1502 | &trail->succ->id, | ||
1503 | sizeof (struct GNUNET_PeerIdentity))) ); | ||
1504 | if (NULL != trail->pred) | ||
1505 | { | ||
1506 | forward_message_on_trail (trail->pred, | ||
1507 | &trail->pred_id, | ||
1508 | ntohs (trm->record_path), | ||
1509 | peer, | ||
1510 | path, | ||
1511 | path_length, | ||
1512 | payload); | ||
1513 | return GNUNET_OK; | ||
1514 | } | ||
1515 | } | ||
1516 | |||
1517 | /* Message is for us, dispatch to handler */ | ||
1518 | th = NULL; | ||
1519 | for (i=0; NULL != handlers[i].callback; i++) | ||
1520 | { | ||
1521 | th = &handlers[i]; | ||
1522 | if (ntohs (payload->type) == th->message_type) | ||
1523 | { | ||
1524 | if ( (0 == th->message_size) || | ||
1525 | (ntohs (payload->size) == th->message_size) ) | ||
1526 | th->callback (th->cls, | ||
1527 | &trm->trail_id, | ||
1528 | payload); | ||
1529 | else | ||
1530 | GNUNET_break_op (0); | ||
1531 | break; | ||
1532 | } | ||
1533 | } | ||
1534 | GNUNET_break_op (NULL != th); | ||
1535 | return GNUNET_OK; | ||
1536 | } | ||
1537 | |||
1538 | |||
1388 | /** | 1539 | /** |
1389 | * Initialize neighbours subsystem. | 1540 | * Initialize neighbours subsystem. |
1390 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 1541 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |