-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Browser Documentation Helia/Libp2p #103
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix!
IMPLEMENTATION.MD
Outdated
|
||
## DataStore and BlockStore | ||
|
||
The datastore is used to hold important information relating to peers and DHT records. If you do not define how you want to store it, it will use one in memory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optionally, we can link the datastore implementation that it uses in memory? i.e. https://github.com/ipfs/helia/blob/main/packages/helia/src/storage.ts#L28 I don't think there are plans to move that out and make a standalone package, but good to have a reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
IMPLEMENTATION.MD
Outdated
|
||
Blockstore is used to hold the blocks on ipfs you want to store locally | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``` | |
```js |
ditto for syntax highlighting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
IMPLEMENTATION.MD
Outdated
## Transports | ||
|
||
Transports define the method in which we connect to different nodes on the network. When implementing Helia its important to know a couple things. | ||
1. Where Helia will be run (Browser (Firefox, Chrome, Safari), Node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the language can be simplified, Browsers (Firefox, Chrome, Safari), JS runtimes (e.g. node, deno, bun)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
1. Where Helia will be run (Browser (Firefox, Chrome, Safari), Node) | ||
2. Which nodes likely have data you need | ||
|
||
The first point is important since tcp is not available in browser for example. It can only be used when running in Nodejs. If you are running in browser, WebTransports are not available in Safari but it is coming to Firefox. https://caniuse.com/webtransport |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so we need to remove from the examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I saw an example, maybe I was wrong.
IMPLEMENTATION.MD
Outdated
|
||
This allows our node to relay traffic to other nodes that you may wish not to be connected directly to the public. Not really helpful in the browser but can be implemented via: | ||
|
||
**TO BE FILLED IN** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not too familiar with this portion and how it works, was hoping someone more knowledgeable could fill in the gap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just remove it, or add a TODO.
IMPLEMENTATION.MD
Outdated
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inconsistent spacing, this does not matter in md but looks better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
IMPLEMENTATION.MD
Outdated
const libp2p = await createLibp2p({ | ||
... // placeholder for remaining config | ||
peerDiscovery: [ | ||
bootstrap({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inconsistent indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
IMPLEMENTATION.MD
Outdated
In the below example, we will want to load IPNS and IPFS since we will be resolving some IPNS names and fetching content as well. | ||
|
||
You will also want to wait a couple seconds to generate all the peers and establish connection to network before trying to access content | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be added to https://github.com/ipfs-examples/helia-examples/tree/main/examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, do i do a pull request just on this portion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, please do that, thanks!
bumping @whizzzkid whenever you get a moment ^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
1. Where Helia will be run (Browser (Firefox, Chrome, Safari), Node) | ||
2. Which nodes likely have data you need | ||
|
||
The first point is important since tcp is not available in browser for example. It can only be used when running in Nodejs. If you are running in browser, WebTransports are not available in Safari but it is coming to Firefox. https://caniuse.com/webtransport |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I saw an example, maybe I was wrong.
IMPLEMENTATION.MD
Outdated
|
||
This allows our node to relay traffic to other nodes that you may wish not to be connected directly to the public. Not really helpful in the browser but can be implemented via: | ||
|
||
**TO BE FILLED IN** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just remove it, or add a TODO.
IMPLEMENTATION.MD
Outdated
In the below example, we will want to load IPNS and IPFS since we will be resolving some IPNS names and fetching content as well. | ||
|
||
You will also want to wait a couple seconds to generate all the peers and establish connection to network before trying to access content | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, please do that, thanks!
made requested changes and added example to helia examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great writeup. I know @achingbrain had some questions about this and maybe wanted this to be a blog post, or potentially post in libp2p directly and then link to it from helia, but I'll leave that decision to him.
|
||
## Circuit Relay | ||
|
||
This allows our node to relay traffic to other nodes that you may wish not to be connected directly to the public. Not really helpful in the browser but can be implemented via: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@achingbrain I saw that we have circuit-relay enabled in the new default libp2p config for the browser. Is this statement true?
|
||
This allows our node to relay traffic to other nodes that you may wish not to be connected directly to the public. Not really helpful in the browser but can be implemented via: | ||
|
||
**TO DO** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The text here, and content below, needs to be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not familiar enough to write this portion. I am still learning helia
IMPLEMENTATION.MD
Outdated
|
||
## Stream Muxing | ||
|
||
It allows multiple conversations on the same line by giving it a unique identifier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It allows multiple conversations on the same line by giving it a unique identifier. | |
It allows multiple conversations(Streams) on the same line(Connection) by giving it a unique identifier. |
It could be useful to use/translate common libp2p terminology with a legend or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
IMPLEMENTATION.MD
Outdated
validators: { | ||
ipns: ipnsValidator, | ||
}, | ||
selectors: { | ||
ipns: ipnsSelector, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't necessary for DHT config to work. It could be beneficial to introduce the ipns config as a subitem of ## DHT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also not too familiar with everything. Still learning and documenting places that caused difficulties for me
IMPLEMENTATION.MD
Outdated
list: [ | ||
"/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", | ||
"/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb", | ||
"/dnsaddr/bootstrap.libp2p.io/p2p/QmZa1sAxajnQjVM8WjWXoMbmPd7NsWhfKsPkErzpm9wGkp", | ||
"/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa", | ||
"/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be updated to use the same as https://github.com/ipfs/helia/blob/main/packages/helia/src/utils/bootstrappers.ts, which is based off of https://github.com/ipfs/kubo/blob/da28fbc65a2e0f1ce59f9923823326ae2bc4f713/config/bootstrap_peers.go#L17
It might be good to mention the place to look(links above) to keep your bootstrap list up to date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
|
||
In the below example, we will want to load IPNS and IPFS since we will be resolving some IPNS names and fetching content as well. | ||
|
||
You will also want to wait a couple seconds to generate all the peers and establish connection to network before trying to access content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be useful to show the users code of how they can do this:
const isHeliaReadyToFetch = async (helia) => {
// return when helia has peers connected. Can simply wait for peer connection event, or handle manually with interval/other.
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a quick example
bumping again @whizzzkid , imo some additional documentation is better than none |
fbeed88
to
9f9bc60
Compare
Thank you so much for opening this PR and for taking the time to respond to feedback. Everything suggested in it is very sensible, so much so that it's basically become the default browser config you get when you invoke createHelia in a browser. This is different to early Helia releases which were a lot more bare bones, which felt right at the time but lead to a lot of duplicated configuration for users, some of it incorrect. Instead now default config makes it a lot easier to get started. This leads to the odd situation where although we're super grateful this PR was opened, the recommendations in the added markdown file are somewhat redundant so I'm going to close this, but thanks again for taking the time to document how to set things up so diligently. For future documentation efforts we have enabled the wiki on this repo so we can iterate on the docs a bit faster. |
Following our discussions at IPFS Thing on implementing Helia (which was incredibly helpful and saved so much time), I wanted to write some top level documentation on implementing it and how to get an in browser node working that supports IPNS and IPFS queries as quickly as possible. It is still missing information and could definitely expand more on it, but I figure this is a good starting point? My goal here was to discuss each component, why its needed and quick example on its implementation.