netw

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package netw is a wrapper around network connections that stores annotations and records metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Listen

func Listen(network, laddr string) (net.Listener, error)

Listen creates a net listener that is instrumented to store per connection annotations and metrics.

func SetAnnotation

func SetAnnotation(conn net.Conn, key string, value any)

SetAnnotation sets an annotation on a connection. The value can be any go value.

Types

type Conn

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

Conn is a wrapper around net.Conn that stores annotations and metrics.

func NewConn added in v0.5.2

func NewConn(c net.Conn) *Conn

func NewConnForTest added in v0.4.3

func NewConnForTest(c net.Conn) *Conn

func (*Conn) Annotation

func (c *Conn) Annotation(key string, defaultValue any) any

Annotation retrieves an annotation that was previously set on the connection. The defaultValue is returned if the annotation was never set.

func (*Conn) ByteRateReceived added in v0.4.1

func (c *Conn) ByteRateReceived() float64

ByteRateReceived returns the rate of bytes received on this connection in the last minute.

func (*Conn) ByteRateSent added in v0.4.1

func (c *Conn) ByteRateSent() float64

ByteRateSent returns the rate of bytes sent on this connection in the last minute.

func (*Conn) BytesReceived

func (c *Conn) BytesReceived() int64

BytesReceived returns the number of bytes received on this connection so far.

func (*Conn) BytesSent

func (c *Conn) BytesSent() int64

BytesSent returns the number of bytes sent on this connection so far.

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) OnClose

func (c *Conn) OnClose(f func())

OnClose sets a callback function that will be called when the connection is closed.

func (*Conn) Peek

func (c *Conn) Peek(b []byte) (int, error)

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

func (*Conn) SetAnnotation

func (c *Conn) SetAnnotation(key string, value any)

SetAnnotation sets an annotation. The value can be any go value.

func (*Conn) SetCounters added in v0.4.1

func (c *Conn) SetCounters(sent, received *counter.Counter)

func (*Conn) SetLimiters added in v0.0.34

func (c *Conn) SetLimiters(ingress, egress *rate.Limiter)

SetLimiter sets the rate limiters for this connection. It must be called before the first Read() or Write(). Peek() is OK.

func (*Conn) StreamID added in v0.3.0

func (c *Conn) StreamID() int64

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

type QUICConn added in v0.3.0

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

QUICConn is a wrapper around quic.Connection.

func (*QUICConn) AcceptStream added in v0.6.0

func (c *QUICConn) AcceptStream(ctx context.Context) (quic.Stream, error)

func (*QUICConn) AcceptUniStream added in v0.6.0

func (c *QUICConn) AcceptUniStream(ctx context.Context) (quic.ReceiveStream, error)

func (*QUICConn) Annotation added in v0.4.3

func (c *QUICConn) Annotation(key string, defaultValue any) any

Annotation retrieves an annotation that was previously set on the connection. The defaultValue is returned if the annotation was never set.

func (*QUICConn) ByteRateReceived added in v0.4.3

func (c *QUICConn) ByteRateReceived() float64

ByteRateReceived returns the rate of bytes received on this connection in the last minute.

func (*QUICConn) ByteRateSent added in v0.4.3

func (c *QUICConn) ByteRateSent() float64

ByteRateSent returns the rate of bytes sent on this connection in the last minute.

func (*QUICConn) BytesReceived added in v0.4.3

func (c *QUICConn) BytesReceived() int64

BytesReceived returns the number of bytes received on this connection so far.

func (*QUICConn) BytesSent added in v0.4.3

func (c *QUICConn) BytesSent() int64

BytesSent returns the number of bytes sent on this connection so far.

func (*QUICConn) Close added in v0.6.0

func (c *QUICConn) Close() error

func (*QUICConn) CloseWithError added in v0.6.0

func (c *QUICConn) CloseWithError(code quic.ApplicationErrorCode, msg string) error

func (*QUICConn) ConnectionState added in v0.6.0

func (c *QUICConn) ConnectionState() quic.ConnectionState

func (*QUICConn) Context added in v0.6.0

func (c *QUICConn) Context() context.Context

func (*QUICConn) HandshakeComplete added in v0.6.0

func (c *QUICConn) HandshakeComplete() <-chan struct{}

func (*QUICConn) LocalAddr added in v0.6.0

func (c *QUICConn) LocalAddr() net.Addr

func (*QUICConn) NextConnection added in v0.6.0

func (c *QUICConn) NextConnection() quic.Connection

func (*QUICConn) OnClose added in v0.6.0

func (c *QUICConn) OnClose(f func())

OnClose sets a callback function that will be called when the connection is closed.

func (*QUICConn) OpenStream added in v0.6.0

func (c *QUICConn) OpenStream() (quic.Stream, error)

func (*QUICConn) OpenStreamSync added in v0.6.0

func (c *QUICConn) OpenStreamSync(ctx context.Context) (quic.Stream, error)

func (*QUICConn) OpenUniStream added in v0.6.0

func (c *QUICConn) OpenUniStream() (quic.SendStream, error)

func (*QUICConn) OpenUniStreamSync added in v0.6.0

func (c *QUICConn) OpenUniStreamSync(ctx context.Context) (quic.SendStream, error)

func (*QUICConn) Read added in v0.6.0

func (c *QUICConn) Read([]byte) (int, error)

func (*QUICConn) ReceiveDatagram added in v0.6.0

func (c *QUICConn) ReceiveDatagram(ctx context.Context) ([]byte, error)

func (*QUICConn) RemoteAddr added in v0.6.0

func (c *QUICConn) RemoteAddr() net.Addr

func (*QUICConn) SendDatagram added in v0.6.0

func (c *QUICConn) SendDatagram(b []byte) error

func (*QUICConn) SetAnnotation added in v0.4.3

func (c *QUICConn) SetAnnotation(key string, value any)

SetAnnotation sets an annotation. The value can be any go value.

func (*QUICConn) SetCounters added in v0.6.0

func (c *QUICConn) SetCounters(sent, received *counter.Counter)

SetCounters sets the byte counters to use for this connection.

func (*QUICConn) SetDeadline added in v0.6.0

func (c *QUICConn) SetDeadline(t time.Time) error

func (*QUICConn) SetLimiters added in v0.6.0

func (c *QUICConn) SetLimiters(ingress, egress *rate.Limiter)

SetLimiter sets the rate limiters for this connection. It must be called before the first Read() or Write(). Peek() is OK.

func (*QUICConn) SetReadDeadline added in v0.6.0

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

func (*QUICConn) SetWriteDeadline added in v0.6.0

func (c *QUICConn) SetWriteDeadline(t time.Time) error

func (*QUICConn) Streams added in v0.3.0

func (c *QUICConn) Streams() []*QUICStream

func (*QUICConn) TLSConnectionState added in v0.6.0

func (c *QUICConn) TLSConnectionState() tls.ConnectionState

func (*QUICConn) WrapConn added in v0.6.0

func (c *QUICConn) WrapConn(s any) *Conn

func (*QUICConn) Write added in v0.6.0

func (c *QUICConn) Write([]byte) (int, error)

type QUICListener added in v0.6.0

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

QUICListener is a wrapper around quic.Listener.

func (*QUICListener) Accept added in v0.6.0

func (l *QUICListener) Accept(ctx context.Context) (*QUICConn, error)

func (*QUICListener) Addr added in v0.6.0

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

func (*QUICListener) Close added in v0.6.0

func (l *QUICListener) Close() error

type QUICStream added in v0.3.0

type QUICStream struct {
	quic.Stream
	// contains filtered or unexported fields
}

QUICStream is a wrapper around quic.Stream that implements the net.Conn interface.

