Documentation
¶
Overview ¶
Package protocol p2p protocol
Index ¶
- Constants
- func AuthenticateMessage(message types.Message, stream network.Stream) bool
- func ClearEventHandler()
- func CloseStream(stream network.Stream)
- func EventHandlerWithRecover(f func(m *queue.Message)) func(m *queue.Message)
- func HandleEvent(msg *queue.Message)
- func HandlerWithAuth(f func(request *types.P2PRequest)) network.StreamHandler
- func HandlerWithAuthAndSign(f func(request *types.P2PRequest, response *types.P2PResponse) error) 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 Init(data *prototypes.P2PEnv)
- 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, handler EventHandler)
- func RegisterProtocolInitializer(initializer Initializer)
- func SignAndWriteStream(message types.Message, stream network.Stream) error
- func WriteStream(data types.Message, stream network.Stream) error
- type EventHandler
- type Initializer
- type P2PEnv
Constants ¶
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
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
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(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 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, 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
SignAndWriteStream signs the message before writing it to the stream.
Types ¶
type EventHandler ¶ added in v1.65.0
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全局公共变量