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

Make saving and loading the responsibility of Tox rather than Messenger #1213

Merged
merged 1 commit into from
Oct 20, 2018

Conversation

zugz
Copy link

@zugz zugz commented Sep 27, 2018

This change is Reviewable

@zugz zugz added this to the v0.2.x milestone Sep 27, 2018
const size_t save_size1 = tox_get_savedata_size(tox2);
ck_assert_msg(save_size1 != 0, "save is invalid size %u", (unsigned)save_size1);
printf("%u\n", (unsigned)save_size1);
VLA(uint8_t, save1, save_size1);
tox_get_savedata(tox2, save1);
VLA(uint8_t, buffer, save_size1 + 2 * extra);
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps while you're changing this code already, remove the vla and use malloc/free?

toxcore/group.h Outdated
/* Save the conferences in data (must be allocated memory of size at least conferences_size()) */
uint8_t *conferences_save(const Group_Chats *g_c, uint8_t *data);

/* Load a section.
Copy link
Member

Choose a reason for hiding this comment

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

/**
 * Load a section.
 *
 * @...

toxcore/state.c Show resolved Hide resolved
@zugz zugz force-pushed the saveInTox branch 4 times, most recently from f1c0e13 to 9038ec4 Compare September 28, 2018 16:53
@codecov
Copy link

codecov bot commented Sep 28, 2018

Codecov Report

Merging #1213 into master will decrease coverage by <.1%.
The diff coverage is 92.8%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1213     +/-   ##
========================================
- Coverage    83.1%     83%   -0.1%     
========================================
  Files          82      82             
  Lines       14694   14683     -11     
========================================
- Hits        12218   12196     -22     
- Misses       2476    2487     +11
Impacted Files Coverage Δ
auto_tests/messenger_test.c 85.8% <ø> (-1.5%) ⬇️
toxcore/group.c 76.2% <100%> (+0.1%) ⬆️
toxcore/DHT.c 76.8% <100%> (ø) ⬆️
toxcore/Messenger.c 86.8% <100%> (-0.1%) ⬇️
toxcore/state.c 56.4% <50%> (-4.8%) ⬇️
toxcore/tox.c 66.7% <93.9%> (+1%) ⬆️
toxav/msi.c 64.8% <0%> (-0.9%) ⬇️
toxcore/onion_client.c 95.3% <0%> (-0.7%) ⬇️
toxav/toxav.c 68.1% <0%> (-0.5%) ⬇️
toxcore/friend_connection.c 93.1% <0%> (-0.3%) ⬇️
... and 6 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 aa5c782...744dc2f. Read the comment docs.

@zugz zugz force-pushed the saveInTox branch 2 times, most recently from b50824f to 4d084e7 Compare September 29, 2018 06:41
@zugz
Copy link
Author

zugz commented Sep 29, 2018 via email

toxcore/tox.c Outdated
memcpy(data32, data, sizeof(uint32_t));
lendian_bytes_to_host32(data32 + 1, data + sizeof(uint32_t));

if (!data32[0] && (data32[1] == STATE_COOKIE_GLOBAL)) {
Copy link
Member

Choose a reason for hiding this comment

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

Replace !num with num == 0 when num is an integer, not a bool. Also, would it make sense to return -1 on the inverted condition, considering it an error return, and returning the success/failure of state_load at the end of the function?

toxcore/tox.c Outdated
}

void tox_get_savedata(const Tox *tox, uint8_t *savedata)
void tox_get_savedata(const Tox *tox, uint8_t *data)
Copy link
Member

@iphydf iphydf Oct 7, 2018

Choose a reason for hiding this comment

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

Why did you rename savedata to data? Now the .c and .h files are out of sync. If you want to use the name "data" in the function, you can assign savedata to data (which may not be such a bad idea anyway, since it avoids assigning to parameters).

Copy link
Member

@iphydf iphydf left a comment

Choose a reason for hiding this comment

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

I need to leave a comment, I can't just put comments on the code without also putting a comment in this box, so here is a comment. Thanks Github.

@iphydf
Copy link
Member

iphydf commented Oct 16, 2018

Can you rebase or merge upstream/master?

@zugz
Copy link
Author

zugz commented Oct 17, 2018 via email

Copy link
Member

@iphydf iphydf 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)


auto_tests/messenger_test.c, line 268 at r3 (raw file):

END_TEST

/* This test is disabled, because saving is now handled by Tox rather than Messenger. */

Is there value in keeping this test around but commented out? Are you planning to delete or revive it in the future?


testing/Messenger_test.c, line 137 at r3 (raw file):

    }

    /* Loading disabled, because loading is now handled by Tox rather than Messenger */

Should this also be deleted instead of commented out?


toxcore/group.h, line 457 at r1 (raw file):

Previously, iphydf wrote…
/**
 * Load a section.
 *
 * @...

Done. (comment on behalf of zugz)


toxcore/state.h, line 25 at r3 (raw file):

#define TOP_STATE_COOKIE_TYPE  0x01ce

typedef enum Top_State_Type {

State_Type, otherwise it's not in the module namespace of module "state", but instead in the namespace of module "top", which we don't have.

Separately, this is not a great place for this enum to live, but I don't have a better suggestion, so let's keep it here for now.


toxcore/state.c, line 109 at r1 (raw file):

Previously, zugz (zugz) wrote…

Hmm... I wouldn't know how best to do it, and I understand we intend to redo saving completely eventually. So I'd rather defer.

Ok, the way you do it is by serialising the integer instead of memcpying it into a byte array. I'm fine with deferring.


toxcore/tox.c, line 368 at r2 (raw file):

Previously, iphydf wrote…

Replace !num with num == 0 when num is an integer, not a bool. Also, would it make sense to return -1 on the inverted condition, considering it an error return, and returning the success/failure of state_load at the end of the function?

Done (comment on behalf of zugz).


toxcore/tox.c, line 604 at r2 (raw file):

Previously, iphydf wrote…

Why did you rename savedata to data? Now the .c and .h files are out of sync. If you want to use the name "data" in the function, you can assign savedata to data (which may not be such a bad idea anyway, since it avoids assigning to parameters).

Done (comment on behalf of zugz).


auto_tests/save_load_test.c, line 100 at r1 (raw file):

Previously, iphydf wrote…

Perhaps while you're changing this code already, remove the vla and use malloc/free?

Done (in separate PR).

@zugz
Copy link
Author

zugz commented Oct 17, 2018 via email

Copy link
Member

@iphydf iphydf 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:

Reviewable status: 1 change requests, 0 of 1 approvals obtained


auto_tests/messenger_test.c, line 268 at r3 (raw file):

Previously, iphydf wrote…

Is there value in keeping this test around but commented out? Are you planning to delete or revive it in the future?

Done (comment on behalf of zugz).


testing/Messenger_test.c, line 137 at r3 (raw file):

Previously, zugz (zugz) wrote…

testing/Messenger_test.c, line 137 at r3 (raw file): > C > } > > /* Loading disabled, because loading is now handled by Tox rather than Messenger */ >

Should this also be deleted instead of commented out?

I'd rather leave it, in case someone one day wants to adapt it.

Done the rest. I can fire up reviewables to say so there if that would really be helpful. I looked again, and the loading code in Messenger_test is trivial enough that actually I don't think there's much point keeping it around. I've deleted it now.

Done (comment on behalf of zugz).


toxcore/state.h, line 25 at r3 (raw file):

Previously, iphydf wrote…

State_Type, otherwise it's not in the module namespace of module "state", but instead in the namespace of module "top", which we don't have.

Separately, this is not a great place for this enum to live, but I don't have a better suggestion, so let's keep it here for now.

Done (comment on behalf of zugz).

@zugz zugz merged commit 744dc2f into TokTok:master Oct 20, 2018
@zugz zugz deleted the saveInTox branch October 20, 2018 11:40
@robinlinden robinlinden modified the milestones: v0.2.x, v0.2.9 Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants