Documentation ¶
Index ¶
- Constants
- Variables
- func NewP2PServerV1() p2p.Server
- type Conn
- type ConnPool
- type MultiStrategy
- type P2PServerV1
- func (p *P2PServerV1) Context() *nctx.NetCtx
- func (p *P2PServerV1) GetPeer(peerInfo pb.PeerInfo, addr string) []*pb.PeerInfo
- func (p *P2PServerV1) GetPeerIdByAccount(account string) (string, error)
- func (p *P2PServerV1) GetPeerInfo(addresses []string) ([]*pb.PeerInfo, error)
- func (p *P2PServerV1) Init(ctx *nctx.NetCtx) error
- func (p *P2PServerV1) NewSubscriber(typ pb.XuperMessage_MessageType, v interface{}, opts ...p2p.SubscriberOption) p2p.Subscriber
- func (p *P2PServerV1) PeerInfo() pb.PeerInfo
- func (p *P2PServerV1) Register(sub p2p.Subscriber) error
- func (p *P2PServerV1) SendMessage(ctx xctx.XContext, msg *pb.XuperMessage, optFunc ...p2p.OptionFunc) error
- func (p *P2PServerV1) SendMessageWithResponse(ctx xctx.XContext, msg *pb.XuperMessage, optFunc ...p2p.OptionFunc) ([]*pb.XuperMessage, error)
- func (p *P2PServerV1) SendP2PMessage(stream pb.P2PService_SendP2PMessageServer) error
- func (p *P2PServerV1) Start()
- func (p *P2PServerV1) Stop()
- func (p *P2PServerV1) UnRegister(sub p2p.Subscriber) error
- type PeerFilter
- type StaticNodeStrategy
Constants ¶
const (
ServerName = "p2pv1"
)
Variables ¶
var ( ErrEmptyPeer = errors.New("empty peer") ErrNoResponse = errors.New("no response") )
Functions ¶
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
func (*Conn) SendMessage ¶
SendMessage send message to a peer
func (*Conn) SendMessageWithResponse ¶
func (c *Conn) SendMessageWithResponse(ctx xctx.XContext, msg *pb.XuperMessage) (*pb.XuperMessage, error)
SendMessageWithResponse send message to a peer with responce
type ConnPool ¶
type ConnPool struct {
// contains filtered or unexported fields
}
ConnPool manage all the connection
type MultiStrategy ¶
type MultiStrategy struct {
// contains filtered or unexported fields
}
MultiStrategy a peer filter that contains multiple filters
func NewMultiStrategy ¶
func NewMultiStrategy(filters []PeerFilter, peerIDs []string) *MultiStrategy
NewMultiStrategy create instance of MultiStrategy
func (*MultiStrategy) Filter ¶
func (cp *MultiStrategy) Filter() ([]string, error)
Filter return peer IDs with multiple filters
type P2PServerV1 ¶
type P2PServerV1 struct {
// contains filtered or unexported fields
}
P2PServerV1
func (*P2PServerV1) Context ¶
func (p *P2PServerV1) Context() *nctx.NetCtx
func (*P2PServerV1) GetPeerIdByAccount ¶
func (p *P2PServerV1) GetPeerIdByAccount(account string) (string, error)
func (*P2PServerV1) GetPeerInfo ¶
func (p *P2PServerV1) GetPeerInfo(addresses []string) ([]*pb.PeerInfo, error)
func (*P2PServerV1) Init ¶
func (p *P2PServerV1) Init(ctx *nctx.NetCtx) error
Init initialize p2p server using given config
func (*P2PServerV1) NewSubscriber ¶
func (p *P2PServerV1) NewSubscriber(typ pb.XuperMessage_MessageType, v interface{}, opts ...p2p.SubscriberOption) p2p.Subscriber
func (*P2PServerV1) PeerInfo ¶
func (p *P2PServerV1) PeerInfo() pb.PeerInfo
func (*P2PServerV1) Register ¶
func (p *P2PServerV1) Register(sub p2p.Subscriber) error
func (*P2PServerV1) SendMessage ¶
func (p *P2PServerV1) SendMessage(ctx xctx.XContext, msg *pb.XuperMessage, optFunc ...p2p.OptionFunc) error
SendMessage send message to peers using given filter strategy
func (*P2PServerV1) SendMessageWithResponse ¶
func (p *P2PServerV1) SendMessageWithResponse(ctx xctx.XContext, msg *pb.XuperMessage, optFunc ...p2p.OptionFunc) ([]*pb.XuperMessage, error)
SendMessageWithResponse send message to peers using given filter strategy, expect response from peers 客户端再使用该方法请求带返回的消息时,最好带上log_id, 否则会导致收消息时收到不匹配的消息而影响后续的处理
func (*P2PServerV1) SendP2PMessage ¶
func (p *P2PServerV1) SendP2PMessage(stream pb.P2PService_SendP2PMessageServer) error
SendP2PMessage implement the SendP2PMessageServer
func (*P2PServerV1) Start ¶
func (p *P2PServerV1) Start()
func (*P2PServerV1) Stop ¶
func (p *P2PServerV1) Stop()
func (*P2PServerV1) UnRegister ¶
func (p *P2PServerV1) UnRegister(sub p2p.Subscriber) error
type PeerFilter ¶
PeerFilter the interface for filter peers
type StaticNodeStrategy ¶
type StaticNodeStrategy struct {
// contains filtered or unexported fields
}
StaticNodeStrategy a peer filter that contains strategy nodes
func (*StaticNodeStrategy) Filter ¶
func (ss *StaticNodeStrategy) Filter() ([]string, error)
Filter return static nodes peers