캐스


Hosting over dat protocol

2018-12-08 11:43, 12 months and 1 day ago
fb9759ce7bece1874135e062789c203f


In an attempt to fight off my sleep deprivation I’ll write this post about a little something called dat. I recently bought a vps for $3.50pm and figured I’d have a go at some things I’ve been wanting to do but never had a dedicated server for.

Hopefully this post acts as a guide to anyone else wanting to serve their site with dat.

So, what is dat? It’s described as: “a new p2p hypermedia protocol”. It’s like http, but instead of being centralised it’s a peer-to-peer distributed web. Nice. So basically if my server dies someone out there in the vast expanse of the internet will have a copy of my trashfire site and other people can grab it from them instead of my choking server.

My dat site is located at: dat://caß.si (yes your really can use the eszett…), which is just the cutest looking domain I’ve seen…

Installing dat

I’m using Debian 9 so your installation process may vary slightly… First, some updates, install node package manager and install dat, easy as.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nodejs
sudo npm install npm
sudo install -g dat 

Test it works via dat -v.

Serving files over dat

Create a new folder, add some content and share it.

mkdir my_folder
cd my_folder
touch index.html
nano index.html
#add some html stuff
dat share

And you should get:

$ dat share
Created new dat
dat://5a4575c632d1a573...

You can think of the dat://5a4575c632d1a573... as your address, paste that into Beaker Browser and you should see the content of your html file:

Hey, neato.

That’s all well and good, but no-one can remember a 64 character address, this is where domains come in.

Setting up a domain name

I want to access my dat site via dat://cass.si. This can easily be achieved by creating a TXT record in your DNS. Note: this method does not work with http mirroring, you have to use a .well-known file for that, more info…

Simply create a TXT record and set the target to datkey=<your_dat_address>, so for my site it looks like the following:

It might take a bit for the DNS to propogate but all things going to plan…

Yay.

Making it permanent

Now then, since dat is peer-to-peer there needs to be at least one person on the network at all times hosting the files, this is where hypercore comes in.

hypercore is a program written by the people that made dat for use in hosting multiple dats. To install it:

sudo npm install -g hypercored

Now we need to add our dat address to it so it knows what to watch, hypercored does this with use of a feeds file:

echo 'dat://<your_dat_address' >> feeds

You can use your domain too, so I did: echo 'dat://cass.si' >> feeds and it works fine.

Finally, start up hypercored.

$ hypercored
Watching ~/dat/feeds for a list of active feeds
Archiver key is 42471e32d36be3cb617ec1df382372532aac1d1ce683982962fb3594c5f9532a
Swarm listening on port 58184

Now it should watch your dats for any changes and update them accordingly. And there you have it.


Comments