aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-06-05 14:07:12 +0000
committerBart Polot <bart@net.in.tum.de>2012-06-05 14:07:12 +0000
commitbf0e2eaecab85fb3c73b192a5027f3f3c26d1dfd (patch)
tree300746e327a00611f0599ce0efff2c5e0ffa6376 /src
parentd05e51355e4ba13094aac8c0a628b253be1a74bd (diff)
downloadgnunet-bf0e2eaecab85fb3c73b192a5027f3f3c26d1dfd.tar.gz
gnunet-bf0e2eaecab85fb3c73b192a5027f3f3c26d1dfd.zip
- WiP new mesh service
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh_new.c434
1 files changed, 210 insertions, 224 deletions
diff --git a/src/mesh/gnunet-service-mesh_new.c b/src/mesh/gnunet-service-mesh_new.c
index 34a48dabe..b60544087 100644
--- a/src/mesh/gnunet-service-mesh_new.c
+++ b/src/mesh/gnunet-service-mesh_new.c
@@ -137,11 +137,6 @@ struct MeshPeerQueue
137 struct MeshPeerInfo *peer; 137 struct MeshPeerInfo *peer;
138 138
139 /** 139 /**
140 * Handle to stop queued transmission
141 */
142 struct GNUNET_CORE_TransmitHandle *core_transmit;
143
144 /**
145 * Pointer to info stucture used as cls. 140 * Pointer to info stucture used as cls.
146 */ 141 */
147 void *cls; 142 void *cls;
@@ -150,6 +145,11 @@ struct MeshPeerQueue
150 * Type of message 145 * Type of message
151 */ 146 */
152 uint16_t type; 147 uint16_t type;
148
149 /**
150 * Size of the message
151 */
152 size_t size;
153}; 153};
154 154
155 155
@@ -168,9 +168,6 @@ struct MeshTransmissionDescriptor
168 /** Ultimate destination of the packet */ 168 /** Ultimate destination of the packet */
169 GNUNET_PEER_Id destination; 169 GNUNET_PEER_Id destination;
170 170
171 /** Which handler was used to request the transmission */
172 struct MeshPeerQueue *queue;
173
174 /** Data descriptor */ 171 /** Data descriptor */
175 struct MeshData* mesh_data; 172 struct MeshData* mesh_data;
176}; 173};
@@ -238,6 +235,11 @@ struct MeshPeerInfo
238 * Number of tunnels this peers participates in 235 * Number of tunnels this peers participates in
239 */ 236 */
240 unsigned int ntunnels; 237 unsigned int ntunnels;
238
239 /**
240 * Handle to stop queued transmission
241 */
242 struct GNUNET_CORE_TransmitHandle *core_transmit;
241}; 243};
242 244
243 245
@@ -431,11 +433,6 @@ struct MeshPathInfo
431 * Path itself 433 * Path itself
432 */ 434 */
433 struct MeshPeerPath *path; 435 struct MeshPeerPath *path;
434
435 /**
436 * Position in peer's transmit queue
437 */
438 struct MeshPeerQueue *queue;
439}; 436};
440 437
441 438
@@ -1161,37 +1158,6 @@ send_client_tunnel_disconnect (struct MeshTunnel *t, struct MeshClient *c)
1161 1158
1162 1159
1163/** 1160/**
1164 * Function called to notify a client about the socket
1165 * being ready to queue more data. "buf" will be
1166 * NULL and "size" zero if the socket was closed for
1167 * writing in the meantime.
1168 *
1169 * @param cls closure
1170 * @param size number of bytes available in buf
1171 * @param buf where the callee should write the message
1172 * @return number of bytes written to buf
1173 */
1174static size_t
1175send_core_create_path (void *cls, size_t size, void *buf);
1176
1177
1178/**
1179 * Function called to notify a client about the socket
1180 * being ready to queue more data. "buf" will be
1181 * NULL and "size" zero if the socket was closed for
1182 * writing in the meantime.
1183 *
1184 * @param cls closure (data itself)
1185 * @param size number of bytes available in buf
1186 * @param buf where the callee should write the message
1187 *
1188 * @return number of bytes written to buf
1189 */
1190static size_t
1191send_core_data_multicast (void *cls, size_t size, void *buf);
1192
1193
1194/**
1195 * Decrements the reference counter and frees all resources if needed 1161 * Decrements the reference counter and frees all resources if needed
1196 * 1162 *
1197 * @param mesh_data Data Descriptor used in a multicast message. 1163 * @param mesh_data Data Descriptor used in a multicast message.
@@ -1224,61 +1190,6 @@ data_descriptor_decrement_multicast (struct MeshData *mesh_data)
1224 1190
1225 1191
1226/** 1192/**
1227 * Cancel a core transmission that was already queued, free all resources
1228 * associated to the request and cancel all external requests (core, ...).
1229 *
1230 * @param queue Queue handler to cancel.
1231 */
1232static void
1233peer_info_cancel_transmission (struct MeshPeerQueue *queue)
1234{
1235 struct MeshTransmissionDescriptor *dd;
1236 struct MeshPathInfo *path_info;
1237 struct MeshPeerInfo *peer;
1238
1239 peer = queue->peer;
1240 if (NULL != queue->core_transmit)
1241 {
1242#if MESH_DEBUG
1243 {
1244 struct GNUNET_PeerIdentity id;
1245
1246 GNUNET_PEER_resolve (peer->id, &id);
1247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1248 " Cancelling data transmission at %s\n",
1249 GNUNET_i2s (&id));
1250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " message type %u\n",
1251 queue->type);
1252 }
1253#endif
1254 GNUNET_CORE_notify_transmit_ready_cancel (queue->core_transmit);
1255 }
1256 /* TODO: notify that transmission has failed */
1257 switch (queue->type)
1258 {
1259 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
1260 case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
1261 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
1262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type payload\n");
1263 dd = queue->cls;
1264 data_descriptor_decrement_multicast (dd->mesh_data);
1265 break;
1266 case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE:
1267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type create path\n");
1268 path_info = queue->cls;
1269 path_destroy (path_info->path);
1270 break;
1271 default:
1272 GNUNET_break (0);
1273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type unknown!\n");
1274 }
1275 GNUNET_free_non_null (queue->cls);
1276 GNUNET_CONTAINER_DLL_remove (peer->queue_head, peer->queue_tail, queue);
1277 GNUNET_free(queue);
1278}
1279
1280
1281/**
1282 * Retrieve the MeshPeerInfo stucture associated with the peer, create one 1193 * Retrieve the MeshPeerInfo stucture associated with the peer, create one
1283 * and insert it in the appropiate structures if the peer is not known yet. 1194 * and insert it in the appropiate structures if the peer is not known yet.
1284 * 1195 *
@@ -1356,6 +1267,17 @@ peer_info_delete_tunnel (void *cls, const GNUNET_HashCode * key, void *value)
1356 1267
1357 1268
1358/** 1269/**
1270 * Queue and pass message to core when possible.
1271 *
1272 * @param cls Closure (type dependant).
1273 * @param type Type of the message.
1274 * @param size Size of the message.
1275 * @param dst Neighbor to send message to.
1276 */
1277static void
1278queue_add (void *cls, uint16_t type, size_t size, struct MeshPeerInfo *dst);
1279
1280/**
1359 * Core callback to write a pre-constructed data packet to core buffer 1281 * Core callback to write a pre-constructed data packet to core buffer
1360 * 1282 *
1361 * @param cls Closure (MeshTransmissionDescriptor with data in "data" member). 1283 * @param cls Closure (MeshTransmissionDescriptor with data in "data" member).
@@ -1369,33 +1291,21 @@ send_core_data_raw (void *cls, size_t size, void *buf)
1369{ 1291{
1370 struct MeshTransmissionDescriptor *info = cls; 1292 struct MeshTransmissionDescriptor *info = cls;
1371 struct GNUNET_MessageHeader *msg; 1293 struct GNUNET_MessageHeader *msg;
1372 struct MeshPeerQueue *queue;
1373 size_t total_size; 1294 size_t total_size;
1374 1295
1375 GNUNET_assert (NULL != info); 1296 GNUNET_assert (NULL != info);
1376 GNUNET_assert (NULL != info->mesh_data); 1297 GNUNET_assert (NULL != info->mesh_data);
1377 msg = (struct GNUNET_MessageHeader *) info->mesh_data->data; 1298 msg = (struct GNUNET_MessageHeader *) info->mesh_data->data;
1378 total_size = ntohs (msg->size); 1299 total_size = ntohs (msg->size);
1379 queue = info->queue;
1380 1300
1381 if (total_size > size) 1301 if (total_size > size)
1382 { 1302 {
1383 struct GNUNET_PeerIdentity id; 1303 GNUNET_break (0);
1384
1385 GNUNET_PEER_resolve (info->peer->id, &id);
1386 queue->core_transmit =
1387 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100,
1388 GNUNET_TIME_UNIT_FOREVER_REL, &id,
1389 size, &send_core_data_raw, info);
1390 return 0; 1304 return 0;
1391 } 1305 }
1392 memcpy (buf, msg, total_size); 1306 memcpy (buf, msg, total_size);
1393 GNUNET_free (info->mesh_data); 1307 GNUNET_free (info->mesh_data);
1394 GNUNET_free (info); 1308 GNUNET_free (info);
1395 GNUNET_CONTAINER_DLL_remove (queue->peer->queue_head,
1396 queue->peer->queue_tail,
1397 queue);
1398 GNUNET_free (queue);
1399 return total_size; 1309 return total_size;
1400} 1310}
1401 1311
@@ -1414,7 +1324,6 @@ send_message (const struct GNUNET_MessageHeader *message,
1414 const struct GNUNET_PeerIdentity *peer) 1324 const struct GNUNET_PeerIdentity *peer)
1415{ 1325{
1416 struct MeshTransmissionDescriptor *info; 1326 struct MeshTransmissionDescriptor *info;
1417 struct MeshPeerQueue *queue;
1418 struct MeshPeerInfo *neighbor; 1327 struct MeshPeerInfo *neighbor;
1419 struct MeshPeerPath *p; 1328 struct MeshPeerPath *p;
1420 size_t size; 1329 size_t size;
@@ -1443,19 +1352,11 @@ send_message (const struct GNUNET_MessageHeader *message,
1443 GNUNET_free (info); 1352 GNUNET_free (info);
1444 return; 1353 return;
1445 } 1354 }
1446 queue = GNUNET_malloc (sizeof(struct MeshPeerQueue));
1447 queue->peer = neighbor;
1448 info->queue = queue;
1449 info->peer = neighbor; 1355 info->peer = neighbor;
1450 queue->type = GNUNET_MESSAGE_TYPE_MESH_UNICAST; 1356 queue_add (info,
1451 queue->cls = info; 1357 GNUNET_MESSAGE_TYPE_MESH_UNICAST,
1452 queue->core_transmit = 1358 size,
1453 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100, 1359 neighbor);
1454 GNUNET_TIME_UNIT_FOREVER_REL, peer,
1455 size, &send_core_data_raw, info);
1456 GNUNET_CONTAINER_DLL_insert (neighbor->queue_head,
1457 neighbor->queue_tail,
1458 queue);
1459} 1360}
1460 1361
1461 1362
@@ -1474,7 +1375,6 @@ send_create_path (struct MeshPeerInfo *peer, struct MeshPeerPath *p,
1474 struct GNUNET_PeerIdentity id; 1375 struct GNUNET_PeerIdentity id;
1475 struct MeshPathInfo *path_info; 1376 struct MeshPathInfo *path_info;
1476 struct MeshPeerInfo *neighbor; 1377 struct MeshPeerInfo *neighbor;
1477 struct MeshPeerQueue *queue;
1478 1378
1479 unsigned int i; 1379 unsigned int i;
1480 1380
@@ -1500,28 +1400,16 @@ send_create_path (struct MeshPeerInfo *peer, struct MeshPeerPath *p,
1500 } 1400 }
1501 GNUNET_PEER_resolve (p->peers[i + 1], &id); 1401 GNUNET_PEER_resolve (p->peers[i + 1], &id);
1502 1402
1503 queue = GNUNET_malloc (sizeof(struct MeshPeerQueue));
1504 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); 1403 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
1505 path_info->path = p; 1404 path_info->path = p;
1506 path_info->t = t; 1405 path_info->t = t;
1507 neighbor = peer_info_get (&id); 1406 neighbor = peer_info_get (&id);
1508 path_info->peer = neighbor; 1407 path_info->peer = neighbor;
1509 path_info->queue = queue; 1408 queue_add (path_info,
1510 queue->type = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE; 1409 GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE,
1511 queue->cls = path_info; 1410 sizeof (struct GNUNET_MESH_ManipulatePath) +
1512 queue->core_transmit = 1411 (p->length * sizeof (struct GNUNET_PeerIdentity)),
1513 GNUNET_CORE_notify_transmit_ready (core_handle, /* handle */ 1412 neighbor);
1514 0, /* cork */
1515 0, /* priority */
1516 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
1517 &id, /* target */
1518 sizeof (struct GNUNET_MESH_ManipulatePath) +
1519 (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */
1520 &send_core_create_path, /* callback */
1521 path_info); /* cls */
1522 GNUNET_CONTAINER_DLL_insert (neighbor->queue_head,
1523 neighbor->queue_tail,
1524 queue);
1525} 1413}
1526 1414
1527 1415
@@ -2344,7 +2232,6 @@ tunnel_send_multicast_iterator (void *cls, GNUNET_PEER_Id neighbor_id)
2344 struct MeshData *mdata = cls; 2232 struct MeshData *mdata = cls;
2345 struct MeshTransmissionDescriptor *info; 2233 struct MeshTransmissionDescriptor *info;
2346 struct GNUNET_PeerIdentity neighbor; 2234 struct GNUNET_PeerIdentity neighbor;
2347 struct MeshPeerQueue *queue;
2348 2235
2349 info = GNUNET_malloc (sizeof (struct MeshTransmissionDescriptor)); 2236 info = GNUNET_malloc (sizeof (struct MeshTransmissionDescriptor));
2350 2237
@@ -2356,19 +2243,11 @@ tunnel_send_multicast_iterator (void *cls, GNUNET_PEER_Id neighbor_id)
2356 GNUNET_i2s (&neighbor)); 2243 GNUNET_i2s (&neighbor));
2357 info->peer = peer_info_get (&neighbor); 2244 info->peer = peer_info_get (&neighbor);
2358 GNUNET_assert (NULL != info->peer); 2245 GNUNET_assert (NULL != info->peer);
2359 queue = GNUNET_malloc (sizeof(struct MeshPeerQueue)); 2246 queue_add(info,
2360 info->queue = queue; 2247 GNUNET_MESSAGE_TYPE_MESH_MULTICAST,
2361 queue->cls = info; 2248 info->mesh_data->data_len,
2362 queue->type = GNUNET_MESSAGE_TYPE_MESH_MULTICAST; 2249 info->peer
2363 queue->core_transmit = 2250 );
2364 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
2365 GNUNET_TIME_UNIT_FOREVER_REL,
2366 &neighbor, info->mesh_data->data_len,
2367 &send_core_data_multicast, info);
2368 queue->peer = info->peer;
2369 GNUNET_CONTAINER_DLL_insert (queue->peer->queue_head,
2370 queue->peer->queue_tail,
2371 queue);
2372} 2251}
2373 2252
2374/** 2253/**
@@ -2649,10 +2528,7 @@ tunnel_reset_timeout (struct MeshTunnel *t)
2649/******************************************************************************/ 2528/******************************************************************************/
2650 2529
2651/** 2530/**
2652 * Function called to notify a client about the socket 2531 * Function to send a create path packet to a peer.
2653 * being ready to queue more data. "buf" will be
2654 * NULL and "size" zero if the socket was closed for
2655 * writing in the meantime.
2656 * 2532 *
2657 * @param cls closure 2533 * @param cls closure
2658 * @param size number of bytes available in buf 2534 * @param size number of bytes available in buf
@@ -2660,12 +2536,11 @@ tunnel_reset_timeout (struct MeshTunnel *t)
2660 * @return number of bytes written to buf 2536 * @return number of bytes written to buf
2661 */ 2537 */
2662static size_t 2538static size_t
2663send_core_create_path (void *cls, size_t size, void *buf) 2539send_core_path_create (void *cls, size_t size, void *buf)
2664{ 2540{
2665 struct MeshPathInfo *info = cls; 2541 struct MeshPathInfo *info = cls;
2666 struct GNUNET_MESH_ManipulatePath *msg; 2542 struct GNUNET_MESH_ManipulatePath *msg;
2667 struct GNUNET_PeerIdentity *peer_ptr; 2543 struct GNUNET_PeerIdentity *peer_ptr;
2668 struct MeshPeerInfo *peer = info->peer;
2669 struct MeshTunnel *t = info->t; 2544 struct MeshTunnel *t = info->t;
2670 struct MeshPeerPath *p = info->path; 2545 struct MeshPeerPath *p = info->path;
2671 size_t size_needed; 2546 size_t size_needed;
@@ -2678,17 +2553,7 @@ send_core_create_path (void *cls, size_t size, void *buf)
2678 2553
2679 if (size < size_needed || NULL == buf) 2554 if (size < size_needed || NULL == buf)
2680 { 2555 {
2681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "create path retransmit!\n"); 2556 GNUNET_break (0);
2682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " buf: %p\n", buf);
2683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " size: (%u/%u)\n", size,
2684 size_needed);
2685 info->queue->core_transmit =
2686 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
2687 GNUNET_TIME_UNIT_FOREVER_REL,
2688 tree_get_first_hop (t->tree,
2689 peer->id),
2690 size_needed, &send_core_create_path,
2691 info);
2692 return 0; 2557 return 0;
2693 } 2558 }
2694 msg = (struct GNUNET_MESH_ManipulatePath *) buf; 2559 msg = (struct GNUNET_MESH_ManipulatePath *) buf;
@@ -2703,10 +2568,6 @@ send_core_create_path (void *cls, size_t size, void *buf)
2703 } 2568 }
2704 2569
2705 path_destroy (p); 2570 path_destroy (p);
2706 GNUNET_CONTAINER_DLL_remove(info->queue->peer->queue_head,
2707 info->queue->peer->queue_tail,
2708 info->queue);
2709 GNUNET_free (info->queue);
2710 GNUNET_free (info); 2571 GNUNET_free (info);
2711 2572
2712 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2573 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2716,10 +2577,7 @@ send_core_create_path (void *cls, size_t size, void *buf)
2716 2577
2717 2578
2718/** 2579/**
2719 * Function called to notify a client about the socket 2580 * Fill the core buffer
2720 * being ready to queue more data. "buf" will be
2721 * NULL and "size" zero if the socket was closed for
2722 * writing in the meantime.
2723 * 2581 *
2724 * @param cls closure (data itself) 2582 * @param cls closure (data itself)
2725 * @param size number of bytes available in buf 2583 * @param size number of bytes available in buf
@@ -2741,18 +2599,7 @@ send_core_data_multicast (void *cls, size_t size, void *buf)
2741 2599
2742 if (total_size > size) 2600 if (total_size > size)
2743 { 2601 {
2744 /* Retry */ 2602 GNUNET_break (0);
2745 struct GNUNET_PeerIdentity id;
2746
2747 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2748 "Multicast: retransmitting... (%u/%u)\n", size,
2749 total_size);
2750 GNUNET_PEER_resolve (info->peer->id, &id);
2751 info->queue->core_transmit =
2752 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
2753 GNUNET_TIME_UNIT_FOREVER_REL, &id,
2754 total_size,
2755 &send_core_data_multicast, info);
2756 return 0; 2603 return 0;
2757 } 2604 }
2758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " copying data...\n"); 2605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " copying data...\n");
@@ -2781,10 +2628,6 @@ send_core_data_multicast (void *cls, size_t size, void *buf)
2781#endif 2628#endif
2782 data_descriptor_decrement_multicast (info->mesh_data); 2629 data_descriptor_decrement_multicast (info->mesh_data);
2783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "freeing info...\n"); 2630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "freeing info...\n");
2784 GNUNET_CONTAINER_DLL_remove(info->queue->peer->queue_head,
2785 info->queue->peer->queue_tail,
2786 info->queue);
2787 GNUNET_free (info->queue);
2788 GNUNET_free (info); 2631 GNUNET_free (info);
2789 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "return %u\n", total_size); 2632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "return %u\n", total_size);
2790 return total_size; 2633 return total_size;
@@ -2792,10 +2635,7 @@ send_core_data_multicast (void *cls, size_t size, void *buf)
2792 2635
2793 2636
2794/** 2637/**
2795 * Function called to notify a client about the socket 2638 * Creates a path ack message in buf and frees all unused resources.
2796 * being ready to queue more data. "buf" will be
2797 * NULL and "size" zero if the socket was closed for
2798 * writing in the meantime.
2799 * 2639 *
2800 * @param cls closure (MeshTransmissionDescriptor) 2640 * @param cls closure (MeshTransmissionDescriptor)
2801 * @param size number of bytes available in buf 2641 * @param size number of bytes available in buf
@@ -2820,13 +2660,6 @@ send_core_path_ack (void *cls, size_t size, void *buf)
2820 msg->tid = htonl (info->origin->tid); 2660 msg->tid = htonl (info->origin->tid);
2821 msg->peer_id = my_full_id; 2661 msg->peer_id = my_full_id;
2822 2662
2823 if (info->queue)
2824 {
2825 GNUNET_CONTAINER_DLL_remove(info->queue->peer->queue_head,
2826 info->queue->peer->queue_tail,
2827 info->queue);
2828 GNUNET_free (info->queue);
2829 }
2830 GNUNET_free (info); 2663 GNUNET_free (info);
2831 /* TODO add signature */ 2664 /* TODO add signature */
2832 2665
@@ -2835,6 +2668,170 @@ send_core_path_ack (void *cls, size_t size, void *buf)
2835} 2668}
2836 2669
2837 2670
2671/**
2672 * Free a transmission that was already queued with all resources
2673 * associated to the request.
2674 *
2675 * @param queue Queue handler to cancel.
2676 */
2677static void
2678queue_destroy (struct MeshPeerQueue *queue)
2679{
2680 struct MeshTransmissionDescriptor *dd;
2681 struct MeshPathInfo *path_info;
2682 struct MeshPeerInfo *peer;
2683
2684 peer = queue->peer;
2685 switch (queue->type)
2686 {
2687 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
2688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type payload\n");
2689 dd = queue->cls;
2690 data_descriptor_decrement_multicast (dd->mesh_data);
2691 break;
2692 case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE:
2693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type create path\n");
2694 path_info = queue->cls;
2695 path_destroy (path_info->path);
2696 break;
2697 default:
2698 GNUNET_break (0);
2699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type unknown!\n");
2700 }
2701 GNUNET_free_non_null (queue->cls);
2702 GNUNET_CONTAINER_DLL_remove (peer->queue_head, peer->queue_tail, queue);
2703 GNUNET_free(queue);
2704}
2705
2706
2707/**
2708 * Core callback to write a queued packet to core buffer
2709 *
2710 * @param cls Closure (peer info).
2711 * @param size Number of bytes available in buf.
2712 * @param buf Where the to write the message.
2713 *
2714 * @return number of bytes written to buf
2715 */
2716static size_t
2717queue_send (void *cls, size_t size, void *buf)
2718{
2719 struct MeshPeerInfo *peer = cls;
2720 struct MeshPeerQueue *queue;
2721 size_t data_size;
2722
2723 peer->core_transmit = NULL;
2724 queue = peer->queue_head;
2725
2726 /* If queue is empty, send should have been cancelled */
2727 if (NULL == queue)
2728 {
2729 GNUNET_break(0);
2730 return 0;
2731 }
2732
2733 /* Check if buffer size is enough for the message */
2734 if (queue->size < size)
2735 {
2736 struct GNUNET_PeerIdentity id;
2737
2738 GNUNET_PEER_resolve (peer->id, &id);
2739 peer->core_transmit =
2740 GNUNET_CORE_notify_transmit_ready(core_handle,
2741 0,
2742 0,
2743 GNUNET_TIME_UNIT_FOREVER_REL,
2744 &id,
2745 queue->size,
2746 &queue_send,
2747 peer);
2748 return 0;
2749 }
2750
2751 /* Fill buf */
2752 switch (queue->type)
2753 {
2754 case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
2755 data_size = send_core_data_raw (queue->cls, size, buf);
2756 break;
2757 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
2758 data_size = send_core_data_multicast(queue->cls, size, buf);
2759 break;
2760 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
2761 data_size = 0;
2762 break;
2763 case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE:
2764 data_size = send_core_path_create(queue->cls, size, buf);
2765 break;
2766 case GNUNET_MESSAGE_TYPE_MESH_PATH_ACK:
2767 data_size = send_core_path_ack(queue->cls, size, buf);
2768 break;
2769 default:
2770 GNUNET_break (0);
2771 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type unknown!\n");
2772 data_size = 0;
2773 }
2774
2775 /* Free resources */
2776 queue_destroy(queue);
2777
2778 /* If more data in queue, send next */
2779 if (NULL != peer->queue_head)
2780 {
2781 struct GNUNET_PeerIdentity id;
2782
2783 GNUNET_PEER_resolve (peer->id, &id);
2784 peer->core_transmit =
2785 GNUNET_CORE_notify_transmit_ready(core_handle,
2786 0,
2787 0,
2788 GNUNET_TIME_UNIT_FOREVER_REL,
2789 &id,
2790 peer->queue_head->size,
2791 &queue_send,
2792 peer);
2793 }
2794 return data_size;
2795}
2796
2797
2798/**
2799 * Queue and pass message to core when possible.
2800 *
2801 * @param cls Closure (type dependant).
2802 * @param type Type of the message.
2803 * @param size Size of the message.
2804 * @param dst Neighbor to send message to.
2805 */
2806static void
2807queue_add (void *cls, uint16_t type, size_t size, struct MeshPeerInfo *dst)
2808{
2809 struct MeshPeerQueue *queue;
2810
2811 queue = GNUNET_malloc (sizeof (struct MeshPeerQueue));
2812 queue->cls = cls;
2813 queue->type = type;
2814 queue->size = size;
2815 queue->peer = dst;
2816 GNUNET_CONTAINER_DLL_insert_tail (dst->queue_head, dst->queue_tail, queue);
2817 if (NULL == dst->core_transmit)
2818 {
2819 struct GNUNET_PeerIdentity id;
2820
2821 GNUNET_PEER_resolve (dst->id, &id);
2822 dst->core_transmit =
2823 GNUNET_CORE_notify_transmit_ready(core_handle,
2824 0,
2825 0,
2826 GNUNET_TIME_UNIT_FOREVER_REL,
2827 &id,
2828 size,
2829 &queue_send,
2830 dst);
2831 }
2832}
2833
2834
2838/******************************************************************************/ 2835/******************************************************************************/
2839/******************** MESH NETWORK HANDLERS **************************/ 2836/******************** MESH NETWORK HANDLERS **************************/
2840/******************************************************************************/ 2837/******************************************************************************/
@@ -2981,7 +2978,6 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2981 { 2978 {
2982 /* It is for us! Send ack. */ 2979 /* It is for us! Send ack. */
2983 struct MeshTransmissionDescriptor *info; 2980 struct MeshTransmissionDescriptor *info;
2984 struct MeshPeerQueue *queue;
2985 2981
2986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n"); 2982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n");
2987 peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO); 2983 peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO);
@@ -2996,24 +2992,14 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2996 peer_info_get 2992 peer_info_get
2997 (&my_full_id), 2993 (&my_full_id),
2998 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); 2994 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
2999 /* FIXME use send_message */
3000 info = GNUNET_malloc (sizeof (struct MeshTransmissionDescriptor)); 2995 info = GNUNET_malloc (sizeof (struct MeshTransmissionDescriptor));
3001 info->origin = &t->id; 2996 info->origin = &t->id;
3002 info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); 2997 info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
3003 GNUNET_assert (NULL != info->peer); 2998 GNUNET_assert (NULL != info->peer);
3004 queue = GNUNET_malloc (sizeof (struct MeshPeerQueue)); 2999 queue_add(info,
3005 info->queue = queue; 3000 GNUNET_MESSAGE_TYPE_MESH_PATH_ACK,
3006 queue->peer = info->peer; 3001 sizeof (struct GNUNET_MESH_PathACK),
3007 queue->type = GNUNET_MESSAGE_TYPE_MESH_PATH_ACK; 3002 info->peer);
3008 queue->cls = info;
3009 queue->core_transmit =
3010 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 10,
3011 GNUNET_TIME_UNIT_FOREVER_REL, peer,
3012 sizeof (struct GNUNET_MESH_PathACK),
3013 &send_core_path_ack, info);
3014 GNUNET_CONTAINER_DLL_insert (queue->peer->queue_head,
3015 queue->peer->queue_tail,
3016 queue);
3017 } 3003 }
3018 else 3004 else
3019 { 3005 {