network

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectAsync added in v0.15.0

func ConnectAsync(ctx context.Context, h lp2phost.Host, addrInfo lp2ppeer.AddrInfo, logger *logger.SubLogger)

func MakeAddressInfo added in v0.15.0

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

MakeAddressInfo from Multi-address 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 Config

type Config struct {
	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"`
	EnableMetrics bool             `toml:"enable_metrics"`
	Bootstrap     *BootstrapConfig `toml:"bootstrap"`
}

func DefaultConfig

func DefaultConfig() *Config

func (*Config) BasicCheck added in v0.15.0

func (conf *Config) BasicCheck() error

BasicCheck performs basic checks on the configuration.

type ConnectEvent added in v0.15.0

type ConnectEvent struct {
	PeerID lp2pcore.PeerID
}

ConnectEvent represents a peer connection event.

func (*ConnectEvent) Type added in v0.15.0

func (*ConnectEvent) Type() EventType

type DisconnectEvent added in v0.15.0

type DisconnectEvent struct {
	PeerID lp2pcore.PeerID
}

DisconnectEvent represents a peer disconnection event.

func (*DisconnectEvent) Type added in v0.15.0

func (*DisconnectEvent) Type() EventType

type Event

type Event interface {
	Type() EventType
}

type EventType

type EventType int
const (
	EventTypeConnect    EventType = 1
	EventTypeDisconnect EventType = 2
	EventTypeGossip     EventType = 3
	EventTypeStream     EventType = 4
)

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 InvalidTopicError added in v0.15.0

type InvalidTopicError struct {
	TopicID TopicID
}

InvalidTopicError is returned when the Pub-Sub topic is invalid.

func (InvalidTopicError) Error added in v0.15.0

func (e InvalidTopicError) Error() string

type LibP2PError added in v0.15.0

type LibP2PError struct {
	Err error
}

LibP2PError is returned when an underlying libp2p operation encounters an error.

func (LibP2PError) Error added in v0.15.0

func (e LibP2PError) Error() string

type MockNetwork

type MockNetwork struct {
	*testsuite.TestSuite

	PublishCh chan PublishData
	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(networkName string, conf *Config) (Network, error)

type NotSubscribedError added in v0.15.0

type NotSubscribedError struct {
	TopicID TopicID
}

NotSubscribedError is returned when the peer is not subscribed to a specific topic.

func (NotSubscribedError) Error added in v0.15.0

func (e NotSubscribedError) Error() string

type NotifeeService added in v0.15.0

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

func (*NotifeeService) Connected added in v0.15.0

func (n *NotifeeService) Connected(lp2pn lp2pnetwork.Network, conn lp2pnetwork.Conn)

func (*NotifeeService) Disconnected added in v0.15.0

func (n *NotifeeService) Disconnected(_ lp2pnetwork.Network, conn lp2pnetwork.Conn)

func (*NotifeeService) Listen added in v0.15.0

func (n *NotifeeService) Listen(_ lp2pnetwork.Network, ma ma.Multiaddr)

func (*NotifeeService) ListenClose added in v0.15.0

func (n *NotifeeService) ListenClose(_ lp2pnetwork.Network, ma ma.Multiaddr)

ListenClose is called when your node stops listening on an address.

type PublishData added in v0.15.0

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

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