-
Notifications
You must be signed in to change notification settings - Fork 5
feat: leverage libp2p v3 features in remote communications #903
Description
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 middleware —
node.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.tsare 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 intransport.tsand reconnection logic. -
Stream backpressure API — v3 streams have
.pause()/.resume()and.send()returnsfalsewhen buffered. We usebyteStream()which abstracts this, but for high-throughput scenarios the lower-level API could be useful. -
@libp2p/utilsstream utilities — BeyondbyteStream(), there'slpStream(length-prefixed) andpbStream(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.