diff options
author | irungentoo <irungentoo@gmail.com> | 2014-11-04 20:59:56 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-11-04 20:59:56 -0500 |
commit | 54beaa485449b70c282e759b4ae81ab759b2bc37 (patch) | |
tree | f696d42f17101a4704ba19d0ebb9b40e91952c16 /toxcore | |
parent | 1f4b061a4c2f9dcc68b3fd7b88a191eb270ec0bd (diff) |
Some initial groupchat lossy packet code.
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.h | 2 | ||||
-rw-r--r-- | toxcore/group.c | 48 |
2 files changed, 46 insertions, 4 deletions
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 372c9785..fd4646e9 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -63,7 +63,7 @@ | |||
63 | #define PACKET_ID_ONLINE_PACKET 97 | 63 | #define PACKET_ID_ONLINE_PACKET 97 |
64 | #define PACKET_ID_DIRECT_GROUPCHAT 98 | 64 | #define PACKET_ID_DIRECT_GROUPCHAT 98 |
65 | #define PACKET_ID_MESSAGE_GROUPCHAT 99 | 65 | #define PACKET_ID_MESSAGE_GROUPCHAT 99 |
66 | 66 | #define PACKET_ID_LOSSY_GROUPCHAT 199 | |
67 | 67 | ||
68 | /* Max number of tcp relays sent to friends */ | 68 | /* Max number of tcp relays sent to friends */ |
69 | #define MAX_SHARED_RELAYS 16 | 69 | #define MAX_SHARED_RELAYS 16 |
diff --git a/toxcore/group.c b/toxcore/group.c index 0b77e013..636803fb 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -577,6 +577,7 @@ static int handle_status(void *object, int friendcon_id, uint8_t status) | |||
577 | } | 577 | } |
578 | 578 | ||
579 | static int handle_packet(void *object, int friendcon_id, uint8_t *data, uint16_t length); | 579 | static int handle_packet(void *object, int friendcon_id, uint8_t *data, uint16_t length); |
580 | static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length); | ||
580 | 581 | ||
581 | /* Add friend to group chat. | 582 | /* Add friend to group chat. |
582 | * | 583 | * |
@@ -614,8 +615,8 @@ static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, int groupnu | |||
614 | g->close[ind].number = friendcon_id; | 615 | g->close[ind].number = friendcon_id; |
615 | g->close[ind].closest = closest; | 616 | g->close[ind].closest = closest; |
616 | //TODO | 617 | //TODO |
617 | friend_connection_callbacks(g_c->m->fr_c, friendcon_id, GROUPCHAT_CALLBACK_INDEX, &handle_status, &handle_packet, 0, | 618 | friend_connection_callbacks(g_c->m->fr_c, friendcon_id, GROUPCHAT_CALLBACK_INDEX, &handle_status, &handle_packet, |
618 | g_c, friendcon_id); | 619 | &handle_lossy, g_c, friendcon_id); |
619 | 620 | ||
620 | return ind; | 621 | return ind; |
621 | } | 622 | } |
@@ -1036,7 +1037,8 @@ static void handle_friend_invite_packet(Messenger *m, int32_t friendnumber, cons | |||
1036 | return; | 1037 | return; |
1037 | 1038 | ||
1038 | uint16_t peer_number = rand(); /* TODO: what if two people enter the group at the same time and | 1039 | uint16_t peer_number = rand(); /* TODO: what if two people enter the group at the same time and |
1039 | are given the same peer_number by different nodes? */ | 1040 | are given the same peer_number by different nodes? */ |
1041 | |||
1040 | unsigned int tries = 0; | 1042 | unsigned int tries = 0; |
1041 | 1043 | ||
1042 | while (get_peer_index(g, peer_number) != -1) { | 1044 | while (get_peer_index(g, peer_number) != -1) { |
@@ -1483,6 +1485,7 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const | |||
1483 | if (peer_number == kill_peer_number) { | 1485 | if (peer_number == kill_peer_number) { |
1484 | delpeer(g_c, groupnumber, index); | 1486 | delpeer(g_c, groupnumber, index); |
1485 | } else { | 1487 | } else { |
1488 | return; | ||
1486 | //TODO | 1489 | //TODO |
1487 | } | 1490 | } |
1488 | } | 1491 | } |
@@ -1577,6 +1580,45 @@ static int handle_packet(void *object, int friendcon_id, uint8_t *data, uint16_t | |||
1577 | return 0; | 1580 | return 0; |
1578 | } | 1581 | } |
1579 | 1582 | ||
1583 | static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length) | ||
1584 | { | ||
1585 | Group_Chats *g_c = object; | ||
1586 | |||
1587 | if (length < 1 + sizeof(uint16_t) + sizeof(uint16_t) + 1) | ||
1588 | return -1; | ||
1589 | |||
1590 | if (data[0] != PACKET_ID_LOSSY_GROUPCHAT) | ||
1591 | return -1; | ||
1592 | |||
1593 | uint16_t groupnumber, peer_number; | ||
1594 | memcpy(&groupnumber, data + 1, sizeof(uint16_t)); | ||
1595 | memcpy(&peer_number, data + 1 + sizeof(uint16_t), sizeof(uint16_t)); | ||
1596 | groupnumber = ntohs(groupnumber); | ||
1597 | peer_number = ntohs(peer_number); | ||
1598 | |||
1599 | Group_c *g = get_group_c(g_c, groupnumber); | ||
1600 | |||
1601 | if (!g) | ||
1602 | return -1; | ||
1603 | |||
1604 | int index = friend_in_close(g, friendcon_id); | ||
1605 | |||
1606 | if (index == -1) | ||
1607 | return -1; | ||
1608 | |||
1609 | int peer_index = get_peer_index(g, peer_number); | ||
1610 | |||
1611 | if (peer_index == -1) | ||
1612 | return -1; | ||
1613 | |||
1614 | const uint8_t *lossy_data = data + 1 + sizeof(uint16_t) * 2; | ||
1615 | uint16_t lossy_length = length - (1 + sizeof(uint16_t) * 2); | ||
1616 | uint8_t message_id = lossy_data[0]; | ||
1617 | ++lossy_data; | ||
1618 | --lossy_length; | ||
1619 | return 0; | ||
1620 | } | ||
1621 | |||
1580 | /* Interval in seconds to send ping messages */ | 1622 | /* Interval in seconds to send ping messages */ |
1581 | #define GROUP_PING_INTERVAL 30 | 1623 | #define GROUP_PING_INTERVAL 30 |
1582 | 1624 | ||