net

package
v0.0.0-...-272971f Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 19 Imported by: 0

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 Dialer

type Dialer interface {
	DialPipe() (Pipe, error)
}

type FrameConn

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

func NewFrameConn

func NewFrameConn(conn net.Conn) *FrameConn

func (*FrameConn) Close

func (f *FrameConn) Close() error

func (*FrameConn) LocalAddr

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

func (*FrameConn) Read

func (f *FrameConn) Read(b []byte) (int, error)

func (*FrameConn) RemoteAddr

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

func (*FrameConn) SetDeadline

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

func (*FrameConn) SetReadDeadline

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

func (*FrameConn) SetWriteDeadline

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

func (*FrameConn) Write

func (f *FrameConn) Write(dat []byte) (int, 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
	// 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
}

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) 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) 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
}

func NewDialSocket

func NewDialSocket(dialer Dialer) Socket

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

type TcpDialer

type TcpDialer struct {
	Url string
}

func (TcpDialer) DialPipe

func (d TcpDialer) DialPipe() (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
	WebsocketFallback bool
}

func (WebRtcDialer) DialPipe

func (d WebRtcDialer) DialPipe() (Pipe, error)

type WebsocketDialer

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

func (WebsocketDialer) DialPipe

func (d WebsocketDialer) DialPipe() (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