protocol

package
v1.65.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2020 License: BSD-3-Clause Imports: 24 Imported by: 1

Documentation

Overview

Package protocol p2p protocol

Index

Constants

View Source
const (
	//p2pstore protocols
	FetchChunk        = "/chain33/fetch-chunk/" + types2.Version
	StoreChunk        = "/chain33/store-chunk/" + types2.Version
	GetHeader         = "/chain33/headers/" + types2.Version
	GetChunkRecord    = "/chain33/chunk-record/" + types2.Version
	BroadcastFullNode = "/chain33/full-node/" + types2.Version

	//sync protocols
	IsSync        = "/chain33/is-sync/" + types2.Version
	IsHealthy     = "/chain33/is-healthy/" + types2.Version
	GetLastHeader = "/chain33/last-header/" + types2.Version
)

all protocols

Variables

This section is empty.

Functions

func AuthenticateMessage added in v1.65.0

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

AuthenticateMessage authenticates p2p message.

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 HandleEvent

func HandleEvent(msg *queue.Message)

HandleEvent handle p2p event

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(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 Init

func Init(data *prototypes.P2PEnv)

Init init p2p protocol

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, handler EventHandler)

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

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

SignAndWriteStream signs the message before writing it to the stream.

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 func(*queue.Message)

EventHandler handle chain33 event

func GetEventHandler added in v1.65.0

func GetEventHandler(eventID int64) EventHandler

GetEventHandler gets event handler by event ID.

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
	QueueClient queue.Client
	Host        core.Host
	P2PManager  *p2p.Manager
	SubConfig   *types2.P2PSubConfig
	DB          ds.Datastore
	*discovery.RoutingDiscovery

	RoutingTable *kbt.RoutingTable
}

P2PEnv p2p全局公共变量

Directories

Path Synopsis
Package broadcast broadcast protocol
Package broadcast broadcast protocol
Package types protocol and stream register `
Package types protocol and stream register `

Jump to

Keyboard shortcuts

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