发生在IPFS上有趣的项目

2018-04-05  本文已影响0人  devabel

发生在IPFS上有趣的项目

https://medium.com/@kidinamoto/%E5%8F%91%E7%94%9F%E5%9C%A8ipfs%E4%B8%8A%E6%9C%89%E8%B6%A3%E7%9A%84%E9%A1%B9%E7%9B%AE-fd4bfb9830b5

ipfs is awesome

最近的研究重点在IPFS上,作为一个基于BitSwap和Merkle DAG的系统,IPFS在不断完善自身的技术栈。ipfs_research 中有许多很有想象力的新的协议。在这些新的协议的启发下,我们能在IPFS上开发出更多有意思的产品。

1. 为什么需要 pubsub?

参考文献https://ipfs.io/blog/25-pubsub/

消息的发布与订阅Publish-Subscribe, 简称为‘pubsub’, 是一种在大型网络中被用于处理事件的模式。发布者(‘Publishers’ )按照主题发送信息或内容;接收者( ‘subscribers’)接受他们感兴趣的主题。 信息的传输不需要发布者和接受者间存在直连。这样一来可以得到更大的网络扩展性和灵活性。

有些文档共享编辑的应用、动态内容的网站、聊天应用、游戏、持续演化的数据集和用户发布信息的webservice都需要用到消息的发布订阅。它使得在数据中心、局域网、大型P2P应用上使用IPFS变得更快速。在不远的将来,IPNS记录可以通过pubsub发布,使得IPNS记录的更新变得更快。节点间可以通过pubsub 追踪一个 merkle-linked global log的头信息。

Demo

<pre name="b88d" id="b88d" class="graf graf--pre graf-after--li" style="overflow: auto; font-family: Menlo, Monaco, "Courier New", Courier, monospace; font-size: 16px; margin: 43px 0px 0px; background: rgba(0, 0, 0, 0.05); padding: 20px; white-space: pre-wrap; color: rgba(0, 0, 0, 0.84); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">ipfs daemon — enable-pubsub-experiment</pre>

<pre name="5526" id="5526" class="graf graf--pre graf-after--li" style="overflow: auto; font-family: Menlo, Monaco, "Courier New", Courier, monospace; font-size: 16px; margin: 43px 0px 0px; background: rgba(0, 0, 0, 0.05); padding: 20px; white-space: pre-wrap; color: rgba(0, 0, 0, 0.84); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">ipfs pubsub sub foo</pre>

<pre name="a638" id="a638" class="graf graf--pre graf-after--li" style="overflow: auto; font-family: Menlo, Monaco, "Courier New", Courier, monospace; font-size: 16px; margin: 43px 0px 0px; background: rgba(0, 0, 0, 0.05); padding: 20px; white-space: pre-wrap; color: rgba(0, 0, 0, 0.84); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">ipfs pubsub pub foo “hello world”</pre>

<pre name="8ce4" id="8ce4" class="graf graf--pre graf-after--li" style="overflow: auto; font-family: Menlo, Monaco, "Courier New", Courier, monospace; font-size: 16px; margin: 43px 0px 0px; background: rgba(0, 0, 0, 0.05); padding: 20px; white-space: pre-wrap; color: rgba(0, 0, 0, 0.84); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">ipfs pubsub peers</pre>

<pre name="1d87" id="1d87" class="graf graf--pre graf-after--li" style="overflow: auto; font-family: Menlo, Monaco, "Courier New", Courier, monospace; font-size: 16px; margin: 43px 0px 0px; background: rgba(0, 0, 0, 0.05); padding: 20px; white-space: pre-wrap; color: rgba(0, 0, 0, 0.84); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">ipfs pubsub ls</pre>

2. OrbitDB

orbit-db是一个去服务器的,分布式的P2P数据库。 orbit-db将数据存储在IPFS上,使用IPFS Pubsub自动同步各个节点的数据。 这是一个能够保证最终一致的数据库,它使用CRDT进行无冲突数据库合并,使orbit-db成为offline-first应用程序的绝佳选择。

案例-orbit

Orbit是一个P2P的聊天软件。

Devcon2上的介绍视频: Orbit Distributed, Real Time Web3 Apps with IPFS and Ethereum

<figure name="636e" id="636e" class="graf graf--figure graf-after--p" style="display: block; margin: 43px 0px 0px; position: relative; clear: both; outline: 0px; box-sizing: border-box; user-select: auto; z-index: 100; color: rgba(0, 0, 0, 0.84); font-family: medium-content-sans-serif-font, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif; font-size: 20px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">

