Skip to content

Conversation

@achingbrain
Copy link
Member

@achingbrain achingbrain commented Mar 28, 2025

  • 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

TODO:

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

…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
@achingbrain achingbrain force-pushed the feat/support-http-over-libp2p branch from 2d876b9 to 82192d7 Compare March 28, 2025 16:46
@achingbrain
Copy link
Member Author

achingbrain commented Mar 28, 2025

Opened as a draft as it still needs some polish and the tests won't pass until libp2p/js-libp2p#3064 is shipped.

@achingbrain achingbrain changed the title feat!: support libp2p over http/websockets and http/websockets over libp2p feat!: support http over libp2p as well as libp2p over http Mar 28, 2025
@MarcoPolo
Copy link
Collaborator

Supports running libp2p streams over HTTP

I don't understand this. Maybe there's some confusion: libp2p/js-libp2p#3030 (comment)

@MarcoPolo
Copy link
Collaborator

I think the confusion is resolved. Happy to review this PR once it's ready, please tag me :)

@achingbrain achingbrain changed the title feat!: support http over libp2p as well as libp2p over http feat!: refactor to support existing HTTP servers and other use cases Apr 29, 2025
@achingbrain achingbrain changed the title feat!: refactor to support existing HTTP servers and other use cases feat!: integrate with node HTTP servers, WebSockets and others Apr 29, 2025
@achingbrain achingbrain marked this pull request as ready for review April 29, 2025 19:02
Copy link
Collaborator

@MarcoPolo MarcoPolo left a 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
Copy link
Collaborator

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?

Copy link
Member Author

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)
Copy link
Collaborator

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?

Copy link
Member Author

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:

  1. A developer integrating with an existing app that accepts a WebSocket as an argument
  2. Allowing developers to treat libp2p as pure networking and keeping libp2p types/abstractions out of any business logic they may have
  3. 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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no-op on purpose?

Copy link
Member Author

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.

@achingbrain achingbrain force-pushed the feat/support-http-over-libp2p branch from e54326c to 8dfddf1 Compare May 28, 2025 09:11
@achingbrain achingbrain merged commit 98bea41 into main May 28, 2025
18 checks passed
@achingbrain achingbrain deleted the feat/support-http-over-libp2p branch May 28, 2025 10:53
achingbrain added a commit that referenced this pull request May 28, 2025
- 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
achingbrain added a commit that referenced this pull request May 28, 2025
- 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
achingbrain added a commit that referenced this pull request May 28, 2025
- 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
achingbrain added a commit that referenced this pull request May 28, 2025
- 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
github-actions bot pushed a commit that referenced this pull request May 28, 2025
## @libp2p/http-peer-id-auth-v1.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))
github-actions bot pushed a commit that referenced this pull request May 28, 2025
## @libp2p/http-utils-v1.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))
github-actions bot pushed a commit that referenced this pull request May 28, 2025
## [@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))
github-actions bot pushed a commit that referenced this pull request May 28, 2025
## @libp2p/http-websocket-v1.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))
github-actions bot pushed a commit that referenced this pull request May 28, 2025
## @libp2p/http-v1.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))
github-actions bot pushed a commit that referenced this pull request May 28, 2025
## @libp2p/http-ping-v1.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))
github-actions bot pushed a commit that referenced this pull request May 28, 2025
## @libp2p/http-server-v1.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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants