p2pv1

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: 25 Imported by: 0

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() netBase.Network

NewP2PServerV1 create P2PServerV1 instance

Types

type Conn

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

func NewConn

func NewConn(ctx *netBase.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

PeerID return conn id

func (*Conn) SendMessage

func (c *Conn) SendMessage(ctx xctx.Context, msg *protos.CoreMessage) error

SendMessage send message to a peer

func (*Conn) SendMessageWithResponse

func (c *Conn) SendMessageWithResponse(ctx xctx.Context, msg *protos.CoreMessage) (*protos.CoreMessage, 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 *netBase.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() *netBase.NetCtx

func (*P2PServerV1) GetPeer

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

func (*P2PServerV1) GetPeerIdByAccount

func (p *P2PServerV1) GetPeerIdByAccount(account string) (string, error)

func (*P2PServerV1) GetPeerInfo

func (p *P2PServerV1) GetPeerInfo(addresses []string) ([]*protos.PeerInfo, error)

func (*P2PServerV1) Init

func (p *P2PServerV1) Init(ctx *netBase.NetCtx) error

Init initialize network server using given config

func (*P2PServerV1) NewSubscriber

func (p *P2PServerV1) NewSubscriber(typ protos.CoreMessage_MessageType, v interface{}, opts ...netBase.SubscriberOption) netBase.Subscriber

func (*P2PServerV1) PeerInfo

func (p *P2PServerV1) PeerInfo() protos.PeerInfo

PeerInfo 获取本节点和远端节点的连接信息

func (*P2PServerV1) Register

func (p *P2PServerV1) Register(sub netBase.Subscriber) error

func (*P2PServerV1) SendMessage

func (p *P2PServerV1) SendMessage(ctx xctx.Context, msg *protos.CoreMessage, optFunc ...base.OptionFunc) error

SendMessage send message to peers using given filter strategy

func (*P2PServerV1) SendMessageWithResponse

func (p *P2PServerV1) SendMessageWithResponse(ctx xctx.Context, msg *protos.CoreMessage, optFunc ...base.OptionFunc) ([]*protos.CoreMessage, error)

SendMessageWithResponse send message to peers using given filter strategy, expect response from peers

func (*P2PServerV1) SendP2PMessage

func (p *P2PServerV1) SendP2PMessage(stream protos.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 netBase.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