protocols

package
v0.0.0-...-b7c645d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message interface {
	Marshal() ([]byte, error)
	Unmarshal([]byte) error
}

Message type is a generic type which is serializable

type Protocol

type Protocol interface {
	// ID returns the protocol Identifier as specified in the libp2p-core pkg
	ID() protocol.ID
	// HandleMsg is used to handle new incoming request on the host. The response is sent
	// back on the same stream
	HandleMsg(Request, peer.ID) (Response, error)
	// SetSender will be used to provide protocols the ability to send messages. It will
	// provide an interface which can be used to send the messages on the wire. This sender
	// can be used within the protocol to initiate message sending
	SetSender(Sender)
	// ReqFactory is used to instantiate a new object for handling the request
	ReqFactory() Request
	// RespFactory is used to instantiate a new object for handling the response
	RespFactory() Response
}

Protocol interface defines contract to implement to have a new P2P protocol registered on the host

type ProtocolsSvc

type ProtocolsSvc interface {
	Register(Protocol)
}

ProtocolsSvc provides an easier interface to write P2P protocols in terms of request-response schemes

func New

func New(h host.Host) ProtocolsSvc

type Request

type Request Message

Request can be any type that satisfies the Message interface

type Response

type Response Message

Response can be any type that satisfies the Message interface

type Sender

type Sender func(context.Context, peer.ID, Request) (Response, error)

Sender is an interface used to provide message sending functionality to the protocol Protocols which register are provided the Sender functionalityto use

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL