Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DBFS - ElixirConf EU 2018 (Lightning Talk)

DBFS - ElixirConf EU 2018 (Lightning Talk)

My lightning talk about building a naive blockchain-based file storage in Elixir and React, with scalability and distribution in mind.

Sheharyar Naseer

April 16, 2018
Tweet

More Decks by Sheharyar Naseer

Other Decks in Technology

Transcript

  1. BLOCKCHAIN BASED
    FILE STORAGE

    View Slide

  2. SHEHARYAR NASEER
    sheharyarn shyr.io

    View Slide

  3. DIDN'T HODL

    View Slide

  4. blockchain
    noun /ˈbläkˌCHān/
    A decentralized, distributed digital ledger that is
    used to record transactions across many computers
    so that the record cannot be altered retroactively
    without the alteration of all subsequent blocks [...]

    View Slide

  5. BLOCK 5
    Data:
    Timestamp:
    Previous:
    Current:
    34k0scf
    2018-01-05 13:24:56
    3662c6f8dc7b519123c
    f9d644657c3d7c80a6f
    rth760ls
    2018-01-07 18:43:12
    f9d644657c3d7c80a6f
    bbd658cb57bb0d2138
    BLOCK 6
    Data:
    Timestamp:
    Previous:
    Current:
    qnb49f0
    2018-01-08 06:11:34
    bbd658cb57bb0d2138
    8327ed293f7834c6572
    BLOCK 7
    Data:
    Timestamp:
    Previous:
    Current:

    View Slide

  6. ARCHITECTURE
    – Blockchain Structure
    – File Storage
    – Cryptography
    – Synchronization
    – Client API

    View Slide

  7. BLOCKCHAIN
    %Block{
    type: ...,
    timestamp: ...,
    data: %{
    file_name: ..., file_hash: ..., file_key: ...,
    },
    prev: ...,
    creator: ...,
    hash: ...,
    signature: ...
    }

    View Slide

  8. FILE STORAGE
    – Nothing fancy
    – Directly on the disk
    – Encrypted
    – Block hash as identifier

    View Slide

  9. CRYPTOGRAPHY
    – Public Key: RSA
    – Symmetric: AES

    View Slide

  10. CRYPTOGRAPHY
    – Public Key: RSA
    – Symmetric: AES
    – Hashing: SHA256
    – Encoding: Base64

    View Slide

  11. SYNCHRONIZATION
    – Erlang VM: Easy Distribution
    – Consensus: Raft
    – Elect 'leader'
    – Use it as a reference

    View Slide

  12. SYNCHRONIZATION
    – Find where the chain diverges
    – Send the succeeding block
    def sync_next(leader, hash) do
    %{block: block, file: file} =
    :rpc.call(leader, Blockchain, :next, [hash])
    Blockchain.insert(block, file)
    end

    View Slide

  13. CLIENT API
    – Phoenix
    – List, Upload, Download
    – Ecto Validations
    – Status Channel

    View Slide

  14. CLIENT API
    – React
    – Encrypt the file on client-side
    – Form the block
    – Sign it and calculate hash
    – Insert it into the blockchain

    View Slide

  15. DEMO

    View Slide

  16. OUTRO
    Elixir App: to.shyr.io/dbfs
    React App: to.shyr.io/dbfs-web
    shyr.io
    [email protected]
    sheharyarn

    View Slide