Skip to content

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

Closed
wants to merge 25 commits into from

Conversation

zoff99
Copy link

@zoff99 zoff99 commented Jul 27, 2018

This change is Reviewable

@zoff99 zoff99 requested review from zugz and robinlinden July 27, 2018 12:09
@zoff99 zoff99 added enhancement New feature for the user, not a new feature for build script messenger Messenger labels Jul 27, 2018
Copy link
Member

@hugbubby hugbubby left a 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.


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 ?
Copy link
Member

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
Copy link
Member

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.

if (packet_id == PACKET_ID_ONLINE && len == 1) {
if (packet_id == PACKET_ID_ONLINE) {

if ((len >= 1) && (len == TOX_CAPABILITIES_SIZE)) {
Copy link
Member

Choose a reason for hiding this comment

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

Remove superfluous ().

if (packet_id == PACKET_ID_ONLINE) {

if ((len >= 1) && (len == TOX_CAPABILITIES_SIZE)) {
uint64_t received_caps = TOX_CAPABILITY_BASIC;
Copy link
Member

Choose a reason for hiding this comment

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

Dead store.

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

Copy link
Member

Choose a reason for hiding this comment

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

Remove empty line.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

Ohhhhhhhh that line

Copy link
Member

@hugbubby hugbubby 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 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

Copy link
Author

@zoff99 zoff99 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: 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?

Copy link
Author

@zoff99 zoff99 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: 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
...

Copy link
Author

@zoff99 zoff99 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: 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.

@iphydf iphydf added this to the v0.2.x milestone Jul 28, 2018
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: 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.

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: 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.

Copy link
Author

@zoff99 zoff99 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 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 by net_unpack_u64.

Done.

Copy link
Author

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

@zugz
Copy link

zugz commented Jul 29, 2018 via email

Copy link
Author

@zoff99 zoff99 left a 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)

Copy link
Author

@zoff99 zoff99 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 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.

@zoff99
Copy link
Author

zoff99 commented Jul 30, 2018

@iphydf
error: ISO C restricts enumerator values to range of 'int'
how can i make the flags 64bit wide?

@iphydf iphydf changed the title add toxcore capabilities Add toxcore capabilities to "online" packet sent to friends Aug 4, 2018
@iphydf
Copy link
Member

iphydf commented Aug 14, 2018

@zoff99 there are open comments from @zugz.

@codecov
Copy link

codecov bot commented Nov 4, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@aa63c13). Click here to learn what that means.
The diff coverage is 80%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master   #1033   +/-   ##
========================================
  Coverage          ?   82.9%           
========================================
  Files             ?      82           
  Lines             ?   14697           
  Branches          ?       0           
========================================
  Hits              ?   12195           
  Misses            ?    2502           
  Partials          ?       0
Impacted Files Coverage Δ
toxcore/Messenger.c 86.6% <80%> (ø)

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 aa63c13...0088abd. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature for the user, not a new feature for build script messenger Messenger
Development

Successfully merging this pull request may close these issues.

5 participants