Skip to content

feat: leverage libp2p v3 features in remote communications #903

@sirtimid

Description

@sirtimid

Context

With the libp2p v3 upgrade (#900) complete, several new features are now available but not yet used. These could improve error handling, observability, and composability of our remote communications layer.

Features to evaluate

  • Stream middlewarenode.use('/protocol', async (stream, connection, next) => { ... }) for Express-like composable protocol handling. Could add cross-cutting concerns (logging, metrics, auth) to the 'whatever' protocol handler without modifying the core handler logic.

  • Async protocol handlers with auto-abort — In v3, handler rejections automatically abort the stream. Our handlers in connection-factory.ts are currently synchronous callbacks. Making them async would propagate errors properly instead of silently dropping them.

  • Fine-grained stream close events — v3 streams emit close events with { error, local } properties, distinguishing "I closed it" vs "remote closed it" and "clean close" vs "error close". This could improve error handling in transport.ts and reconnection logic.

  • Stream backpressure API — v3 streams have .pause()/.resume() and .send() returns false when buffered. We use byteStream() which abstracts this, but for high-throughput scenarios the lower-level API could be useful.

  • @libp2p/utils stream utilities — Beyond byteStream(), there's lpStream (length-prefixed) and pbStream (protobuf). Could replace custom framing if we ever need structured messaging.

Priority

None of these are urgent — the upgrade gives us the foundation. Evaluate and adopt incrementally based on actual pain points.

Metadata

Metadata

Assignees

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