irungentoo/ProjectTox-Core — pull request #576 by FullName (2013-09-13 17:21:29+00:00)
Title: State loading/saving: Instead of a blob, segment into sections marked with tags.

Primary rationale: The part that DHT saves changes if IP is expanded to IPv6. To let people keep their friends/name, change the datafile format now, while everybody is still on the same page.

Loading/Saving rewritten to allow a part of the file to be incomprehensible to the loading routine.
Added a magic cookie at the beginning to mark the file as tox's.
Changes in some part of the datafile can be skipped and the remaining parts still be consumed.
Allows a wide margin of forward compatibility (like the IP to IPv6 transition, but also e.g. a change in the key format).
As long as the file is not garbled, the routine will read as much as possible. Only the key section is considered "special": a malformed key section (wrong size) exists immediately with a negative return code.

util.*:
- holds the driving function which jumps from section to section and calls back with section length and tag (type)

Messenger.c,DHT.*:
- new loading functions call the util-function with a callback, which subsequently consumes the sections
- old routines are kept to fall back onto if the magic cookie at the beginning isn't present
- saving is still done in one local routine
- DHT only saves those clients that will be later used at all when loading (i.e. with timestamp > 0)