diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-06-25 12:10:12 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-06-25 12:10:12 +0000 |
commit | 10d31847527f5f76d1511407e8844aaa64000fc3 (patch) | |
tree | 118d294f7392ffa857fe1bee3b33e07ea49f7cad /src/dv | |
parent | 758527000f4955985dfd1d3b651fb9f621d6a72d (diff) | |
download | gnunet-10d31847527f5f76d1511407e8844aaa64000fc3.tar.gz gnunet-10d31847527f5f76d1511407e8844aaa64000fc3.zip |
remove variables
Diffstat (limited to 'src/dv')
-rw-r--r-- | src/dv/gnunet-service-dv.c | 88 |
1 files changed, 53 insertions, 35 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index fdff7e666..8366348d5 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c | |||
@@ -54,6 +54,11 @@ | |||
54 | #define USE_PEER_ID GNUNET_YES | 54 | #define USE_PEER_ID GNUNET_YES |
55 | 55 | ||
56 | /** | 56 | /** |
57 | * How many outstanding messages (unknown sender) will we allow per peer? | ||
58 | */ | ||
59 | #define MAX_OUTSTANDING_MESSAGES 5 | ||
60 | |||
61 | /** | ||
57 | * How often do we check about sending out more peer information (if | 62 | * How often do we check about sending out more peer information (if |
58 | * we are connected to no peers previously). | 63 | * we are connected to no peers previously). |
59 | */ | 64 | */ |
@@ -313,11 +318,11 @@ struct DirectNeighbor | |||
313 | int hidden; | 318 | int hidden; |
314 | 319 | ||
315 | /** | 320 | /** |
316 | * Save a single message from a direct neighbor from a peer | 321 | * Save messages immediately from this direct neighbor from a |
317 | * we don't know on the chance that it will be gossiped about | 322 | * distan peer we don't know on the chance that it will be |
318 | * and we can deliver the message. | 323 | * gossiped about and we can deliver the message. |
319 | */ | 324 | */ |
320 | struct UnknownSenderMessage pending_message; | 325 | struct UnknownSenderMessage pending_messages[MAX_OUTSTANDING_MESSAGES]; |
321 | }; | 326 | }; |
322 | 327 | ||
323 | 328 | ||
@@ -1324,23 +1329,22 @@ static int handle_dv_data_message (void *cls, | |||
1324 | struct GNUNET_PeerIdentity *destination; | 1329 | struct GNUNET_PeerIdentity *destination; |
1325 | struct FindDestinationContext fdc; | 1330 | struct FindDestinationContext fdc; |
1326 | struct TokenizedMessageContext tkm_ctx; | 1331 | struct TokenizedMessageContext tkm_ctx; |
1332 | int i; | ||
1333 | int found_pos; | ||
1327 | #if DELAY_FORWARDS | 1334 | #if DELAY_FORWARDS |
1328 | struct DelayedMessageContext *delayed_context; | 1335 | struct DelayedMessageContext *delayed_context; |
1329 | #endif | 1336 | #endif |
1330 | #if USE_PEER_ID | 1337 | #if USE_PEER_ID |
1331 | struct CheckPeerContext checkPeerCtx; | 1338 | struct CheckPeerContext checkPeerCtx; |
1332 | #endif | 1339 | #endif |
1340 | #if DEBUG_DV_MESSAGES | ||
1333 | char *sender_id; | 1341 | char *sender_id; |
1334 | char *direct_id; | 1342 | #endif |
1335 | int ret; | 1343 | int ret; |
1336 | size_t packed_message_size; | 1344 | size_t packed_message_size; |
1337 | char *cbuf; | 1345 | char *cbuf; |
1338 | #if NO_MST | ||
1339 | size_t offset; | ||
1340 | #endif | ||
1341 | packed_message_size = ntohs(incoming->header.size) - sizeof(p2p_dv_MESSAGE_Data); | ||
1342 | |||
1343 | 1346 | ||
1347 | packed_message_size = ntohs(incoming->header.size) - sizeof(p2p_dv_MESSAGE_Data); | ||
1344 | #if DEBUG_DV | 1348 | #if DEBUG_DV |
1345 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1346 | "%s: Receives DATA message from %s size %d, packed size %d!\n", my_short_id, GNUNET_i2s(peer) , ntohs(incoming->header.size), packed_message_size); | 1350 | "%s: Receives DATA message from %s size %d, packed size %d!\n", my_short_id, GNUNET_i2s(peer) , ntohs(incoming->header.size), packed_message_size); |
@@ -1384,10 +1388,8 @@ static int handle_dv_data_message (void *cls, | |||
1384 | if (pos == NULL) | 1388 | if (pos == NULL) |
1385 | { | 1389 | { |
1386 | #if DEBUG_DV_MESSAGES | 1390 | #if DEBUG_DV_MESSAGES |
1387 | direct_id = GNUNET_strdup(GNUNET_i2s(&dn->identity)); | ||
1388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1389 | "%s: unknown sender (%u), Message uid %llu from %s!\n", GNUNET_i2s(&my_identity), ntohl(incoming->sender), ntohl(incoming->uid), direct_id); | 1392 | "%s: unknown sender (%u), Message uid %llu from %s!\n", my_short_id, ntohl(incoming->sender), ntohl(incoming->uid), GNUNET_i2s(&dn->identity)); |
1390 | GNUNET_free(direct_id); | ||
1391 | pos = dn->referee_head; | 1393 | pos = dn->referee_head; |
1392 | while ((NULL != pos) && (pos->referrer_id != sid)) | 1394 | while ((NULL != pos) && (pos->referrer_id != sid)) |
1393 | { | 1395 | { |
@@ -1397,24 +1399,33 @@ static int handle_dv_data_message (void *cls, | |||
1397 | pos = pos->next; | 1399 | pos = pos->next; |
1398 | } | 1400 | } |
1399 | #endif | 1401 | #endif |
1400 | if (dn->pending_message.sender_id != 0) | 1402 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1403 | "%s: unknown sender (%u), Message uid %llu from %s!\n", my_short_id, ntohl(incoming->sender), ntohl(incoming->uid), GNUNET_i2s(&dn->identity)); | ||
1404 | |||
1405 | found_pos = -1; | ||
1406 | for (i = 0; i< MAX_OUTSTANDING_MESSAGES; i++) | ||
1401 | { | 1407 | { |
1402 | GNUNET_free(dn->pending_message.message); | 1408 | if (dn->pending_messages[i].sender_id == 0) |
1409 | { | ||
1410 | found_pos = i; | ||
1411 | break; | ||
1412 | } | ||
1403 | } | 1413 | } |
1404 | 1414 | ||
1405 | dn->pending_message.message = GNUNET_malloc(ntohs (message->size)); | 1415 | if (found_pos == -1) |
1406 | memcpy(dn->pending_message.message, message, ntohs(message->size)); | 1416 | { |
1407 | dn->pending_message.distance = distance; | 1417 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1408 | dn->pending_message.latency = latency; | 1418 | "%s: Too many unknown senders (%u), ignoring message! Message uid %llu from %s!\n", my_short_id, ntohl(incoming->sender), ntohl(incoming->uid), GNUNET_i2s(&dn->identity)); |
1409 | memcpy(&dn->pending_message.sender, peer, sizeof(struct GNUNET_PeerIdentity)); | 1419 | } |
1410 | dn->pending_message.sender_id = sid; | 1420 | else |
1411 | 1421 | { | |
1412 | #if DEBUG_MESSAGE_DROP | 1422 | dn->pending_messages[found_pos].message = GNUNET_malloc(ntohs (message->size)); |
1413 | direct_id = GNUNET_strdup(GNUNET_i2s(&dn->identity)); | 1423 | memcpy(dn->pending_messages[found_pos].message, message, ntohs(message->size)); |
1414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1424 | dn->pending_messages[found_pos].distance = distance; |
1415 | "%s: DROPPING MESSAGE type %d, unknown sender! Message immediately from %s!\n", GNUNET_i2s(&my_identity), ntohs(((struct GNUNET_MessageHeader *)&incoming[1])->type), direct_id); | 1425 | dn->pending_messages[found_pos].latency = latency; |
1416 | GNUNET_free(direct_id); | 1426 | memcpy(&dn->pending_messages[found_pos].sender, peer, sizeof(struct GNUNET_PeerIdentity)); |
1417 | #endif | 1427 | dn->pending_messages[found_pos].sender_id = sid; |
1428 | } | ||
1418 | /* unknown sender */ | 1429 | /* unknown sender */ |
1419 | return GNUNET_OK; | 1430 | return GNUNET_OK; |
1420 | } | 1431 | } |
@@ -2331,6 +2342,7 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, struct GNUNET_CRYPTO | |||
2331 | unsigned int our_id; | 2342 | unsigned int our_id; |
2332 | char *addr1; | 2343 | char *addr1; |
2333 | char *addr2; | 2344 | char *addr2; |
2345 | int i; | ||
2334 | 2346 | ||
2335 | #if DEBUG_DV_PEER_NUMBERS | 2347 | #if DEBUG_DV_PEER_NUMBERS |
2336 | char *encAbout; | 2348 | char *encAbout; |
@@ -2447,17 +2459,21 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, struct GNUNET_CRYPTO | |||
2447 | GNUNET_CONTAINER_multihashmap_put (extended_neighbors, &peer->hashPubKey, | 2459 | GNUNET_CONTAINER_multihashmap_put (extended_neighbors, &peer->hashPubKey, |
2448 | neighbor, | 2460 | neighbor, |
2449 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 2461 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
2450 | 2462 | if (referrer_peer_id != 0) | |
2451 | if ((referrer_peer_id != 0) && (referrer->pending_message.sender_id == referrer_peer_id)) /* We have a queued message from just learned about peer! */ | ||
2452 | { | 2463 | { |
2464 | for (i = 0; i< MAX_OUTSTANDING_MESSAGES; i++) | ||
2465 | { | ||
2466 | if (referrer->pending_messages[i].sender_id == referrer_peer_id) /* We have a queued message from just learned about peer! */ | ||
2467 | { | ||
2453 | #if DEBUG_DV_MESSAGES | 2468 | #if DEBUG_DV_MESSAGES |
2454 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: learned about peer %llu from which we have a previous unknown message, processing!\n", my_short_id, referrer_peer_id); | 2469 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: learned about peer %llu from which we have a previous unknown message, processing!\n", my_short_id, referrer_peer_id); |
2455 | #endif | 2470 | #endif |
2456 | handle_dv_data_message(NULL, &referrer->pending_message.sender, referrer->pending_message.message, referrer->pending_message.latency, referrer->pending_message.distance); | 2471 | handle_dv_data_message(NULL, &referrer->pending_messages[i].sender, referrer->pending_messages[i].message, referrer->pending_messages[i].latency, referrer->pending_messages[i].distance); |
2457 | GNUNET_free(referrer->pending_message.message); | 2472 | GNUNET_free(referrer->pending_messages[i].message); |
2458 | referrer->pending_message.sender_id = 0; | 2473 | referrer->pending_messages[i].sender_id = 0; |
2474 | } | ||
2475 | } | ||
2459 | } | 2476 | } |
2460 | |||
2461 | if (cost != DIRECT_NEIGHBOR_COST) | 2477 | if (cost != DIRECT_NEIGHBOR_COST) |
2462 | { | 2478 | { |
2463 | /* Added neighbor, now send HELLO to transport */ | 2479 | /* Added neighbor, now send HELLO to transport */ |
@@ -2469,7 +2485,9 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, struct GNUNET_CRYPTO | |||
2469 | GNUNET_assert(memcmp(hello_context->direct_peer, &hello_context->distant_peer, sizeof(struct GNUNET_PeerIdentity)) != 0); | 2485 | GNUNET_assert(memcmp(hello_context->direct_peer, &hello_context->distant_peer, sizeof(struct GNUNET_PeerIdentity)) != 0); |
2470 | addr1 = GNUNET_strdup(GNUNET_i2s(hello_context->direct_peer)); | 2486 | addr1 = GNUNET_strdup(GNUNET_i2s(hello_context->direct_peer)); |
2471 | addr2 = GNUNET_strdup(GNUNET_i2s(&hello_context->distant_peer)); | 2487 | addr2 = GNUNET_strdup(GNUNET_i2s(&hello_context->distant_peer)); |
2488 | #if DEBUG_DV | ||
2472 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: GIVING HELLO size %d for %s via %s to TRANSPORT\n", my_short_id, GNUNET_HELLO_size(hello_msg), addr2, addr1); | 2489 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: GIVING HELLO size %d for %s via %s to TRANSPORT\n", my_short_id, GNUNET_HELLO_size(hello_msg), addr2, addr1); |
2490 | #endif | ||
2473 | GNUNET_free(addr1); | 2491 | GNUNET_free(addr1); |
2474 | GNUNET_free(addr2); | 2492 | GNUNET_free(addr2); |
2475 | send_to_plugin(hello_context->direct_peer, GNUNET_HELLO_get_header(hello_msg), GNUNET_HELLO_size(hello_msg), &hello_context->distant_peer, cost); | 2493 | send_to_plugin(hello_context->direct_peer, GNUNET_HELLO_get_header(hello_msg), GNUNET_HELLO_size(hello_msg), &hello_context->distant_peer, cost); |