Documentation
¶
Index ¶
- Constants
- func ReadMessage(r io.Reader) (string, []byte, error)
- func WriteMessage(w io.Writer, msgType string, data []byte) error
- type Discovery
- type Host
- func (h *Host) AddrStrings() []string
- func (h *Host) Addrs() []multiaddr.Multiaddr
- func (h *Host) Close() error
- func (h *Host) Connect(ctx context.Context, pi peer.AddrInfo) error
- func (h *Host) Disconnect(p peer.ID) error
- func (h *Host) ID() peer.ID
- func (h *Host) NewStream(ctx context.Context, p peer.ID, protocols ...string) error
- func (h *Host) Peerstore() peerstore.Peerstore
- func (h *Host) RawHost() host.Host
- type MessageHandler
- type PubSub
- func (ps *PubSub) Close() error
- func (ps *PubSub) GetTopics() []string
- func (ps *PubSub) JoinTopic(ctx context.Context, topic string) (*pubsub.Topic, error)
- func (ps *PubSub) ListPeers(topic string) []peer.ID
- func (ps *PubSub) Publish(ctx context.Context, topic string, data []byte) error
- func (ps *PubSub) Raw() *pubsub.PubSub
- func (ps *PubSub) RegisterTopicValidator(topic string, ...) error
- func (ps *PubSub) Subscribe(ctx context.Context, topic string) (*pubsub.Subscription, error)
- type StreamHandler
- type X402MessageHandler
- type X402StreamHandler
Constants ¶
const ProtocolID = "/betar/marketplace/1.0.0"
ProtocolID is the marketplace protocol identifier
const X402ProtocolID = "/x402/libp2p/1.0.0"
X402ProtocolID is the libp2p protocol identifier for the x402-over-libp2p standard.
Variables ¶
This section is empty.
Functions ¶
func ReadMessage ¶
ReadMessage reads a message from a stream using msgio
Types ¶
type Discovery ¶
type Discovery struct {
// contains filtered or unexported fields
}
Discovery handles peer discovery
func NewDiscovery ¶
NewDiscovery creates a new discovery service
func (*Discovery) DiscoverPeers ¶
DiscoverPeers discovers peers on the network
func (*Discovery) Routing ¶
func (d *Discovery) Routing() corerouting.Routing
Routing returns the routing implementation used by discovery.
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host wraps the libp2p host
func (*Host) AddrStrings ¶
AddrStrings returns the listen addresses as strings
func (*Host) Disconnect ¶
Disconnect disconnects from a peer
type MessageHandler ¶
MessageHandler handles incoming messages
type PubSub ¶
type PubSub struct {
// contains filtered or unexported fields
}
PubSub handles pubsub messaging
func (*PubSub) Raw ¶
func (ps *PubSub) Raw() *pubsub.PubSub
Raw returns the underlying libp2p pubsub instance.
type StreamHandler ¶
type StreamHandler struct {
// contains filtered or unexported fields
}
StreamHandler handles direct P2P streams
func NewStreamHandler ¶
func NewStreamHandler(h host.Host) *StreamHandler
NewStreamHandler creates a new stream handler
func (*StreamHandler) RegisterHandler ¶
func (s *StreamHandler) RegisterHandler(msgType string, handler MessageHandler)
RegisterHandler registers a message handler
type X402MessageHandler ¶
type X402MessageHandler func(ctx context.Context, from peer.ID, msgType string, data []byte) (string, []byte, error)
X402MessageHandler handles typed x402 messages. It returns (responseType, responseBytes, error). The error causes an x402.error to be sent; normal typed responses set responseType to the desired message type (e.g., x402.response).
type X402StreamHandler ¶
type X402StreamHandler struct {
// contains filtered or unexported fields
}
X402StreamHandler manages streams using the /x402/libp2p/1.0.0 protocol. Unlike the existing StreamHandler, both requests and responses carry a type field, enabling a single stream to exchange multiple distinct message types.
func NewX402StreamHandler ¶
func NewX402StreamHandler(h host.Host) *X402StreamHandler
NewX402StreamHandler creates and registers the x402 stream handler on the given host.
func (*X402StreamHandler) RegisterHandler ¶
func (s *X402StreamHandler) RegisterHandler(msgType string, fn X402MessageHandler)
RegisterHandler registers a handler for the given message type.
func (*X402StreamHandler) SendX402Message ¶
func (s *X402StreamHandler) SendX402Message(ctx context.Context, to peer.ID, msgType string, payload []byte) (string, []byte, error)
SendX402Message opens a new stream to the target peer, writes a typed frame, reads the typed response frame, and returns (responseType, responseData, error).