Skip to content
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

feat(protocol): add HTTP protocol implementation for libp2p #3046

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

devlux76
Copy link
Contributor

Title

feat(protocol): add HTTP protocol implementation for libp2p

Description

This PR introduces a complete HTTP protocol implementation for libp2p, following the official libp2p HTTP specification. The implementation provides both client and server components allowing peers to exchange HTTP messages over libp2p streams.

Key features include:

  • HTTP client and server with HTTP/1.1 semantics over libp2p streams
  • WHATWG Fetch API compatibility layer for familiar web usage
  • Path-based request routing with middleware support
  • Protocol Buffers-based message encoding/decoding
  • Protocol discovery via .well-known/libp2p/protocols as specified
  • Comprehensive test coverage and documentation

This implementation enables HTTP-based communication in peer-to-peer networks using libp2p, opening up possibilities for distributed web applications, REST APIs over libp2p, and more interoperable P2P services.

Notes & open questions

  • The implementation deviates slightly from traditional HTTP due to Protocol Buffers v3 constraints, using a composition pattern instead of inheritance for message structures.
  • Authentication mechanisms beyond libp2p's transport security are not fully implemented as the specification indicates these will be defined in future specs.
  • Not all HTTP features (caching, range requests, etc.) are fully implemented yet, as noted in the DESIGN document. These could be added in future iterations.
  • There may be opportunities to optimize performance for high-throughput scenarios in follow-up PRs.

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

@devlux76 devlux76 requested a review from a team as a code owner March 14, 2025 09:39
@devlux76
Copy link
Contributor Author

Seems the build is failing because interfaces is relying on an outdated version of a package I've just set to the latest version? I'm not really sure what the best path to take here is. I don't feel right trying to update someone else's dependencies, but it build and runs cleanly here.

@achingbrain
Copy link
Member

Thanks for submitting this. Did you see this response in regard to your approach here? - #3030 (comment)

@devlux76
Copy link
Contributor Author

Thanks for submitting this. Did you see this response in regard to your approach here? - #3030 (comment)

I didn't see it before. I see it now. I respectfully disagree though. Existing web-server stacks make a lot of presumptions about the transport layer. We aren't going to be able to interface with them at the transport layer like that.

It's far better IMHO to create the web stack and expose familiar semantics, specifically HTTP semantics over libp2p.
This way people just need to import this lib instead of express for instance.
As far as maintainability, this relies solely on existing libp2p code with no external deps.
The HTTP protocol stack isn't likely to go anywhere, anytime soon. I'd say it's pretty solid in that regard.

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.

2 participants