aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh_peer.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-10-09 17:26:57 +0000
committerBart Polot <bart@net.in.tum.de>2013-10-09 17:26:57 +0000
commit332efc3109755769bca3dfd4711453013178f0f9 (patch)
tree8ce4cf880f47c7e3d4e37e8a49b59648b72f5340 /src/mesh/gnunet-service-mesh_peer.c
parent39169a1ba1f64d4ce5a06edff19eda6786deeb99 (diff)
downloadgnunet-332efc3109755769bca3dfd4711453013178f0f9.tar.gz
gnunet-332efc3109755769bca3dfd4711453013178f0f9.zip
- add callback when we give a message to CORE
Diffstat (limited to 'src/mesh/gnunet-service-mesh_peer.c')
-rw-r--r--src/mesh/gnunet-service-mesh_peer.c98
1 files changed, 90 insertions, 8 deletions
diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c
index 2c3967d8a..d700f3aa2 100644
--- a/src/mesh/gnunet-service-mesh_peer.c
+++ b/src/mesh/gnunet-service-mesh_peer.c
@@ -41,6 +41,72 @@
41/******************************************************************************/ 41/******************************************************************************/
42 42
43/** 43/**
44 * Struct containing info about a queued transmission to this peer
45 */
46struct MeshPeerQueue
47{
48 /**
49 * DLL next
50 */
51 struct MeshPeerQueue *next;
52
53 /**
54 * DLL previous
55 */
56 struct MeshPeerQueue *prev;
57
58 /**
59 * Peer this transmission is directed to.
60 */
61 struct MeshPeer *peer;
62
63 /**
64 * Connection this message belongs to.
65 */
66 struct MeshConnection *c;
67
68 /**
69 * Is FWD in c?
70 */
71 int fwd;
72
73 /**
74 * Channel this message belongs to, if known.
75 */
76 struct MeshChannel *ch;
77
78 /**
79 * Pointer to info stucture used as cls.
80 */
81 void *cls;
82
83 /**
84 * Type of message
85 */
86 uint16_t type;
87
88 /**
89 * Size of the message
90 */
91 size_t size;
92
93 /**
94 * Set when this message starts waiting for CORE.
95 */
96 struct GNUNET_TIME_Absolute start_waiting;
97
98 /**
99 * Function to call on sending.
100 */
101 GMP_sent callback;
102
103 /**
104 * Closure for callback.
105 */
106 void *callback_cls;
107};
108
109/**
44 * Struct containing all information regarding a given peer 110 * Struct containing all information regarding a given peer
45 */ 111 */
46struct MeshPeer 112struct MeshPeer
@@ -822,7 +888,7 @@ path_add_to_peers (struct MeshPeerPath *p, int confirmed)
822 { 888 {
823 struct MeshPeer *aux; 889 struct MeshPeer *aux;
824 struct MeshPeerPath *copy; 890 struct MeshPeerPath *copy;
825 891
826 aux = peer_get_short (p->peers[i]); 892 aux = peer_get_short (p->peers[i]);
827 copy = path_duplicate (p); 893 copy = path_duplicate (p);
828 copy->length = i + 1; 894 copy->length = i + 1;
@@ -977,7 +1043,7 @@ queue_send (void *cls, size_t size, void *buf)
977 } 1043 }
978 1044
979 if (0 < drop_percent && 1045 if (0 < drop_percent &&
980 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 101) < drop_percent) 1046 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 101) < drop_percent)
981 { 1047 {
982 LOG (GNUNET_ERROR_TYPE_WARNING, 1048 LOG (GNUNET_ERROR_TYPE_WARNING,
983 "Dropping message of type %s\n", 1049 "Dropping message of type %s\n",
@@ -985,9 +1051,17 @@ queue_send (void *cls, size_t size, void *buf)
985 data_size = 0; 1051 data_size = 0;
986 } 1052 }
987 1053
1054 if (NULL != queue->callback)
1055 {
1056 LOG (GNUNET_ERROR_TYPE_DEBUG, "* Calling callback\n");
1057 queue->callback (queue->callback_cls,
1058 queue->c,
1059 GNUNET_TIME_absolute_get_duration (queue->start_waiting));
1060 }
1061
988 /* Free queue, but cls was freed by send_core_* */ 1062 /* Free queue, but cls was freed by send_core_* */
989 ch = queue->ch; 1063 ch = queue->ch;
990 queue_destroy (queue, GNUNET_NO); 1064 GMP_queue_destroy (queue, GNUNET_NO);
991 1065
992 /* Send ACK if needed, after accounting for sent ID in fc->queue_n */ 1066 /* Send ACK if needed, after accounting for sent ID in fc->queue_n */
993 switch (type) 1067 switch (type)
@@ -1018,6 +1092,7 @@ queue_send (void *cls, size_t size, void *buf)
1018 queue->size, 1092 queue->size,
1019 &queue_send, 1093 &queue_send,
1020 peer); 1094 peer);
1095 queue->start_waiting = GNUNET_TIME_absolute_get ();
1021 } 1096 }
1022 else 1097 else
1023 { 1098 {
@@ -1193,12 +1268,15 @@ GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls)
1193 * @param c Connection this message belongs to (cannot be NULL). 1268 * @param c Connection this message belongs to (cannot be NULL).
1194 * @param ch Channel this message belongs to, if applicable (otherwise NULL). 1269 * @param ch Channel this message belongs to, if applicable (otherwise NULL).
1195 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!) 1270 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
1271 * @param callback Function to be called once CORE has taken the message.
1272 * @param callback_cls Closure for @c callback.
1196 */ 1273 */
1197void 1274void
1198GMP_queue_add (void *cls, uint16_t type, size_t size, 1275GMP_queue_add (void *cls, uint16_t type, size_t size,
1199 struct MeshConnection *c, 1276 struct MeshConnection *c,
1200 struct MeshChannel *ch, 1277 struct MeshChannel *ch,
1201 int fwd) 1278 int fwd,
1279 GMP_sent callback, void *callback_cls)
1202{ 1280{
1203 struct MeshPeerQueue *queue; 1281 struct MeshPeerQueue *queue;
1204 struct MeshFlowControl *fc; 1282 struct MeshFlowControl *fc;
@@ -1274,6 +1352,8 @@ GMP_queue_add (void *cls, uint16_t type, size_t size,
1274 queue->c = c; 1352 queue->c = c;
1275 queue->ch = ch; 1353 queue->ch = ch;
1276 queue->fwd = fwd; 1354 queue->fwd = fwd;
1355 queue->callback = callback;
1356 queue->callback_cls = callback_cls;
1277 if (100 <= priority) 1357 if (100 <= priority)
1278 { 1358 {
1279 struct MeshPeerQueue *copy; 1359 struct MeshPeerQueue *copy;
@@ -1285,7 +1365,7 @@ GMP_queue_add (void *cls, uint16_t type, size_t size,
1285 if (copy->type == type && copy->c == c && copy->fwd == fwd) 1365 if (copy->type == type && copy->c == c && copy->fwd == fwd)
1286 { 1366 {
1287 /* Example: also a FWD ACK for connection XYZ */ 1367 /* Example: also a FWD ACK for connection XYZ */
1288 queue_destroy (copy, GNUNET_YES); 1368 GMP_queue_destroy (copy, GNUNET_YES);
1289 } 1369 }
1290 } 1370 }
1291 GNUNET_CONTAINER_DLL_insert (peer->queue_head, peer->queue_tail, queue); 1371 GNUNET_CONTAINER_DLL_insert (peer->queue_head, peer->queue_tail, queue);
@@ -1312,6 +1392,7 @@ GMP_queue_add (void *cls, uint16_t type, size_t size,
1312 size, 1392 size,
1313 &queue_send, 1393 &queue_send,
1314 peer); 1394 peer);
1395 queue->start_waiting = GNUNET_TIME_absolute_get ();
1315 } 1396 }
1316 else 1397 else
1317 { 1398 {
@@ -1457,8 +1538,9 @@ GMP_connect (struct MeshPeer *peer)
1457 { 1538 {
1458 GMD_search_stop (peer->search_h); 1539 GMD_search_stop (peer->search_h);
1459 peer->search_h = NULL; 1540 peer->search_h = NULL;
1460 LOG (GNUNET_ERROR_TYPE_DEBUG, 1541 LOG (GNUNET_ERROR_TYPE_DEBUG,
1461 " Stopping DHT GET for peer %s\n", peer2s (peer)); 1542 " Stopping DHT GET for peer %s\n",
1543 GMP_2s (peer));
1462 } 1544 }
1463 1545
1464 if (NULL == peer->search_h) 1546 if (NULL == peer->search_h)