network

package
v0.0.0-...-34de315 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Odin = []byte{79, 68, 73, 78}
	Thor = []byte{84, 72, 79, 82}
	Loki = []byte{76, 79, 75, 73}
)

Enumeration of different networks available. A node configured with one network will only successfully connect to nodes of the same network. To be used for testing & iteration.

Functions

func AnyMsgFilter

func AnyMsgFilter(addresses ...string) func(interface{}) bool

AnyMsgFilter filter for any message type

func MsgFilter

func MsgFilter(msgType MsgType, addresses ...string) func(interface{}) bool

MsgFilter can be used to filter out message types.

func SetAddress

func SetAddress(address string) func(*Config)

SetAddress allows us to configure a custom listen address.

func SetListen

func SetListen(listen bool) func(*Config)

SetListen allows us to configure a custom server status.

func SetMaxPeers

func SetMaxPeers(maxPeers uint) func(*Config)

SetMaxPeers allows us to configure a custom number for maximum peers.

func SetMaxPending

func SetMaxPending(maxPending uint) func(*Config)

SetMaxPending allows us to configure the custom number for maximum pending.

func SetMinPeers

func SetMinPeers(minPeers uint) func(*Config)

SetMinPeers allows us to configure a custom number for minimum peers.

func SetNetwork

func SetNetwork(network []byte) func(*Config)

SetNetwork allows us to configure a custom network ID.

Types

type Codec

type Codec interface {
	Encode(w io.Writer, i interface{}) error
	Decode(r io.Reader) (interface{}, error)
}

Codec represents a module for network serialization & encoding, as well as deserialization & decoding, using the same format.

type Config

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

Config represents the configuration parameters available to configure a node on the peer-to-peer network.

type Connected

type Connected struct {
	Address   string
	Timestamp time.Time
}

Connected represents a connection event.

type Disconnected

type Disconnected struct {
	Address   string
	Timestamp time.Time
}

Disconnected represents a disconnection event.

type Discover

type Discover struct {
}

Discover represents a discovery message sent on the network.

type Listener

type Listener interface {
	Accept() (net.Conn, error)
	Close() error
	SetDeadline(t time.Time) error
}

Listener defines our own listener as the standard library interface doesn't have the deadline functions.

type MsgType

type MsgType uint16

MsgType enum.

type Network

type Network interface {
	Add(address string)
	Send(address string, msg interface{}) error
	Broadcast(msg interface{}, exclude ...string) error
	Stop()
	Stats()
}

Network defines the exposed API of the Alvalor network package.

func New

func New(log zerolog.Logger, codec Codec, options ...func(*Config)) Network

New will initialize the network component.

type Peers

type Peers struct {
	Addresses []string
}

Peers represents a list of peer addresses shared on the network.

type Ping

type Ping struct {
	Nonce uint32
}

Ping represents an outgoing heartbeat message sent on the network.

type Pong

type Pong struct {
	Nonce uint32
}

Pong represents a heartbeat response sent on the network.

type Received

type Received struct {
	Address   string
	Timestamp time.Time
	Message   interface{}
}

Received represents a message received event.

Jump to

Keyboard shortcuts

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