func (*QUICStream) BridgeAddr added in v0.3.0

func (s *QUICStream) BridgeAddr() string

func (*QUICStream) CancelRead added in v0.6.0

func (s *QUICStream) CancelRead(e quic.StreamErrorCode)

func (*QUICStream) CancelWrite added in v0.6.0

func (s *QUICStream) CancelWrite(e quic.StreamErrorCode)

func (*QUICStream) Close added in v0.6.0

func (s *QUICStream) Close() error

func (*QUICStream) CloseRead added in v0.6.0

func (s *QUICStream) CloseRead() error

func (*QUICStream) CloseWrite added in v0.6.0

func (s *QUICStream) CloseWrite() error

func (*QUICStream) LocalAddr added in v0.6.0

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

func (*QUICStream) Read added in v0.6.0

func (s *QUICStream) Read(b []byte) (int, error)

func (*QUICStream) RemoteAddr added in v0.6.0

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

func (*QUICStream) SetBridgeAddr added in v0.6.0

func (s *QUICStream) SetBridgeAddr(v string)

func (*QUICStream) Write added in v0.6.0

func (s *QUICStream) Write(b []byte) (int, error)

type QUICTransport added in v0.6.0

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

QUICTransport is a wrapper around quic.Transport.

func NewQUIC added in v0.6.0

func NewQUIC(addr string, statelessResetKey quic.StatelessResetKey) (*QUICTransport, error)

NewQUIC returns a wrapper around a quic.Transport to keep track of metrics and annotations.

func (*QUICTransport) Addr added in v0.6.0

func (t *QUICTransport) Addr() net.Addr

func (*QUICTransport) Close added in v0.6.0

func (t *QUICTransport) Close() error

func (*QUICTransport) Dial added in v0.6.0

func (t *QUICTransport) Dial(ctx context.Context, addr net.Addr, tc *tls.Config) (*QUICConn, error)

func (*QUICTransport) DialEarly added in v0.6.0

func (t *QUICTransport) DialEarly(ctx context.Context, addr net.Addr, tc *tls.Config, enableDatagrams bool) (*QUICConn, error)

func (*QUICTransport) Listen added in v0.6.0

func (t *QUICTransport) Listen(tc *tls.Config) (*QUICListener, error)

type ReceiveOnlyStream added in v0.6.0

type ReceiveOnlyStream struct {
	quic.ReceiveStream
	// contains filtered or unexported fields
}

func (*ReceiveOnlyStream) CancelWrite added in v0.6.0

func (s *ReceiveOnlyStream) CancelWrite(quic.StreamErrorCode)

func (*ReceiveOnlyStream) Close added in v0.6.0

func (s *ReceiveOnlyStream) Close() error

func (*ReceiveOnlyStream) Context added in v0.6.0

func (s *ReceiveOnlyStream) Context() context.Context

func (*ReceiveOnlyStream) SetDeadline added in v0.6.0

func (s *ReceiveOnlyStream) SetDeadline(t time.Time) error

func (*ReceiveOnlyStream) SetWriteDeadline added in v0.6.0

func (s *ReceiveOnlyStream) SetWriteDeadline(time.Time) error

func (*ReceiveOnlyStream) Write added in v0.6.0

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

type SendOnlyStream added in v0.6.0

type SendOnlyStream struct {
	quic.SendStream
	// contains filtered or unexported fields
}

func (*SendOnlyStream) CancelRead added in v0.6.0

func (s *SendOnlyStream) CancelRead(quic.StreamErrorCode)

func (*SendOnlyStream) Read added in v0.6.0

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

func (*SendOnlyStream) SetDeadline added in v0.6.0

func (s *SendOnlyStream) SetDeadline(t time.Time) error

func (*SendOnlyStream) SetReadDeadline added in v0.6.0

func (s *SendOnlyStream) SetReadDeadline(time.Time) error

Jump to

Keyboard shortcuts

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