net

package
v0.0.0-...-8fa2440 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2016 License: MIT Imports: 15 Imported by: 26

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDialer = NetDialer

Default dialer. May be changed.

View Source
var ErrLimitExceeded = errors.New("reader size limit exceeded")

Error returned if the number of bytes read from a LimitReader exceeds the limit.

View Source
var NetDialer netDialer

Standard package net dialer.

View Source
var WasTruncated error = errors.New("datagram was truncated")

Functions

func ErrorIsConnAborted

func ErrorIsConnAborted(e error) bool

func ErrorIsConnRefused

func ErrorIsConnRefused(e error) bool

func ErrorIsConnReset

func ErrorIsConnReset(e error) bool

func ErrorIsPortUnreachable

func ErrorIsPortUnreachable(e error) bool

Hacky function to determine whether an error returned from UDPConn.Write corresponds to an ICMP Port Unreachable message.

func FuzzySplitHostPort

func FuzzySplitHostPort(hostport string) (host, port string, err error)

Like net.SplitHostPort, but supports absence of port. For example, "192.0.2.1" is accepted.

func FuzzySplitHostPortI

func FuzzySplitHostPortI(network, hostport string) (host string, port uint16, err error)

Like FuzzySplitHostPort, but returns an integer for the port. Supports symbolic port names (e.g. "http"). If the port name is unknown, returns error.

"net" must be the port namespace (e.g. "tcp" or "udp"). If "", the port must be given as an integer.

If a port was not specified, port is 0.

func FuzzySplitHostPortIPI

func FuzzySplitHostPortIPI(network, hostport string) (host net.IP, port uint16, err error)

Like FuzzySplitHostPortIPI, but the host part must be an IP address, not a hostname.

func Hostname

func Hostname() string

Returns the fully-qualified hostname for the local machine. May return "" if a hostname cannot be determined. Note that this may return a non-meaningful hostname like "localhost.localdomain".

func IsRFC1918

func IsRFC1918(ip gnet.IP) bool

func LimitReader

func LimitReader(r io.Reader, limit int) io.Reader

Creates a limit reader. This is similar to io.LimitReader, except that if more than limit bytes are read from the stream, an error is returned rather than EOF. Thus, accidental truncation of oversized byte streams is avoided in favour of a hard error.

Returns ErrLimitExceeded once more than limit bytes are read. The read operation still occurs.

func MaxDatagramSize

func MaxDatagramSize() int

In order to call UDPConn.Read, we have to have a buffer of appropriate size. If the buffer is too short for the datagram received, it will be truncated. This is undesirable. There is no way to get the length of the next datagram without calling Read and go doesn't give us any way to pass the PEEK and TRUNC flags, which would allow us to get the size and then call Read again.

The maximum size of an IPv6 packet is 2**32-1 using jumbograms. However, IPv6 fragmentation supports maximum packet sizes of 2**16-1, so a packet of size greater than 2**16-1 can only be sent via a sequence of links all having an MTU sufficient to enable unfragmented transmission. Therefore, the maximum size of an incoming datagram is 2**16-1 or the MTU, whichever is higher. Rather than try and tell which interface a datagram arrived on, we simply use the largest MTU of all interfaces on the system.

If a link has an MTU in excess of 2**31-1, then it is possible for a datagram to be received of a size unrepresentable by the integer return type of the Read method, which is supposed to represent the number of bytes read. This is a bug in the Go standard library. Therefore, this implementation cannot support reception of datagrams larger than 2**31-1. The determined maximum receive size is capped at 2**31-2. Subtracting an extra byte from the maximum receive size allows one to determine whether a packet may have exceeded the limitation of the Go API; such packets can then be discarded rather than being processed. It is assumed that it is undesirable to process truncated packets.

This function returns the determined maximum receive size.

func ReadDatagram

func ReadDatagram(c net.Conn) (buf []byte, err error)

Reads a datagram into a buffer using the determined maximum receive size, truncates the buffer to the length actually received and returns it.

