p2pv1

package
v0.0.0-...-b2d87a2 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 26 Imported by: 2

README

p2pv1

p2pv1组件实现。

Documentation

Index

Constants

View Source
const (
	ServerName = "p2pv1"
)

Variables

View Source
var (
	ErrEmptyPeer  = errors.New("empty peer")
	ErrNoResponse = errors.New("no response")
)
View Source
var (
	ErrAddressIllegal  = errors.New("address illegal")
	ErrLoadAccount     = errors.New("load account error")
	ErrAccountNotExist = errors.New("account not exist")
)

Functions

func NewP2PServerV1

func NewP2PServerV1() p2p.Server

NewP2PServerV1 create P2PServerV1 instance

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func NewConn

func NewConn(ctx *nctx.NetCtx, addr string) (*Conn, error)

NewConn create new connection with addr

func (*Conn) Close

func (c *Conn) Close()

Close close this conn

func (*Conn) PeerID

func (c *Conn) PeerID() string

GetConnID return conn id

func (*Conn) SendMessage

func (c *Conn) SendMessage(ctx xctx.XContext, msg *pb.XuperMessage) error

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

func NewConnPool

func NewConnPool(ctx *nctx.NetCtx) (*ConnPool, error)

func (*ConnPool) Get

func (p *ConnPool) Get(addr string) (*Conn, error)

func (*ConnPool) GetAll

func (p *ConnPool) GetAll() map[string]string

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() *netCtx.NetCtx

func (*P2PServerV1) GetPeer

func (p *P2PServerV1) GetPeer(peerInfo pb.PeerInfo, addr string) []*pb.PeerInfo

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 *netCtx.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

type PeerFilter interface {
	Filter() ([]string, error)
}

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

Jump to

Keyboard shortcuts

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