+------------------+
| Chrome Extension |
+------------------+
|
1.|
|
v
+-----+ 2 +--------+ 5 +------+
+->| DHT |<------| client |---->| IPFS |
| +-----+ +--------+ +------+
6.| | |
| 3.| 4.|
| +----------+ | |
| | server 1 |<--+ |
| +----------+ |
| ^ |
| 7.| |
| | |
| +----------+ |
+--| server 2 |<--------+
+----------+
clientis a JS-only site that runs a IPFS node, talks to theserversand displays the comments. This site can be hosted ongithub.iosince it doesn't have any server-side code.serveris a VPS with a static IP address that runs a IPFS node and stores comments posted by theclients. Theserverpublishes its IP address and port to the DHT using the hardcodednetwork-idDHT key.network-idis a random 192/256-bit value used as the DHT key to makeserversdiscoverable byclientsand otherservers.
- The extension grabs the tab URL and gives its hash to the client:
client5.github.io/#<url-hash> - The client uses the DHT (WebTorrent DHT or IPFS DHT) to find
servers in the network. It uses the hardcoded network id as the
DHT key:
The DHT finds 2 servers and returns their IP addresses and ports:
for prov in $(ipfs dht findprovs $networkid); do timeout 3 ipfs dht findpeer $prov; done
[server 1] 11.22.33.44:12345 [server 2] 22.33.44.55:54321 - The client sends a
GET /<url-hash>to server 1 to get comments for this URL. The server usesipfs addto publish the folder with comments to IPFS and returns the<folder-id>. - The client sends a
POST /<url-hash>to add a comment for the URL. - The client gets files for
<folder-id>from IPFS. - Server 2 uses the DHT to find other servers.
- Server 2 sends a
GET /to server 1 to get a IPFS folder id for all the comments for all the URLs it knows.
+--------+
| client | Web
+--------+
|
--- 1.| -------------------
v
+-------------+
| http server | VPS
+-------------+
| |
2.| +--------+
| 4.|
v v
+----------+ +-----------+
| HTTP GET | | HTTP POST |
+----------+ +-----------+
|
| +---------+
3.| | watcher |
| +---------+
v
+-------------+ +------+
| ipfs daemon | | sync |
+-------------+ +------+
^ |
| 5. |
+--------------+
The server or VPS consists of a few processes:
- The
http serverprocess listens on a certain port and accepts theGETandPOSTrequests from theclients. It doesn't do the work, but rather forwards requests to the designated handlers. - The
HTTP GEThandler is a process that works on theGETrequests. It runs theipfs addcommand that can be slow sometimes. - The
HTTP POSThandler is a process that works on thePOSTrequests. It creates files with new comments and doesn't need to use IPFS commands. ipfs daemonruns in its own process.- The
watcherprocess keeps an eye on all the other processes and restarts them if needed. This especially applies to the IPFS daemon that tends to leak memory. syncis the process that connects to otherserversand pulls comments from them. It uses the DHT to discover otherserversand uses IPFS to get comments.
- The
clientsends aGETrequest to fetch comments for a URL. - The
http serverforwards theGETto theHTTP GEThandler. - The
HTTP GEThandler runsipfs addto generate a IPFS folder id for the comments. - If the
clientsends aPOSTrequest to add a comment, the request is processed by theHTTP POSThandler that creates a file with this comment. It doesn't need access to the IPFS daemon. - The
syncprocess uses the DHT to find otherservers, sendsGET /to them and uses IPFS to download comments.