Returns error WasTruncated and an empty slice if the incoming packet may have been truncated.

func ReadDatagramFromUDP

func ReadDatagramFromUDP(c UDPConn) (buf []byte, addr *net.UDPAddr, err error)

func RepadBase32

func RepadBase32(s string) string

untested

func RepadBase64

func RepadBase64(s string) string

func Require200

func Require200(res *http.Response, err error) (*http.Response, error)

func UpdateMaxDatagramSize

func UpdateMaxDatagramSize() int

Updates the determined maximum receive size. Necessary if the maximum MTU of all the interfaces configured on the system changes, and that value exceeds 2**16-1.

Types

type Backoff

type Backoff struct {
	// The maximum number of attempts which may be made.
	// If this is 0, the number of attempts is unlimited.
	MaxTries int

	// The initial delay, in milliseconds. This is the delay used after the first
	// failed attempt.
	InitialDelay time.Duration // ms

	// The maximum delay, in milliseconds. This is the maximum delay between
	// attempts.
	MaxDelay time.Duration // ms

	// Determines when the maximum delay should be reached. If this is 5, the
	// maximum delay will be reached after 5 attempts have been made.
	MaxDelayAfterTries int

	// Positive float expressing the maximum factor by which the delay value may
	// be randomly inflated. e.g. specify 0.05 for a 5% variation. Set to zero to
	// disable jitter.
	Jitter float64

	// The current try. You should not need to set this yourself.
	CurrentTry int
}

Expresses a backoff and retry specification.

The nil value of this structure results in sensible defaults being used.

func (*Backoff) InitDefaults

func (rc *Backoff) InitDefaults()

Initialises any nil field in Backoff with sensible defaults. You normally do not need to call this method yourself, as it will be called automatically.

func (*Backoff) NextDelay

func (rc *Backoff) NextDelay() time.Duration

Gets the next delay in milliseconds and increments the internal try counter.

func (*Backoff) Reset

func (rc *Backoff) Reset()

Sets the internal try counter to zero; the next delay returned will be InitialDelay again.

func (*Backoff) Sleep

func (rc *Backoff) Sleep() bool

Sleep for the duration returned by NextDelay().

type Base64

type Base64 []byte

func (Base64) MarshalJSON

func (b Base64) MarshalJSON() ([]byte, error)

func (*Base64) UnmarshalJSON

func (b *Base64) UnmarshalJSON(data []byte) error

type Base64up

type Base64up []byte

func (Base64up) MarshalJSON

func (b Base64up) MarshalJSON() ([]byte, error)

func (*Base64up) UnmarshalJSON

func (b *Base64up) UnmarshalJSON(data []byte) error

type Dialer

type Dialer interface {
	Dial(net, addr string, ctx context.Context) (net.Conn, error)
}

Dial with deadline awareness.

type DialerFunc

type DialerFunc func(net, addr string, ctx context.Context) (net.Conn, error)

Dialer function adapter.

func (DialerFunc) Dial

func (df DialerFunc) Dial(net, addr string, ctx context.Context) (net.Conn, error)

type UDPConn

type UDPConn interface {
	Close() error
	ReadFromUDP(b []byte) (int, *net.UDPAddr, error)
	WriteToUDP(b []byte, addr *net.UDPAddr) (int, error)
}

Directories

Path Synopsis
Package bsda provides message framing on top of ordered reliable byte streams.
Package bsda provides message framing on top of ordered reliable byte streams.
Package connect provides functions for connecting to services using SRV records, TLS, etc.
Package connect provides functions for connecting to services using SRV records, TLS, etc.
Package curvecp implements a CurveCP-esque protocol over stateful reliable ordered bidirectional point-to-point datagram streams.
Package curvecp implements a CurveCP-esque protocol over stateful reliable ordered bidirectional point-to-point datagram streams.
Package unixhttp provides utilities to allow HTTP connections to be made over Unix domain sockets.
Package unixhttp provides utilities to allow HTTP connections to be made over Unix domain sockets.

Jump to

Keyboard shortcuts

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