My lightning talk about building a naive blockchain-based file storage in Elixir and React, with scalability and distribution in mind.
BLOCKCHAIN BASEDFILE STORAGE
View Slide
SHEHARYAR NASEERsheharyarn shyr.io
DIDN'T HODL
blockchainnoun /ˈbläkˌCHān/A decentralized, distributed digital ledger that isused to record transactions across many computersso that the record cannot be altered retroactivelywithout the alteration of all subsequent blocks [...]
BLOCK 5Data:Timestamp:Previous:Current:34k0scf2018-01-05 13:24:563662c6f8dc7b519123cf9d644657c3d7c80a6frth760ls2018-01-07 18:43:12f9d644657c3d7c80a6fbbd658cb57bb0d2138BLOCK 6Data:Timestamp:Previous:Current:qnb49f02018-01-08 06:11:34bbd658cb57bb0d21388327ed293f7834c6572BLOCK 7Data:Timestamp:Previous:Current:
ARCHITECTURE– Blockchain Structure– File Storage– Cryptography– Synchronization– Client API
BLOCKCHAIN%Block{type: ...,timestamp: ...,data: %{file_name: ..., file_hash: ..., file_key: ...,},prev: ...,creator: ...,hash: ...,signature: ...}
FILE STORAGE– Nothing fancy– Directly on the disk– Encrypted– Block hash as identifier
CRYPTOGRAPHY– Public Key: RSA– Symmetric: AES
CRYPTOGRAPHY– Public Key: RSA– Symmetric: AES– Hashing: SHA256– Encoding: Base64
SYNCHRONIZATION– Erlang VM: Easy Distribution– Consensus: Raft– Elect 'leader'– Use it as a reference
SYNCHRONIZATION– Find where the chain diverges– Send the succeeding blockdef sync_next(leader, hash) do%{block: block, file: file} =:rpc.call(leader, Blockchain, :next, [hash])Blockchain.insert(block, file)end
CLIENT API– Phoenix– List, Upload, Download– Ecto Validations– Status Channel
CLIENT API– React– Encrypt the file on client-side– Form the block– Sign it and calculate hash– Insert it into the blockchain
DEMO
OUTROElixir App: to.shyr.io/dbfsReact App: to.shyr.io/dbfs-webshyr.io[email protected]sheharyarn