network

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2018 License: AGPL-3.0 Imports: 7 Imported by: 4

Documentation

Overview

Package network provides a portable interface for network I/O, constraining its usage allowing only to send & receive data in a packet format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	packet.TagSet
	MaxIdle time.Duration
}

type Conn

type Conn struct {

	// Err is filled when the connection gets closed.
	Err error
	// contains filtered or unexported fields
}

Conn manages the serialization and deserialization of the entire communication system between booster nodes. Only one consumer per time is allowed.

func Open

func Open(conn net.Conn, config Config) *Conn

Open creates a new connection backed by conn configured with config.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection.

func (*Conn) Consume

func (c *Conn) Consume() (<-chan *packet.Packet, error)

Consume keeps on reading on the connection, decoding each message received and exiting with an error if it is not able to decode the data collected into a packet. Each packet is sent into the decoded channel. When it gets closed, check c.Err.

func (*Conn) Recv

func (c *Conn) Recv() (*packet.Packet, error)

Recv reads one packet from the connection. Returns an error if the connection is already consuming packets.

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

RemoteAddr returns the address of the remote endpoint.

func (*Conn) Send

func (c *Conn) Send(p *packet.Packet) error

Send sends the packet trough the connection. It is safe to call from multiple goroutines.

type Dialer

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

Dialer wraps a network dialer.

func NewDialer

func NewDialer(d *net.Dialer, config Config) *Dialer

NewDialer returns a new dialer instance.

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, addr string) (*Conn, error)

DialContext dials a new net.Conn with addr, wrapping the new connection with a packet encoder/decoder.

type Listener

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

Listener wraps a net.Listener.

func Listen

func Listen(network, addr string, config Config) (*Listener, error)

Listen announces to the local network address.

func (*Listener) Accept

func (l *Listener) Accept() (*Conn, error)

Accept accepts incoming network connections, wrapping it into a booster connection.

func (*Listener) Close

func (l *Listener) Close() error

Close closes the underlying listener, macking Accecpt to quit and refute any other network connection.

type NetworkIO added in v0.4.0

type NetworkIO struct {
	Ticker        *time.Ticker
	NextCopyDelay time.Duration

	sync.Mutex
	N         int64 // N is the number of bytes transmitted
	Bandwidth int64
	// contains filtered or unexported fields
}

NetworkIO implements the io.CopyN method, keeping track of the bandwidth while doing so.

func (*NetworkIO) CopyN added in v0.4.0

func (b *NetworkIO) CopyN(dst io.Writer, src io.Reader, n int64) (int64, error)

CopyN copies data from src into dst, using a buffer of size n. Keeps track of the number of bytes copied.

func (*NetworkIO) TickerFunc added in v0.4.0

func (b *NetworkIO) TickerFunc(d time.Duration, f func())

TickerFunc calls f repeatedly after d. Badwidth is calculated right before calling f.

Directories

Path Synopsis
Package packet provides functionalities for building, encoding and decoding data.
Package packet provides functionalities for building, encoding and decoding data.

Jump to

Keyboard shortcuts

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