aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-01-24 02:51:18 +0000
committerBart Polot <bart@net.in.tum.de>2012-01-24 02:51:18 +0000
commit006b19654d3083c381a16f683e920021e2cf91d8 (patch)
treeff3ad7941522490000d4b39374dcae890cdef246 /src/mesh
parenta7191ca787d1274832aede62b44d58063bde3b15 (diff)
downloadgnunet-006b19654d3083c381a16f683e920021e2cf91d8.tar.gz
gnunet-006b19654d3083c381a16f683e920021e2cf91d8.zip
- Fixed #2090, removed ugly debug lines
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/mesh_api.c72
1 files changed, 55 insertions, 17 deletions
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index 2c6d90675..48d8251ba 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -70,7 +70,7 @@ struct GNUNET_MESH_TransmitHandle
70 struct GNUNET_MESH_TransmitHandle *prev; 70 struct GNUNET_MESH_TransmitHandle *prev;
71 71
72 /** 72 /**
73 * Tunnel this message is sent over (may be NULL for control messages). 73 * Tunnel this message is sent on / for (may be NULL for control messages).
74 */ 74 */
75 struct GNUNET_MESH_Tunnel *tunnel; 75 struct GNUNET_MESH_Tunnel *tunnel;
76 76
@@ -565,12 +565,15 @@ add_to_queue (struct GNUNET_MESH_Handle *h,
565 * Auxiliary function to send an already constructed packet to the service. 565 * Auxiliary function to send an already constructed packet to the service.
566 * Takes care of creating a new queue element, copying the message and 566 * Takes care of creating a new queue element, copying the message and
567 * calling the tmt_rdy function if necessary. 567 * calling the tmt_rdy function if necessary.
568 *
568 * @param h mesh handle 569 * @param h mesh handle
569 * @param msg message to transmit 570 * @param msg message to transmit
571 * @param tunnel tunnel this send is related to (NULL if N/A)
570 */ 572 */
571static void 573static void
572send_packet (struct GNUNET_MESH_Handle *h, 574send_packet (struct GNUNET_MESH_Handle *h,
573 const struct GNUNET_MessageHeader *msg); 575 const struct GNUNET_MessageHeader *msg,
576 struct GNUNET_MESH_Tunnel *tunnel);
574 577
575 578
576/** 579/**
@@ -626,7 +629,7 @@ send_connect (struct GNUNET_MESH_Handle *h)
626 "mesh: Sending %lu bytes long message %d types and %d apps\n", 629 "mesh: Sending %lu bytes long message %d types and %d apps\n",
627 ntohs (msg->header.size), ntypes, napps); 630 ntohs (msg->header.size), ntypes, napps);
628#endif 631#endif
629 send_packet (h, &msg->header); 632 send_packet (h, &msg->header, NULL);
630 } 633 }
631} 634}
632 635
@@ -697,7 +700,7 @@ reconnect (struct GNUNET_MESH_Handle *h)
697 tmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); 700 tmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
698 tmsg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); 701 tmsg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
699 tmsg.tunnel_id = htonl (t->tid); 702 tmsg.tunnel_id = htonl (t->tid);
700 send_packet (h, &tmsg.header); 703 send_packet (h, &tmsg.header, t);
701 704
702 pmsg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 705 pmsg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
703 pmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD); 706 pmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
@@ -711,7 +714,7 @@ reconnect (struct GNUNET_MESH_Handle *h)
711 t->disconnect_handler (t->cls, &pmsg.peer); 714 t->disconnect_handler (t->cls, &pmsg.peer);
712 /* If the tunnel was "by type", dont connect individual peers */ 715 /* If the tunnel was "by type", dont connect individual peers */
713 if (0 == t->napps) 716 if (0 == t->napps)
714 send_packet (t->mesh, &pmsg.header); 717 send_packet (t->mesh, &pmsg.header, t);
715 } 718 }
716 /* Reconnect all types, if any */ 719 /* Reconnect all types, if any */
717 for (i = 0; i < t->napps; i++) 720 for (i = 0; i < t->napps; i++)
@@ -722,7 +725,7 @@ reconnect (struct GNUNET_MESH_Handle *h)
722 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE); 725 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE);
723 msg.tunnel_id = htonl (t->tid); 726 msg.tunnel_id = htonl (t->tid);
724 msg.type = htonl (t->apps[i]); 727 msg.type = htonl (t->apps[i]);
725 send_packet (t->mesh, &msg.header); 728 send_packet (t->mesh, &msg.header, t);
726 } 729 }
727 } 730 }
728 return GNUNET_YES; 731 return GNUNET_YES;
@@ -1171,12 +1174,15 @@ send_callback (void *cls, size_t size, void *buf)
1171 * Auxiliary function to send an already constructed packet to the service. 1174 * Auxiliary function to send an already constructed packet to the service.
1172 * Takes care of creating a new queue element, copying the message and 1175 * Takes care of creating a new queue element, copying the message and
1173 * calling the tmt_rdy function if necessary. 1176 * calling the tmt_rdy function if necessary.
1177 *
1174 * @param h mesh handle 1178 * @param h mesh handle
1175 * @param msg message to transmit 1179 * @param msg message to transmit
1180 * @param tunnel tunnel this send is related to (NULL if N/A)
1176 */ 1181 */
1177static void 1182static void
1178send_packet (struct GNUNET_MESH_Handle *h, 1183send_packet (struct GNUNET_MESH_Handle *h,
1179 const struct GNUNET_MessageHeader *msg) 1184 const struct GNUNET_MessageHeader *msg,
1185 struct GNUNET_MESH_Tunnel *tunnel)
1180{ 1186{
1181 struct GNUNET_MESH_TransmitHandle *th; 1187 struct GNUNET_MESH_TransmitHandle *th;
1182 size_t msize; 1188 size_t msize;
@@ -1186,6 +1192,7 @@ send_packet (struct GNUNET_MESH_Handle *h,
1186 th->priority = UINT32_MAX; 1192 th->priority = UINT32_MAX;
1187 th->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 1193 th->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
1188 th->size = msize; 1194 th->size = msize;
1195 th->tunnel = tunnel;
1189 memcpy (&th[1], msg, msize); 1196 memcpy (&th[1], msg, msize);
1190 add_to_queue (h, th); 1197 add_to_queue (h, th);
1191 if (NULL != h->th) 1198 if (NULL != h->th)
@@ -1280,6 +1287,14 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
1280 while (NULL != t) 1287 while (NULL != t)
1281 { 1288 {
1282 aux = t->next; 1289 aux = t->next;
1290 if (t->tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
1291 {
1292 GNUNET_break (0);
1293#if MESH_API_DEBUG
1294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: tunnel %X not destroyed\n",
1295 t->tid);
1296#endif
1297 }
1283 destroy_tunnel (t, GNUNET_YES); 1298 destroy_tunnel (t, GNUNET_YES);
1284 t = aux; 1299 t = aux;
1285 } 1300 }
@@ -1287,18 +1302,22 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
1287 { 1302 {
1288 struct GNUNET_MessageHeader *msg; 1303 struct GNUNET_MessageHeader *msg;
1289 1304
1290 /* Make sure it is a connect packet (everything else should have been 1305 /* Make sure it is an allowed packet (everything else should have been
1291 * already canceled). 1306 * already canceled).
1292 */ 1307 */
1293 GNUNET_break (UINT32_MAX == th->priority); 1308 GNUNET_break (UINT32_MAX == th->priority);
1294 GNUNET_break (NULL == th->notify); 1309 GNUNET_break (NULL == th->notify);
1295 msg = (struct GNUNET_MessageHeader *) &th[1]; 1310 msg = (struct GNUNET_MessageHeader *) &th[1];
1296 if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT != ntohs(msg->type)) 1311 switch (ntohs(msg->type))
1297 { 1312 {
1298 GNUNET_break (0); 1313 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT:
1314 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY:
1315 break;
1316 default:
1317 GNUNET_break (0);
1299#if MESH_API_DEBUG 1318#if MESH_API_DEBUG
1300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: expected %u, got %u\n", 1319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: unexpected msg %u\n",
1301 GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, ntohs(msg->type)); 1320 ntohs(msg->type));
1302#endif 1321#endif
1303 } 1322 }
1304 1323
@@ -1346,7 +1365,7 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx,
1346 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); 1365 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
1347 msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); 1366 msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
1348 msg.tunnel_id = htonl (t->tid); 1367 msg.tunnel_id = htonl (t->tid);
1349 send_packet (h, &msg.header); 1368 send_packet (h, &msg.header, t);
1350 return t; 1369 return t;
1351} 1370}
1352 1371
@@ -1362,6 +1381,7 @@ GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel)
1362{ 1381{
1363 struct GNUNET_MESH_Handle *h; 1382 struct GNUNET_MESH_Handle *h;
1364 struct GNUNET_MESH_TunnelMessage msg; 1383 struct GNUNET_MESH_TunnelMessage msg;
1384 struct GNUNET_MESH_TransmitHandle *th;
1365 1385
1366 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n"); 1386 LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n");
1367 h = tunnel->mesh; 1387 h = tunnel->mesh;
@@ -1369,8 +1389,26 @@ GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel)
1369 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); 1389 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
1370 msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); 1390 msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
1371 msg.tunnel_id = htonl (tunnel->tid); 1391 msg.tunnel_id = htonl (tunnel->tid);
1392 th = h->th_head;
1393 while (th != NULL)
1394 {
1395 struct GNUNET_MESH_TransmitHandle *aux;
1396 if (th->tunnel == tunnel)
1397 {
1398 aux = th->next;
1399 /* FIXME call the handler? */
1400 if (NULL != th->notify)
1401 th->notify (th->notify_cls, 0, NULL);
1402 GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th);
1403 GNUNET_free (th);
1404 th = aux;
1405 }
1406 else
1407 th = th->next;
1408 }
1409
1372 destroy_tunnel (tunnel, GNUNET_NO); 1410 destroy_tunnel (tunnel, GNUNET_NO);
1373 send_packet (h, &msg.header); 1411 send_packet (h, &msg.header, tunnel);
1374} 1412}
1375 1413
1376 1414
@@ -1409,7 +1447,7 @@ GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
1409 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD); 1447 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
1410 msg.tunnel_id = htonl (tunnel->tid); 1448 msg.tunnel_id = htonl (tunnel->tid);
1411 msg.peer = *peer; 1449 msg.peer = *peer;
1412 send_packet (tunnel->mesh, &msg.header); 1450 send_packet (tunnel->mesh, &msg.header, tunnel);
1413 1451
1414 return; 1452 return;
1415} 1453}
@@ -1455,7 +1493,7 @@ GNUNET_MESH_peer_request_connect_del (struct GNUNET_MESH_Tunnel *tunnel,
1455 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL); 1493 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL);
1456 msg.tunnel_id = htonl (tunnel->tid); 1494 msg.tunnel_id = htonl (tunnel->tid);
1457 memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity)); 1495 memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity));
1458 send_packet (tunnel->mesh, &msg.header); 1496 send_packet (tunnel->mesh, &msg.header, tunnel);
1459} 1497}
1460 1498
1461 1499
@@ -1479,7 +1517,7 @@ GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel,
1479 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE); 1517 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE);
1480 msg.tunnel_id = htonl (tunnel->tid); 1518 msg.tunnel_id = htonl (tunnel->tid);
1481 msg.type = htonl (app_type); 1519 msg.type = htonl (app_type);
1482 send_packet (tunnel->mesh, &msg.header); 1520 send_packet (tunnel->mesh, &msg.header, tunnel);
1483} 1521}
1484 1522
1485 1523