Back to godoc.org

Package pipenet

v0.0.0-...-3cf7f3f
Latest Go to latest

The latest major version is .

Published: May 27, 2020 | License: GPL3 | Module: lab.nexedi.com/kirr/go123

Overview

Package pipenet provides TCP-like synchronous in-memory network of net.Pipes.

Addresses on pipenet are host:port pairs. A host is xnet.Networker and so can be worked with similarly to regular TCP network with Dial/Listen/Accept/...

Example:

net := pipenet.New("")
h1 := net.Host("abc")
h2 := net.Host("def")

l, err := h1.Listen(":10")          // starts listening on address "abc:10"
go func() {
	csrv, err := l.Accept()     // csrv will have LocalAddr "abc:1"
}()
ccli, err := h2.Dial(ctx, "abc:10") // ccli will be connection between "def:1" - "abc:1"

Pipenet might be handy for testing interaction of networked applications in 1 process without going to OS networking stack.

See also package lab.nexedi.com/kirr/go123/xnet/lonet for similar network that can work across several OS-level processes.

Index

func AsVirtNet

func AsVirtNet(n *Network) *virtnet.SubNetwork

AsVirtNet exposes Network as virtnet subnetwork.

Since pipenet works entirely in RAM and in 1 OS process, its user interface is simpler compared to more general virtnet - for example there is no error when creating hosts. However sometimes it is handy to get access to pipenet network via full virtnet interface, when the code that is using pipenet network does not want to depend on pipenet API specifics.

type Network

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

Network implements synchronous in-memory TCP-like network of pipes.

func New

func New(name string) *Network

New creates new pipenet Network.

Name is name of this network under "pipe" namespace, e.g. "α" will give full network name "pipeα".

New does not check whether network name provided is unique.

func (*Network) Host

func (n *Network) Host(name string) *virtnet.Host

Host returns network access point by name.

If there was no such host before it creates new one.

Host panics if underlying virtnet subnetwork was shut down.

func (*Network) Network

func (n *Network) Network() string

Network returns name of the network.

Package Files

  • pipenet.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