aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-05-10 10:10:25 +0000
committerBart Polot <bart@net.in.tum.de>2013-05-10 10:10:25 +0000
commit6d7655f42cbec2163209ff6b445e1d1f96f3b719 (patch)
tree93bbd0512e13ccd7d311a96a9605bc2ccc8b0b5d
parent1582b76198cd7764922d80b8d7610e5c51cfbad0 (diff)
downloadgnunet-6d7655f42cbec2163209ff6b445e1d1f96f3b719.tar.gz
gnunet-6d7655f42cbec2163209ff6b445e1d1f96f3b719.zip
- remove the use of ntermediate MeshPathInfo struct, all can be passed in tunnel
-rw-r--r--src/mesh/gnunet-service-mesh-new.c170
1 files changed, 21 insertions, 149 deletions
diff --git a/src/mesh/gnunet-service-mesh-new.c b/src/mesh/gnunet-service-mesh-new.c
index d51c4b8dc..f0583fbd4 100644
--- a/src/mesh/gnunet-service-mesh-new.c
+++ b/src/mesh/gnunet-service-mesh-new.c
@@ -192,11 +192,6 @@ struct MeshPeerInfo
192 struct GNUNET_TIME_Absolute last_contact; 192 struct GNUNET_TIME_Absolute last_contact;
193 193
194 /** 194 /**
195 * Task handler for delayed connect task;
196 */
197 GNUNET_SCHEDULER_TaskIdentifier connect_task;
198
199 /**
200 * Number of attempts to reconnect so far 195 * Number of attempts to reconnect so far
201 */ 196 */
202 int n_reconnect_attempts; 197 int n_reconnect_attempts;
@@ -217,13 +212,8 @@ struct MeshPeerInfo
217 struct GNUNET_DHT_GetHandle *dhtget; 212 struct GNUNET_DHT_GetHandle *dhtget;
218 213
219 /** 214 /**
220 * Closure given to the DHT GET 215 * Array of tunnels this peer is the target of.
221 */ 216 * Most probably a small amount, therefore not a hashmap.
222 struct MeshPathInfo *dhtgetcls;
223
224 /**
225 * Array of tunnels this peer participates in
226 * (most probably a small amount, therefore not a hashmap)
227 * When the path to the peer changes, notify these tunnels to let them 217 * When the path to the peer changes, notify these tunnels to let them
228 * re-adjust their path trees. 218 * re-adjust their path trees.
229 */ 219 */
@@ -472,28 +462,6 @@ struct MeshTunnelClientInfo
472 462
473 463
474/** 464/**
475 * Info needed to work with tunnel paths and peers
476 */
477struct MeshPathInfo
478{
479 /**
480 * Tunnel
481 */
482 struct MeshTunnel *t;
483
484 /**
485 * Neighbouring peer to whom we send the packet to
486 */
487 struct MeshPeerInfo *peer;
488
489 /**
490 * Path itself
491 */
492 struct MeshPeerPath *path;
493};
494
495
496/**
497 * Struct containing information about a client of the service 465 * Struct containing information about a client of the service
498 */ 466 */
499struct MeshClient 467struct MeshClient
@@ -1394,20 +1362,14 @@ peer_get_best_path (const struct MeshPeerInfo *peer, const struct MeshTunnel *t)
1394 1362
1395 1363
1396/** 1364/**
1397 * Iterator to remove the tunnel from the list of tunnels a peer participates 1365 * Remove the tunnel from the list of tunnels to which a peer is target.
1398 * in.
1399 *
1400 * @param cls Closure (tunnel info)
1401 * @param key GNUNET_PeerIdentity of the peer (unused)
1402 * @param value PeerInfo of the peer
1403 * 1366 *
1404 * @return always GNUNET_YES, to keep iterating 1367 * @param peer PeerInfo of the peer.
1368 * @param t Tunnel to remove.
1405 */ 1369 */
1406static int 1370static void
1407peer_info_delete_tunnel (void *cls, const struct GNUNET_HashCode * key, void *value) 1371peer_remove_tunnel (struct MeshPeerInfo *peer, struct MeshTunnel *t)
1408{ 1372{
1409 struct MeshTunnel *t = cls;
1410 struct MeshPeerInfo *peer = value;
1411 unsigned int i; 1373 unsigned int i;
1412 1374
1413 for (i = 0; i < peer->ntunnels; i++) 1375 for (i = 0; i < peer->ntunnels; i++)
@@ -1420,10 +1382,9 @@ peer_info_delete_tunnel (void *cls, const struct GNUNET_HashCode * key, void *va
1420 peer->tunnels = 1382 peer->tunnels =
1421 GNUNET_realloc (peer->tunnels, 1383 GNUNET_realloc (peer->tunnels,
1422 peer->ntunnels * sizeof(struct MeshTunnel *)); 1384 peer->ntunnels * sizeof(struct MeshTunnel *));
1423 return GNUNET_YES; 1385 return;
1424 } 1386 }
1425 } 1387 }
1426 return GNUNET_YES;
1427} 1388}
1428 1389
1429 1390
@@ -1565,7 +1526,6 @@ static void
1565send_create_path (struct MeshPeerInfo *peer, struct MeshPeerPath *p, 1526send_create_path (struct MeshPeerInfo *peer, struct MeshPeerPath *p,
1566 struct MeshTunnel *t) 1527 struct MeshTunnel *t)
1567{ 1528{
1568 struct MeshPathInfo *path_info;
1569 struct MeshPeerInfo *neighbor; 1529 struct MeshPeerInfo *neighbor;
1570 1530
1571 if (NULL == p) 1531 if (NULL == p)
@@ -1574,12 +1534,8 @@ send_create_path (struct MeshPeerInfo *peer, struct MeshPeerPath *p,
1574 return; 1534 return;
1575 } 1535 }
1576 1536
1577 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
1578 path_info->path = p;
1579 path_info->t = t;
1580 neighbor = peer_get_short (t->next_hop); 1537 neighbor = peer_get_short (t->next_hop);
1581 path_info->peer = neighbor; 1538 queue_add (t,
1582 queue_add (path_info,
1583 GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 1539 GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE,
1584 sizeof (struct GNUNET_MESH_ManipulatePath) + 1540 sizeof (struct GNUNET_MESH_ManipulatePath) +
1585 (p->length * sizeof (struct GNUNET_PeerIdentity)), 1541 (p->length * sizeof (struct GNUNET_PeerIdentity)),
@@ -1589,49 +1545,6 @@ send_create_path (struct MeshPeerInfo *peer, struct MeshPeerPath *p,
1589 1545
1590 1546
1591/** 1547/**
1592 * Sends a DESTROY PATH message to free resources for a path in a tunnel.
1593 * Does not free the path itself.
1594 *
1595 * @param t Tunnel whose path to destroy.
1596 * @param destination Short ID of the peer to whom the path to destroy.
1597 */
1598static void
1599send_destroy_path (struct MeshTunnel *t)
1600{
1601 struct MeshPeerPath *p;
1602 size_t size;
1603
1604 p = t->path;
1605 if (NULL == p)
1606 {
1607 GNUNET_break (0);
1608 return;
1609 }
1610 size = sizeof (struct GNUNET_MESH_ManipulatePath);
1611 size += p->length * sizeof (struct GNUNET_PeerIdentity);
1612 {
1613 struct GNUNET_MESH_ManipulatePath *msg;
1614 struct GNUNET_PeerIdentity *pi;
1615 struct GNUNET_PeerIdentity id;
1616 char cbuf[size];
1617 unsigned int i;
1618
1619 msg = (struct GNUNET_MESH_ManipulatePath *) cbuf;
1620 msg->header.size = htons (size);
1621 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY);
1622 msg->tid = htonl (t->id.tid);
1623 pi = (struct GNUNET_PeerIdentity *) &msg[1];
1624 for (i = 0; i < p->length; i++)
1625 {
1626 GNUNET_PEER_resolve (p->peers[i], &pi[i]);
1627 }
1628 GNUNET_PEER_resolve (t->next_hop, &id);
1629 send_prebuilt_message (&msg->header, &id, t);
1630 }
1631}
1632
1633
1634/**
1635 * Sends a PATH ACK message in reponse to a received PATH_CREATE directed to us. 1548 * Sends a PATH ACK message in reponse to a received PATH_CREATE directed to us.
1636 * 1549 *
1637 * @param t Tunnel which to confirm. 1550 * @param t Tunnel which to confirm.
@@ -1667,7 +1580,6 @@ send_path_ack (struct MeshTunnel *t)
1667static void 1580static void
1668peer_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t) 1581peer_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t)
1669{ 1582{
1670 struct MeshPathInfo *path_info;
1671 struct MeshPeerPath *p; 1583 struct MeshPeerPath *p;
1672 1584
1673 if (NULL != peer->path_head) 1585 if (NULL != peer->path_head)
@@ -1681,52 +1593,23 @@ peer_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t)
1681 struct GNUNET_PeerIdentity id; 1593 struct GNUNET_PeerIdentity id;
1682 1594
1683 GNUNET_PEER_resolve (peer->id, &id); 1595 GNUNET_PEER_resolve (peer->id, &id);
1684 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
1685 path_info->peer = peer;
1686 path_info->t = t;
1687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1688 " Starting DHT GET for peer %s\n", GNUNET_i2s (&id)); 1597 " Starting DHT GET for peer %s\n", GNUNET_i2s (&id));
1689 peer->dhtgetcls = path_info;
1690 peer->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ 1598 peer->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */
1691 GNUNET_BLOCK_TYPE_MESH_PEER, /* type */ 1599 GNUNET_BLOCK_TYPE_MESH_PEER, /* type */
1692 &id.hashPubKey, /* key to search */ 1600 &id.hashPubKey, /* key to search */
1693 dht_replication_level, /* replication level */ 1601 dht_replication_level, /* replication level */
1694 GNUNET_DHT_RO_RECORD_ROUTE | 1602 GNUNET_DHT_RO_RECORD_ROUTE |
1695 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 1603 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
1696 NULL, /* xquery */ // FIXME BLOOMFILTER 1604 NULL, /* xquery */
1697 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE 1605 0, /* xquery bits */
1698 &dht_get_id_handler, path_info); 1606 &dht_get_id_handler, peer);
1699 } 1607 }
1700 /* Otherwise, there is no path but the DHT get is already started. */ 1608 /* Otherwise, there is no path but the DHT get is already started. */
1701} 1609}
1702 1610
1703 1611
1704/** 1612/**
1705 * Task to delay the connection of a peer
1706 *
1707 * @param cls Closure (path info with tunnel and peer to connect).
1708 * Will be free'd on exection.
1709 * @param tc TaskContext
1710 */
1711static void
1712peer_info_connect_task (void *cls,
1713 const struct GNUNET_SCHEDULER_TaskContext *tc)
1714{
1715 struct MeshPathInfo *path_info = cls;
1716
1717 path_info->peer->connect_task = GNUNET_SCHEDULER_NO_TASK;
1718
1719 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
1720 {
1721 GNUNET_free (cls);
1722 return;
1723 }
1724 peer_connect (path_info->peer, path_info->t);
1725 GNUNET_free (cls);
1726}
1727
1728
1729/**
1730 * Destroy the peer_info and free any allocated resources linked to it 1613 * Destroy the peer_info and free any allocated resources linked to it
1731 * 1614 *
1732 * @param pi The peer_info to destroy. 1615 * @param pi The peer_info to destroy.
@@ -1753,7 +1636,6 @@ peer_info_destroy (struct MeshPeerInfo *pi)
1753 if (NULL != pi->dhtget) 1636 if (NULL != pi->dhtget)
1754 { 1637 {
1755 GNUNET_DHT_get_stop (pi->dhtget); 1638 GNUNET_DHT_get_stop (pi->dhtget);
1756 GNUNET_free (pi->dhtgetcls);
1757 } 1639 }
1758 p = pi->path_head; 1640 p = pi->path_head;
1759 while (NULL != p) 1641 while (NULL != p)
@@ -1763,10 +1645,6 @@ peer_info_destroy (struct MeshPeerInfo *pi)
1763 path_destroy (p); 1645 path_destroy (p);
1764 p = nextp; 1646 p = nextp;
1765 } 1647 }
1766 if (GNUNET_SCHEDULER_NO_TASK != pi->connect_task)
1767 {
1768 GNUNET_free (GNUNET_SCHEDULER_cancel (pi->connect_task));
1769 }
1770 GNUNET_free (pi); 1648 GNUNET_free (pi);
1771 return GNUNET_OK; 1649 return GNUNET_OK;
1772} 1650}
@@ -1784,7 +1662,7 @@ peer_info_destroy (struct MeshPeerInfo *pi)
1784 * TODO: optimize (see below) 1662 * TODO: optimize (see below)
1785 */ 1663 */
1786static void 1664static void
1787peer_info_remove_path (struct MeshPeerInfo *peer, GNUNET_PEER_Id p1, 1665peer_remove_path (struct MeshPeerInfo *peer, GNUNET_PEER_Id p1,
1788 GNUNET_PEER_Id p2) 1666 GNUNET_PEER_Id p2)
1789{ 1667{
1790 struct MeshPeerPath *p; 1668 struct MeshPeerPath *p;
@@ -3197,11 +3075,10 @@ tunnel_reset_timeout (struct MeshTunnel *t)
3197static size_t 3075static size_t
3198send_core_path_create (void *cls, size_t size, void *buf) 3076send_core_path_create (void *cls, size_t size, void *buf)
3199{ 3077{
3200 struct MeshPathInfo *info = cls; 3078 struct MeshTunnel *t = cls;
3201 struct GNUNET_MESH_ManipulatePath *msg; 3079 struct GNUNET_MESH_ManipulatePath *msg;
3202 struct GNUNET_PeerIdentity *peer_ptr; 3080 struct GNUNET_PeerIdentity *peer_ptr;
3203 struct MeshTunnel *t = info->t; 3081 struct MeshPeerPath *p = t->path;
3204 struct MeshPeerPath *p = info->path;
3205 size_t size_needed; 3082 size_t size_needed;
3206 uint32_t opt; 3083 uint32_t opt;
3207 int i; 3084 int i;
@@ -3233,9 +3110,6 @@ send_core_path_create (void *cls, size_t size, void *buf)
3233 GNUNET_PEER_resolve (p->peers[i], peer_ptr++); 3110 GNUNET_PEER_resolve (p->peers[i], peer_ptr++);
3234 } 3111 }
3235 3112
3236 path_destroy (p);
3237 GNUNET_free (info);
3238
3239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3240 "CREATE PATH (%u bytes long) sent!\n", size_needed); 3114 "CREATE PATH (%u bytes long) sent!\n", size_needed);
3241 return size_needed; 3115 return size_needed;
@@ -3332,7 +3206,6 @@ static void
3332queue_destroy (struct MeshPeerQueue *queue, int clear_cls) 3206queue_destroy (struct MeshPeerQueue *queue, int clear_cls)
3333{ 3207{
3334 struct MeshTransmissionDescriptor *dd; 3208 struct MeshTransmissionDescriptor *dd;
3335 struct MeshPathInfo *path_info;
3336// unsigned int max; 3209// unsigned int max;
3337 3210
3338 if (GNUNET_YES == clear_cls) 3211 if (GNUNET_YES == clear_cls)
@@ -3358,8 +3231,6 @@ queue_destroy (struct MeshPeerQueue *queue, int clear_cls)
3358 break; 3231 break;
3359 case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE: 3232 case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE:
3360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type create path\n"); 3233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type create path\n");
3361 path_info = queue->cls;
3362 path_destroy (path_info->path);
3363 break; 3234 break;
3364 default: 3235 default:
3365 GNUNET_break (0); 3236 GNUNET_break (0);
@@ -4678,22 +4549,22 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
4678 unsigned int put_path_length, enum GNUNET_BLOCK_Type type, 4549 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
4679 size_t size, const void *data) 4550 size_t size, const void *data)
4680{ 4551{
4681 struct MeshPathInfo *path_info = cls; 4552 struct MeshPeerInfo *peer = cls;
4682 struct MeshPeerPath *p; 4553 struct MeshPeerPath *p;
4683 struct GNUNET_PeerIdentity pi; 4554 struct GNUNET_PeerIdentity pi;
4684 int i; 4555 int i;
4685 4556
4686 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got results from DHT!\n"); 4557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got results from DHT!\n");
4687 GNUNET_PEER_resolve (path_info->peer->id, &pi); 4558 GNUNET_PEER_resolve (peer->id, &pi);
4688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " for %s\n", GNUNET_i2s (&pi)); 4559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " for %s\n", GNUNET_i2s (&pi));
4689 4560
4690 p = path_build_from_dht (get_path, get_path_length, 4561 p = path_build_from_dht (get_path, get_path_length,
4691 put_path, put_path_length); 4562 put_path, put_path_length);
4692 path_add_to_peers (p, GNUNET_NO); 4563 path_add_to_peers (p, GNUNET_NO);
4693 path_destroy (p); 4564 path_destroy (p);
4694 for (i = 0; i < path_info->peer->ntunnels; i++) 4565 for (i = 0; i < peer->ntunnels; i++)
4695 { 4566 {
4696 peer_connect (path_info->peer, path_info->t); 4567 peer_connect (peer, peer->tunnels[i]); // FIXME add if
4697 } 4568 }
4698 4569
4699 return; 4570 return;
@@ -4971,6 +4842,7 @@ handle_local_tunnel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
4971 /* Don't try to ACK the client about the tunnel_destroy multicast packet */ 4842 /* Don't try to ACK the client about the tunnel_destroy multicast packet */
4972 t->owner = NULL; 4843 t->owner = NULL;
4973 tunnel_send_destroy (t); 4844 tunnel_send_destroy (t);
4845 peer_remove_tunnel (peer_get_short(t->peer), t);
4974 t->destroy = GNUNET_YES; 4846 t->destroy = GNUNET_YES;
4975 /* The tunnel will be destroyed when the last message is transmitted. */ 4847 /* The tunnel will be destroyed when the last message is transmitted. */
4976 GNUNET_SERVER_receive_done (client, GNUNET_OK); 4848 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -5566,7 +5438,7 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
5566 GNUNET_CORE_notify_transmit_ready_cancel(pi->core_transmit); 5438 GNUNET_CORE_notify_transmit_ready_cancel(pi->core_transmit);
5567 pi->core_transmit = NULL; 5439 pi->core_transmit = NULL;
5568 } 5440 }
5569 peer_info_remove_path (pi, pi->id, myid); 5441 peer_remove_path (pi, pi->id, myid);
5570 if (myid == pi->id) 5442 if (myid == pi->id)
5571 { 5443 {
5572 DEBUG_CONN (" (self)\n"); 5444 DEBUG_CONN (" (self)\n");