tcpreuse

package
Version: v0.0.0-...-ce94876 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2019 License: MIT, MIT Imports: 11 Imported by: 0

README

go-reuseport-transport

standard-readme compliant GoDoc Coverage Status Build Status

Basic reuseport TCP transport

This package provides a basic transport for automatically (and intelligently) reusing TCP ports.

To use, construct a new Transport (the zero value is safe to use) and configure any listeners (tr.Listen(...)).

Then, when dialing (tr.Dial(...)), the transport will attempt to reuse the ports it's currently listening on, choosing the best one depending on the destination address.

NOTE: Currently, we don't make any attempts to prevent two reusport transports from interfering with each other (reusing each other's ports). However, we reserve the right to fix this in the future.

Install

go-reuseport-transport is a standard Go module which can be installed with:

go get github.com/libp2p/go-reuseport-transport

Note that go-reuseport-transport is packaged with Gx, so it is recommended to use Gx to install and use it (see the Usage section).

Usage

This module is packaged with Gx. In order to use it in your own project it is recommended that you:

go get -u github.com/whyrusleeping/gx
go get -u github.com/whyrusleeping/gx-go
cd <your-project-repository>
gx init
gx import github.com/libp2p/go-reuseport-transport
gx install --global
gx-go --rewrite

Please check Gx and Gx-go documentation for more information.

This package is currently used by the go-tcp-transport libp2p transport and will likely be used by more libp2p transports in the future.

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

Want to hack on IPFS?

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWrongProto = errors.New("can only dial TCP over IPv4 or IPv6")

ErrWrongProto is returned when dialing a protocol other than tcp.

Functions

This section is empty.

Types

type Transport

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

Transport is a TCP reuse transport that reuses listener ports.

func (*Transport) Dial

func (t *Transport) Dial(raddr ma.Multiaddr) (manet.Conn, error)

Dial dials the given multiaddr, reusing ports we're currently listening on if possible.

Dial attempts to be smart about choosing the source port. For example, If we're dialing a loopback address and we're listening on one or more loopback ports, Dial will randomly choose one of the loopback ports and addresses and reuse it.

func (*Transport) DialContext

func (t *Transport) DialContext(ctx context.Context, raddr ma.Multiaddr) (manet.Conn, error)

DialContext is like Dial but takes a context.

func (*Transport) Listen

func (t *Transport) Listen(laddr ma.Multiaddr) (manet.Listener, error)

Listen listens on the given multiaddr.

If reuseport is supported, it will be enabled for this listener and future dials from this transport may reuse the port.

Note: You can listen on the same multiaddr as many times as you want (although only *one* listener will end up handling the inbound connection).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL