Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add configurable limit on number of stored frozen peers #1309

Merged
merged 1 commit into from
May 20, 2019

Conversation

zugz
Copy link

@zugz zugz commented Feb 17, 2019

closes #1306


This change is Reviewable

Copy link

@sudden6 sudden6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 6 files at r1.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @zugz)


auto_tests/conference_test.c, line 168 at r1 (raw file):

    const bool check_name_change_propagation = false;

    /* each peer should freeze at least its two friends, but freezing more

This test seems to only test the function that sets the limit, but doesn't actually check if the limit is enforced, right? I think testing for the later is the most important part of this PR, no?


toxcore/group.c, line 789 at r1 (raw file):

    qsort(g->frozen, g->numfrozen, sizeof(Group_Peer), cmp_frozen);

    g->numfrozen = g->maxfrozen;

Why is the now unused memory not freed?


toxcore/group.c, line 3306 at r1 (raw file):

        if (g->numfrozen > g->maxfrozen) {
            g->maxfrozen = g->numfrozen;

shouldn't we trim the list here using remove_old_frozen()?

@nurupo
Copy link
Member

nurupo commented Feb 19, 2019


toxcore/group.c, line 1293 at r1 (raw file):

    }

    g->maxfrozen = maxfrozen;

Shouldn't the g->frozen array be resized to make sure it can fit the requested maxfrozen?

@nurupo
Copy link
Member

nurupo commented Feb 19, 2019


toxcore/group.c, line 781 at r1 (raw file):

 * return true if any frozen peers are removed.
 */
static bool remove_old_frozen(Group_c *g)

The function is called remove_old_frozen, which implies some kind of deallocation. If it doesn't actually deallocate any memory, perhaps it should be renamed more appropriately, like trim_frozen or something, idk, I'm horrible at naming things.

@codecov
Copy link

codecov bot commented Feb 19, 2019

Codecov Report

Merging #1309 into master will decrease coverage by 0.5%.
The diff coverage is 88.4%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1309     +/-   ##
========================================
- Coverage    84.6%     84%   -0.6%     
========================================
  Files          86      85      -1     
  Lines       15705   15491    -214     
========================================
- Hits        13291   13024    -267     
- Misses       2414    2467     +53
Impacted Files Coverage Δ
auto_tests/conference_test.c 99.3% <100%> (ø) ⬆️
toxcore/tox.c 65% <83.3%> (+0.8%) ⬆️
toxcore/group.c 91.5% <86.8%> (-0.3%) ⬇️
toxcore/crypto_core_test.cc 90.3% <0%> (-9.7%) ⬇️
toxcore/state.c 66.6% <0%> (-7.4%) ⬇️
toxav/audio.c 65.7% <0%> (-4.1%) ⬇️
toxcore/tox_api.c 61.2% <0%> (-3.6%) ⬇️
toxcore/ping_array.c 91.9% <0%> (-3.3%) ⬇️
toxcore/TCP_client.c 62.3% <0%> (-2.4%) ⬇️
toxcore/TCP_server.c 80.3% <0%> (-2.4%) ⬇️
... and 59 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d26b11d...306dd1f. Read the comment docs.

Copy link
Author

@zugz zugz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 approvals obtained (waiting on @nurupo and @sudden6)


auto_tests/conference_test.c, line 168 at r1 (raw file):

Previously, sudden6 wrote…

This test seems to only test the function that sets the limit, but doesn't actually check if the limit is enforced, right? I think testing for the later is the most important part of this PR, no?

Done. Which did turn up a bug (is_friend wasn't being set on loaded peers), so good call.


toxcore/group.c, line 781 at r1 (raw file):

Previously, nurupo wrote…

The function is called remove_old_frozen, which implies some kind of deallocation. If it doesn't actually deallocate any memory, perhaps it should be renamed more appropriately, like trim_frozen or something, idk, I'm horrible at naming things.

deallocates now


toxcore/group.c, line 789 at r1 (raw file):

Previously, sudden6 wrote…

Why is the now unused memory not freed?

Right, we could be calling this as a result of reducing the max with the aim of freeing memory. Done.


toxcore/group.c, line 1293 at r1 (raw file):

Previously, nurupo wrote…

Shouldn't the g->frozen array be resized to make sure it can fit the requested maxfrozen?

I don't think so. It's just a limit, returning success isn't a guarantee that the memory will actually be available. I don't think we want to reserve the memory, quite possibly needlessly, just to be able to make that guarantee.


toxcore/group.c, line 3306 at r1 (raw file):

Previously, sudden6 wrote…

shouldn't we trim the list here using remove_old_frozen()?

No, that wouldn't do anything.

Copy link

@sudden6 sudden6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 6 files at r1.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @nurupo and @zugz)