<canvas class="progressiveMedia-canvas js-progressiveMedia-canvas" width="75" height="40" style="display: block; vertical-align: baseline; position: absolute; top: 0px; left: 0px; width: 700px; height: 394.797px; margin: auto; box-sizing: border-box; visibility: hidden; opacity: 0; backface-visibility: hidden; transition: visibility 0s linear 0.5s, opacity 0.1s 0.4s;"></canvas>

[图片上传失败...(image-a34ad7-1522941041721)]

</figure>

线上测试环境:https://orbit.chat/#/loading

Orbit在IPFS上开发出了P2P数据库OrbitDB。

Orbit的Git项目地址:https://github.com/orbitdb

安装

当Nodejs版本在8.0之上,

npm install -g orbit-db-cli

测试是否安装成功

orbitdb help

应出现以下内容:

_     _ _         _ _                | |   (_) |       | | |       ___  _ __| |__  _| |_    __| | |__      / _ \| '__| '_ \| | __|  / _` | '_ \     | (_) | |  | |_) | | |_  | (_| | |_) |      \___/|_|  |_.__/|_|\__|  \__,_|_.__/             Peer-to-Peer Database       https://github.com/orbitdb/orbit-dbUsage: orbitdb <command> <database>Commands:  add <database> [<data>]            Add an entry to an eventlog or feed                                     database. Can be only used on:                                     eventlog|feed  create <database> <type>           Create a new database. Type can be one of:                                     eventlog|feed|docstore|keyvalue|counter                                                                  [aliases: new]  del <database> <key>               Delete an entry from a database. Only valid                                     for data types of: docstore|keyvalue|feed                                                       [aliases: delete, remove]  demo <name>                        Runs a sequence of commands as an example                                                                 [aliases: tour]  drop <database> yes                Remove a database locally. This doesn't                                     remove data on other nodes that have the                                     removed database replicated.                                                              [aliases: destroy]  get <database> [<search>]          Query the database.                                                        [aliases: query, search]  id                                 Show information about current orbit-db id  import <file> <database> <schema>  Import a CSV file to a document database                                                                  [aliases: csv]  inc <database> [<increment>]       Increase the value of a counter database.                                     Default increment is 1\. [aliases: increase]  info <database>                    Show information about a database                                                               [aliases: status]  put <database> <document>          Add a document to a document database  replicate <database>               Replicate a database with peers.  set <database> <key> <value>       Set a value of a key in KeyValue database  version                            Show information about current orbit-dbOptions:  -h, --help  Show help                                                [boolean]

测试数据库存储日志的特性:

orbitdb create hello feed/orbitdb/QmfSUsdr34iGio68eMezDzZLCKZTnbsxNJgiNipimZtpi1/hello
orbitdb add /orbitdb/QmfSUsdr34iGio68eMezDzZLCKZTnbsxNJgiNipimZtpi1/hello "world"Added QmSwYZheHVa3eWf83XwnWNJtjGG7EWjiWTaTKLeFozVRnz
$ orbitdb get /orbitdb/QmfSUsdr34iGio68eMezDzZLCKZTnbsxNJgiNipimZtpi1/hello"world"
$ orbitdb del /orbitdb/QmfSUsdr34iGio68eMezDzZLCKZTnbsxNJgiNipimZtpi1/hello QmSwYZheHVa3eWf83XwnWNJtjGG7EWjiWTaTKLeFozVRnzDeleted QmSwYZheHVa3eWf83XwnWNJtjGG7EWjiWTaTKLeFozVRnz
orbitdb get /orbitdb/QmfSUsdr34iGio68eMezDzZLCKZTnbsxNJgiNipimZtpi1/helloDatabase '/orbitdb/QmfSUsdr34iGio68eMezDzZLCKZTnbsxNJgiNipimZtpi1/hello' is empty!
orbitdb info hello/orbitdb/QmfSUsdr34iGio68eMezDzZLCKZTnbsxNJgiNipimZtpi1/hello> Type: feed> Owner: QmfSUsdr34iGio68eMezDzZLCKZTnbsxNJgiNipimZtpi1> Data file: ./orbitdb/QmfSUsdr34iGio68eMezDzZLCKZTnbsxNJgiNipimZtpi1/hello.orbitdb> Entries: 0> Oplog length: 2

参考文献:

https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type

上一篇 下一篇

猜你喜欢

热点阅读