Version: v0.0.0-...-01e8697 Latest Latest

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

Go to latest
Published: Nov 24, 2021 License: GPL-3.0 Imports: 16 Imported by: 2



Package lonet provides TCP network simulated on top of localhost TCP loopback.

For testing distributed systems it is sometimes handy to imitate network of several TCP hosts. It is also handy that ports allocated on Dial/Listen/Accept on that hosts be predictable - that would help tests to verify network events against expected sequence. When whole system could be imitated in 1 OS-level process, package lab.nexedi.com/kirr/go123/xnet/pipenet serves the task via providing TCP-like synchronous in-memory network of net.Pipes. However pipenet cannot be used for cases where tested system consists of 2 or more OS-level processes. This is where lonet comes into play:

Similarly to pipenet addresses on lonet are host:port pairs and several hosts could be created with different names. A host is xnet.Networker and so can be worked with similarly to regular TCP network access-point with Dial/Listen/Accept. Host's ports allocation is predictable: ports of a host are contiguous integer sequence starting from 1 that are all initially free, and whenever autobind is requested the first free port of the host will be used.

Internally lonet network maintains registry of hosts so that lonet addresses could be resolved to OS-level addresses, for example α:1 and β:1 to and, and once lonet connection is established it becomes served by OS-level TCP connection over loopback.


net, err := lonet.Join(ctx, "mynet")
hα, err := net.NewHost(ctx, "α")
hβ, err := net.NewHost(ctx, "β")

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

Once again lonet is similar to pipenet, but since it works via OS TCP stack it could be handy for testing networked application when there are several OS-level processes involved.

Package lonet also provides corresponding Python package for accessing lonet networks from Python(*).


(*) use https://pypi.org/project/pygolang to import.



This section is empty.


This section is empty.


func Join

func Join(ctx context.Context, network string) (_ *virtnet.SubNetwork, err error)

Join joins or creates new lonet network with given name.

Network is the name of this network under "lonet" namespace, e.g. "α" will give full network name "lonetα".

If network is "" new network with random unique name will be created.

Join returns new subnetwork on the joined network.

See package lab.nexedi.com/kirr/go123/xnet/virtnet for documentation on how to use returned subnetwork.


This section is empty.

Jump to

Keyboard shortcuts

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