summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
authorCoren[m] <Break@Ocean>2013-11-17 01:04:49 +0100
committerCoren[m] <Break@Ocean>2013-11-17 01:05:00 +0100
commitb132c92b3ae3aeee293a4e815336cac76c7cfe69 (patch)
tree1878864ea5a27d571ac758bb5ad2875f0b9460a6 /toxcore/Messenger.c
parent0d8329b3a9b16cd6089810e61ce958fde00046b8 (diff)
Assoc's array is now allocated dynamically and per default much smaller (320 entries).
id_hash() was not at all working as expected for very small bucket size (when (size / 4) was zero). Simplified to be trivially correct. Also added a used flag on adding an entry, which is set by callers if they have that association in active use. Those get priority over unused entries on collision. Fleshed out test to be at least elementary useful. Each group chat now uses an own, small assoc (80 entries).
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 49cffc98..904c3ecc 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -786,7 +786,7 @@ int add_groupchat(Messenger *m)
786 786
787 for (i = 0; i < m->numchats; ++i) { 787 for (i = 0; i < m->numchats; ++i) {
788 if (m->chats[i] == NULL) { 788 if (m->chats[i] == NULL) {
789 Group_Chat *newchat = new_groupchat(m->net, m->dht->assoc); 789 Group_Chat *newchat = new_groupchat(m->net);
790 790
791 if (newchat == NULL) 791 if (newchat == NULL)
792 return -1; 792 return -1;
@@ -805,7 +805,7 @@ int add_groupchat(Messenger *m)
805 if (temp == NULL) 805 if (temp == NULL)
806 return -1; 806 return -1;
807 807
808 temp[m->numchats] = new_groupchat(m->net, m->dht->assoc); 808 temp[m->numchats] = new_groupchat(m->net);
809 809
810 if (temp[m->numchats] == NULL) 810 if (temp[m->numchats] == NULL)
811 return -1; 811 return -1;
@@ -1821,6 +1821,18 @@ void do_messenger(Messenger *m)
1821 1821
1822 if (unix_time() > lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) { 1822 if (unix_time() > lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) {
1823 loglog(" = = = = = = = = \n"); 1823 loglog(" = = = = = = = = \n");
1824 Assoc_status(m->dht->assoc);
1825
1826 if (m->numchats > 0) {
1827 size_t c;
1828
1829 for (c = 0; c < m->numchats; c++) {
1830 loglog("---------------- \n");
1831 Assoc_status(m->chats[c]->assoc);
1832 }
1833 }
1834
1835 loglog(" = = = = = = = = \n");
1824 1836
1825 lastdump = unix_time(); 1837 lastdump = unix_time();
1826 uint32_t client, last_pinged; 1838 uint32_t client, last_pinged;
@@ -2010,7 +2022,7 @@ static int messenger_load_state_callback(void *outer, uint8_t *data, uint32_t le
2010 load_keys(m->net_crypto, &data[sizeof(uint32_t)]); 2022 load_keys(m->net_crypto, &data[sizeof(uint32_t)]);
2011 2023
2012 if (m->dht->assoc) 2024 if (m->dht->assoc)
2013 Assoc_self_client_id_changed(m->dht->assoc); 2025 Assoc_self_client_id_changed(m->dht->assoc, m->net_crypto->self_public_key);
2014 } else 2026 } else
2015 return -1; /* critical */ 2027 return -1; /* critical */
2016 2028