Giter Site home page Giter Site logo

js-libp2p-examples's Introduction

libp2p hex logo

A collection of js-libp2p examples


Explore the docs ยท Report Bug ยท Request Feature/Example

Table of Contents

About The Project

Getting Started

Examples

Feel free to jump directly into the examples, however going through the following sections will help build context and background knowledge.

Understanding how libp2p works

Other examples

libp2p in the Browser

There are a number of ways libp2p can be used in the browser. Here are some examples:

There is also an tutorial of how all of these transports can be universally connected

Prerequisites

Make sure you have installed all of the following prerequisites on your development machine:

Documentation

Contribute

See CONTRIBUTING.md.

License

Licensed under either of

js-libp2p-examples's People

Contributors

achingbrain avatar dependabot[bot] avatar scenaristeur avatar web-flow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-libp2p-examples's Issues

Incorrect function signature of callback function libp2p.dial

The function signature of callback function libp2p.dial at
here is incorrect according to the doc.

Also it throws the below error even after correcting the signature for the latest release of js-libp2p.

/Users/shresthagrawal/Desktop/study/libp2p/my-chat/index2.js:44
         if (err) throw err
                  ^

Error: Dial was aborted
    at createError (/Users/shresthagrawal/Desktop/study/libp2p/my-chat/node_modules/err-code/index.js:4:44)
    at DIAL_ABORTED (/Users/shresthagrawal/Desktop/study/libp2p/my-chat/node_modules/libp2p/src/switch/errors.js:7:23)
    at Queue.abort (/Users/shresthagrawal/Desktop/study/libp2p/my-chat/node_modules/libp2p/src/switch/dialer/queue.js:144:21)
    at Queue.denylist (/Users/shresthagrawal/Desktop/study/libp2p/my-chat/node_modules/libp2p/src/switch/dialer/queue.js:169:10)
    at ClassIsWrapper.<anonymous> (/Users/shresthagrawal/Desktop/study/libp2p/my-chat/node_modules/libp2p/src/switch/dialer/queue.js:252:12)
    at Object.onceWrapper (events.js:284:20)
    at ClassIsWrapper.emit (events.js:196:13)
    at ClassIsWrapper.emit (/Users/shresthagrawal/Desktop/study/libp2p/my-chat/node_modules/libp2p/src/switch/connection/base.js:36:13)
    at ClassIsWrapper.close (/Users/shresthagrawal/Desktop/study/libp2p/my-chat/node_modules/libp2p/src/switch/connection/base.js:27:12)
    at /Users/shresthagrawal/Desktop/study/libp2p/my-chat/node_modules/libp2p/src/switch/connection/index.js:318:23

Missing examples linked in README

Hi there,

Wondering where did the libp2p-in-the-browser examples went? The 3 links in this section of the README are pointing nowhere. I'm most interested in these examples, but when trying to understand what happened, I thought I'd dig a bit deeper and found some other things missing.

If I understand correctly, right before libp2p/js-libp2p#2171 was merged, there were all in here https://github.com/libp2p/js-libp2p/tree/c6db2104dbe4257e14e66cda75bd8daf6a27f3c5/examples with this list:

But it seems only a few of them made it as a separate repo? I can see:

I'm most interested in the libp2p-in-the-browser/webrtc example, but hopefully it's helpful to have a list of the other ones ๐Ÿ˜„

CC @achingbrain

Multiple errors in the build of the browser chat example.

After the npm clean-install of the browser based chat examples, I am getting error with parcel build issue whenever I am trying to run. Maybe downgrading the parcel version fixes the problem.

I am getting this error when i am trying to run the clean build of the examples.

Server running at http://localhost:1234 
๐Ÿšจ  /home/ankanghosh/jsbuild/master-code/js-libp2p-examples/chat/browser/08-End/index.js: Invalid Version: undefined
    at new SemVer (/home/ankanghosh/jsbuild/master-code/js-libp2p-examples/chat/browser/node_modules/@babel/preset-env/node_modules/semver/semver.js:314:11)
    at compare (/home/ankanghosh/jsbuild/master-code/js-libp2p-examples/chat/browser/node_modules/@babel/preset-env/node_modules/semver/semver.js:647:10)
    at lt (/home/ankanghosh/jsbuild/master-code/js-libp2p-examples/chat/browser/node_modules/@babel/preset-env/node_modules/semver/semver.js:688:10)
    at /home/ankanghosh/jsbuild/master-code/js-libp2p-examples/chat/browser/node_modules/@babel/preset-env/lib/index.js:280:22
    at Object.default (/home/ankanghosh/jsbuild/master-code/js-libp2p-examples/chat/browser/node_modules/@babel/helper-plugin-utils/lib/index.js:22:12)
    at getEnvPlugins (/home/ankanghosh/jsbuild/master-code/js-libp2p-examples/chat/browser/node_modules/parcel/src/transforms/babel/env.js:62:34)

