• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

peterhuba/d-chat: Decentralized, serverless chat webapp based on OrbitDB and IPF ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

peterhuba/d-chat

开源软件地址:

https://github.com/peterhuba/d-chat

开源编程语言:

JavaScript 84.7%

开源软件介绍:

d-chat

Decentralized messaging app based on IPFS and OrbitDB with peer-to-peer web page hosting

React-based chat app POC that demonstrates advantages of a decentralized architecture in a web context. It can serve as a reliable communication platform thanks to the IPFS-based OrbitDB, a distributed, serverless, peer-to-peer database.

By running an IPFS node in the service worker and pulling the web pages' source there, the app itself can be a server and contibute to hosting the website. This, besides offering efficient scaling, improves reliability, since new users can still load the page when the origin server is not available.

How does it work?

  • Once the user tries to load a page, the browser will be redirected to an IPFS gateway thanks to the CNAME DNS record.

  • The client browser loads the app from a server running an IPFS implementation, where the built source of the webapp is present. The page gets loaded via any public IPFS gateway, which will get the requested content from the IPFS network and send it back to the client via HTTP.

  • The client creates an instance of js-ipfs in a service worker, thanks to which it can start taking advantage of the benefits of the peer-to-peer web: any future fetch request of IPFS content-addressed information can be loaded from anywhere where it is present on an IPFS node. It can load parts of the webpage from the devices of other visitors, which can act as a server.

  • The service worker then opens OrbitDB distibuted databases and replicates them and the messages found will be displayed.

  • Any new sent/received message will appear at the other clients when the DBs are replicated. There is no guarantee of strong consistency, only strong eventual consistency, i.e. once all instances have received all the updates, their state will be the same (no conflicts, divergence).

  • Later, the web application's source itself will be loaded into the IPFS node running in the client's service worker, which means that even if the origin server goes unavailable, new clients can still access the page, because the gateways will be able to get and send back the page to the newly joining client from any existing client online. The web application's version to be "pinned" i.e. hosted at the clients' side will be obtained either via IPNS by resolving /ipns/yourdomain.com or by the application retrieving the hash from the DNS record of the domain.

Run on local

Install with: npm install

Build with: npm run build-local

Install any tool for serving statically the built directory e.g. npm install -g node-static

Run it using: static -p <port> and go to localhost:<port>/d-chat

Deploy

  • set up a domain with a provider that supports IPFS (i.e. Cloudflare) a CNAME DNS record that will redirect to couldflare-ipfs.com

  • run a build with npm run build

  • run jsipfs add -r build to add the app's folder to the local IPFS node's repo

  • pin the contents by running jsipfs pin add <hash> so that it won't be deleted from the cache

To deploy dynamic content:

  • run jsipfs name publish <hash>

  • then, add the output hash (which is the node's ID) a to TXT DNS record with the name _dnslink and value dnslink=/ipns/<nodeIdHash>

For static content:

  • add the output hash (which is the node's ID) to TXT DNS record with the name _dnslink and value dnslink=/ipfs/<contentHash>

For the moment, the latter is recommended since IPNS discovery seems to time out frequently.

Potential simplified usage of IPFS for webapps

The whole burden of running an IPFS implementation for the app can be avoided if the users happen to have the IPFS browser extentsion installed or when natively IPFS-compatible browsers will be available. brave/brave-browser#819




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap