Documentation
¶
Index ¶
- Variables
- func Checksum(msg *protos.CoreMessage) uint32
- func Compress(msg *protos.CoreMessage) *protos.CoreMessage
- func Decompress(msg *protos.CoreMessage) ([]byte, error)
- func Drivers() []string
- func GenerateKeyPairWithPath(path string) error
- func GeneratePemKeyFromNetKey(path string) error
- func GetKeyPairFromPath(path string) (crypto.PrivKey, error)
- func GetPeerIDFromPath(path string) (string, error)
- func GetRespMessageType(msgType protos.CoreMessage_MessageType) protos.CoreMessage_MessageType
- func MessageKey(msg *protos.CoreMessage) string
- func NewDispatcher(ctx *netBase.NetCtx) netBase.Dispatcher
- func NewMessage(typ protos.CoreMessage_MessageType, message proto.Message, ...) *protos.CoreMessage
- func NewNetwork(ctx *netBase.NetCtx) (netBase.Network, error)
- func NewSubscriber(ctx *netBase.NetCtx, typ protos.CoreMessage_MessageType, v interface{}, ...) netBase.Subscriber
- func NewTLS(path, serviceName string) (credentials.TransportCredentials, error)
- func Register(name string, f NewP2PServFunc)
- func Unmarshal(msg *protos.CoreMessage, message proto.Message) error
- func VerifyChecksum(msg *protos.CoreMessage) bool
- func VerifyMessageType(request *protos.CoreMessage, response *protos.CoreMessage, peerID string) bool
- func WithFilterBCName(bcName string) netBase.SubscriberOption
- func WithFilterFrom(from string) netBase.SubscriberOption
- type DispatcherImpl
- func (d *DispatcherImpl) Dispatch(msg *protos.CoreMessage, stream netBase.Stream) error
- func (d *DispatcherImpl) IsHandled(msg *protos.CoreMessage) bool
- func (d *DispatcherImpl) MaskHandled(msg *protos.CoreMessage)
- func (d *DispatcherImpl) Register(sub netBase.Subscriber) error
- func (d *DispatcherImpl) UnRegister(sub netBase.Subscriber) error
- type HandleFunc
- type MessageOption
- type NetworkImpl
- func (t *NetworkImpl) Context() *netBase.NetCtx
- func (t *NetworkImpl) Init(ctx *netBase.NetCtx) error
- func (t *NetworkImpl) NewSubscriber(typ protos.CoreMessage_MessageType, v interface{}, ...) netBase.Subscriber
- func (t *NetworkImpl) PeerInfo() protos.PeerInfo
- func (t *NetworkImpl) Register(sub netBase.Subscriber) error
- func (t *NetworkImpl) SendMessage(ctx xctx.Context, msg *protos.CoreMessage, opts ...netBase.OptionFunc) error
- func (t *NetworkImpl) SendMessageWithResponse(ctx xctx.Context, msg *protos.CoreMessage, opts ...netBase.OptionFunc) ([]*protos.CoreMessage, error)
- func (t *NetworkImpl) Start()
- func (t *NetworkImpl) Stop()
- func (t *NetworkImpl) UnRegister(sub netBase.Subscriber) error
- type NewP2PServFunc
- type SubscriberImpl
Constants ¶
This section is empty.
Variables ¶
var ( ErrSubscriber = errors.New("subscribe error") ErrRegistered = errors.New("SubscriberImpl already registered") ErrMessageEmpty = errors.New("message empty") ErrStreamNil = errors.New("stream is nil") ErrNotRegister = errors.New("message not register") )
Functions ¶
func Checksum ¶
func Checksum(msg *protos.CoreMessage) uint32
Checksum calculate checksum of message
func Decompress ¶
func Decompress(msg *protos.CoreMessage) ([]byte, error)
Decompress decompress msg
func Drivers ¶
func Drivers() []string
Drivers returns a sorted list of the names of the registered drivers.
func GenerateKeyPairWithPath ¶
GenerateKeyPairWithPath generate xuper net key pair
func GeneratePemKeyFromNetKey ¶
GeneratePemKeyFromNetKey get pem format private key from net private key
func GetKeyPairFromPath ¶
GetKeyPairFromPath get xuper net key from file path
func GetPeerIDFromPath ¶
GetPeerIDFromPath return peer id of given private key path
func GetRespMessageType ¶
func GetRespMessageType(msgType protos.CoreMessage_MessageType) protos.CoreMessage_MessageType
GetRespMessageType get the message type
func MessageKey ¶
func MessageKey(msg *protos.CoreMessage) string
func NewDispatcher ¶
func NewDispatcher(ctx *netBase.NetCtx) netBase.Dispatcher
func NewMessage ¶
func NewMessage(typ protos.CoreMessage_MessageType, message proto.Message, opts ...MessageOption) *protos.CoreMessage
NewMessage create P2P message instance with given params
func NewSubscriber ¶
func NewSubscriber(ctx *netBase.NetCtx, typ protos.CoreMessage_MessageType, v interface{}, opts ...netBase.SubscriberOption) netBase.Subscriber
func NewTLS ¶
func NewTLS(path, serviceName string) (credentials.TransportCredentials, error)
func Register ¶
func Register(name string, f NewP2PServFunc)
Register makes a driver available by the provided name. If Register is called twice with the same name or if driver is nil,it panics.
func Unmarshal ¶
func Unmarshal(msg *protos.CoreMessage, message proto.Message) error
Unmarshal unmarshal msgInfo
func VerifyChecksum ¶
func VerifyChecksum(msg *protos.CoreMessage) bool
VerifyChecksum verify the checksum of message
func VerifyMessageType ¶
func VerifyMessageType(request *protos.CoreMessage, response *protos.CoreMessage, peerID string) bool
VerifyMessageType 用于带返回的请求场景下验证收到的消息是否为预期的消息
func WithFilterBCName ¶
func WithFilterBCName(bcName string) netBase.SubscriberOption
func WithFilterFrom ¶
func WithFilterFrom(from string) netBase.SubscriberOption
Types ¶
type DispatcherImpl ¶
type DispatcherImpl struct {
// contains filtered or unexported fields
}
DispatcherImpl implement interface Dispatcher
func (*DispatcherImpl) Dispatch ¶
func (d *DispatcherImpl) Dispatch(msg *protos.CoreMessage, stream netBase.Stream) error
func (*DispatcherImpl) IsHandled ¶
func (d *DispatcherImpl) IsHandled(msg *protos.CoreMessage) bool
func (*DispatcherImpl) MaskHandled ¶
func (d *DispatcherImpl) MaskHandled(msg *protos.CoreMessage)
filter handled message
func (*DispatcherImpl) Register ¶
func (d *DispatcherImpl) Register(sub netBase.Subscriber) error
func (*DispatcherImpl) UnRegister ¶
func (d *DispatcherImpl) UnRegister(sub netBase.Subscriber) error
type HandleFunc ¶
type HandleFunc func(xctx.Context, *protos.CoreMessage) (*protos.CoreMessage, error)
type MessageOption ¶
type MessageOption func(*protos.CoreMessage)
func WithBCName ¶
func WithBCName(bcname string) MessageOption
func WithErrorType ¶
func WithErrorType(errorType protos.CoreMessage_ErrorType) MessageOption
func WithVersion ¶
func WithVersion(version string) MessageOption
type NetworkImpl ¶
type NetworkImpl struct {
// contains filtered or unexported fields
}
如果有领域内公共逻辑,可以在这层扩展,对上层暴露高级接口 暂时没有特殊的逻辑,先简单透传,预留方便后续扩展
func (*NetworkImpl) Context ¶
func (t *NetworkImpl) Context() *netBase.NetCtx
func (*NetworkImpl) NewSubscriber ¶
func (t *NetworkImpl) NewSubscriber(typ protos.CoreMessage_MessageType, v interface{}, opts ...netBase.SubscriberOption) netBase.Subscriber
func (*NetworkImpl) PeerInfo ¶
func (t *NetworkImpl) PeerInfo() protos.PeerInfo
func (*NetworkImpl) Register ¶
func (t *NetworkImpl) Register(sub netBase.Subscriber) error
func (*NetworkImpl) SendMessage ¶
func (t *NetworkImpl) SendMessage(ctx xctx.Context, msg *protos.CoreMessage, opts ...netBase.OptionFunc) error
func (*NetworkImpl) SendMessageWithResponse ¶
func (t *NetworkImpl) SendMessageWithResponse(ctx xctx.Context, msg *protos.CoreMessage, opts ...netBase.OptionFunc) ([]*protos.CoreMessage, error)
func (*NetworkImpl) Start ¶
func (t *NetworkImpl) Start()
func (*NetworkImpl) Stop ¶
func (t *NetworkImpl) Stop()
func (*NetworkImpl) UnRegister ¶
func (t *NetworkImpl) UnRegister(sub netBase.Subscriber) error
type SubscriberImpl ¶
type SubscriberImpl struct {
// contains filtered or unexported fields
}
func (*SubscriberImpl) GetMessageType ¶
func (s *SubscriberImpl) GetMessageType() protos.CoreMessage_MessageType
func (*SubscriberImpl) HandleMessage ¶
func (s *SubscriberImpl) HandleMessage(ctx xctx.Context, msg *protos.CoreMessage, stream netBase.Stream) error
func (*SubscriberImpl) Match ¶
func (s *SubscriberImpl) Match(msg *protos.CoreMessage) bool