Help us shape the future of Go! Take the 2026 Go Developer Survey

twamplight

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PacketSize = 48
)

Variables

View Source
var (
	ErrInvalidPacket        = errors.New("invalid packet format")
	ErrPlatformNotSupported = errors.New("platform not supported")
)

Functions

This section is empty.

Types

type BasicReflector

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

Reflector listens for incoming TWAMP probe packets and reflects them back to the sender.

It runs a single-threaded event loop using a UDP socket with a read timeout. The reflector is designed for test environments or single-client usage and is not optimized for high concurrency.

Use Run(ctx) to start the reflector; it blocks until the context is cancelled. Use Close() to stop the reflector and release the socket.

Reflector is not safe for concurrent use.

func NewBasicReflector

func NewBasicReflector(log *slog.Logger, addr string, timeout time.Duration) (*BasicReflector, error)

func (*BasicReflector) Close

func (r *BasicReflector) Close() error

Close closes the TWAMP reflector by closing the listener connection.

func (*BasicReflector) LocalAddr

func (r *BasicReflector) LocalAddr() *net.UDPAddr

LocalAddr returns the address the reflector is listening on.

func (*BasicReflector) Run

func (r *BasicReflector) Run(ctx context.Context) error

Run starts the TWAMP reflector.

It listens on the configured UDP port and reflects back the received packets.

It's a blocking function that will run until the context is done.

type BasicSender

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

func NewBasicSender

func NewBasicSender(ctx context.Context, log *slog.Logger, iface string, localAddr, remoteAddr *net.UDPAddr) (*BasicSender, error)

func (*BasicSender) Close

func (s *BasicSender) Close() error

func (*BasicSender) LocalAddr

func (s *BasicSender) LocalAddr() *net.UDPAddr

LocalAddr returns the local address of the sender connection.

func (*BasicSender) Probe

func (s *BasicSender) Probe(ctx context.Context) (time.Duration, error)

Probe sends a TWAMP probe packet to the given address and returns the RTT.

If the probe fails, it returns a zero duration and an error.

type LinuxReflector

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

func NewLinuxReflector

func NewLinuxReflector(addr string, timeout time.Duration) (*LinuxReflector, error)

func (*LinuxReflector) Close

func (r *LinuxReflector) Close() error

func (*LinuxReflector) LocalAddr

func (r *LinuxReflector) LocalAddr() *net.UDPAddr

func (*LinuxReflector) Run

func (r *LinuxReflector) Run(ctx context.Context) error

type LinuxSender

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

func NewLinuxSender

func NewLinuxSender(ctx context.Context, iface string, local *net.UDPAddr, remote *net.UDPAddr) (*LinuxSender, error)

func (*LinuxSender) Close

func (s *LinuxSender) Close() error

func (*LinuxSender) LocalAddr

func (s *LinuxSender) LocalAddr() *net.UDPAddr

func (*LinuxSender) Probe

func (s *LinuxSender) Probe(ctx context.Context) (time.Duration, error)

type Packet

type Packet struct {
	Seq  uint32
	Sec  uint32
	Frac uint32
	Pad  [36]byte
}

func NewPacket

func NewPacket(seq uint32) *Packet

func UnmarshalPacket

func UnmarshalPacket(buf []byte) (*Packet, error)

func (*Packet) Marshal

func (p *Packet) Marshal(buf []byte) error

type Reflector

type Reflector interface {
	Run(ctx context.Context) error
	Close() error
	LocalAddr() *net.UDPAddr
}

func NewReflector

func NewReflector(log *slog.Logger, addr string, timeout time.Duration) (Reflector, error)

type Sender

type Sender interface {
	Probe(ctx context.Context) (time.Duration, error)
	Close() error
	LocalAddr() *net.UDPAddr
}

func NewSender

func NewSender(ctx context.Context, log *slog.Logger, iface string, localAddr, remoteAddr *net.UDPAddr) (Sender, error)

Jump to

Keyboard shortcuts

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