-
Notifications
You must be signed in to change notification settings - Fork 296
Add toxcore capabilities to "online" packet sent to friends #1033
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
Conversation
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.
Would you mind writing a better commit description and name for this?
Reviewable status: 0 of 2 LGTMs obtained (waiting on @zugz and @robinlinden)
toxcore/Messenger.c, line 2177 at r1 (raw file):
/* get capabilities of friend's toxcore * return TOX_CAPABILITY_BASIC on any error
I don't like that. The function should turn an error code in case of any error, and let the caller decide whether or not to assume TOX_COMPATIBILITY_BASIC. People that call this function will have no idea if there was an error code or their compatibility is really basic.
toxcore/Messenger.c
Outdated
|
||
write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, | ||
m->friendlist[friendnumber].friendcon_id), buf, TOX_CAPABILITIES_SIZE + 1, 0); | ||
// TODO: what to do if res == -1 ? |
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.
Probably return -1.
@@ -2157,6 +2173,23 @@ static int m_handle_status(void *object, int i, uint8_t status, void *userdata) | |||
return 0; | |||
} | |||
|
|||
/* get capabilities of friend's toxcore | |||
* return TOX_CAPABILITY_BASIC on any error |
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.
That's a surprising error behaviour. If the friend doesn't exist, you say that they have basic capabilities. In fact they have no capabilities at all.
toxcore/Messenger.c
Outdated
if (packet_id == PACKET_ID_ONLINE && len == 1) { | ||
if (packet_id == PACKET_ID_ONLINE) { | ||
|
||
if ((len >= 1) && (len == TOX_CAPABILITIES_SIZE)) { |
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.
Remove superfluous ().
toxcore/Messenger.c
Outdated
if (packet_id == PACKET_ID_ONLINE) { | ||
|
||
if ((len >= 1) && (len == TOX_CAPABILITIES_SIZE)) { | ||
uint64_t received_caps = TOX_CAPABILITY_BASIC; |
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.
Dead store.
toxcore/Messenger.c
Outdated
@@ -2169,7 +2202,14 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le | |||
uint32_t data_length = len - 1; | |||
|
|||
if (m->friendlist[i].status != FRIEND_ONLINE) { | |||
if (packet_id == PACKET_ID_ONLINE && len == 1) { | |||
if (packet_id == PACKET_ID_ONLINE) { | |||
|
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.
Remove empty line.
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.
The line is removed, read the line numbers, github is just weird.
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.
Line 2206 is an empty line. I checked in my editor on the actual file.
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.
Ohhhhhhhh that line
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 2 LGTMs obtained (waiting on @zugz and @robinlinden)
toxcore/Messenger.h, line 76 at r1 (raw file):
Previously, iphydf wrote…
The size of a capabilities packet is 1 + sizeof(uint64_t).
The size of the capabilities byte is sizeof(uint64_t) though, so this definition is correct. He correctly adds one later on when specifying the packet size.
If you want he could create another definition detailing the packet size or rename this macro to something else
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: 2 change requests, 0 of 1 approvals obtained (waiting on @zoff99, @iphydf, @zugz, and @robinlinden)
toxcore/Messenger.h, line 76 at r1 (raw file):
Previously, zoff99 (Zoff) wrote…
but the pure data size of the capabilties is sizeof(uint64_t)
Done.
toxcore/Messenger.c, line 2177 at r1 (raw file):
Previously, hugbubby wrote…
I don't like that. The function should turn an error code in case of any error, and let the caller decide whether or not to assume TOX_COMPATIBILITY_BASIC. People that call this function will have no idea if there was an error code or their compatibility is really basic.
its not an API function. also there is no error (code).
if something does not work, whatever it is then we must assume the "current status" meaning we have no special capabilities
toxcore/Messenger.c, line 2177 at r1 (raw file):
Previously, iphydf wrote…
That's a surprising error behaviour. If the friend doesn't exist, you say that they have basic capabilities. In fact they have no capabilities at all.
i think thats sort of correct. if we dont get the new capabilties we must assume the status as in <=0.2.4
what else would you do?
toxcore/Messenger.c, line 2206 at r1 (raw file):
Previously, hugbubby wrote…
Ohhhhhhhh that line
Done.
toxcore/Messenger.c, line 2207 at r1 (raw file):
Previously, iphydf wrote…
Remove superfluous ().
Done.
toxcore/Messenger.c, line 2208 at r1 (raw file):
Previously, iphydf wrote…
Dead store.
my C knowledge is not that firm. can i just use a define as pointer?
net_unpack_u64(data, &TOX_CAPABILITY_BASIC);
not sure if that works?
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: 2 change requests, 0 of 1 approvals obtained (waiting on @hugbubby, @zoff99, @iphydf, @zugz, and @robinlinden)
toxcore/Messenger.c, line 170 at r1 (raw file):
Previously, iphydf wrote…
Probably return -1.
does the caller of send_online_packet() handle that correctly?
maybe we need more measures here. it could result in a horrible loop:
send new online packet -> error -> return -1
caller calls again now send "old" online packet -> error -> return -1
caller calls again now send new online packet -> error -> return -1
...
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: 2 change requests, 0 of 1 approvals obtained (waiting on @zoff99, @iphydf, @zugz, and @robinlinden)
toxcore/Messenger.c, line 2177 at r1 (raw file):
Previously, zoff99 (Zoff) wrote…
its not an API function. also there is no error (code).
if something does not work, whatever it is then we must assume the "current status" meaning we have no special capabilities
no "people" will be calling this function.
thats the point, its not allowed to decide the value. it must be set by strict rules in toxcore.
the value is hardcoded in each version / branch of toxcore sourcecode. it's not changed at runtime
maybe later we will add client capabilities aswell, then that's correct.
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 2 LGTMs obtained (waiting on @zugz and @robinlinden)
toxcore/Messenger.c, line 2208 at r1 (raw file):
Previously, zoff99 (Zoff) wrote…
my C knowledge is not that firm. can i just use a define as pointer?
net_unpack_u64(data, &TOX_CAPABILITY_BASIC);
not sure if that works?
Remove the initialisation. received_caps
is initialised by net_unpack_u64
.
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 2 LGTMs obtained (waiting on @zugz and @robinlinden)
toxcore/Messenger.c, line 2177 at r1 (raw file):
Previously, zoff99 (Zoff) wrote…
i think thats sort of correct. if we dont get the new capabilties we must assume the status as in <=0.2.4
what else would you do?
Error and handle it in the caller. The logic is the same, but the location is different.
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 2 LGTMs obtained (waiting on @zugz and @robinlinden)
toxcore/Messenger.c, line 2208 at r1 (raw file):
Previously, iphydf wrote…
Remove the initialisation.
received_caps
is initialised bynet_unpack_u64
.
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: 0 of 2 LGTMs obtained (waiting on @zugz and @robinlinden)
toxcore/Messenger.c, line 2177 at r1 (raw file):
Previously, iphydf wrote…
Error and handle it in the caller. The logic is the same, but the location is different.
i don't think this is correct in this case.
what would an error mean actually?
you can't ask to receive the packet again.
you can't do anything.
either you get capabilities or it's "BASIC"
the only real error is "friend not valid" but even then i am not sure.
also with -1 as error you cant give the result back (doesnt fit in uint64_t)
What is the purpose of the TOX_CAPABILITY_BASIC flag? What does it mean
if it is set to false?
I don't think we should actually reserve flags for anything yet where we
can't specify exactly what it will mean, as is the case at least for the
PGC flag.
Separately: perhaps it would make sense to reserve the first bit for
future expansion - if it's set, it means "ignore this bitmap, and look
instead at the successor method of specifying capabilities" (whatever
that turns out to be).
|
add comment of int64_t to int conversion
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.
fixed both things
Reviewable status: 0 of 2 LGTMs obtained (waiting on @zugz and @robinlinden)
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 2 LGTMs obtained (waiting on @zugz and @robinlinden)
toxcore/Messenger.c, line 170 at r1 (raw file):
Previously, zoff99 (Zoff) wrote…
does the caller of send_online_packet() handle that correctly?
maybe we need more measures here. it could result in a horrible loop:
send new online packet -> error -> return -1
caller calls again now send "old" online packet -> error -> return -1
caller calls again now send new online packet -> error -> return -1
...
Done.
@iphydf |
Codecov Report
@@ Coverage Diff @@
## master #1033 +/- ##
========================================
Coverage ? 82.9%
========================================
Files ? 82
Lines ? 14697
Branches ? 0
========================================
Hits ? 12195
Misses ? 2502
Partials ? 0
Continue to review full report at Codecov.
|
add TOX_CAPABILITY_CAPABILITIES as new default
(in case of a future bug *mocking* reserved)
This change is