network

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakePeer added in v0.11.0

func MakePeer(addr string) (*lp2ppeer.AddrInfo, error)

MakePeer from multiaddress string.

func PeerAddrsToAddrInfo

func PeerAddrsToAddrInfo(addrs []string) ([]lp2ppeer.AddrInfo, error)

PeerAddrsToAddrInfo converts a slice of string peer addresses to AddrInfo.

Types

type BootstrapConfig

type BootstrapConfig struct {
	Addresses    []string      `toml:"addresses"`
	MinThreshold int           `toml:"min_threshold"`
	MaxThreshold int           `toml:"max_threshold"`
	Period       time.Duration `toml:"period"`
}

BootstrapConfig holds all configuration options related to bootstrap nodes.

type BroadcastData

type BroadcastData struct {
	Data   []byte
	Target *lp2pcore.PeerID
}

type Config

type Config struct {
	Name        string           `toml:"name"`
	Listens     []string         `toml:"listens"`
	NetworkKey  string           `toml:"network_key"`
	EnableNAT   bool             `toml:"enable_nat"`
	EnableRelay bool             `toml:"enable_relay"`
	RelayAddrs  []string         `toml:"relay_addresses"`
	EnableMdns  bool             `toml:"enable_mdns"`
	Bootstrap   *BootstrapConfig `toml:"bootstrap"`
}

func DefaultConfig

func DefaultConfig() *Config

func (*Config) SanityCheck

func (conf *Config) SanityCheck() error

SanityCheck performs basic checks on the configuration.

type Event

type Event interface {
	Type() EventType
}

type EventType

type EventType int
const (
	EventTypeGossip EventType = 1
	EventTypeStream EventType = 2
)

func (EventType) String

func (t EventType) String() string

type GossipMessage

type GossipMessage struct {
	Source lp2pcore.PeerID
	From   lp2pcore.PeerID
	Data   []byte
}

GossipMessage represents message from PubSub module. `Source` is the ID of the peer that initiate the message and `From` is the ID of the peer that we received a message from. They are not necessarily the same, especially in a decentralized network.

func (*GossipMessage) Type

func (*GossipMessage) Type() EventType

type MockNetwork

type MockNetwork struct {
	*testsuite.TestSuite

	BroadcastCh chan BroadcastData
	EventCh     chan Event
	ID          peer.ID
	OtherNets   []*MockNetwork
	SendError   error
}

func MockingNetwork

func MockingNetwork(ts *testsuite.TestSuite, id peer.ID) *MockNetwork

func (*MockNetwork) AddAnotherNetwork

func (mock *MockNetwork) AddAnotherNetwork(net *MockNetwork)

func (*MockNetwork) Broadcast

func (mock *MockNetwork) Broadcast(data []byte, _ TopicID) error

func (*MockNetwork) CloseConnection

func (mock *MockNetwork) CloseConnection(pid peer.ID)

func (*MockNetwork) EventChannel

func (mock *MockNetwork) EventChannel() <-chan Event

func (*MockNetwork) IsClosed

func (mock *MockNetwork) IsClosed(pid peer.ID) bool

func (*MockNetwork) JoinConsensusTopic

func (mock *MockNetwork) JoinConsensusTopic() error

func (*MockNetwork) JoinGeneralTopic

func (mock *MockNetwork) JoinGeneralTopic() error

func (*MockNetwork) NumConnectedPeers

func (mock *MockNetwork) NumConnectedPeers() int

func (*MockNetwork) SelfID

func (mock *MockNetwork) SelfID() peer.ID

func (*MockNetwork) SendTo

func (mock *MockNetwork) SendTo(data []byte, pid lp2pcore.PeerID) error

func (*MockNetwork) SendToOthers

func (mock *MockNetwork) SendToOthers(data []byte, target *peer.ID)

func (*MockNetwork) Start

func (mock *MockNetwork) Start() error

func (*MockNetwork) Stop

func (mock *MockNetwork) Stop()

type Network

type Network interface {
	Start() error
	Stop()
	EventChannel() <-chan Event
	Broadcast([]byte, TopicID) error
	SendTo([]byte, lp2pcore.PeerID) error
	JoinGeneralTopic() error
	JoinConsensusTopic() error
	CloseConnection(pid lp2pcore.PeerID)
	SelfID() lp2pcore.PeerID
	NumConnectedPeers() int
}

func NewNetwork

func NewNetwork(conf *Config) (Network, error)

type StreamMessage

type StreamMessage struct {
	Source lp2pcore.PeerID
	Reader io.ReadCloser
}

StreamMessage represents message from stream module.

func (*StreamMessage) Type

func (*StreamMessage) Type() EventType

type TopicID

type TopicID int
const (
	TopicIDGeneral   TopicID = 1
	TopicIDConsensus TopicID = 2
)

func (TopicID) String

func (t TopicID) String() string

Jump to

Keyboard shortcuts

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