Can you please let me know which version of node is required to be used here ?

Run this example using the web-rtc-star server

I want to use this example to connect nodejs node with a browser node but not locally
So I'm using the rendezvous server "/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star/" for experimental use.
I get to connect the peers but i'm not able to send/receive any messages.
Is there a way to do so ?

18 broken links from README.md

Hi, I ran a link checker on this page and it found 18 broken links:

https://github.com/libp2p/js-libp2p/raw/master/img/libp2p.png?raw=true
/libp2p/js-libp2p-examples/blob/main/libp2p-in-the-browser/webrtc/README.md
/libp2p/js-libp2p-examples/blob/main/libp2p-in-the-browser/websockets/README.md
/libp2p/js-libp2p-examples/blob/main/libp2p-in-the-browser/webtransport/README.md
/libp2p/js-libp2p-examples/blob/main/LICENSE-APACHE
/libp2p/js-libp2p-examples/blob/main/LICENSE-MIT
/libp2p/rust-libp2p/issues?q=label%3A%22help+wanted%22+is%3Aissue+is%3Aopen
/libp2p/go-libp2p/issues?q=label%3A%22help+wanted%22+is%3Aissue+is%3Aopen
/libp2p/js-libp2p/issues?q=label%3A%22help+wanted%22+is%3Aissue+is%3Aopen
/libp2p/test-plans/issues?q=label%3A%22help+wanted%22+is%3Aissue+is%3Aopen
/libp2p/specs/issues?q=label%3A%22help+wanted%22+is%3Aissue+is%3Aopen
/libp2p/js-libp2p-examples/pulls?q=is%3Apr+is%3Aopen+label%3Adependencies
/libp2p/js-libp2p-examples/actions/caches
/libp2p/js-libp2p-example-browser-pubsub/blob/main/LICENSE-APACHE
/libp2p/js-libp2p-example-browser-pubsub/blob/main/LICENSE-MIT
{{ authorUrl }}
{{ authorAvatarUrl }}
{{ contributorUrl }}

You can run a link checker on any site using docker:

docker run --rm dcycle/broken-link-checker:3 -r2 https://github.com/libp2p/js-libp2p-examples > js-libp2p-examples.csv  

Attached are the results.
js-libp2p-examples.csv

Tutorials needs more clarity, otherwise not very useful for beginners

Not a very clear tutorial. Feels more like copy pasta than any substantive explanation of whats is going on.

Would there be a way to clear it up? Or to create one simple example application that highlights the main parts of libp2p?

I'm trying to find resources and so far nothing is very helpful.

Async issue with multistream-select

System

Node Version: v12.18.4
NPM: 6.14.6

Steps to reproduce

  • Run npm clean-install in browser project
  • Run npm start in 08-End
  • View in browser, with following error

image

image

enable discussions

probably enable discussion in this repo might be helpful, it's about example of use, there are many questions devs would like to ask approaching this library

I can not make browser pubsub example working - Uncaught (in promise) Error: PublishError.InsufficientPeers

I'm on Linux Mint 21.2 Cinnamon 5.15.0-87-generic #97-Ubuntu SMP Mon Oct 2 21:09:21 UTC 2023 x86_64 GNU/Linux
node V18.18.0

[email protected] /home/smag/dev/js-libp2p-examples
โ””โ”€โ”ฌ @libp2p/[email protected] -> ./examples/js-libp2p-example-browser-pubsub
โ”œโ”€โ”€ @chainsafe/[email protected]
โ”œโ”€โ”€ @chainsafe/[email protected]
โ”œโ”€โ”€ @chainsafe/[email protected]
โ”œโ”€โ”€ @libp2p/[email protected]
โ”œโ”€โ”€ @libp2p/[email protected]
โ”œโ”€โ”€ @multiformats/[email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ””โ”€โ”€ [email protected]

image

Pubsub error when running the index.js

I get the following error in the console when running the index.js of the 08-End example.

libp2pWS/chat/nodejs/node_modules/libp2p/src/config.js:95
Expected a value of type undefined for config.EXPERIMENTAL but received {"pubsub":true}.

Does anyone have the same ?

high severity vulnerabilities

I tried the chat example
I have seen that the examples use a vulnerable version

npm clean-install

added 374 packages, and audited 375 packages in 35s
8 high severity vulnerabilities

After running the command
npm audit fix --force

08-End example gives me a series of errors

Can you update the example with the version of the library without vulnerabilities?

which version of node is recommended?

What address to use for multiaddress in the chapter 02?

Hi! I am a beginner in lib2p and peer-to-peer tech in general. I'm trying the chapter 02.
I tried several addresses including the one from the chapter 03.

/ip4/127.0.0.1/tcp/63786/ws/ipfs/QmWjz6xb8v9K4KnYEwP5Yk75k5mMBCehzWFLCvvQpYxF3d
/ip4/0.0.0.0/tcp/15555/ws/p2p-webrtc-star/p2p/QmWjz6xb8v9K4KnYEwP5Yk75k5mMBCehzWFLCvvQpYxF3d
/ip4/192.168.1.205/tcp/63786/ws

The error for the first 2 addresses is:

Download the React DevTools for a better development experience: https://fb.me/react-devtools react-dom.development.js:24994:16
Getting our PeerId App.js:26:14
Creating our Libp2p instance App.js:34:16
AggregateError: 
    parcelRequire<["../node_modules/multistream-select/src/select.js"]</module.exports@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:118789:17
    async*select@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:118909:12
    _encryptOutbound@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:119685:21
    upgradeOutbound@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:119447:22
    dial@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:133719:39
    async*dial@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:102821:30
    dialAction@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:106492:36
    run/<@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:106296:29
    Async*run@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:106289:36
    _createPendingDial@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:106508:28
    connectToPeer@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:106414:71
    _maybeConnect@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:122213:29
    _onDidStart/<@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:122166:12
    emit@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:29160:17
    add@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:120027:16
    _createDialTarget@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:106455:34
    connectToPeer@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:106408:29
    dialProtocol@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:122026:38
    dial@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:122003:17
    createLibp2p@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:145687:18
    async*App/</<@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:99659:28
    App/<@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:99662:9
    commitHookEffectListMount@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:23768:30
    commitPassiveHookEffects@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:23805:40
    callCallback@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:4350:18
    invokeGuardedCallbackDev@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:4399:20
    invokeGuardedCallback@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:4452:35
    flushPassiveEffectsImpl@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:26869:34
    unstable_runWithPriority@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:3598:16
    runWithPriority$1@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:15237:14
    flushPassiveEffects@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:26837:16
    commitBeforeMutationEffects/<@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:26716:15
    workLoop@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:3542:46
    flushWork@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:3498:20
    performWorkUntilDeadline@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:3102:52
    EventHandlerNonNull*parcelRequire<["../node_modules/scheduler/cjs/scheduler.development.js"]</<@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:3126:7
    parcelRequire<["../node_modules/scheduler/cjs/scheduler.development.js"]<@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:3795:5
    newRequire@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:47:24
    localRequire@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:53:14
    parcelRequire<["../node_modules/scheduler/index.js"]<@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:3803:20
    newRequire@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:47:24
    localRequire@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:53:14
    parcelRequire<["../node_modules/react-dom/cjs/react-dom.development.js"]</<@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:4180:28
    parcelRequire<["../node_modules/react-dom/cjs/react-dom.development.js"]<@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:28979:5
    newRequire@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:47:24
    localRequire@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:53:14
    parcelRequire<["../node_modules/react-dom/index.js"]<@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:29017:20
    newRequire@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:47:24
    localRequire@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:53:14
    parcelRequire<["index.js"]<@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:145705:40
    newRequire@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:47:24
    parcelRequire<@http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:81:17
    @http://localhost:1234/03-Muxing-Encryption.e31bb0bc.js:120:3
    AggregateError index.js:33
    maybeSettle index.js:31
    pSome index.js:69
    pSome index.js:51
    _promise index.js:61
    PCancelable index.js:31
    pSome index.js:7
    exports index.js:6
    run dial-request.js:53
    _createPendingDial index.js:167
    connectToPeer index.js:76
    _maybeConnect index.js:509
    _onDidStart index.js:466
    emit events.js:152
    add address-book.js:134
    _createDialTarget index.js:112
    connectToPeer index.js:71
    dialProtocol index.js:324
    dial index.js:305
    createLibp2p libp2p.js:34
    App App.js:35
    App App.js:33
    React 6
    unstable_runWithPriority scheduler.development.js:653
    React 3
    workLoop scheduler.development.js:597
    flushWork scheduler.development.js:552
    performWorkUntilDeadline scheduler.development.js:164
    EventHandlerNonNull*parcelRequire<["../node_modules/scheduler/cjs/scheduler.development.js"]</< scheduler.development.js:187
    parcelRequire<["../node_modules/scheduler/cjs/scheduler.development.js"]< scheduler.development.js:15
    newRequire 03-Muxing-Encryption.e31bb0bc.js:47
    localRequire 03-Muxing-Encryption.e31bb0bc.js:53
    parcelRequire<["../node_modules/scheduler/index.js"]< index.js:6
    newRequire 03-Muxing-Encryption.e31bb0bc.js:47
    localRequire 03-Muxing-Encryption.e31bb0bc.js:53
    React 2
    newRequire 03-Muxing-Encryption.e31bb0bc.js:47
    localRequire 03-Muxing-Encryption.e31bb0bc.js:53
    parcelRequire<["../node_modules/react-dom/index.js"]< React
    newRequire 03-Muxing-Encryption.e31bb0bc.js:47
    localRequire 03-Muxing-Encryption.e31bb0bc.js:53
    parcelRequire<["index.js"]< index.js:3
    newRequire 03-Muxing-Encryption.e31bb0bc.js:47
    parcelRequire 03-Muxing-Encryption.e31bb0bc.js:81
    <anonymous> 03-Muxing-Encryption.e31bb0bc.js:120
libp2p.js:37:12
    createLibp2p libp2p.js:37
    App App.js:35
    App App.js:33
    React 6
    unstable_runWithPriority scheduler.development.js:653
    React 3
    workLoop scheduler.development.js:597
    flushWork scheduler.development.js:552
    performWorkUntilDeadline scheduler.development.js:164
    (Async: EventHandlerNonNull)
    parcelRequire<["../node_modules/scheduler/cjs/scheduler.development.js"]</< scheduler.development.js:187
    parcelRequire<["../node_modules/scheduler/cjs/scheduler.development.js"]< scheduler.development.js:15
    newRequire 03-Muxing-Encryption.e31bb0bc.js:47
    localRequire 03-Muxing-Encryption.e31bb0bc.js:53
    parcelRequire<["../node_modules/scheduler/index.js"]< index.js:6
    newRequire 03-Muxing-Encryption.e31bb0bc.js:47
    localRequire 03-Muxing-Encryption.e31bb0bc.js:53
    React 2
    newRequire 03-Muxing-Encryption.e31bb0bc.js:47
    localRequire 03-Muxing-Encryption.e31bb0bc.js:53
    parcelRequire<["../node_modules/react-dom/index.js"]< React
    newRequire 03-Muxing-Encryption.e31bb0bc.js:47
    localRequire 03-Muxing-Encryption.e31bb0bc.js:53
    parcelRequire<["index.js"]< index.js:3
    newRequire 03-Muxing-Encryption.e31bb0bc.js:47
    parcelRequire 03-Muxing-Encryption.e31bb0bc.js:81
    <anonymous> 03-Muxing-Encryption.e31bb0bc.js:120

Bootstrap starting log:

$ node index.js 
Signaling server running at /ip4/0.0.0.0/tcp/15555/ws/p2p-webrtc-star
Node started with addresses:
/ip4/0.0.0.0/tcp/15555/ws/p2p-webrtc-star/p2p/QmWjz6xb8v9K4KnYEwP5Yk75k5mMBCehzWFLCvvQpYxF3d
/ip4/127.0.0.1/tcp/63785
/ip4/192.168.1.205/tcp/63785
/ip4/127.0.0.1/tcp/63786/ws
/ip4/192.168.1.205/tcp/63786/ws

Node supports protocols:
/libp2p/circuit/relay/0.1.0
/ipfs/id/1.0.0
/ipfs/id/push/1.0.0
/ipfs/ping/1.0.0
/libp2p/chat/1.0.0
/meshsub/1.0.0
/floodsub/1.0.0
/ipfs/kad/1.0.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.