network

package
v0.0.0-...-b124b1e Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2022 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var (
	ErrMessageChecksum   = errors.New("verify checksum error")
	ErrMessageDecompress = errors.New("decompress error")
	ErrMessageUnmarshal  = errors.New("message unmarshal error")
)
View Source
var (
	ErrHandlerError    = errors.New("handler error")
	ErrResponseNil     = errors.New("handler response is nil")
	ErrStreamSendError = errors.New("send response error")
	ErrChannelBlock    = errors.New("channel block")
)

Functions

func Checksum

func Checksum(msg *protos.CoreMessage) uint32

Checksum calculate checksum of message

func Compress

func Compress(msg *protos.CoreMessage) *protos.CoreMessage

Compressed compress msg

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

func GenerateKeyPairWithPath(path string) error

GenerateKeyPairWithPath generate xuper net key pair

func GeneratePemKeyFromNetKey

func GeneratePemKeyFromNetKey(path string) error

GeneratePemKeyFromNetKey get pem format private key from net private key

func GetKeyPairFromPath

func GetKeyPairFromPath(path string) (crypto.PrivKey, error)

GetKeyPairFromPath get xuper net key from file path

func GetPeerIDFromPath

func GetPeerIDFromPath(path string) (string, error)

GetPeerIDFromPath return peer id of given private key path

func GetRespMessageType

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 NewNetwork

func NewNetwork(ctx *netBase.NetCtx) (netBase.Network, error)

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 WithLogId

func WithLogId(logid string) MessageOption

WithLogId set message logId

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

func (t *NetworkImpl) Init(ctx *netBase.NetCtx) error

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 NewP2PServFunc

type NewP2PServFunc func() netBase.Network

创建P2PServer实例方法

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL