net

package
v0.0.0-...-9bd7cc4 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const MaxRecvMsgSize = 64 * 1024 // 8 KB // TODO! - this is arbitrary. Need a better way to manage message sizes. I'm just setting this to be big enough for my mmo

TODO - Ensure sent messages remain under this Calculation: 1460 Byte = 1500 Byte - 20 Byte IP Header - 20 Byte TCP Header const MaxMsgSize = 1460 // bytes

Variables

View Source
var ErrClosed = errors.New("socket closed") // Indicates that the socket is closed. Currently if you get this error then it means the socket will never receive or send again!
View Source
var ErrDisconnected = errors.New("socket disconnected")
View Source
var ErrNetwork = errors.New("network error")

Functions

func SetLogger

func SetLogger(newLogger zerolog.Logger)

Types

type DialAttempt

type DialAttempt struct {
	Dialer  Dialer
	Timeout time.Duration // How long this attempt gets to connect before we move on to the next one
}

type Dialer

type Dialer interface {
	// Dials a new pipe, giving up once the context is done. The context only bounds the dial, the returned pipe outlives it
	DialPipe(context.Context) (Pipe, error)
}

type FallbackDialer

type FallbackDialer []DialAttempt

Dials with each attempt in order, and returns the first pipe that connects

func (FallbackDialer) DialPipe

func (d FallbackDialer) DialPipe(ctx context.Context) (Pipe, error)

type ListenConfig

type ListenConfig struct {
	Url       string // Note: We only use the [scheme]://[host] portion of this
	TlsConfig *tls.Config

	HttpServer     *http.Server // TODO - For Websockets only, maybe split up? - Note we have to wrap their Handler with our own handler!
	OriginPatterns []string
	IceServers     []string
	PublicIP       string // WebRTC only: the IPv4 address clients reach the listener at. See rtcnet.ListenConfig
	IceLite        bool   // WebRTC only: requires IceServers to be empty. See rtcnet.ListenConfig
	// contains filtered or unexported fields
}

-------------------------------------------------------------------------------- - Listener -------------------------------------------------------------------------------- For listening for sockets

func (*ListenConfig) Listen

func (c *ListenConfig) Listen() (Listener, error)

type Listener

type Listener interface {
	// Accept waits for and returns the next connection to the listener.
	Accept() (Socket, error)

	// Close closes the listener.
	// Any blocked Accept operations will be unblocked and return errors.
	Close() error

	// Addr returns the listener's network address.
	Addr() net.Addr
}

type Pipe

type Pipe interface {
	Read([]byte) (int, error)
	Write([]byte) (int, error)
	Close() error

	// LocalAddr returns the local network address, if known.
	LocalAddr() net.Addr

	// RemoteAddr returns the remote network address, if known.
	RemoteAddr() net.Addr

	// SetReadTimeout(time.Duration)
	// SetWriteTimeout(time.Duration)
	Transport() string
}

TODO: This is basically a net.Conn

type PipeSocket

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

-------------------------------------------------------------------------------- - Transport based sockets --------------------------------------------------------------------------------

func (*PipeSocket) Close

func (s *PipeSocket) Close() error

func (*PipeSocket) Closed

func (s *PipeSocket) Closed() bool

func (*PipeSocket) Connected

func (s *PipeSocket) Connected() bool

func (*PipeSocket) LocalAddr

func (s *PipeSocket) LocalAddr() net.Addr

func (*PipeSocket) Read

func (s *PipeSocket) Read(buf []byte) (int, error)

func (*PipeSocket) ReadEgress

func (s *PipeSocket) ReadEgress() int64

func (*PipeSocket) ReadIngress

func (s *PipeSocket) ReadIngress() int64

func (*PipeSocket) RemoteAddr

func (s *PipeSocket) RemoteAddr() net.Addr

func (*PipeSocket) Transport

func (s *PipeSocket) Transport() string

func (*PipeSocket) Write

func (s *PipeSocket) Write(dat []byte) (int, error)

type SimSocket

type SimSocket struct {
	Socket

	Packetloss float64       // This is the probability that the packet will be lossed for every send/recv
	MinDelay   time.Duration // This is the min delay added to every packet sent or recved
	MaxDelay   time.Duration // This is the max delay added to every packet sent or recved
	// contains filtered or unexported fields
}

-------------------------------------------------------------------------------- - Packetloss code --------------------------------------------------------------------------------

func NewSimSocket

func NewSimSocket(s Socket) *SimSocket

func (*SimSocket) Read

func (s *SimSocket) Read(buf []byte) (int, error)

func (*SimSocket) Write

func (s *SimSocket) Write(buf []byte) (int, error)

type Socket

type Socket interface {
	Read([]byte) (int, error)
	Write([]byte) (int, error)

	Close() error

	Connected() bool
	Closed() bool

	// Reads and clears the number egress bytes
	ReadEgress() int64
	// Reads and clears the number ingress bytes
	ReadIngress() int64
	Transport() string

	// LocalAddr returns the local network address, if known.
	LocalAddr() net.Addr

	// RemoteAddr returns the remote network address, if known.
	RemoteAddr() net.Addr
}

func NewDialSocket

func NewDialSocket(dialer Dialer) Socket

-------------------------------------------------------------------------------- - Dialer --------------------------------------------------------------------------------

type TcpDialer

type TcpDialer struct {
	Url string
}

func (TcpDialer) DialPipe

func (d TcpDialer) DialPipe(ctx context.Context) (Pipe, error)

type TcpListener

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

func (*TcpListener) Accept

func (l *TcpListener) Accept() (Socket, error)

func (*TcpListener) Addr

func (l *TcpListener) Addr() net.Addr

func (*TcpListener) Close

func (l *TcpListener) Close() error

type WebRtcDialer

type WebRtcDialer struct {
	Url        string
	TlsConfig  *tls.Config
	Ordered    bool
	IceServers []string
}

func (WebRtcDialer) DialPipe

func (d WebRtcDialer) DialPipe(ctx context.Context) (Pipe, error)

func (WebRtcDialer) WebsocketFallback

func (d WebRtcDialer) WebsocketFallback() WebsocketDialer

Dials the same listener over websockets, which it also serves for dialers that can't connect with webrtc. See FallbackDialer

type WebTransportDialer

type WebTransportDialer struct {
	Url       string
	TlsConfig *tls.Config // Note: Unused in the browser, which only trusts certs from its own roots
}

func (WebTransportDialer) DialPipe

func (d WebTransportDialer) DialPipe(ctx context.Context) (Pipe, error)

type WebsocketDialer

type WebsocketDialer struct {
	Url       string
	TlsConfig *tls.Config
}

func (WebsocketDialer) DialPipe

func (d WebsocketDialer) DialPipe(ctx context.Context) (Pipe, error)

type WebsocketListener

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

-------------------------------------------------------------------------------- - Listener --------------------------------------------------------------------------------

func (*WebsocketListener) Accept

func (l *WebsocketListener) Accept() (Socket, error)

func (*WebsocketListener) Addr

func (l *WebsocketListener) Addr() net.Addr

func (*WebsocketListener) Close

func (l *WebsocketListener) Close() error

func (*WebsocketListener) ServeHTTP

func (l *WebsocketListener) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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