Skip to content

Commit

Permalink
Add messenger state plugin system.
Browse files Browse the repository at this point in the history
This is for modules like groups to hook into to have their own state
management in the `tox_savedata` format.
  • Loading branch information
iphydf authored and e0ff committed Aug 13, 2018
1 parent f1eee02 commit 41dabc9
Show file tree
Hide file tree
Showing 5 changed files with 426 additions and 212 deletions.
17 changes: 4 additions & 13 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -2811,26 +2811,16 @@ uint32_t dht_size(const DHT *dht)
return size32 + sizesubhead + packed_node_size(net_family_ipv4) * numv4 + packed_node_size(net_family_ipv6) * numv6;
}

static uint8_t *dht_save_subheader(uint8_t *data, uint32_t len, uint16_t type)
{
host_to_lendian32(data, len);
data += sizeof(uint32_t);
host_to_lendian32(data, (host_tolendian16(DHT_STATE_COOKIE_TYPE) << 16) | host_tolendian16(type));
data += sizeof(uint32_t);
return data;
}


/* Save the DHT in data where data is an array of size dht_size(). */
void dht_save(const DHT *dht, uint8_t *data)
{
host_to_lendian32(data, DHT_STATE_COOKIE_GLOBAL);
host_to_lendian32(data, DHT_STATE_COOKIE_GLOBAL);
data += sizeof(uint32_t);

uint8_t *const old_data = data;

/* get right offset. we write the actual header later. */
data = dht_save_subheader(data, 0, 0);
data = state_write_section_header(data, DHT_STATE_COOKIE_TYPE, 0, 0);

Node_format clients[MAX_SAVED_DHT_NODES];

Expand Down Expand Up @@ -2868,7 +2858,8 @@ void dht_save(const DHT *dht, uint8_t *data)
}
}

dht_save_subheader(old_data, pack_nodes(data, sizeof(Node_format) * num, clients, num), DHT_STATE_TYPE_NODES);
state_write_section_header(old_data, DHT_STATE_COOKIE_TYPE, pack_nodes(data, sizeof(Node_format) * num, clients, num),
DHT_STATE_TYPE_NODES);
}

/* Bootstrap from this number of nodes every time dht_connect_after_load() is called */
Expand Down
Loading

0 comments on commit 41dabc9

Please sign in to comment.