network

package
v0.0.0-...-782863c Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNodeWithZeroID = errors.New("network: received invalid Node ID: 0")
)

Error values.

Functions

func AbnormalError

func AbnormalError(err error) bool

AbnormalError returns whether the given error was abnormal, i.e. not EOF or a timeout error.

Types

type Conn

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

Conn represents a connection to a Chainspace node.

func NewConn

func NewConn(conn net.Conn) *Conn

NewConn instantiates a Conn value with the given network connection.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the underlying connection.

func (*Conn) ReadHello

func (c *Conn) ReadHello(limit int, timeout time.Duration) (*service.Hello, error)

ReadHello reads a service.Hello from the underlying connection.

func (*Conn) ReadMessage

func (c *Conn) ReadMessage(limit int, timeout time.Duration) (*service.Message, error)

ReadMessage reads a service.Message from the underlying connection.

func (*Conn) WritePayload

func (c *Conn) WritePayload(pb proto.Message, limit int, timeout time.Duration) error

WritePayload encodes the given payload into protobuf and writes the marshalled data to the underlying connection, along with a header indicating the length of the data.

func (*Conn) WriteRequest

func (c *Conn) WriteRequest(msg *service.Message, limit int, timeout time.Duration) (id uint64, err error)

WriteRequest adds a connection-specific ID to the given message before writing it out on the underlying connection.

type NetTopology

type NetTopology interface {
	Dial(nodeID uint64, timeout time.Duration) (*Conn, error)
	TotalNodes() uint64
	SeedPublicKeys() map[uint64]signature.PublicKey
}

type Topology

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

Topology represents a Chainspace network.

func New

func New(name string, cfg *config.Network) (*Topology, error)

New parses the given network configuration and creates a network topology for connecting to nodes.

func (*Topology) BootstrapMDNS

func (t *Topology) BootstrapMDNS()

BootstrapMDNS will try to auto-discover the addresses of initial nodes using multicast DNS.

func (*Topology) BootstrapRegistries

func (t *Topology) BootstrapRegistries(registries []config.Registry)

BootstrapRegistries will use the given registries to discover the initial addresses of nodes in the network.

func (*Topology) BootstrapStatic

func (t *Topology) BootstrapStatic(addresses map[uint64]string) error

BootstrapStatic will use the given static map of addresses for the initial addresses of nodes in the network.

func (*Topology) Dial

func (t *Topology) Dial(nodeID uint64, timeout time.Duration) (*Conn, error)

Dial opens a connection to a node in the given network. It will block if unable to find a routing address for the given node.

func (*Topology) Lookup

func (t *Topology) Lookup(nodeID uint64) string

Lookup returns the latest host:port address for a given node ID.

func (*Topology) Nodes

func (t *Topology) Nodes() []uint64

TotalNodes returns the total number of nodes in the network.

func (*Topology) SeedPublicKeys

func (t *Topology) SeedPublicKeys() map[uint64]signature.PublicKey

func (*Topology) TotalNodes

func (t *Topology) TotalNodes() uint64

TotalNodes returns the total number of nodes in the network.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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