net

package
v0.0.0-...-42befb5 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection interface {
	ID() string
	Send(message []byte, id []byte)
	Close() error
	LastOpTime() time.Time // last rw op time for this connection
	RemoteAddr() net.Addr
}

Connection is a closeable network connection, that can send and receive messages from a remote instance. Connection is an io.Writer and an io.Closer.

type ConnectionError

type ConnectionError struct {
	Connection Connection
	Err        error
	ID         []byte // optional outgoing message id
}

ConnectionError specifies a connection error.

type ConnectionSource

type ConnectionSource int

ConnectionSource specifies the connection originator - local or remote node.

const (
	Local ConnectionSource = iota
	Remote
)

ConnectionSource values.

type IncomingMessage

type IncomingMessage struct {
	Connection Connection
	Message    []byte
}

IncomingMessage specifies incoming network message data.

type MessageSendError

type MessageSendError struct {
	Connection Connection
	Message    []byte
	Err        error
	ID         []byte
}

MessageSendError defines an error condition for sending a message.

type MessageSentEvent

type MessageSentEvent struct {
	Connection Connection
	ID         []byte
}

MessageSentEvent specifies a sent network message data.

type Net

type Net interface {
	DialTCP(address string, timeOut time.Duration, keepAlive time.Duration) (Connection, error) // Connect to a remote node. Can send when no error.
	GetNewConnections() chan Connection
	GetClosingConnections() chan Connection
	GetConnectionErrors() chan ConnectionError
	GetIncomingMessage() chan IncomingMessage
	GetMessageSendErrors() chan MessageSendError
	GetMessageSentCallback() chan MessageSentEvent
	Shutdown()
}

Net is a connection manager able to dial remote endpoints. Net clients should register all callbacks.

Connections may be initiated by DialTCP() or by remote clients connecting to the listen address. ConnManager includes a TCP server, and a TCP client.

It provides full duplex messaging functionality over the same tcp/ip connection. Network should not know about higher-level networking types such as remoteNode, swarm and networkSession. Network main client is the swarm. Net has no channel events processing loops - clients are responsible for polling these channels and popping events from them

func NewNet

func NewNet(tcpListenAddress string, config nodeconfig.Config) (Net, error)

NewNet creates a new network. It attempts to tcp listen on address. e.g. localhost:1234.

type OutgoingMessage

type OutgoingMessage struct {
	Message []byte
	ID      []byte
}

OutgoingMessage specifies an outgoing message data.

Jump to

Keyboard shortcuts

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