simple

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 11 Imported by: 11

Documentation

Overview

Package simple contains simplistic implementation for the wire.Dialer and wire.Listener interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account added in v0.10.5

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

Account is a wire account.

func NewAccount added in v0.10.5

func NewAccount(addr *Address) *Account

NewAccount creates a new account.

func NewRandomAccount added in v0.10.5

func NewRandomAccount(rng *rand.Rand) *Account

NewRandomAccount generates a new random account.

func (*Account) Address added in v0.10.5

func (acc *Account) Address() wire.Address

Address returns the account's address.

type Address added in v0.10.5

type Address string

Address is a wire address.

func NewAddress added in v0.10.5

func NewAddress(host string) *Address

NewAddress returns a new address.

func NewRandomAddress added in v0.10.5

func NewRandomAddress(rng *rand.Rand) *Address

NewRandomAddress returns a new random peer address.

func (Address) Cmp added in v0.10.5

func (a Address) Cmp(b wire.Address) int

Cmp compares the byte representation of two addresses. For `a.Cmp(b)` returns -1 if a < b, 0 if a == b, 1 if a > b.

func (Address) Equal added in v0.10.5

func (a Address) Equal(b wire.Address) bool

Equal returns whether the two addresses are equal.

func (Address) MarshalBinary added in v0.10.5

func (a Address) MarshalBinary() ([]byte, error)

MarshalBinary marshals the address to binary.

func (*Address) UnmarshalBinary added in v0.10.5

func (a *Address) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals an address from binary.

type Dialer

type Dialer struct {
	pkgsync.Closer
	// contains filtered or unexported fields
}

Dialer is a simple lookup-table based dialer that can dial known peers. New peer addresses can be added via Register().

func NewNetDialer

func NewNetDialer(network string, defaultTimeout time.Duration) *Dialer

NewNetDialer creates a new dialer with a preset default timeout for dial attempts. Leaving the timeout as 0 will result in no timeouts. Standard OS timeouts may still apply even when no timeout is selected. The network string controls the type of connection that the dialer can dial. `serializer` defines the message encoding.

func NewTCPDialer

func NewTCPDialer(defaultTimeout time.Duration) *Dialer

NewTCPDialer is a short-hand version of NewNetDialer for creating TCP dialers.

func NewUnixDialer

func NewUnixDialer(defaultTimeout time.Duration) *Dialer

NewUnixDialer is a short-hand version of NewNetDialer for creating Unix dialers.

func (*Dialer) Dial

Dial implements Dialer.Dial().

func (*Dialer) Register

func (d *Dialer) Register(addr wire.Address, address string)

Register registers a network address for a peer address.

type Listener

type Listener struct {
	net.Listener
}

Listener is a TCP Listener.

func NewNetListener

func NewNetListener(network string, address string) (*Listener, error)

NewNetListener creates a listener reachable under the requested address.

func NewTCPListener

func NewTCPListener(address string) (*Listener, error)

NewTCPListener is a short-hand version of NewNetListener for TCP listeners.

func NewUnixListener

func NewUnixListener(address string) (*Listener, error)

NewUnixListener is a short-hand version of NewNetListener for Unix listeners.

func (*Listener) Accept

func (l *Listener) Accept(ser wire.EnvelopeSerializer) (wirenet.Conn, error)

Accept implements peer.Dialer.Accept().

Jump to

Keyboard shortcuts

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