pipenet

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: 6 Imported by: 0

Documentation

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(ctx, ":10")     // starts listening on address "abc:10"
go func() {
	csrv, err := l.Accept(ctx)  // 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

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

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.

Jump to

Keyboard shortcuts

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