Documentation
¶
Index ¶
- Variables
- func ErrorIsConnAborted(e error) bool
- func ErrorIsConnRefused(e error) bool
- func ErrorIsConnReset(e error) bool
- func ErrorIsPortUnreachable(e error) bool
- func FuzzySplitHostPort(hostport string) (host, port string, err error)
- func FuzzySplitHostPortI(network, hostport string) (host string, port uint16, err error)
- func FuzzySplitHostPortIPI(network, hostport string) (host net.IP, port uint16, err error)
- func Hostname() string
- func IsRFC1918(ip gnet.IP) bool
- func LimitReader(r io.Reader, limit int) io.Reader
- func MaxDatagramSize() int
- func ReadDatagram(c net.Conn) (buf []byte, err error)
- func ReadDatagramFromUDP(c UDPConn) (buf []byte, addr *net.UDPAddr, err error)
- func RepadBase32(s string) string
- func RepadBase64(s string) string
- func Require200(res *http.Response, err error) (*http.Response, error)
- func UpdateMaxDatagramSize() int
- type Backoff
- type Base64
- type Base64up
- type Dialer
- type DialerFunc
- type UDPConn
Constants ¶
This section is empty.
Variables ¶
var DefaultDialer = NetDialer
Default dialer. May be changed.
var ErrLimitExceeded = errors.New("reader size limit exceeded")
Error returned if the number of bytes read from a LimitReader exceeds the limit.
var NetDialer netDialer
Standard package net dialer.
var WasTruncated error = errors.New("datagram was truncated")
Functions ¶
func ErrorIsConnAborted ¶
func ErrorIsConnRefused ¶
func ErrorIsConnReset ¶
func ErrorIsPortUnreachable ¶
Hacky function to determine whether an error returned from UDPConn.Write corresponds to an ICMP Port Unreachable message.
func FuzzySplitHostPort ¶
Like net.SplitHostPort, but supports absence of port. For example, "192.0.2.1" is accepted.
func FuzzySplitHostPortI ¶
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 ¶
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 LimitReader ¶
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 ¶
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 RepadBase64 ¶
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 ¶
Gets the next delay in milliseconds and increments the internal try counter.
type DialerFunc ¶
Dialer function adapter.
Source Files
¶
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. |