toxcore/group.c, line 3306 at r1 (raw file):

Previously, zugz (zugz) wrote…

No, that wouldn't do anything.

Why not? Imagine the following scenario: Client A saves a conference with 200 numfrozen peers, now Client B loads this .tox save
and never reduces the file size to the intended maximum (default 128). IMO that's not the desired outcome?

Copy link
Author

@zugz zugz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @nurupo and @sudden6)


toxcore/group.c, line 3306 at r1 (raw file):

Previously, sudden6 wrote…

Why not? Imagine the following scenario: Client A saves a conference with 200 numfrozen peers, now Client B loads this .tox save
and never reduces the file size to the intended maximum (default 128). IMO that's not the desired outcome?

That was intended. The alternative is to throw away information that's in the save file. I don't think that should happen unless it's explicitly asked for by resetting the maximum. There's also the problem that, currently, we can't increase the maximum until after the group is loaded, at which point it's too late.

Copy link

@sudden6 sudden6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 2 files at r2.
Reviewable status: 0 of 1 approvals obtained (waiting on @nurupo)


toxcore/group.c, line 3306 at r1 (raw file):

Previously, zugz (zugz) wrote…

That was intended. The alternative is to throw away information that's in the save file. I don't think that should happen unless it's explicitly asked for by resetting the maximum. There's also the problem that, currently, we can't increase the maximum until after the group is loaded, at which point it's too late.

ok, with that reasoning it makes sense.

Copy link

@sudden6 sudden6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm_strong: from my side

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @nurupo)

@sudden6
Copy link

sudden6 commented Mar 9, 2019

@nurupo what's your state on this? If there are no further issues, I'll go ahead an merge it.

Copy link
Member

@nurupo nurupo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @nurupo and @zugz)


toxcore/group.c, line 789 at r2 (raw file):

    qsort(g->frozen, g->numfrozen, sizeof(Group_Peer), cmp_frozen);

    g->numfrozen = g->maxfrozen;

You should update g->numfrozen after you actually shrunk the array, so I suggest to move this assignment to right after the if-statement and accordingly change g->numfrozen to g->maxfrozen in the realloc. The reasoning is that if realloc does fail and the function returns early, this g->numfrozen = g->maxfrozen; causes an inconsistent state, you basically say "hey, this array is 10 items less now!" but then you failed to remove those 10 items.


toxcore/group.c, line 791 at r2 (raw file):

    g->numfrozen = g->maxfrozen;

    Group_Peer *temp = (Group_Peer *)realloc(g->frozen, sizeof(Group_Peer) * g->numfrozen);

Just to make sure, can the 2nd arg here ever be 0? Because realloc() with new size being 0 is an undefined behavior.


toxcore/group.c, line 3312 at r2 (raw file):

            data += peer->nick_len;

            // XXX: this relies on friends being loaded before conferences.

What's "XXX"?

@zugz
Copy link
Author

zugz commented Mar 17, 2019 via email

@zugz
Copy link
Author

zugz commented Mar 17, 2019 via email

Copy link
Member

@nurupo nurupo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r3.
Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @zugz)

@nurupo
Copy link
Member

nurupo commented Apr 5, 2019

Looks good to me. At least just the the code you have added, when considered locally as in the diff. Can't say anything about the global picture, about how it ties in with the whole conferences thing, if the changes you have made are complete and are done right, since I'm not familiar with conferences code.

@zugz
Copy link
Author

zugz commented Apr 6, 2019 via email

Copy link
Member

@nurupo nurupo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @zugz)


toxcore/group.c, line 831 at r4 (raw file):

    }

    ++g->numfrozen;

Shouldn't that increment be above the if-statement? Otherwise you grow g->frozen by one but don't increment g->numfrozen accordingly.

@zugz
Copy link
Author

zugz commented Apr 7, 2019 via email

Copy link
Member

@nurupo nurupo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so you don't track the size of the array. I guess this makes sense.

Reviewed 4 of 6 files at r1, 2 of 2 files at r4.
Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @zugz)

@zugz zugz mentioned this pull request May 4, 2019
Copy link

@sudden6 sudden6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed again, :lgtm_strong: ping @robinli to merge

Reviewed 1 of 2 files at r4, 1 of 1 files at r5.
Reviewable status: :shipit: complete! 2 of 1 approvals obtained (waiting on @zugz)

@sudden6
Copy link

sudden6 commented May 19, 2019

@zugz I think you need to rebase this on master in order to get CI fixed.

@robinlinden robinlinden merged commit 306dd1f into TokTok:master May 20, 2019
@robinlinden robinlinden added this to the v0.2.10 milestone May 20, 2019
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Persistent conference's offline peer list always grows and never decreases
4 participants