libp2p-hs-0.1.0.0: Haskell implementation of the libp2p networking stack
Safe HaskellNone
LanguageGHC2021

LibP2P.Protocol.Perf

Description

Perf protocol implementation (specs/perf).

Protocol ID: perf1.0.0

Wire format: the client sends a single 8-byte big-endian uint64 naming the number of bytes it wants the server to send back, then streams its upload payload, then half-closes its write side. The server reads the 8-byte header, drains the upload until EOF, and only then (perf.md: the response "MUST NOT be run concurrently" with the upload) writes the requested number of bytes back and closes the stream.

Each measurement runs on its own stream; there is no framing and no protobuf. Payload bytes carry no meaning, so both sides send zeros.

Synopsis

Protocol ID

perfProtocolId :: Text Source #

Perf protocol ID.

Types

data PerfError Source #

Perf error types.

Constructors

PerfNegotiationError !String

Stream open or protocol negotiation failed

PerfStreamError !String

I/O error during the exchange

Instances

Instances details
Show PerfError Source # 
Instance details

Defined in LibP2P.Protocol.Perf

Eq PerfError Source # 
Instance details

Defined in LibP2P.Protocol.Perf

data PerfResult Source #

Successful perf exchange result.

Constructors

PerfResult 

Fields

Instances

Instances details
Show PerfResult Source # 
Instance details

Defined in LibP2P.Protocol.Perf

Eq PerfResult Source # 
Instance details

Defined in LibP2P.Protocol.Perf

Responder

handlePerf :: StreamIO -> PeerId -> IO () Source #

Handle an inbound perf request (responder).

Reads the 8-byte download size, drains the client's upload until it half-closes, then sends the requested bytes back and closes. A client that closes before sending a full header is dropped silently.

Initiator

perfOnStream :: StreamIO -> Word64 -> Word64 -> IO (Either PerfError PerfResult) Source #

One perf exchange on an already-negotiated stream (initiator).

Sends the header and uploadBytes zeros, half-closes the write side, then reads exactly downloadBytes back. The elapsed time covers the full exchange, header write to last byte read.

runPerf :: Switch -> Connection -> Word64 -> Word64 -> IO (Either PerfError PerfResult) Source #

Run one perf measurement against a connected peer: open a stream, negotiate perf1.0.0, run the exchange, and release the stream.

Registration

registerPerfHandler :: Switch -> IO () Source #

Register the perf handler on the Switch.