aboutsummaryrefslogtreecommitdiff
path: root/src/dv
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-06-24 16:24:22 +0000
committerNathan S. Evans <evans@in.tum.de>2010-06-24 16:24:22 +0000
commita76188dae2c7271ae26f556e39dc2037e2e94b4f (patch)
tree261946e93b5d9c2440baf5c31df2282ffb31ac28 /src/dv
parent05dd08f8547cf495cbe3edf61108f2bebfc1f37d (diff)
downloadgnunet-a76188dae2c7271ae26f556e39dc2037e2e94b4f.tar.gz
gnunet-a76188dae2c7271ae26f556e39dc2037e2e94b4f.zip
delay message sending to test hypothesis
Diffstat (limited to 'src/dv')
-rw-r--r--src/dv/gnunet-service-dv.c106
1 files changed, 77 insertions, 29 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c
index 7dfc171ff..00de78aae 100644
--- a/src/dv/gnunet-service-dv.c
+++ b/src/dv/gnunet-service-dv.c
@@ -330,6 +330,11 @@ struct DistantNeighbor
330 struct GNUNET_TIME_Absolute last_activity; 330 struct GNUNET_TIME_Absolute last_activity;
331 331
332 /** 332 /**
333 * Last time we sent routing information about this peer
334 */
335 struct GNUNET_TIME_Absolute last_gossip;
336
337 /**
333 * Cost to neighbor, used for actual distance vector computations 338 * Cost to neighbor, used for actual distance vector computations
334 */ 339 */
335 unsigned int cost; 340 unsigned int cost;
@@ -989,14 +994,8 @@ send_message_via (const struct GNUNET_PeerIdentity *sender,
989 core_pending_tail, 994 core_pending_tail,
990 pending_message); 995 pending_message);
991 996
992 if (core_transmit_handle == NULL) 997 GNUNET_SCHEDULER_add_now(sched, try_core_send, NULL);
993 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, send_context->importance, send_context->timeout, recipient, msg_size, &core_transmit_notify, NULL); 998
994 else
995 {
996#if DEBUG_DV
997 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "`%s': Failed to schedule pending transmission (must be one in progress!)\n", "dv service");
998#endif
999 }
1000 return GNUNET_YES; 999 return GNUNET_YES;
1001} 1000}
1002 1001
@@ -1149,10 +1148,12 @@ send_message (const struct GNUNET_PeerIdentity * recipient,
1149#if DEBUG_DV 1148#if DEBUG_DV
1150 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Notifying core of send size %d to destination `%s'\n", "DV SEND MESSAGE", msg_size, GNUNET_i2s(recipient)); 1149 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Notifying core of send size %d to destination `%s'\n", "DV SEND MESSAGE", msg_size, GNUNET_i2s(recipient));
1151#endif 1150#endif
1152 if (core_transmit_handle == NULL) 1151
1152 GNUNET_SCHEDULER_add_now(sched, try_core_send, NULL);
1153 /*if (core_transmit_handle == NULL)
1153 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, importance, timeout, &target->referrer->identity, msg_size, &core_transmit_notify, NULL); 1154 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, importance, timeout, &target->referrer->identity, msg_size, &core_transmit_notify, NULL);
1154 else 1155 else
1155 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: CORE ALREADY SENDING\n", "DV SEND MESSAGE", msg_size); 1156 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: CORE ALREADY SENDING\n", "DV SEND MESSAGE", msg_size);*/
1156 return (int) cost; 1157 return (int) cost;
1157} 1158}
1158 1159
@@ -1225,6 +1226,34 @@ void tokenized_message_handler (void *cls,
1225 } 1226 }
1226} 1227}
1227 1228
1229struct DelayedMessageContext
1230{
1231 struct GNUNET_PeerIdentity dest;
1232 struct GNUNET_PeerIdentity sender;
1233 struct GNUNET_MessageHeader *message;
1234 size_t message_size;
1235 uint32_t uid;
1236};
1237
1238void send_message_delayed (void *cls,
1239 const struct GNUNET_SCHEDULER_TaskContext *tc)
1240{
1241 struct DelayedMessageContext *msg_ctx = cls;
1242 if (msg_ctx != NULL)
1243 {
1244 send_message(&msg_ctx->dest,
1245 &msg_ctx->sender,
1246 NULL,
1247 msg_ctx->message,
1248 msg_ctx->message_size,
1249 default_dv_priority,
1250 msg_ctx->uid,
1251 GNUNET_TIME_relative_get_forever());
1252 }
1253 GNUNET_free(msg_ctx->message);
1254 GNUNET_free(msg_ctx);
1255}
1256
1228/** 1257/**
1229 * Core handler for dv data messages. Whatever this message 1258 * Core handler for dv data messages. Whatever this message
1230 * contains all we really have to do is rip it out of its 1259 * contains all we really have to do is rip it out of its
@@ -1249,10 +1278,11 @@ static int handle_dv_data_message (void *cls,
1249 struct DistantNeighbor *pos; 1278 struct DistantNeighbor *pos;
1250 unsigned int sid; /* Sender id */ 1279 unsigned int sid; /* Sender id */
1251 unsigned int tid; /* Target id */ 1280 unsigned int tid; /* Target id */
1252 struct GNUNET_PeerIdentity original_sender; 1281 struct GNUNET_PeerIdentity *original_sender;
1253 struct GNUNET_PeerIdentity destination; 1282 struct GNUNET_PeerIdentity *destination;
1254 struct FindDestinationContext fdc; 1283 struct FindDestinationContext fdc;
1255 struct TokenizedMessageContext tkm_ctx; 1284 struct TokenizedMessageContext tkm_ctx;
1285 struct DelayedMessageContext *delayed_context;
1256#if USE_PEER_ID 1286#if USE_PEER_ID
1257 struct CheckPeerContext checkPeerCtx; 1287 struct CheckPeerContext checkPeerCtx;
1258#endif 1288#endif
@@ -1338,7 +1368,7 @@ static int handle_dv_data_message (void *cls,
1338 /* unknown sender */ 1368 /* unknown sender */
1339 return GNUNET_OK; 1369 return GNUNET_OK;
1340 } 1370 }
1341 original_sender = pos->identity; 1371 original_sender = &pos->identity;
1342 tid = ntohl (incoming->recipient); 1372 tid = ntohl (incoming->recipient);
1343 if (tid == 0) 1373 if (tid == 0)
1344 { 1374 {
@@ -1408,9 +1438,9 @@ static int handle_dv_data_message (void *cls,
1408#endif 1438#endif
1409 return GNUNET_OK; 1439 return GNUNET_OK;
1410 } 1440 }
1411 destination = fdc.dest->identity; 1441 destination = &fdc.dest->identity;
1412 1442
1413 if (0 == memcmp (&destination, peer, sizeof (struct GNUNET_PeerIdentity))) 1443 if (0 == memcmp (destination, peer, sizeof (struct GNUNET_PeerIdentity)))
1414 { 1444 {
1415 /* FIXME: create stat: routing loop-discard! */ 1445 /* FIXME: create stat: routing loop-discard! */
1416#if DEBUG_DV_PEER_NUMBERS 1446#if DEBUG_DV_PEER_NUMBERS
@@ -1437,18 +1467,33 @@ static int handle_dv_data_message (void *cls,
1437 1467
1438#if DEBUG_DV_MESSAGES 1468#if DEBUG_DV_MESSAGES
1439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1440 "%s: FORWARD %s message for %s, uid %u, size %d type %d, cost %u!\n", my_short_id, "DV DATA", GNUNET_i2s(&destination), ntohl(incoming->uid), ntohs(packed_message->size), ntohs(packed_message->type), pos->cost); 1470 "%s: FORWARD %s message for %s, uid %u, size %d type %d, cost %u!\n", my_short_id, "DV DATA", GNUNET_i2s(destination), ntohl(incoming->uid), ntohs(packed_message->size), ntohs(packed_message->type), pos->cost);
1441#endif 1471#endif
1442 1472
1443 ret = send_message(&destination, 1473 if (GNUNET_TIME_absolute_get_duration(pos->last_gossip).value < GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2).value)
1444 &original_sender, 1474 {
1445 NULL, 1475 delayed_context = GNUNET_malloc(sizeof(struct DelayedMessageContext));
1446 packed_message, 1476 memcpy(&delayed_context->dest, destination, sizeof(struct GNUNET_PeerIdentity));
1447 packed_message_size, 1477 memcpy(&delayed_context->sender, original_sender, sizeof(struct GNUNET_PeerIdentity));
1448 default_dv_priority, 1478 delayed_context->message = GNUNET_malloc(packed_message_size);
1449 ntohl(incoming->uid), 1479 memcpy(delayed_context->message, packed_message, packed_message_size);
1450 GNUNET_TIME_relative_get_forever()); 1480 delayed_context->message_size = packed_message_size;
1451 1481 delayed_context->uid = ntohl(incoming->uid);
1482 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 2500), &send_message_delayed, delayed_context);
1483 //GNUNET_SCHEDULER_add_now(sched, &send_message_delayed, delayed_context);
1484 return GNUNET_OK;
1485 }
1486 else
1487 {
1488 ret = send_message(destination,
1489 original_sender,
1490 NULL,
1491 packed_message,
1492 packed_message_size,
1493 default_dv_priority,
1494 ntohl(incoming->uid),
1495 GNUNET_TIME_relative_get_forever());
1496 }
1452 if (ret != GNUNET_SYSERR) 1497 if (ret != GNUNET_SYSERR)
1453 return GNUNET_OK; 1498 return GNUNET_OK;
1454 else 1499 else
@@ -1566,6 +1611,7 @@ neighbor_send_task (void *cls,
1566 GNUNET_free(encPeerAbout); 1611 GNUNET_free(encPeerAbout);
1567 GNUNET_free(encPeerTo); 1612 GNUNET_free(encPeerTo);
1568#endif 1613#endif
1614 about->last_gossip = GNUNET_TIME_absolute_get();
1569 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(p2p_dv_MESSAGE_NeighborInfo)); 1615 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(p2p_dv_MESSAGE_NeighborInfo));
1570 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; 1616 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
1571 pending_message->importance = default_dv_priority; 1617 pending_message->importance = default_dv_priority;
@@ -1587,8 +1633,9 @@ neighbor_send_task (void *cls,
1587 core_pending_tail, 1633 core_pending_tail,
1588 pending_message); 1634 pending_message);
1589 1635
1590 if (core_transmit_handle == NULL) 1636 GNUNET_SCHEDULER_add_now(sched, try_core_send, NULL);
1591 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, default_dv_priority, GNUNET_TIME_relative_get_forever(), &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, NULL); 1637 /*if (core_transmit_handle == NULL)
1638 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, default_dv_priority, GNUNET_TIME_relative_get_forever(), &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, NULL);*/
1592 1639
1593 } 1640 }
1594 1641
@@ -1964,8 +2011,9 @@ static int schedule_disconnect_messages (void *cls,
1964 core_pending_tail, 2011 core_pending_tail,
1965 pending_message); 2012 pending_message);
1966 2013
1967 if (core_transmit_handle == NULL) 2014 GNUNET_SCHEDULER_add_now(sched, try_core_send, NULL);
1968 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, default_dv_priority, GNUNET_TIME_relative_get_forever(), &notify->identity, sizeof(p2p_dv_MESSAGE_Disconnect), &core_transmit_notify, NULL); 2015 /*if (core_transmit_handle == NULL)
2016 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, default_dv_priority, GNUNET_TIME_relative_get_forever(), &notify->identity, sizeof(p2p_dv_MESSAGE_Disconnect), &core_transmit_notify, NULL);*/
1969 2017
1970 return GNUNET_YES; 2018 return GNUNET_YES;
1971} 2019}