Skip to content

Add secure request/response helper #1287

Description

@GautamBytes

Description

Proposed work

Add a generic request/response layer that:

  • opens a fresh substream per request
  • uses length-prefixed framing
  • enforces bounded request/response sizes by default
  • enforces a request timeout by default
  • owns close/reset behavior internally
  • supports pluggable codecs without forcing one serialization format

Public API

Add a new libp2p.request_response package exposing:

  • RequestResponse
  • RequestResponseConfig
  • RequestContext
  • RequestResponseCodec
  • BytesCodec
  • JSONCodec
  • typed request/response exceptions

Initial scope

  • one request
  • one response
  • one substream
  • no retries
  • no request IDs
  • no streaming responses
  • no protocol-specific or Filecoin-specific behavior

Validation goals

  • unit tests for framing and codecs
  • integration tests over real hosts
  • example demonstrating a listener and dialer round trip
  • docs for API and example usage

Acceptance criteria

  • callers can register a handler for a protocol and send one request to a peer
  • default limits and timeout are enforced
  • malformed payloads and handler failures fail safely
  • protocol negotiation failures are translated into typed helper errors
  • docs and example are included

Motivation

Add a new libp2p.request_response helper that provides a safe, one-shot request/response API on top of libp2p streams.

Current Implementation

Today, applications that want a simple request/response pattern on top of py-libp2p have to build it manually on raw streams. That requires every caller to reimplement:

  • framing
  • timeouts
  • payload size limits
  • close vs reset behavior
  • encode/decode error handling

This is easy to get wrong and leads to inconsistent security and reliability across applications.

Are you planning to do it yourself in a pull request ?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions