protocol

package
v1.68.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: BSD-3-Clause Imports: 27 Imported by: 1

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 added in v1.65.0

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

AuthenticateMessage authenticates p2p message.

func AwaitEOF added in v1.65.3

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 added in v1.65.0

func ClearEventHandler()

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

func CloseStream added in v1.65.0

func CloseStream(stream network.Stream)

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

func EventHandlerWithRecover added in v1.65.0

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 added in v1.65.0

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

HandlerWithAuth wraps HandlerWithRead with authenticating.

func HandlerWithAuthAndSign added in v1.65.0

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 added in v1.65.0

func HandlerWithClose(f network.StreamHandler) network.StreamHandler

HandlerWithClose wraps handler with closing stream and recovering from panic.

func HandlerWithRW added in v1.65.0

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 added in v1.65.0

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

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

func HandlerWithWrite added in v1.65.1

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

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

func InitAllProtocol added in v1.65.0

func InitAllProtocol(env *P2PEnv)

InitAllProtocol initials all protocols.

func ReadStream added in v1.65.0

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

ReadStream reads message from stream.

func ReadStreamAndAuthenticate added in v1.65.0

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

ReadStreamAndAuthenticate verifies the message after reading it from the stream.

func RegisterEventHandler added in v1.65.0

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

RegisterEventHandler registers a handler with an event ID.

func RegisterProtocolInitializer added in v1.65.0

func RegisterProtocolInitializer(initializer Initializer)

RegisterProtocolInitializer registers the initial function.

func RegisterStreamHandler added in v1.65.1

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

RegisterStreamHandler registers stream handler

func SignAndWriteStream added in v1.65.0

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

SignAndWriteStream signs the message before writing it to the stream.

func WithEventOptInline added in v1.66.1

func WithEventOptInline(handler *EventHandler) error

WithEventOptInline invoke event callback inline

func WriteStream added in v1.65.0

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

WriteStream writes message to stream.

Types

type EventHandler added in v1.65.0

type EventHandler struct {
	CallBack EventHandlerFunc
	Inline   bool
}

EventHandler chain33 internal event handler

func GetEventHandler added in v1.65.0

func GetEventHandler(eventID int64) *EventHandler

GetEventHandler gets event handler by event ID.

type EventHandlerFunc added in v1.66.1

type EventHandlerFunc func(*queue.Message)

EventHandlerFunc event handler call back

type EventOpt added in v1.66.1

type EventOpt func(*EventHandler) error

EventOpt event options

type IConnManager added in v1.65.1

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 added in v1.65.1

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 added in v1.65.0

type Initializer func(env *P2PEnv)

Initializer is a initial function which any protocol should have.

type P2PEnv added in v1.65.0

type P2PEnv struct {
	Ctx             context.Context
	ChainCfg        *types.Chain33Config
	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 added in v1.65.1

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