Skip to content

Instantly share code, notes, and snippets.

@joehand
Last active April 15, 2017 01:41
Show Gist options
  • Save joehand/33c9df92c1cf3653efb906203950ff10 to your computer and use it in GitHub Desktop.
Save joehand/33c9df92c1cf3653efb906203950ff10 to your computer and use it in GitHub Desktop.
SLEEP - Hyperdrive v8 for Dat!

SLEEP

Syncable Lightweight Event Emitting Persistence

SLEEP metadata allow files to be accessed randomly, cryptographically verified, and dynamically updated. SLEEP files can be shared for easy distribution and we also specify a way to expose SLEEP over REST. The Dat project uses SLEEP to distribute data over decentralized networks securely.

Docs in progress

Our docs page on SLEEP and in progress whitepaper have a more in depth look at SLEEP, but does not reflect the recent v8 release changes. We're in the process of updating the docs.

SLEEP Files

There are six types of SLEEP files: a key, secret_key, signatures, bitfield, tree, and data. The key and secret_key files are static and all other files are append-only.There are two sets of files: one to store & verify the directory structure and file system metadata, referred to as archive.metadata), and the other to store & verify the file content (referred to as archive.content).

metadata = [
  'key',         // Public key of the archive & metadata feed
  'signatures',
  'bitfield',
  'tree',
  'data',
  'secret_key'  // Secret key of the archive allow writes (optional)
]

content = [
  'key',        // Public key of the content feed
  'signatures',
  'bitfield',
  'tree',
  'data'       // File content, usually stored as files
]

There are many ways to store the SLEEP files, including in memory using random-access-memory. For a basic usage, we may store an archive with this layout:

my-archive/
  |   readme.md
  |   cats.jpg
  \--- more-data/
      |   cats.csv
      |   dogs.txt
  \--- .dat/
      \--- metadata/
          |   key
          |   secret_key
          |   signatures
          |   bitfield
          |   tree
          |   data
      \--- content/
          |   key
          |   signatures
          |   bitfield
          |   tree

On a server, we'd store the all the files as a single, append-only data file in the content folder:

server-dats/
  \--- my-archive-backup/
      \--- metadata/
          |   key
          |   secret_key
          |   signatures
          |   bitfield
          |   tree
          |   data
      \--- content/
          |   key
          |   signatures
          |   bitfield
          |   tree
          |   data // so many cats in here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment