xnet

package
v0.0.0-...-8299741 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: GPL-3.0 Imports: 9 Imported by: 7

Documentation

Overview

Package xnet provides addons to std package net.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindCtxL

func BindCtxL(l Listener, ctx context.Context) net.Listener

BindCtxL binds Listener l and ctx into net.Listener which passes ctx to l on every Accept.

Types

type Listener

type Listener interface {
	Accept(ctx context.Context) (net.Conn, error)

	// same as in net.Listener
	Close() error
	Addr() net.Addr
}

Listener amends net.Listener for Accept to handle cancellation.

func WithCtxL

func WithCtxL(l net.Listener) Listener

WithCtxL converts net.Listener l into Listener that accepts ctx in Accept.

It returns original xnet object if l was created via BindCtx*.

type Networker

type Networker interface {
	// Network returns name of the network.
	Network() string

	// Name returns name of the access-point on the network.
	//
	// Example of name is local hostname if networker provides access to
	// OS-level dial/listen.
	Name() string

	// Dial connects to addr on underlying network.
	//
	// See net.Dial for semantic details.
	Dial(ctx context.Context, addr string) (net.Conn, error)

	// Listen starts listening on local address laddr on underlying network access-point.
	//
	// See net.Listen for semantic details.
	Listen(ctx context.Context, laddr string) (Listener, error)

	// Close releases resources associated with the network access-point.
	//
	// In-progress and future network operations such as Dial and Listen,
	// originated via this access-point, will return with an error.
	Close() error
}

Networker is interface representing access-point to a streaming network.

func NetPlain

func NetPlain(network string) Networker

NetPlain creates Networker corresponding to regular network accessors from std package net.

network is "tcp", "tcp4", "tcp6", "unix", etc...

func NetTLS

func NetTLS(inner Networker, config *tls.Config) Networker

NetTLS wraps underlying networker with TLS layer according to config.

The config must be valid:

  • for tls.Client -- for Dial to work,
  • for tls.Server -- for Listen to work.

type TraceConnect

type TraceConnect struct {
	// XXX also put networker?
	Src, Dst net.Addr
	Dialed   string
}

TraceConnect is event corresponding to established network connection.

type TraceDial

type TraceDial struct {
	// XXX also put networker?
	Dialer, Addr string
}

TraceDial is event corresponding to network dial start.

type TraceListen

type TraceListen struct {
	// XXX also put networker?
	Laddr net.Addr
}

TraceListen is event corresponding to network listening.

type TraceReceiver

type TraceReceiver interface {
	TraceNetDial(*TraceDial)
	TraceNetConnect(*TraceConnect)
	TraceNetListen(*TraceListen)
	TraceNetTx(*TraceTx)
}

TraceReceiver is the interface that needs to be implemented by network trace receivers.

type TraceTx

type TraceTx struct {
	// XXX also put network somehow?
	Src, Dst net.Addr
	Pkt      []byte
}

TraceTx is event corresponding to network transmission.

type Tracer

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

Tracer wraps underlying Networker to emit events on networking operations.

Create it via NetTrace.

func NetTrace

func NetTrace(inner Networker, tracerx TraceReceiver) *Tracer

NetTrace wraps underlying networker with IO tracing layer.

Tracing is done via calling trace func right after corresponding networking event happenned. No synchronization for notification is performed - if one is required tracing func must implement such synchronization itself.

only initiation events are traced:

1. Tx only (no Rx):

  • because Write, contrary to Read, never writes partial data on non-error
  • because in case of pipenet tracing writes only is enough to get whole network exchange picture

2. Dial only (no Accept)

  • for similar reasons.

WARNING NetTrace functionality is currently very draft.

func (*Tracer) Close

func (t *Tracer) Close() error

Close implements Networker.

func (*Tracer) Dial

func (t *Tracer) Dial(ctx context.Context, addr string) (net.Conn, error)

Dial implements Networker.

func (*Tracer) Listen

func (t *Tracer) Listen(ctx context.Context, laddr string) (Listener, error)

Listen implements Networker.

func (*Tracer) Name

func (t *Tracer) Name() string

Name implements Networker.

func (*Tracer) Network

func (t *Tracer) Network() string

Network implements Networker.

func (*Tracer) TraceOff

func (t *Tracer) TraceOff()

TraceOff tells tracer to disable delivery of trace events.

func (*Tracer) TraceOn

func (t *Tracer) TraceOn()

TraceOn tells the tracer to (re)enable delivery of trace events.

Directories

Path Synopsis
internal
virtnettest
Package virtnettest provides basic tests to be run on virtnet network implementations.
Package virtnettest provides basic tests to be run on virtnet network implementations.
Package lonet provides TCP network simulated on top of localhost TCP loopback.
Package lonet provides TCP network simulated on top of localhost TCP loopback.
Package pipenet provides TCP-like synchronous in-memory network of net.Pipes.
Package pipenet provides TCP-like synchronous in-memory network of net.Pipes.
Package virtnet provides infrastructure for TCP-like virtual networks.
Package virtnet provides infrastructure for TCP-like virtual networks.

Jump to

Keyboard shortcuts

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