diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-07-24 15:30:26 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-07-24 15:30:26 +0000 |
commit | a5925e5a5203a89c289ad18f5eb7b006798693c1 (patch) | |
tree | 76dfc3d983821fc1ee02b9b6b697c0b7bcec899a /src/mesh | |
parent | a80e30a923e16a37565786e6c9c8f6543f9d7ee5 (diff) | |
download | gnunet-a5925e5a5203a89c289ad18f5eb7b006798693c1.tar.gz gnunet-a5925e5a5203a89c289ad18f5eb7b006798693c1.zip |
- calcualte path cost including overlap
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh-enc.c | 75 |
1 files changed, 48 insertions, 27 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c index f75ddd9b4..97c2f6da1 100644 --- a/src/mesh/gnunet-service-mesh-enc.c +++ b/src/mesh/gnunet-service-mesh-enc.c | |||
@@ -1614,61 +1614,82 @@ peer_get_short (const GNUNET_PEER_Id peer) | |||
1614 | * Select which PID to POLL for, to compensate for lost messages. | 1614 | * Select which PID to POLL for, to compensate for lost messages. |
1615 | * | 1615 | * |
1616 | * @param pi Peer we want to poll. | 1616 | * @param pi Peer we want to poll. |
1617 | * @param t Tunnel about which we want to poll. | 1617 | * |
1618 | * | 1618 | * @return PID to use, (last sent). |
1619 | * @return PID to use, either last sent or first_in_queue - 1 | ||
1620 | */ | 1619 | */ |
1621 | static uint32_t | 1620 | static uint32_t |
1622 | peer_get_first_payload_pid (struct MeshPeer *p, struct MeshTunnel *t) | 1621 | peer_get_first_pid (struct MeshPeer *p) |
1623 | { | 1622 | { |
1624 | struct MeshPeerQueue *q; | 1623 | return p->fc->last_pid_sent; |
1625 | uint16_t type; | 1624 | } |
1626 | 1625 | ||
1627 | type = p->id == t->next_hop ? GNUNET_MESSAGE_TYPE_MESH_UNICAST : | ||
1628 | GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN; | ||
1629 | 1626 | ||
1630 | for (q = p->queue_head; NULL != q; q = q->next) | 1627 | /** |
1631 | { | 1628 | * Get a cost of a path for a peer considering existing tunnel connections. |
1632 | if (q->type == type && q->tunnel == t) | 1629 | * |
1633 | { | 1630 | * @param peer Peer towards which the path is considered. |
1634 | struct GNUNET_MESH_Data *msg = q->cls; | 1631 | * @param path Candidate path. |
1632 | * | ||
1633 | * @return Cost of the path (path length + number of overlapping nodes) | ||
1634 | */ | ||
1635 | static unsigned int | ||
1636 | peer_get_path_cost (const struct MeshPeer *peer, | ||
1637 | const struct MeshPeerPath *path) | ||
1638 | { | ||
1639 | struct MeshConnection *c; | ||
1640 | unsigned int overlap; | ||
1641 | unsigned int i; | ||
1642 | unsigned int j; | ||
1635 | 1643 | ||
1636 | /* Pretend that the last one sent was the previous to this */ | 1644 | if (NULL == path) |
1637 | return ntohl (msg->pid) - 1; | 1645 | return 0; |
1638 | } | ||
1639 | } | ||
1640 | 1646 | ||
1641 | /* No data in queue, use last sent */ | 1647 | overlap = 0; |
1648 | GNUNET_assert (NULL != peer->tunnel); | ||
1649 | /* If tunnel has no connection, choose shortest one */ | ||
1650 | if (NULL == peer->tunnel->connection_head) | ||
1642 | { | 1651 | { |
1643 | struct MeshFlowControl *fc; | 1652 | return path->length; |
1644 | |||
1645 | fc = p->id == t->next_hop ? &t->next_fc : &t->prev_fc; | ||
1646 | return fc->last_pid_sent; | ||
1647 | } | 1653 | } |
1654 | for (i = 0; i < path->length; i++) | ||
1655 | { | ||
1656 | for (c = peer->tunnel->connection_head; NULL != c; c = c->next) | ||
1657 | { | ||
1658 | for (j = 0; j < c->path->length; j++) | ||
1659 | { | ||
1660 | if (path->peers[i] == c->path->peers[j]) | ||
1661 | { | ||
1662 | overlap++; | ||
1663 | break; | ||
1664 | } | ||
1665 | } | ||
1666 | } | ||
1667 | } | ||
1668 | return path->length + overlap; | ||
1648 | } | 1669 | } |
1649 | 1670 | ||
1650 | 1671 | ||
1651 | /** | 1672 | /** |
1652 | * Choose the best path towards a peer considering the tunnel properties. | 1673 | * Choose the best path towards a peer considering the tunnel properties. |
1653 | * | 1674 | * |
1654 | * @param peer The destination peer. | 1675 | * @param peer The destination peer. |
1655 | * @param t The tunnel the path is for. | 1676 | * @param t The tunnel the path is for. |
1656 | * | 1677 | * |
1657 | * @return Best current known path towards the peer, if any. | 1678 | * @return Best current known path towards the peer, if any. |
1658 | */ | 1679 | */ |
1659 | static struct MeshPeerPath * | 1680 | static struct MeshPeerPath * |
1660 | peer_get_best_path (const struct MeshPeer *peer, const struct MeshTunnel *t) | 1681 | peer_get_best_path (const struct MeshPeer *peer) |
1661 | { | 1682 | { |
1662 | struct MeshPeerPath *best_p; | 1683 | struct MeshPeerPath *best_p; |
1663 | struct MeshPeerPath *p; | 1684 | struct MeshPeerPath *p; |
1664 | unsigned int best_cost; | 1685 | unsigned int best_cost; |
1665 | unsigned int cost; | 1686 | unsigned int cost; |
1666 | 1687 | ||
1667 | best_p = p = peer->path_head; | 1688 | best_p = p = peer->path_head; |
1668 | best_cost = cost = p->length; | 1689 | best_cost = cost = peer_get_path_cost (peer, p); |
1669 | while (NULL != p) | 1690 | while (NULL != p) |
1670 | { | 1691 | { |
1671 | if ((cost = p->length) < best_cost) | 1692 | if ((cost = peer_get_path_cost (peer, p)) < best_cost) |
1672 | { | 1693 | { |
1673 | best_cost = cost; | 1694 | best_cost = cost; |
1674 | best_p = p; | 1695 | best_p = p; |