p2p

package
v0.0.0-...-8526a12 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RequestCodeBytesLen = 3
)

Variables

View Source
var (
	TopicsMap = make(map[string]*pubsub.Topic, 0)
	SubsMap   = make(map[string]*pubsub.Subscription, 0)
)

Functions

This section is empty.

Types

type LibP2P

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

todo: use stream pool to optimize it

func (*LibP2P) AddDefaultTopics

func (p *LibP2P) AddDefaultTopics()

func (*LibP2P) AddTopic

func (p *LibP2P) AddTopic(topicName string)

func (*LibP2P) ConnectBootNodes

func (p *LibP2P) ConnectBootNodes() error

func (*LibP2P) GetBootNodes

func (p *LibP2P) GetBootNodes() (peers []peerstore.ID)

func (*LibP2P) LocalID

func (p *LibP2P) LocalID() peerstore.ID

func (*LibP2P) LocalIdString

func (p *LibP2P) LocalIdString() string

func (*LibP2P) PubP2P

func (p *LibP2P) PubP2P(topic string, msg []byte) error

func (*LibP2P) RequestPeer

func (p *LibP2P) RequestPeer(peerID peerstore.ID, code int, request []byte) ([]byte, error)

func (*LibP2P) SetHandlers

func (p *LibP2P) SetHandlers(handlers map[int]dev.P2pHandler)

func (*LibP2P) SubP2P

func (p *LibP2P) SubP2P(topic string) ([]byte, error)

type MockP2p

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

func NewMockP2p

func NewMockP2p(nodesNum int) *MockP2p

func (*MockP2p) AddTopic

func (m *MockP2p) AddTopic(topicName string)

func (*MockP2p) ConnectBootNodes

func (m *MockP2p) ConnectBootNodes() error

func (*MockP2p) GetBootNodes

func (m *MockP2p) GetBootNodes() []peer.ID

func (*MockP2p) LocalID

func (m *MockP2p) LocalID() peer.ID

func (*MockP2p) LocalIdString

func (m *MockP2p) LocalIdString() string

func (*MockP2p) PubP2P

func (m *MockP2p) PubP2P(topic string, msg []byte) error

func (*MockP2p) RequestPeer

func (m *MockP2p) RequestPeer(peerID peer.ID, code int, request []byte) (response []byte, err error)

func (*MockP2p) SetHandlers

func (m *MockP2p) SetHandlers(handlers map[int]dev.P2pHandler)

func (*MockP2p) SubP2P

func (m *MockP2p) SubP2P(topic string) ([]byte, error)

type P2pNetwork

type P2pNetwork interface {
	LocalID() peer.ID
	LocalIdString() string

	GetBootNodes() []peer.ID
	ConnectBootNodes() error

	AddTopic(topicName string)

	SetHandlers(handlers map[int]dev.P2pHandler)
	RequestPeer(peerID peer.ID, code int, request []byte) (response []byte, err error)

	PubP2P(topic string, msg []byte) error
	SubP2P(topic string) ([]byte, error)
}

func NewP2P

func NewP2P(cfg *config.P2pConf) P2pNetwork

Jump to

Keyboard shortcuts

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