diff options
-rw-r--r-- | toxcore/group.c | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/toxcore/group.c b/toxcore/group.c index de8c4558..eb795721 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -1634,7 +1634,7 @@ static unsigned int send_lossy_all_close(const Group_Chats *g_c, int groupnumber | |||
1634 | if (!g) | 1634 | if (!g) |
1635 | return 0; | 1635 | return 0; |
1636 | 1636 | ||
1637 | uint16_t i, sent = 0; | 1637 | unsigned int i, sent = 0, num_connected_closest = 0, connected_closest[DESIRED_CLOSE_CONNECTIONS]; |
1638 | 1638 | ||
1639 | for (i = 0; i < MAX_GROUP_CONNECTIONS; ++i) { | 1639 | for (i = 0; i < MAX_GROUP_CONNECTIONS; ++i) { |
1640 | if (g->close[i].type != GROUPCHAT_CLOSE_ONLINE) | 1640 | if (g->close[i].type != GROUPCHAT_CLOSE_ONLINE) |
@@ -1643,11 +1643,65 @@ static unsigned int send_lossy_all_close(const Group_Chats *g_c, int groupnumber | |||
1643 | if ((int)i == receiver) | 1643 | if ((int)i == receiver) |
1644 | continue; | 1644 | continue; |
1645 | 1645 | ||
1646 | if (g->close[i].closest) { | ||
1647 | connected_closest[num_connected_closest] = i; | ||
1648 | ++num_connected_closest; | ||
1649 | continue; | ||
1650 | } | ||
1651 | |||
1646 | if (send_lossy_group_peer(g_c->fr_c, g->close[i].number, PACKET_ID_LOSSY_GROUPCHAT, g->close[i].group_number, data, | 1652 | if (send_lossy_group_peer(g_c->fr_c, g->close[i].number, PACKET_ID_LOSSY_GROUPCHAT, g->close[i].group_number, data, |
1647 | length)) | 1653 | length)) |
1648 | ++sent; | 1654 | ++sent; |
1649 | } | 1655 | } |
1650 | 1656 | ||
1657 | if (!num_connected_closest) { | ||
1658 | return sent; | ||
1659 | } | ||
1660 | |||
1661 | unsigned int to_send = 0; | ||
1662 | uint64_t comp_val_old = ~0; | ||
1663 | |||
1664 | for (i = 0; i < num_connected_closest; ++i) { | ||
1665 | uint8_t real_pk[crypto_box_PUBLICKEYBYTES]; | ||
1666 | uint8_t dht_temp_pk[crypto_box_PUBLICKEYBYTES]; | ||
1667 | get_friendcon_public_keys(real_pk, dht_temp_pk, g_c->fr_c, g->close[connected_closest[i]].number); | ||
1668 | uint64_t comp_val = calculate_comp_value(g->real_pk, real_pk); | ||
1669 | |||
1670 | if (comp_val < comp_val_old) { | ||
1671 | to_send = connected_closest[i]; | ||
1672 | comp_val_old = comp_val; | ||
1673 | } | ||
1674 | } | ||
1675 | |||
1676 | if (send_lossy_group_peer(g_c->fr_c, g->close[to_send].number, PACKET_ID_LOSSY_GROUPCHAT, | ||
1677 | g->close[to_send].group_number, data, length)) { | ||
1678 | ++sent; | ||
1679 | } | ||
1680 | |||
1681 | unsigned int to_send_other = 0; | ||
1682 | comp_val_old = ~0; | ||
1683 | |||
1684 | for (i = 0; i < num_connected_closest; ++i) { | ||
1685 | uint8_t real_pk[crypto_box_PUBLICKEYBYTES]; | ||
1686 | uint8_t dht_temp_pk[crypto_box_PUBLICKEYBYTES]; | ||
1687 | get_friendcon_public_keys(real_pk, dht_temp_pk, g_c->fr_c, g->close[connected_closest[i]].number); | ||
1688 | uint64_t comp_val = calculate_comp_value(real_pk, g->real_pk); | ||
1689 | |||
1690 | if (comp_val < comp_val_old) { | ||
1691 | to_send_other = connected_closest[i]; | ||
1692 | comp_val_old = comp_val; | ||
1693 | } | ||
1694 | } | ||
1695 | |||
1696 | if (to_send_other == to_send) { | ||
1697 | return sent; | ||
1698 | } | ||
1699 | |||
1700 | if (send_lossy_group_peer(g_c->fr_c, g->close[to_send_other].number, PACKET_ID_LOSSY_GROUPCHAT, | ||
1701 | g->close[to_send_other].group_number, data, length)) { | ||
1702 | ++sent; | ||
1703 | } | ||
1704 | |||
1651 | return sent; | 1705 | return sent; |
1652 | } | 1706 | } |
1653 | 1707 | ||