/* * returns a FRIEND_ADDRESS_SIZE byte address to give to others. * format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] * */ void getaddress(Messenger *m, uint8_t *address) { memcpy(address, m->net_crypto->self_public_key, crypto_box_PUBLICKEYBYTES); uint32_t nospam = get_nospam(&(m->fr)); memcpy(address + crypto_box_PUBLICKEYBYTES, &nospam, sizeof(nospam)); uint16_t checksum = address_checksum(address, FRIEND_ADDRESS_SIZE - sizeof(checksum)); memcpy(address + crypto_box_PUBLICKEYBYTES + sizeof(nospam), &checksum, sizeof(checksum)); }
/* save the messenger in data of size Messenger_size() */ void Messenger_save(Messenger *m, uint8_t *data) { save_keys(data); data += crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES; uint32_t nospam = get_nospam(); memcpy(data, &nospam, sizeof(nospam)); data += sizeof(nospam); uint32_t size = DHT_size(); memcpy(data, &size, sizeof(size)); data += sizeof(size); DHT_save(data); data += size; size = sizeof(Friend) * m->numfriends; memcpy(data, &size, sizeof(size)); data += sizeof(size); memcpy(data, m->friendlist, sizeof(Friend) * m->numfriends); data += size; uint16_t small_size = m->name_length; memcpy(data, &small_size, sizeof(small_size)); data += sizeof(small_size); memcpy(data, m->name, small_size); }
/* Functions to get/set the nospam part of the id. */ uint32_t tox_get_nospam(const Tox *tox) { const Messenger *m = tox; return get_nospam(&(m->fr)); }
/* Functions to get/set the nospam part of the id. */ uint32_t tox_get_nospam(Tox *tox) { Messenger *m = tox; return get_nospam(&(m->fr)); }