Organize your Project with Dat

Blockchain Dealer
5 min readAug 5, 2018

--

Dat is an interesting protocol made for peer-to-peer file sharing and versioning. It is similar to Git and already has many usable implementations.

With the power of proper decentralized networking (syncing, versioning, permissions), managing your project [with Dat] becomes easy and breezy.

Quick primer on Dat and useful concepts

Dat refers to an umbrella of projects which are built on top of the Dat protocol — defined in dat paper which I have read and will now brief you on.

Relevant implementations before we get started:

Using Dat — skip to Demo

Referring to Dat and the command line interface: it is the most efficient and actively maintained of the above options.

Install Dat command line interface

From there, a few commands are made available to you for peer-to-peer file-sharing and versioning purposes.

terms enclosed by <> are variable; terms enclosed by [] can be omitted.

dat create [<dir>]

The create command prompts you to make a dat.json file and creates a new dat. Import the files with sync or share.

dat clone dat://<link> [<dir>]

Use dat clone to download files from a remote computer sharing files with Dat. This will create a folder with the key name if no [<dir>] is specified.

dat pull [<dir>]

Update a cloned dat archive with the latest files and exit.

dat sync [<dir>] [ --no-import] [--no-watch]

Start sharing your dat archive over the network. Sync will import new or updated files since you last ran create or sync. Sync watches files for changes and imports updated files. Sync Also works for remote sources.

Use--no-import to not import any new or updated files.
Use --no-watch to not watch directory for changes.

dat <link> <dir>

will run dat clone for new dats or resume the existing dat in <dir>

dat <dir>

is the same as running sync <dir>

Demonstration Use of Dat Command Line Interface

Running a popular Linux distribution with Long Term Support, same rules apply for Windows and Mac installations of Dat CLI.

1. Make a folder and change into it

mkdir ~/dat && mkdir ~/dat/demo && cd ~/dat/demo

2. Make a .datignore to prevent sharing unwanted files

nano .datignore and use this sample or create your own:

node_modules/
**demo_file**

Save the nano file with CTRL + X, then Y then ENTER

3. Create a dat

dat create and enter a title and a description for your new archive; the prompt looks like:

Welcome to dat program!
You can turn any folder on your computer into a Dat.
A Dat is a folder with some magic.
Your dat is ready!
We will walk you through creating a 'dat.json' file.
(You can skip dat.json and get started now.)
Learn more about dat.json: https://github.com/datprotocol/dat.jsonCtrl+C to exit at any time
Title: Demo Dat CLI Use
Description: Something eternal
Created empty Dat in /home/HIHI/dat/demo/.dat
Now you can add files and share:
* Run dat share to create metadata and sync.
* Copy the unique dat link and securely share it.
dat://a8eb195af6e7c667c15c129766a3b049d3451a9161859a20196bdc91c688627a

4. Populate your local dat archive with files

For this demonstration, we are installing an npm package which is automatically saved in the present folder’s node_modules/ sub-directory — we have indicated dat to ignore this sub-folder in our .datignore, therefore its large content won’t be available to others.

npm install blockchain-dealer-resource

Additionally, I will write a small README which others will be able to view.

nano README > fill it with some data

The following demo_file shouldn’t be shared with other peers, also because of .datignore.

nano demo_file > fill it with some data

5. Share or Sync and test a dat

dat share and save the dat link (shouldn’t have changed since dat create ) sample output:

dat v13.11.3
dat://a8eb195af6e7c667c15c129766a3b049d3451a9161859a20196bdc91c688627a
Sharing dat: 4 files (3.5 KB)
0 connections | Download 0 B/s Upload 0 B/sWatching for file updatesCtrl+C to Exit

using dat sync instead of dat share will automatically make local file changes available to peers in possession of the archive’s dat:// link.

6. Clone another peer’s dat

For this demonstration, you may use your own dat:// link to see what another peer would have access to.

To make sure you are still running dat share while you try to copy it, you must use another terminal window and dat clone it.

In order to separate the original files from the newly cloned archive, I am making a new directory adjacent to demo/ (where the original archives are).

So the folder structure looks like:

cd ../ && mkdir demo_clone && ls && ls demo...demo/
dat.json demo_file node_modules README
demo_clone/ (still empty)

Now you can clone to demo_clone/:

dat clone <link> demo_clone/

During cloning, in the terminal windows which you are sharing the dat archive over, you should see byte values change for data transfer from “one peer to the other”.

Sample output from the terminal in which we run dat clone:

dat v13.11.3
Created new dat in /home/HIHI/dat/demo_clone/.dat
Cloning: 4 files (3.5 KB)
1 connection | Download 4.0 KB/s Upload 0 B/sdat sync complete.
Version 6
Exiting the Dat program...

By using ls you should be able to see the newly added archive under demo_clone/.

ls demo_clone/...dat.json  README

7. Pull another peer’s dat

For now, it’s still all fun and games! But when someone makes changes to a project file and you want to track it, you have to go the extra mile.

run dat pull in the local clone of the remote archive.

To verify that we understand how to perform this task, let’s try to modify our original demo/ folder and pull it from our demo_clone/ folder.

Firstly, let’s stop sharing the original archive with CTRL+C in the relevant terminal window.

Then, we will remove **demo_file** from the contents of .datignore before running dat sync from the original demo/ folder.

Lastly, we run dat pull from the demo_clone/ folder and see whether or not we now have access to demo_file.

Sample output:

dat v13.11.3
Downloading dat: 3 files (192 B)
1 connection | Download 78 B/s Upload 0 B/sdat sync complete.
Version 5
Exiting the Dat program...ls...dat.json demo_file README

Since we used dat sync , all changes to the original archive are available to be pulled from anyone in possession of the dat:// link

8. Versioning Similar to Git

You may be used to Git, maybe not.

In either case, the recommended methodology for tracking changes from different contributors for a mutual project is to maintain a separate archive for every participant and potentially sub-folders for isolated code branches, which can be differentiated by using the diff command or other logic supplied by 3rd parties.

This sucks from the standpoint of someone who is used to having the easy out-of-the-box sleaze of Git; therefore:

I commit to developing a wrapper that can be used with Dat, because I love it, in a way much similar to Git but with added flavor based on the wrapper’s version: built-in Gitting for Git: a feature attempted by many!

I need to practice my OpenCL anyways.

--

--