network

package
v0.0.0-...-df2b3d5 Latest Latest
Warning

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

Go to latest
Published: May 8, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Peer

type Peer interface {
	Send(*pb.Message) error
	Disconnect(error)
	Endpoint() string
}

Peer represents a remote node in the network its an interface the may be backed by any concrete transport.

type Server

type Server struct {
	// Configuration of the server.
	ServerConfig
	// contains filtered or unexported fields
}

Server represents a remote node in the p2p network.

func NewServer

func NewServer(cfg ServerConfig, engine consensus.Engine) *Server

NewServer returns a new Server object.

func (*Server) Relay

func (s *Server) Relay(msg *pb.Message)

Relay will forward any given message to the connected peers.

func (*Server) Start

func (s *Server) Start() error

Start attempts to start running the server.

type ServerConfig

type ServerConfig struct {
	// The listen address of the server.
	ListenAddr int

	// A list of seed nodes to bootstrap the initial network.
	BootstrapNodes []string

	// The number of seconds it may take for dialing outbound connections.
	// Note that you need to pass N * time.Second to get the time.Duration
	// in seconds.
	DialTimeout time.Duration

	// When set to true this node will act as a faulty node in the network.
	Faulty bool

	// Whether this node will act as a consensus node (block producer).
	Consensus bool

	// PrivateKey of the server. This can be left empty if consensus is set
	// to false.
	PrivateKey *ecdsa.PrivateKey
}

ServerConfig holds the server configuration.

type TCPPeer

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

TCPPeer represents a remote node backed by TCP transport.

func NewTCPPeer

func NewTCPPeer(conn net.Conn) *TCPPeer

NewTCPPeer returns a new TCPPeer object.

func (*TCPPeer) Disconnect

func (p *TCPPeer) Disconnect(err error)

Disconnect implements the Peer interface.

func (*TCPPeer) Endpoint

func (p *TCPPeer) Endpoint() string

Endpoint implements the Peer interface.

func (*TCPPeer) Send

func (p *TCPPeer) Send(msg *pb.Message) error

Send implements the Peer interface.

type TCPTransport

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

TCPTransport represents network transportation backed by plain TCP.

func NewTCPTransport

func NewTCPTransport(s *Server) *TCPTransport

NewTCPTransport return a new TCPTransport.

func (*TCPTransport) Close

func (t *TCPTransport) Close()

Close implements the Transport interface.

func (*TCPTransport) Dial

func (t *TCPTransport) Dial(addr string, d time.Duration) error

Dial implements the Transport interface.

func (*TCPTransport) Listen

func (t *TCPTransport) Listen(addr string) error

Listen implements the Transport inteface.

type Transport

type Transport interface {
	Dial(string, time.Duration) error
	Listen(string) error
	Close()
}

Transport is an interface that abstracts the underlying network transport. It could be backed by any kind (Thrift, GRPC, plain TCP,..)

Jump to

Keyboard shortcuts

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