summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Messenger.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/core/Messenger.c b/core/Messenger.c
index ae7c5ff3..2787193e 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -114,8 +114,15 @@ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
114 return FAERR_NOMESSAGE; 114 return FAERR_NOMESSAGE;
115 if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) 115 if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0)
116 return FAERR_OWNKEY; 116 return FAERR_OWNKEY;
117 if (getfriend_id(m, client_id) != -1) 117 int friend_id = getfriend_id(m, client_id);
118 return FAERR_ALREADYSENT; 118 if (friend_id != -1) {
119 uint32_t nospam;
120 memcpy(&nospam, address + crypto_box_PUBLICKEYBYTES, sizeof(uint32_t));
121 if(m->friendlist[friend_id].friendrequest_nospam == nospam)
122 return FAERR_ALREADYSENT;
123 m->friendlist[friend_id].friendrequest_nospam = nospam;
124 return FAERR_ALREADYSENT; /*TODO: decide what to return when updating the nospam of a friend*/
125 }
119 126
120 /* resize the friend list if necessary */ 127 /* resize the friend list if necessary */
121 realloc_friendlist(m, m->numfriends + 1); 128 realloc_friendlist(m, m->numfriends + 1);
@@ -730,6 +737,9 @@ void Messenger_save(Messenger *m, uint8_t *data)
730{ 737{
731 save_keys(data); 738 save_keys(data);
732 data += crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES; 739 data += crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
740 uint32_t nospam = get_nospam();
741 memcpy(data, &nospam, sizeof(nospam));
742 data += sizeof(nospam);
733 uint32_t size = DHT_size(); 743 uint32_t size = DHT_size();
734 memcpy(data, &size, sizeof(size)); 744 memcpy(data, &size, sizeof(size));
735 data += sizeof(size); 745 data += sizeof(size);
@@ -746,11 +756,15 @@ int Messenger_load(Messenger *m, uint8_t * data, uint32_t length)
746{ 756{
747 if (length == ~0) 757 if (length == ~0)
748 return -1; 758 return -1;
749 if (length < crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t) * 2) 759 if (length < crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t) * 3)
750 return -1; 760 return -1;
751 length -= crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t) * 2; 761 length -= crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t) * 3;
752 load_keys(data); 762 load_keys(data);
753 data += crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES; 763 data += crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
764 uint32_t nospam;
765 memcpy(&nospam, data, sizeof(nospam));
766 set_nospam(nospam);
767 data += sizeof(nospam);
754 uint32_t size; 768 uint32_t size;
755 memcpy(&size, data, sizeof(size)); 769 memcpy(&size, data, sizeof(size));
756 data += sizeof(size); 770 data += sizeof(size);