protocol

package
v1.1.21 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Overview

Package protocol p2p protocol

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticateMessage

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

AuthenticateMessage authenticates p2p message.

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

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) error

SignAndWriteStream signs the message before writing it to the stream.

func WriteStream

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

WriteStream writes message to stream.

Types

type EventHandler

type EventHandler func(*queue.Message)

EventHandler handles turingchain event

func GetEventHandler

func GetEventHandler(eventID int64) EventHandler

GetEventHandler gets event handler by event ID.

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.TuringchainConfig
	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.RoutingDiscovery
}

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