util

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPortProhibited      = errors.New("peer port administratively prohibited")
	ErrInvalidPeerProtocol = errors.New("unknown peer transport protocol")
)

Functions

func Diff

func Diff(a, b []string) ([]string, []string)

Diff computes the diff of two string slices a and b, returns a-b and b-a

func IsClosedErr added in v0.11.1

func IsClosedErr(err error) bool

IsClosedErr is a helper function to check for "already closed" errors, which are usually harmless but still show up in logs, code adapted from https://stackoverflow.com/questions/44974984/how-to-check-a-net-conn-is-closed

func Member

func Member(list []string, a string) bool

check is list contains element a

func NewFileConn added in v0.11.3

func NewFileConn(file *os.File) net.Conn

NewFileConn returns a wrapper that shows an os.File as a net.Conn.

func NewPortRangePacketConn added in v0.16.1

func NewPortRangePacketConn(c net.PacketConn, listenerName string, minPort, maxPort int, log logging.LeveledLogger) net.PacketConn

NewPortRangePacketConn decorates a PacketConn with filtering on a target port range. Errors are reported per listener name.

func Remove

func Remove(ss []string, e string) []string

Remove removes a given element from string slice

func Unique

func Unique(s []string) []string

Unique returns unique elements in a string slice

Types

type FileConn added in v0.11.3

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

func (*FileConn) Close added in v0.11.3

func (f *FileConn) Close() error

func (*FileConn) LocalAddr added in v0.11.3

func (f *FileConn) LocalAddr() net.Addr

func (*FileConn) Read added in v0.11.3

func (f *FileConn) Read(b []byte) (n int, err error)

func (*FileConn) RemoteAddr added in v0.11.3

func (f *FileConn) RemoteAddr() net.Addr

func (*FileConn) SetDeadline added in v0.11.3

func (f *FileConn) SetDeadline(t time.Time) error

func (*FileConn) SetReadDeadline added in v0.11.3

func (f *FileConn) SetReadDeadline(t time.Time) error

func (*FileConn) SetWriteDeadline added in v0.11.3

func (f *FileConn) SetWriteDeadline(t time.Time) error

func (*FileConn) Write added in v0.11.3

func (f *FileConn) Write(b []byte) (n int, err error)

type FileConnAddr added in v0.11.3

type FileConnAddr struct {
	File *os.File
}

func (*FileConnAddr) Network added in v0.11.3

func (s *FileConnAddr) Network() string

func (*FileConnAddr) String added in v0.11.3

func (s *FileConnAddr) String() string

type PacketConnPool added in v0.14.1

type PacketConnPool interface {
	// Make creates a PacketConnPool, caller must make sure to close the sockets.
	Make(network, address string) ([]net.PacketConn, error)
	// Size returns the number of sockets in the pool.
	Size() int
}

PacketConnPool is a factory to create pools of related PacketConns, which may either be a set of PacketConns bound to the same local IP using SO_REUSEPORT (on unix, under certain circumstances) that can do multithreaded readloops, or a single PacketConn as a fallback for non-unic architectures and for testing.

func NewPacketConnPool added in v0.14.1

func NewPacketConnPool(vnet transport.Net, threadNum int) PacketConnPool

NewPacketConnPool creates a new packet connection pool. Pooling is disabled if threadNum is zero or if we are running on top of transport.VNet (which does not support reuseport), or if we are on non-unix, see the fallback in socketpool.go.

type PortRangePacketConn added in v0.16.1

type PortRangePacketConn struct {
	net.PacketConn
	// contains filtered or unexported fields
}

PortRangePacketConn is a net.PacketConn that filters on the target port range.

func (*PortRangePacketConn) ReadFrom added in v0.16.1

func (c *PortRangePacketConn) ReadFrom(p []byte) (int, net.Addr, error)

ReadFrom reads from the PortRangePacketConn. Blocks until a packet from the speciifed port range is received and drops all other packets.

func (*PortRangePacketConn) SetReadDeadline added in v0.16.1

func (c *PortRangePacketConn) SetReadDeadline(t time.Time) error

func (*PortRangePacketConn) WriteTo added in v0.16.1

func (c *PortRangePacketConn) WriteTo(p []byte, peerAddr net.Addr) (int, error)

WriteTo writes to the PacketConn.

type RelayAddressGenerator added in v0.16.1

type RelayAddressGenerator struct {
	// ListenerName is the name of the listener this relay address generator belongs to. Note that
	// packets sent to/received from upstream cluster are reported with the name of the
	// *listener* that the packet belongs to, and not the cluster.
	ListenerName string

	// RelayAddress is the IP returned to the user when the relay is created.
	RelayAddress net.IP

	// MinRelayPort the minimum target port (inclusive).
	MinRelayPort int

	// MaxRelayPort the maximum target port (inclusive).
	MaxRelayPort int

	// Address is passed to Listen/ListenPacket when creating the Relay.
	Address string

	// Net is a pion/transport VNet, used for testing.
	Net transport.Net

	// Logger is a logger factory we can use to generate per-listener relay loggers.
	Logger *logger.LeveledLoggerFactory
}

RelayAddressGenerator can be used to only allocate connections inside a defined target port range. A static ip address can be set.

func (*RelayAddressGenerator) AllocateConn added in v0.16.1

func (g *RelayAddressGenerator) AllocateConn(network string, requestedPort int) (net.Conn, net.Addr, error)

AllocateConn generates a new Conn to receive traffic on and the IP/Port to populate the allocation response with

func (*RelayAddressGenerator) AllocatePacketConn added in v0.16.1

func (r *RelayAddressGenerator) AllocatePacketConn(network string, requestedPort int) (net.PacketConn, net.Addr, error)

AllocatePacketConn generates a new transport relay connection and returns the IP/Port to be returned to the client in the allocation response.

func (*RelayAddressGenerator) Validate added in v0.16.1

func (r *RelayAddressGenerator) Validate() error

Validate is called on server startup and confirms the RelayAddressGenerator is properly configured.

Jump to

Keyboard shortcuts

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