Documentation ¶
Overview ¶
Package protocol p2p protocol
Index ¶
- Variables
- func AuthenticateMessage(message types.Message, stream network.Stream) bool
- func AwaitEOF(s network.Stream) error
- func ClearEventHandler()
- func CloseStream(stream network.Stream)
- func EventHandlerWithRecover(f func(m *queue.Message)) func(m *queue.Message)
- func HandlerWithAuth(f func(request *types.P2PRequest)) network.StreamHandler
- func HandlerWithAuthAndSign(h core.Host, ...) network.StreamHandler
- func HandlerWithClose(f network.StreamHandler) network.StreamHandler
- func HandlerWithRW(f func(request *types.P2PRequest, response *types.P2PResponse) error) network.StreamHandler
- func HandlerWithRead(f func(request *types.P2PRequest)) network.StreamHandler
- func HandlerWithWrite(f func(resp *types.P2PResponse) error) network.StreamHandler
- func InitAllProtocol(env *P2PEnv)
- func ReadStream(data types.Message, stream network.Stream) error
- func ReadStreamAndAuthenticate(message types.Message, stream network.Stream) error
- func RegisterEventHandler(eventID int64, cb EventHandlerFunc, opts ...EventOpt)
- func RegisterProtocolInitializer(initializer Initializer)
- func RegisterStreamHandler(h host.Host, p protocol.ID, handler network.StreamHandler)
- func SignAndWriteStream(message types.Message, stream network.Stream, pk crypto.PrivKey) error
- func WithEventOptInline(handler *EventHandler) error
- func WriteStream(data types.Message, stream network.Stream) error
- type EventHandler
- type EventHandlerFunc
- type EventOpt
- type IConnManager
- type IPeerInfoManager
- type Initializer
- type P2PEnv
Constants ¶
This section is empty.
Variables ¶
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.
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
AuthenticateMessage authenticates p2p message.
func AwaitEOF ¶ added in v1.65.3
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
CloseStream closes the stream after writing, and waits for the EOF.
func EventHandlerWithRecover ¶ added in v1.65.0
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
ReadStream reads message from stream.
func ReadStreamAndAuthenticate ¶ added in v1.65.0
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
RegisterStreamHandler registers stream handler
func SignAndWriteStream ¶ added in v1.65.0
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
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
EventHandlerFunc event handler call back
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全局公共变量