| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
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
- perfProtocolId :: Text
- data PerfError
- data PerfResult = PerfResult {}
- handlePerf :: StreamIO -> PeerId -> IO ()
- perfOnStream :: StreamIO -> Word64 -> Word64 -> IO (Either PerfError PerfResult)
- runPerf :: Switch -> Connection -> Word64 -> Word64 -> IO (Either PerfError PerfResult)
- registerPerfHandler :: Switch -> IO ()
Protocol ID
perfProtocolId :: Text Source #
Perf protocol ID.
Types
Perf error types.
Constructors
| PerfNegotiationError !String | Stream open or protocol negotiation failed |
| PerfStreamError !String | I/O error during the exchange |
data PerfResult Source #
Successful perf exchange result.
Constructors
| PerfResult | |
Fields
| |
Instances
| Show PerfResult Source # | |
Defined in LibP2P.Protocol.Perf Methods showsPrec :: Int -> PerfResult -> ShowS # show :: PerfResult -> String # showList :: [PerfResult] -> ShowS # | |
| Eq PerfResult Source # | |
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.