protocol

package
v0.0.0-...-3c905e5 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Overview

Package protocol p2p protocol

Index

Constants

This section is empty.

Variables

View Source
var EOFTimeout = time.Second * 60

EOFTimeout is the maximum amount of time to wait to successfully observe an EOF on the stream. Defaults to 60 seconds.

View Source
var ErrExpectedEOF = errors.New("read data when expecting EOF")

ErrExpectedEOF is returned when we read data while expecting an EOF.

Functions

func AuthenticateMessage

func AuthenticateMessage(message types.Message, stream network.Stream) bool

AuthenticateMessage authenticates p2p message.

func AwaitEOF

func AwaitEOF(s network.Stream) error

AwaitEOF waits for an EOF on the given stream, returning an error if that fails. It waits at most EOFTimeout (defaults to 1 minute) after which it resets the stream.

func ClearEventHandler

func ClearEventHandler()

ClearEventHandler clear event handler map, plugin存在多个p2p实例测试,会导致重复注册,需要清除

func CloseStream

func CloseStream(stream network.Stream)

CloseStream closes the stream after writing, and waits for the EOF.

func EventHandlerWithRecover

func EventHandlerWithRecover(f func(m *queue.Message)) func(m *queue.Message)

EventHandlerWithRecover warps the event handler with recover for catching the panic while processing message.

func HandlerWithAuth

func HandlerWithAuth(f func(request *types.P2PRequest)) network.StreamHandler

HandlerWithAuth wraps HandlerWithRead with authenticating.

func HandlerWithAuthAndSign

func HandlerWithAuthAndSign(h core.Host, f func(request *types.P2PRequest, response *types.P2PResponse) error) network.StreamHandler

HandlerWithAuthAndSign wraps HandlerWithRW with signing and authenticating.

func HandlerWithClose

func HandlerWithClose(f network.StreamHandler) network.StreamHandler

HandlerWithClose wraps handler with closing stream and recovering from panic.

func HandlerWithRW

func HandlerWithRW(f func(request *types.P2PRequest, response *types.P2PResponse) error) network.StreamHandler

HandlerWithRW wraps handler with reading, writing, closing stream and recovering from panic.

func HandlerWithRead

func HandlerWithRead(f func(request *types.P2PRequest)) network.StreamHandler

HandlerWithRead wraps handler with reading, closing stream and recovering from panic.

func HandlerWithWrite

func HandlerWithWrite(f func(resp *types.P2PResponse) error) network.StreamHandler

HandlerWithWrite wraps handler with writing, closing stream and recovering from panic.

func InitAllProtocol

func InitAllProtocol(env *P2PEnv)

InitAllProtocol initials all protocols.

func ReadStream

func ReadStream(data types.Message, stream network.Stream) error

ReadStream reads message from stream.

func ReadStreamAndAuthenticate

func ReadStreamAndAuthenticate(message types.Message, stream network.Stream) error

ReadStreamAndAuthenticate verifies the message after reading it from the stream.

func RegisterEventHandler

func RegisterEventHandler(eventID int64, cb EventHandlerFunc, opts ...EventOpt)

RegisterEventHandler registers a handler with an event ID.

func RegisterProtocolInitializer

func RegisterProtocolInitializer(initializer Initializer)

RegisterProtocolInitializer registers the initial function.

func RegisterStreamHandler

func RegisterStreamHandler(h host.Host, p protocol.ID, handler network.StreamHandler)

RegisterStreamHandler registers stream handler

func SignAndWriteStream

func SignAndWriteStream(message types.Message, stream network.Stream, pk crypto.PrivKey) error

SignAndWriteStream signs the message before writing it to the stream.

func WithEventOptInline

func WithEventOptInline(handler *EventHandler) error

WithEventOptInline invoke event callback inline

func WriteStream

func WriteStream(data types.Message, stream network.Stream) error

WriteStream writes message to stream.

Types

type EventHandler

type EventHandler struct {
	CallBack EventHandlerFunc
	Inline   bool
}

EventHandler chain internal event handler

func GetEventHandler

func GetEventHandler(eventID int64) *EventHandler

GetEventHandler gets event handler by event ID.

type EventHandlerFunc

type EventHandlerFunc func(*queue.Message)

EventHandlerFunc event handler call back

type EventOpt

type EventOpt func(*EventHandler) error

EventOpt event options

type IConnManager

type IConnManager interface {
	FetchConnPeers() []peer.ID
	BoundSize() (in int, out int)
	GetNetRate() metrics.Stats
	BandTrackerByProtocol() *types.NetProtocolInfos
	RateCalculate(ratebytes float64) string
}

IConnManager is interface of ConnManager

type IPeerInfoManager

type IPeerInfoManager interface {
	Refresh(info *types.Peer)
	Fetch(pid peer.ID) *types.Peer
	FetchAll() []*types.Peer
	PeerHeight(pid peer.ID) int64
	PeerMaxHeight() int64
}

IPeerInfoManager is interface of PeerInfoManager

type Initializer

type Initializer func(env *P2PEnv)

Initializer is a initial function which any protocol should have.

type P2PEnv

type P2PEnv struct {
	Ctx             context.Context
	ChainCfg        *types.ChainConfig
	SubConfig       *types2.P2PSubConfig
	API             client.QueueProtocolAPI
	QueueClient     queue.Client
	Host            host.Host
	P2PManager      *p2p.Manager
	DB              dbm.DB
	PeerInfoManager IPeerInfoManager
	ConnManager     IConnManager
	ConnBlackList   iLRU
	Pubsub          *extension.PubSub
	RoutingTable    *kbt.RoutingTable
	Discovery       discovery.Discovery
}

P2PEnv p2p全局公共变量

func (*P2PEnv) QueryModule

func (p *P2PEnv) QueryModule(topic string, ty int64, data interface{}) (interface{}, error)

QueryModule sends message to other module and waits response

Directories

Path Synopsis
Package broadcast broadcast protocol
Package broadcast broadcast protocol

Jump to

Keyboard shortcuts

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