Documentation
¶
Overview ¶
Package protocol p2p protocol
Index ¶
- 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 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 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, handler EventHandler)
- func RegisterProtocolInitializer(initializer Initializer)
- func RegisterStreamHandler(h host.Host, p protocol.ID, handler network.StreamHandler)
- func SignAndWriteStream(message types.Message, stream network.Stream) error
- func WriteStream(data types.Message, stream network.Stream) error
- type EventHandler
- type IConnManager
- type IPeerInfoManager
- type Initializer
- type P2PEnv
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthenticateMessage ¶
AuthenticateMessage authenticates p2p message.
func ClearEventHandler ¶
func ClearEventHandler()
ClearEventHandler clear event handler map, plugin存在多个p2p实例测试,会导致重复注册,需要清除
func CloseStream ¶
CloseStream closes the stream after writing, and waits for the EOF.
func EventHandlerWithRecover ¶
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 ReadStream ¶
ReadStream reads message from stream.
func ReadStreamAndAuthenticate ¶
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 ¶
RegisterStreamHandler registers stream handler
func SignAndWriteStream ¶
SignAndWriteStream signs the message before writing it to the stream.
Types ¶
type EventHandler ¶
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全局公共变量