Back to

Package xnet

Latest Go to latest

The latest major version is .

Published: May 27, 2020 | License: GPL3 | Module:


Package xnet provides addons to std package net.


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.
	// XXX also introduce xnet.Listener in which Accept() accepts also ctx?
	Listen(laddr string) (net.Listener, 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.

func NetTrace

func NetTrace(inner Networker, tracer Tracer) Networker

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.

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 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 interface {

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

Package Files

  • net.go
  • trace.go
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier