-
Notifications
You must be signed in to change notification settings - Fork 2
feat!: integrate with node HTTP servers, WebSockets and others #57
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
Conversation
…ibp2p Supports running libp2p streams over HTTPm, as well as HTTP requests over libp2p. Also supports upgrading HTTP-over-libp2p requests to WebSockets, as well as libp2p-over-HTTP requests so you can do full-duplex libp2p things and aren't limited to simple request/response protocols. As a bonus, it also supports accepting HTTP & WebSocket requests in browsers without having to polyfill and Node.js internals. BREAKING CHANGE: the API has change significantly, this module has been renamed `@libp2p/http` since it now does much more than fetch
2d876b9 to
82192d7
Compare
|
Opened as a draft as it still needs some polish and the tests won't pass until libp2p/js-libp2p#3064 is shipped. |
I don't understand this. Maybe there's some confusion: libp2p/js-libp2p#3030 (comment) |
|
I think the confusion is resolved. Happy to review this PR once it's ready, please tag me :) |
MarcoPolo
left a comment
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've skimmed the code and the examples.
Holy smokes, this is a herculean effort! You've done an incredible amount of great work.
If there's anything you want me to dive deep on, I'm happy to give you a review. If you want me to review the whole thing it'll take some time.
In the mean time, I'd like to update the Go implementation here to the latest version. I'll open a PR targetting this branch
|
|
||
| ## Step 3 - run the HTTP proxy | ||
|
|
||
| Unfortunately we still can't listen on a socket in a web browser, so if we want |
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 don't understand this section. Can't you connect the two browsers via webrtc?
Why do you need a proxy server?
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 demo is to use a web browser to load a page from a server running in another web browser, but without the first browser loading any intermediate page or running code.
You can't use the browser address bar to make a WebRTC connection, open a data channel and send an HTTP request so the proxy server is necessary.
| --> | ||
|
|
||
| This is an implementation of the [WebSocket API](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) |
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 you explain here and for me, what the use case is for a WebSocket api on top
of libp2p streams?
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.
We discussed this on the go-libp2p call but for anyone reading this in the future the use cases are:
- A developer integrating with an existing app that accepts a WebSocket as an argument
- Allowing developers to treat libp2p as pure networking and keeping libp2p types/abstractions out of any business logic they may have
- Because we can! It's a small jump to transform a HTTP request into a WebSocket and it shows how flexible the underlying transport primitives are
| return this._listening | ||
| } | ||
|
|
||
| set listening (listening: boolean) { |
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.
no-op on purpose?
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, this is a setter so it makes the listening property read-only.
e54326c to
8dfddf1
Compare
- Provides adapters for working with W3C Request/Response based servers (e.g. Hono) and with Node.js `http.Server` ones (basically everything else) - Adds support for opening WebSockets over libp2p and integration with existing WebSocket servers - Ensures server code is opt-in to reduce client-only bundle sizes - Adds browser-friendly server capabilities to allow serving webapps from browsers - Allows using libp2p as the routing layer with Node.js native fetch and/or http client via custom agents - Updates all examples to use new API BREAKING CHANGE: the API has change significantly, this module has been renamed `@libp2p/http` since it now does much more than fetch
- Provides adapters for working with W3C Request/Response based servers (e.g. Hono) and with Node.js `http.Server` ones (basically everything else) - Adds support for opening WebSockets over libp2p and integration with existing WebSocket servers - Ensures server code is opt-in to reduce client-only bundle sizes - Adds browser-friendly server capabilities to allow serving webapps from browsers - Allows using libp2p as the routing layer with Node.js native fetch and/or http client via custom agents - Updates all examples to use new API BREAKING CHANGE: the API has change significantly, this module has been renamed `@libp2p/http` since it now does much more than fetch
- Provides adapters for working with W3C Request/Response based servers (e.g. Hono) and with Node.js `http.Server` ones (basically everything else) - Adds support for opening WebSockets over libp2p and integration with existing WebSocket servers - Ensures server code is opt-in to reduce client-only bundle sizes - Adds browser-friendly server capabilities to allow serving webapps from browsers - Allows using libp2p as the routing layer with Node.js native fetch and/or http client via custom agents - Updates all examples to use new API BREAKING CHANGE: the API has change significantly, this module has been renamed `@libp2p/http` since it now does much more than fetch
- Provides adapters for working with W3C Request/Response based servers (e.g. Hono) and with Node.js `http.Server` ones (basically everything else) - Adds support for opening WebSockets over libp2p and integration with existing WebSocket servers - Ensures server code is opt-in to reduce client-only bundle sizes - Adds browser-friendly server capabilities to allow serving webapps from browsers - Allows using libp2p as the routing layer with Node.js native fetch and/or http client via custom agents - Updates all examples to use new API BREAKING CHANGE: the API has change significantly, this module has been renamed `@libp2p/http` since it now does much more than fetch
## [@libp2p/http-fetch-v3.0.0](https://github.com/libp2p/js-libp2p-http/compare/@libp2p/http-fetch-2.2.2...@libp2p/http-fetch-3.0.0) (2025-05-28) ### ⚠ BREAKING CHANGES * the API has change significantly, this module has been renamed `@libp2p/http` since it now does much more than fetch ### Features * integrate with node HTTP servers, WebSockets and others ([#57](#57)) ([6aa9551](6aa9551))
http.Serverones (basically everything else)BREAKING CHANGE: the API has change significantly, this module has been renamed
@libp2p/httpsince it now does much more than fetchTODO:
.fetchand.connectmethodsChange checklist