Skip to content

[request-response] Permit sending of responses directly on a ResponseChannel? #1648

Description

@romanb

It has been brought up in #1639, that it would be nice if the API of libp2p-request-response would offer ResponseChannel::send(response) instead of RequestResponse::send_response(channel, response). The advantage is obviously that one does not need to have access to the RequestResponse behaviour in order to send responses, i.e. one can distribute the ResponseChannels received from inbound requests in the application and send responses "from anywhere". Since RequestResponse::send_response currently needs no access to any state of the RequestResponse behaviour (contrary to RequestResponse::send_request), this would be easy to do. The main concern is one of future-proofness, i.e. if RequestResponse::send_response should later need access to RequestResponse state, the change may potentially be not backward-compatible or at least require more effort (i.e. it may be possible to do such a change without breaking the public API if the ResponseChannel that the behaviour exposes contains another oneshot channel whose receiving end is kept by the RequestResponse behaviour; once resolved (i.e. the response is send) it would forward the response to the oneshot channel whose receiving end is in the InboundUpgrade). Thus, if we change the API to offer ResponseChannel::send(response) and later need access to RequestResponse state, that would require some more indirection or a breaking change to the API. This issue is about weighing the pros/cons of providing ResponseChannel::send(response) vs the loss of flexibility in how sending of responses is implemented internally and gathering opinions on this matter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions