-
Notifications
You must be signed in to change notification settings - Fork 282
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 save file generator, compatibility test, and generate a savefile #1051
Conversation
dc14553
to
fcec1b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't submit the savefile in this PR. It's not used, so it serves no purpose. Once you add a test for loading it, you can submit the data for it as well.
other/save-generator.c
Outdated
int main(int argc, char *argv[]) | ||
{ | ||
if (argc < 3) { | ||
printf("Usage: ./save-generator <name> <friend id>\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could make this tool a little more versatile, maybe have some way of generating a savefile with multiple friends, groups, etc. I'm happy to have this version submitted as an initial version, but I think the interesting bits of save parsing happen when you have more than 1 of a thing.
other/save-generator.c
Outdated
#define SAVE_FILE "save.tox" | ||
#define STATUS_MESSAGE "Hello World" | ||
|
||
static const char *bootstrap_ip = "185.14.30.213"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const char *const
other/save-generator.c
Outdated
#include "../testing/misc_tools.h" | ||
#include "../toxcore/ccompat.h" | ||
|
||
#define SAVE_FILE "save.tox" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these macros and the constants below are variables?
other/save-generator.c
Outdated
while (true) { | ||
tox_iterate(tox, nullptr); | ||
|
||
if (tox_self_get_connection_status(tox) == TOX_CONNECTION_UDP) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer callbacks. This main function is quite long. Given that we'll want to extend it in the future, it's probably good to split it into a few functions.
other/save-generator.c
Outdated
} | ||
|
||
const uint8_t *name = (uint8_t *)argv[1]; | ||
bool ret = tox_self_set_name(tox, name, strlen((char *)name), nullptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer error pointers.
other/save-generator.c
Outdated
return -1; | ||
} | ||
|
||
tox_bootstrap(tox, bootstrap_ip, udp_port, key, nullptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No error checking done.
other/save-generator.c
Outdated
uint32_t friend_num = tox_friend_add(tox, address, (const uint8_t *)msg, strlen(msg), nullptr); | ||
free(address); | ||
|
||
if (friend_num == UINT32_MAX) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Friend number in case of failure is unspecified. This is relying on knowledge of internals. Prefer error enums.
other/save-generator.c
Outdated
tox_self_get_address(tox, tox_id); | ||
to_hex(tox_id_str, tox_id, TOX_ADDRESS_SIZE); | ||
|
||
char nospam_str[TOX_NOSPAM_SIZE * 2]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not enough space for the null terminator.
There was a problem hiding this 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 LGTMs obtained
other/save-generator.c, line 10 at r1 (raw file):
Previously, iphydf wrote…
Why are these macros and the constants below are variables?
Done.
other/save-generator.c, line 13 at r1 (raw file):
Previously, iphydf wrote…
const char *const
Done.
other/save-generator.c, line 37 at r1 (raw file):
Previously, iphydf wrote…
I wonder if we could make this tool a little more versatile, maybe have some way of generating a savefile with multiple friends, groups, etc. I'm happy to have this version submitted as an initial version, but I think the interesting bits of save parsing happen when you have more than 1 of a thing.
I added in adding multiple friends. I'll add in groupchats when persistent groupchats is merged.
other/save-generator.c, line 55 at r1 (raw file):
Previously, iphydf wrote…
No error checking done.
Done.
other/save-generator.c, line 61 at r1 (raw file):
Previously, iphydf wrote…
Prefer callbacks. This main function is quite long. Given that we'll want to extend it in the future, it's probably good to split it into a few functions.
Done.
other/save-generator.c, line 70 at r1 (raw file):
Previously, iphydf wrote…
Prefer error pointers.
Done.
other/save-generator.c, line 87 at r1 (raw file):
Previously, iphydf wrote…
Friend number in case of failure is unspecified. This is relying on knowledge of internals. Prefer error enums.
Done.
other/save-generator.c, line 117 at r1 (raw file):
Previously, iphydf wrote…
Not enough space for the null terminator.
I just use the length to write the nospam out same with the tox id.
I think such things should go into @iphydf Btw, I have written a bit different save file generator several weeks ago, do you think it makes sense to add it to the repo too? It doesn't use toxcore at all though, it crafts the save file using the current save file binary format, much like |
There was a problem hiding this 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 @iphydf)
other/save-generator.c, line 117 at r1 (raw file):
Previously, endoffile78 (Endoffile) wrote…
I just use the length to write the nospam out same with the tox id.
Done.
@nurupo yes, and it seems like a good idea to put these things into other/fun. |
There was a problem hiding this 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 @iphydf and @endoffile78)
other/save-generator.c, line 50 at r2 (raw file):
if (err != TOX_ERR_BOOTSTRAP_OK) { printf("Failed to bootstrap. Error number: %u", err);
Error numbers are signed ints (enum values), so %d
.
other/save-generator.c, line 89 at r2 (raw file):
printf("Name: %s.\n", name); printf("Status message: %s.\n", STATUS_MESSAGE); printf("Number of friends: %lu.\n", tox_self_get_friend_list_size(tox));
%zu
other/save-generator.c, line 133 at r2 (raw file):
} int num_friends = atoi(argv[2]);
This isn't used.
other/save-generator.c, line 138 at r2 (raw file):
uint8_t *address = hex_string_to_bin(argv[i]); Tox_Err_Friend_Add friend_err; uint32_t friend_num = tox_friend_add(tox, address, (const uint8_t *)REQUEST_MESSAGE, strlen(REQUEST_MESSAGE),
Remove dead assignment.
There was a problem hiding this 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 @iphydf)
other/save-generator.c, line 50 at r2 (raw file):
Previously, iphydf wrote…
Error numbers are signed ints (enum values), so
%d
.
Done.
other/save-generator.c, line 89 at r2 (raw file):
Previously, iphydf wrote…
%zu
Done.
other/save-generator.c, line 133 at r2 (raw file):
Previously, iphydf wrote…
This isn't used.
Done.
other/save-generator.c, line 138 at r2 (raw file):
Previously, iphydf wrote…
Remove dead assignment.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 5 files at r1, 1 of 4 files at r3.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @endoffile78)
auto_tests/data/save.tox, line 0 at r3 (raw file):
This file should be moved to a different PR where we actually use it.
other/save-generator.c, line 50 at r2 (raw file):
Previously, endoffile78 (Endoffile) wrote…
Done.
Not really.
There was a problem hiding this 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 @endoffile78)
other/fun/save-generator.c, line 137 at r3 (raw file):
if (friend_err != TOX_ERR_FRIEND_ADD_OK) { printf("Failed to add friend number %u. Error number: %d\n", i - 1, friend_err);
i
is int
, so %d
, or make i
unsigned and keep %u
.
There was a problem hiding this 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 @endoffile78)
other/fun/save-generator.c, line 3 at r3 (raw file):
#include <stdio.h> #include <string.h> #include <stdint.h>
Also sort these includes.
other/fun/save-generator.c, line 7 at r3 (raw file):
#include "../../toxcore/tox.h" #include "../../testing/misc_tools.h"
Sort includes.
There was a problem hiding this 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 @endoffile78 and @iphydf)
auto_tests/data/save.tox, line at r3 (raw file):
Previously, iphydf wrote…
This file should be moved to a different PR where we actually use it.
Added a test that uses it
other/fun/save-generator.c, line 3 at r3 (raw file):
Previously, iphydf wrote…
Also sort these includes.
Done.
other/fun/save-generator.c, line 7 at r3 (raw file):
Previously, iphydf wrote…
Sort includes.
Done.
other/fun/save-generator.c, line 137 at r3 (raw file):
Previously, iphydf wrote…
i
isint
, so%d
, or makei
unsigned and keep%u
.
Done.
There was a problem hiding this 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 @endoffile78)
auto_tests/save_compatibility_test.c, line 74 at r4 (raw file):
struct Tox_Options options; memset(&options, 0, sizeof(struct Tox_Options));
Use regular struct zero-initialisation instead of memset.
auto_tests/save_compatibility_test.c, line 94 at r4 (raw file):
uint8_t name[name_size]; tox_self_get_name(tox, name); ck_assert_msg(strncmp((char *)name, NAME, name_size) == 0, "Names do not match, expected %s got %s.", NAME, name);
const char *
auto_tests/save_compatibility_test.c, line 103 at r4 (raw file):
tox_self_get_status_message(tox, status_message); ck_assert_msg(strncmp((char *)status_message, STATUS_MESSAGE, status_message_size) == 0, "Status messages do not match, expeceted %s got %s.",
expected
auto_tests/save_compatibility_test.c, line 114 at r4 (raw file):
size_t length = snprintf(nospam_str, sizeof(nospam_str), "%08X", nospam); nospam_str[length] = '\0'; ck_assert_msg(strcmp(nospam_str, NOSPAM) == 0, "Nospam does not match, expected %s got %s.", NOSPAM, nospam_str);
Error messages here should start with lowercase and not have a "." at the end.
other/fun/save-generator.c, line 3 at r3 (raw file):
Previously, endoffile78 (Endoffile) wrote…
Done.
Not done.
other/fun/save-generator.c, line 112 at r4 (raw file):
while (!connected) { tox_iterate(tox, nullptr);
Pass &connected to tox_iterate, so it ends up in userdata for the connection callback.
There was a problem hiding this 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 @iphydf)
auto_tests/save_compatibility_test.c, line 74 at r4 (raw file):
Previously, iphydf wrote…
Use regular struct zero-initialisation instead of memset.
Done.
auto_tests/save_compatibility_test.c, line 94 at r4 (raw file):
Previously, iphydf wrote…
const char *
Done.
auto_tests/save_compatibility_test.c, line 103 at r4 (raw file):
Previously, iphydf wrote…
expected
Done.
auto_tests/save_compatibility_test.c, line 114 at r4 (raw file):
Previously, iphydf wrote…
Error messages here should start with lowercase and not have a "." at the end.
Done.
other/fun/save-generator.c, line 112 at r4 (raw file):
Previously, iphydf wrote…
Pass &connected to tox_iterate, so it ends up in userdata for the connection callback.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 4 files at r3, 1 of 3 files at r4, 2 of 2 files at r5.
Reviewable status: 1 change requests, 0 of 1 approvals obtained
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status:
complete! 1 of 1 approvals obtained (waiting on @endoffile78)
auto_tests/save_compatibility_test.c, line 67 at r5 (raw file):
*length = size; return data;
Add fclose here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the generator tool to other/fun/BUILD.bazel?
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @endoffile78)
auto_tests/save_compatibility_test.c, line 98 at r5 (raw file):
STATUS_MESSAGE_SIZE, status_message_size); uint8_t status_message[status_message_size];
You'll need to use the VLA macro here, or preferably avoid VLAs altogether. Rather malloc and free, or allocate the maximum size (from tox.h).
There was a problem hiding this 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 @endoffile78)
There was a problem hiding this 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 @iphydf)
auto_tests/save_compatibility_test.c, line 67 at r5 (raw file):
Previously, iphydf wrote…
Add fclose here.
Done.
auto_tests/save_compatibility_test.c, line 98 at r5 (raw file):
Previously, iphydf wrote…
You'll need to use the VLA macro here, or preferably avoid VLAs altogether. Rather malloc and free, or allocate the maximum size (from tox.h).
Done.
1c64bbe
to
2b17ed4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 4 files at r6.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @endoffile78)
CMakeLists.txt, line 442 at r6 (raw file):
auto_test(typing) auto_test(version) auto_test(save_compatibility)
Sort these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status:
complete! 1 of 1 approvals obtained (waiting on @iphydf)
CMakeLists.txt, line 442 at r6 (raw file):
Previously, iphydf wrote…
Sort these.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status:
complete! 1 of 1 approvals obtained (waiting on @iphydf and @endoffile78)
other/fun/BUILD.bazel, line 34 at r7 (raw file):
deps = [ "//c-toxcore/testing:misc_tools", "//c-toxcore/toxcore"
Add "," at end of line.
other/fun/BUILD.bazel, line 35 at r7 (raw file):
"//c-toxcore/testing:misc_tools", "//c-toxcore/toxcore" ]
Here too.
Try running buildifier
on this file, it'll fix these kinds of style issues.
After fixing the last style issues, rebase on master and I'll merge it. |
The save file will be used to ensure that #1046 is compatible with older save files. The output of the save generator was:
The added friend was toxirc: A922A51E1C91205B9F7992E2273107D47C72E8AE909C61C28A77A4A2A115431B14592AB38A3B.
This change is![Reviewable](https://camo.githubusercontent.com/23b05f5fb48215c989e92cc44cf6512512d083132bd3daf689867c8d9d386888/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)