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

Network.LibP2P.Protocol.Identify.Identify

Description

Identify protocol implementation (docs/07-protocols.md).

Protocol ID: ipfsid/1.0.0

After a connection is established, both sides exchange IdentifyInfo messages to learn about each other's capabilities, listen addresses, and agent version. The message has no length prefix — the boundary is determined by stream closure.

Also implements Identify Push (ipfsidpush1.0.0) for proactive updates when local state changes.

Synopsis

Protocol IDs

identifyProtocolId :: ProtocolId Source #

Identify protocol ID.

identifyPushProtocolId :: ProtocolId Source #

Identify Push protocol ID.

Protocol logic

handleIdentify :: Switch -> StreamIO -> PeerId -> IO () Source #

Handle an inbound Identify request (responder side).

Sends our local IdentifyInfo as protobuf to the stream, then closes. The remote side reads until EOF.

requestIdentify :: Connection -> IO (Either String IdentifyInfo) Source #

Request Identify from a remote peer (initiator side).

Opens a new stream, negotiates ipfsid/1.0.0, reads until EOF, then decodes the protobuf message.

handleIdentifyPush :: Switch -> StreamIO -> PeerId -> IO () Source #

Handle an inbound Identify Push (responder side).

Reads the pushed IdentifyInfo from the remote peer.

Building local info

buildLocalIdentify :: Switch -> Maybe Connection -> IO IdentifyInfo Source #

Build our local IdentifyInfo from Switch state.

Registration

registerIdentifyHandlers :: Switch -> IO () Source #

Register Identify protocol handlers on the Switch.

Registers: ipfsid/1.0.0 — respond to Identify requests ipfsidpush1.0.0 — handle Identify Push from remote

Helpers

readUntilEOF :: StreamIO -> Int -> IO (Either String ByteString) Source #

Read bytes from a StreamIO until EOF, up to a maximum size.

Identify uses stream closure as message boundary (no length prefix). Accumulates bytes until streamReadByte throws (EOF/stream closed).