network

package
v0.0.0-...-8220f0d Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2019 License: MIT Imports: 29 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)
	NodesInShard(shardID uint64) []uint64
	RandNodeInShard(shardID uint64) uint64
	ShardForNode(nodeID uint64) uint64
	ShardForVersionID(key []byte) uint64
	ShardSize() uint64
	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) BootstrapFile

func (t *Topology) BootstrapFile(path string) error

BootstrapFile will use the JSON file at the given path for the initial set of addresses for nodes in the network.

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) NodesInShard

func (t *Topology) NodesInShard(shardID uint64) []uint64

NodesInShard returns a slice of node IDs for the given shard ID.

func (*Topology) RandNodeInShard

func (t *Topology) RandNodeInShard(shardID uint64) uint64

RandNodeFromShard return a random node id from a given shard

func (*Topology) SeedPublicKeys

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

SeedPublicKeys returns a map of the signing keys for each of the seed nodes.

func (*Topology) ShardForNode

func (t *Topology) ShardForNode(nodeID uint64) uint64

ShardForNode returns the shard ID for the given node ID.

func (*Topology) ShardForVersionID

func (t *Topology) ShardForVersionID(key []byte) uint64

ShardForVersionID returns the shard ID for the given object key.

func (*Topology) ShardSize

func (t *Topology) ShardSize() uint64

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