-
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
Changes from 5 commits
37e7e64
257fedc
4547372
374d5fd
8ca9e08
0b7c473
63ca9fe
3ded7ba
f16015e
5572a77
47f6e3f
1c1f80e
8b944a9
273dd1f
60c64af
d8575ad
c90438e
2858d31
c0f7a40
5e6b3ae
3b510e3
44f48ee
cf926ba
94f0785
0088abd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,16 +152,30 @@ void getaddress(const Messenger *m, uint8_t *address) | |
memcpy(address + CRYPTO_PUBLIC_KEY_SIZE + sizeof(nospam), &checksum, sizeof(checksum)); | ||
} | ||
|
||
/* | ||
* -- CAPABILITIES -- | ||
*/ | ||
static int send_online_packet(Messenger *m, int32_t friendnumber) | ||
{ | ||
if (friend_not_valid(m, friendnumber)) { | ||
return 0; | ||
} | ||
|
||
uint8_t buf[TOX_CAPABILITIES_SIZE + 1]; | ||
buf[0] = PACKET_ID_ONLINE; | ||
net_pack_u64(buf + 1, TOX_CAPABILITIES_CURRENT); | ||
|
||
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 ? | ||
|
||
uint8_t packet = PACKET_ID_ONLINE; | ||
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, | ||
m->friendlist[friendnumber].friendcon_id), &packet, sizeof(packet), 0) != -1; | ||
} | ||
/* | ||
* -- CAPABILITIES -- | ||
*/ | ||
|
||
static int send_offline_packet(Messenger *m, int friendcon_id) | ||
{ | ||
|
@@ -183,6 +197,7 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta | |
} | ||
|
||
memset(&m->friendlist[m->numfriends], 0, sizeof(Friend)); | ||
m->friendlist[m->numfriends].toxcore_capabilities = TOX_CAPABILITY_BASIC; | ||
|
||
int friendcon_id = new_friend_connection(m->fr_c, real_pk); | ||
|
||
|
@@ -202,6 +217,7 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta | |
m->friendlist[i].userstatus = USERSTATUS_NONE; | ||
m->friendlist[i].is_typing = 0; | ||
m->friendlist[i].message_id = 0; | ||
m->friendlist[i].toxcore_capabilities = TOX_CAPABILITY_BASIC; | ||
friend_connection_callbacks(m->fr_c, friendcon_id, MESSENGER_CALLBACK_INDEX, &m_handle_status, &m_handle_packet, | ||
&m_handle_lossy_packet, m, i); | ||
|
||
|
@@ -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 commentThe 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. |
||
*/ | ||
uint64_t m_get_friend_toxcore_capabilities(const Messenger *m, int32_t friendnumber) | ||
{ | ||
if (friend_not_valid(m, friendnumber)) { | ||
return TOX_CAPABILITY_BASIC; | ||
} | ||
|
||
// TODO: maybe also return the value for OFFLINE friends? | ||
if (m->friendlist[friendnumber].status == FRIEND_ONLINE) { | ||
return m->friendlist[friendnumber].toxcore_capabilities; | ||
} | ||
|
||
return TOX_CAPABILITY_BASIC; | ||
} | ||
|
||
static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t len, void *userdata) | ||
{ | ||
if (len == 0) { | ||
|
@@ -2169,7 +2202,13 @@ 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) { | ||
if (len == TOX_CAPABILITIES_SIZE) { | ||
uint64_t received_caps = TOX_CAPABILITY_BASIC; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead store. |
||
net_unpack_u64(data, &received_caps); | ||
m->friendlist[i].toxcore_capabilities = received_caps; | ||
} | ||
|
||
set_friend_status(m, i, FRIEND_ONLINE, userdata); | ||
send_online_packet(m, i); | ||
} 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.
Probably return -1.