transport

package
v0.0.0-...-1f64b99 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TCP is the "tcp" network.
	TCP = "tcp"

	// TCPHeaderLength is the TCP header length.
	TCPHeaderLength = 20

	// TCPMTU (TCP maximum transmission unit) is the maximum number of bytes that are
	// allowed on the payload of a TCP segment (the transport layer name for a packet).
	TCPMTU = network.MTU - TCPHeaderLength

	// TCPWindowSize is the maximum amount of bytes that TCP will send before blocking
	// and waiting for the respective ACKs.
	TCPWindowSize = (1 << 16) - 1

	// UDP is the "udp" network.
	UDP = "udp"

	// UDPHeaderLength is the UDP header length.
	UDPHeaderLength = 8

	// UDPMTU (UDP maximum transmission unit) is the maximum number of bytes that are
	// allowed on the payload of a UDP segment (the transport layer name for a packet).
	UDPMTU = network.MTU - UDPHeaderLength
)

Variables

View Source
var (
	ErrInvalidNetwork       = errors.New("invalid network")
	ErrPortAlreadyInUse     = errors.New("port already in use")
	ErrAllPortsAlreadyInUse = errors.New("all ports already in use")
	ErrProtocolClosed       = errors.New("protocol closed")
	ErrListenerClosed       = fmt.Errorf("listener closed (os error msg: %s)", useOfClosedConn)
	ErrDeadlineExceeded     = errors.New("deadline exceeded")
	ErrConnReset            = errors.New("connection reset")
	ErrWriteClosed          = errors.New("write closed")
)

Functions

func DeserializeTCPSegment

func DeserializeTCPSegment(datagram *gplayers.IPv4) (*gplayers.TCP, error)

func DeserializeUDPSegment

func DeserializeUDPSegment(datagram *gplayers.IPv4) (*gplayers.UDP, error)

func IsUseOfClosedConn

func IsUseOfClosedConn(err error) bool

IsUseOfClosedConn tells whether the error is due to the port/connection being closed.

Types

type BidirectionalStream

type BidirectionalStream interface {
	CloseWrite() error
}

type Dialer

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

type Layer

type Layer interface {
	// Listen binds the given IPv4:port localAddr on the
	// given network ("tcp" or "udp") and returns a
	// handler for accepting connections into that port.
	// The port is said to be on the "listen" mode, which
	// allows it to receive incoming connections.
	//
	// The IPv4 part of the address is optional, and if present
	// should match the IP address of one of the underlying
	// network interfaces. This means that the port will
	// only accept incoming connections targeted to this
	// IP address.
	//
	// If the port "0" is used, a random
	// port will be chosen.
	Listen(ctx context.Context, network, localAddr string) (net.Listener, error)

	// Dial starts a connection with the given IPv4:port remoteAddr
	// on the given network ("tcp" or "udp") and returns a handler
	// for reading and writing data from/into this connection.
	// The local port is chosen at random and will not accept
	// any incoming connections.
	//
	// For UDP, creating a connection
	// means just binding the dst IPv4:port address to the
	// connection handler (there's no handshake).
	//
	// DNS resolution is not support yet.
	Dial(ctx context.Context, network, remoteAddr string) (net.Conn, error)
	Dialer() LayerDialer

	// Close makes the transport layer stop listening to
	// IP datagrams received and provided by the network
	// layer. It does not close the network layer, it only
	// causes the underlying call to network.Layer.Listen()
	// to return, releasing the Recv() channels of the
	// underlying network interfaces to be taken over by
	// something else, like a new instance of the transport
	// layer.
	Close() error
}

Layer represents the transport layer of a device, where the TCP and UDP protocols are implemented. Its responsibility is to route application data to/from the IP network interfaces through these two protocols.

func NewLayer

func NewLayer(networkLayer network.Layer) Layer

NewLayer creates the concrete implementation of Layer and calls networkLayer.Listen() on a thread. Use Close() to stop and wait for this thread.

type LayerDialer

type LayerDialer interface {
	Dialer
	WithLocalAddr(localAddr net.Addr) LayerDialer
}

LayerDialer allows for specifying the localAddr when dialing. The network ("tcp" or "udp") where the dialing will take place is fetched from the localAddr specified via WithLocalAddr().

Jump to

Keyboard shortcuts

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