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

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

Protocol ID

pingProtocolId :: Text Source #

Ping protocol ID.

Types

data PingError Source #

Ping error types.

Constructors

PingTimeout

No response within timeout

PingMismatch

Response doesn't match sent bytes

PingStreamError !String

Stream I/O error

Instances

Instances details
Show PingError Source # 
Instance details

Defined in Network.LibP2P.Protocol.Ping.Ping

Eq PingError Source # 
Instance details

Defined in Network.LibP2P.Protocol.Ping.Ping

data PingResult Source #

Successful ping result.

Constructors

PingResult 

Fields

Instances

Instances details
Show PingResult Source # 
Instance details

Defined in Network.LibP2P.Protocol.Ping.Ping

Eq PingResult Source # 
Instance details

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.

Constants

pingSize :: Int Source #

Ping payload size: 32 bytes.