| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Network.LibP2P.Protocol.Ping.Ping
Description
Ping protocol implementation (docs/07-protocols.md).
Protocol ID: ipfsping/1.0.0
Wire format: 32 bytes random → 32 bytes echo. No framing, no protobuf. The handler runs an echo loop: reads 32 bytes, writes them back, until the stream closes. The initiator sends 32 random bytes, measures round-trip time, and verifies the echo matches.
Synopsis
- pingProtocolId :: Text
- data PingError
- data PingResult = PingResult {}
- handlePing :: StreamIO -> PeerId -> IO ()
- sendPing :: Connection -> IO (Either PingError PingResult)
- registerPingHandler :: Switch -> IO ()
- pingSize :: Int
Protocol ID
pingProtocolId :: Text Source #
Ping protocol ID.
Types
Ping error types.
Constructors
| PingTimeout | No response within timeout |
| PingMismatch | Response doesn't match sent bytes |
| PingStreamError !String | Stream I/O error |
data PingResult Source #
Successful ping result.
Constructors
| PingResult | |
Fields
| |
Instances
| Show PingResult Source # | |
Defined in Network.LibP2P.Protocol.Ping.Ping Methods showsPrec :: Int -> PingResult -> ShowS # show :: PingResult -> String # showList :: [PingResult] -> ShowS # | |
| Eq PingResult Source # | |
Defined in Network.LibP2P.Protocol.Ping.Ping | |
Protocol logic
handlePing :: StreamIO -> PeerId -> IO () Source #
Handle an inbound Ping request (responder / echo loop).
Reads 32 bytes, writes them back. Repeats until stream closes.
sendPing :: Connection -> IO (Either PingError PingResult) Source #
Send a Ping to a remote peer (initiator side).
Opens a new stream, negotiates ipfsping/1.0.0, sends 32 random bytes, reads 32 bytes back, verifies match, measures RTT.
Registration
registerPingHandler :: Switch -> IO () Source #
Register the Ping handler on the Switch.