transport

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package transport provides a memberlist.Transport implementation

Index

Constants

View Source
const (
	// DefaultBindRetry indicates how many times we will try binding a port
	DefaultBindRetry = 4
	// DefaultPort indicates the default TCP/UDP Port to use when zero
	DefaultPort = 7946
)
View Source
const (
	// Subsystem indicates our name on the logs
	Subsystem = "gossiptransport"
	// SubsystemLabel is the Field label for the Subsystem
	SubsystemLabel = "subsystem"
	// RemoteAddrLabel is the Field label for the remote party on a connection
	RemoteAddrLabel = "conn"
	// ListenerAddrLabel is the Field label for the local party on a connection
	ListenerAddrLabel = "addr"
	// PacketSizeLabel is the Field label used when logging message size
	PacketSizeLabel = "bytes"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// BindInterface is the list of interfaces to listen on
	BindInterface []string
	// BindAddress is the list of addresses to listen on
	BindAddress []string
	// BindPort is the port to listen on, for both TCP and UDP
	BindPort int
	// BindPortStrict tells us not to try other ports
	BindPortStrict bool
	// BindPortRetry indicates how many times we will try finding a port
	BindPortRetry int

	// ListenTCP is the helper to use to listen on a TCP port
	ListenTCP func(network string, laddr *net.TCPAddr) (*net.TCPListener, error)
	// ListenUDP is the helper to use to listen on a UDP port
	ListenUDP func(network string, laddr *net.UDPAddr) (*net.UDPConn, error)

	// OnError is called when a worker returns an error, before initiating
	// a shutdown
	OnError func(error)

	// Context
	Context context.Context
	// Logger is the optional logger to record events
	Logger slog.Logger
}

Config is the configuration data for Transport

func (*Config) Addresses

func (cfg *Config) Addresses() ([]net.IP, error)

Addresses returns the BindAddress list parsed into net.IP

func (*Config) SetDefaults

func (cfg *Config) SetDefaults() error

SetDefaults attempts to fill any configuration gap, specially the IP Addresses when interfaces are provided instead

type Listeners

type Listeners struct {
	TCP []*net.TCPListener
	UDP []*net.UDPConn
}

Listeners contains externally prepared listeners for our Transport

func (*Listeners) Close

func (lsn *Listeners) Close() error

Close closes all listeners

func (*Listeners) Validate

func (lsn *Listeners) Validate() ([]string, int, error)

Validate checks if the listeners are suitable, and returns the addresses and port used

type Transport

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

Transport implements a memberlist.Transport that uses an slog.Logger, Cancellable Context, ListenTCP/ListenUDP callbacks

func New

func New(config *Config) (*Transport, error)

New creates a new Transport based on the given configuration or defaults. If succeeds, the created transport needs to be explicitly Close()ed once it's no longer used

func NewWithListeners

func NewWithListeners(config *Config, lsn *Listeners) (*Transport, error)

NewWithListeners creates a new transport using preallocated listeners. If it fails, it's your responsibility to close them. If succeeds, the created transport needs to be explicitly Close()ed once it's no longer used

func (*Transport) DialAddressTimeout

func (*Transport) DialAddressTimeout(addr memberlist.Address, timeout time.Duration) (
	net.Conn, error)

DialAddressTimeout is used by memberlist to establish a TCP connection to a particular node

func (*Transport) DialTimeout

func (t *Transport) DialTimeout(addr string, timeout time.Duration) (net.Conn, error)

DialTimeout is used by memberlist to connect to a particular TCP Address

func (*Transport) FinalAdvertiseAddr

func (t *Transport) FinalAdvertiseAddr(ip string, port int) (net.IP, int, error)

FinalAdvertiseAddr is used by memberlist to find what address and port to advertise to other nodes

func (*Transport) PacketCh

func (t *Transport) PacketCh() <-chan *memberlist.Packet

PacketCh is used by memberlist to receive UDP messages

func (*Transport) Shutdown

func (t *Transport) Shutdown() error

Shutdown closes the listening ports and cancels the workers, and then waits until all workers have exited

func (*Transport) StreamCh

func (t *Transport) StreamCh() <-chan net.Conn

StreamCh is used by memberlist to receive incoming TCP connections

func (*Transport) WriteTo

func (t *Transport) WriteTo(b []byte, addr string) (time.Time, error)

WriteTo is used by memberlist to send a UDP message to a particular address

func (*Transport) WriteToAddress

func (t *Transport) WriteToAddress(b []byte, addr memberlist.Address) (time.Time, error)

WriteToAddress is used by memberlist to send a UDP message to a particular Node

Jump to

Keyboard shortcuts

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