Mesh networked computer terminals with RFID logon - part 5

After a chunk of work I've got file syncing working fully. The code does a simple manifest of everything on the SD card except for the irritating "System Volume Information" directory Windows puts on there if you view the card on a Windows system.

As my mesh network isn't designed to be high bandwidth and I'm not expecting the files on there to change often, this is a slow, lightweight process. After all it's only running on an ESP8266, don't expect BitTorrent.

The steps the mesh takes to sync are broadly...
  • Recursively iterate the whole file system on the SD card
  • Open each file and do a CRC16 of it
  • Store the full path and filename, size and CRC16 in a data structure
  • Write this to a simple flat file to save this across restarts. Each file is given a sequence number starting at one that increments with each change
  • Once all the files have been read, XOR all their CRC16s together and store it
  • The total number of files and this XOR of the CRC16s are advertised periodically by each node flooding the whole mesh
  • If a node receives a XOR that doesn't match its own it asks for the CRC16, size and sequence number of each file on the other node, one at a time
  • Some simple if/then/else logic decides if it needs the other node's version of the file
  • Files are transferred 64 bytes at a time in a TFTP-esque manner
  • Once the XOR and number of files match the two nodes are considered synced and stop
  • To detect change from an initially synced state, if a file is changed the new CRC16, size and sequence number are flooded to the whole mesh immediately
  • Notification of deleted files use a similar mechanism and stay in the data structure
  • There are timeouts and retries on the various steps in the process so it will fail fairly gracefully and restart
This is probably full of edge case horrors and has no way to handle file conflict resolution. I don't care, this is not an enterprise class distributed file system, it's a bunch of microcontrollers in a field that I need to have the same files on, mostly, and stay in sync, mostly.

Watch the awesome log output!


No comments: