transport

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2022 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaxNodeInfoSize

func MaxNodeInfoSize() int

Max size of the NodeInfo struct

Types

type ConnFilterFunc

type ConnFilterFunc func(p2p.ConnSet, net.Conn, []net.IP) error

ConnFilterFunc to be implemented by filter hooks after a new connection has been established. The set of exisiting connections is passed along together with all resolved IPs for the new connection.

type ErrCurrentlyDialingOrExistingAddress

type ErrCurrentlyDialingOrExistingAddress struct {
	Addr string
}

ErrCurrentlyDialingOrExistingAddress indicates that we're currently dialing this address or it belongs to an existing peer.

func (ErrCurrentlyDialingOrExistingAddress) Error

type ErrFilterTimeout

type ErrFilterTimeout struct{}

ErrFilterTimeout indicates that a filter operation timed out.

func (ErrFilterTimeout) Error

func (e ErrFilterTimeout) Error() string

type ErrNetAddressInvalid

type ErrNetAddressInvalid struct {
	Addr string
	Err  error
}

func (ErrNetAddressInvalid) Error

func (e ErrNetAddressInvalid) Error() string

type ErrNetAddressLookup

type ErrNetAddressLookup struct {
	Addr string
	Err  error
}

func (ErrNetAddressLookup) Error

func (e ErrNetAddressLookup) Error() string

type ErrNetAddressNoID

type ErrNetAddressNoID struct {
	Addr string
}

func (ErrNetAddressNoID) Error

func (e ErrNetAddressNoID) Error() string

type ErrRejected

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

ErrRejected indicates that a Peer was rejected carrying additional information as to the reason.

func (ErrRejected) Addr

func (e ErrRejected) Addr() p2p.NetAddress

Addr returns the NetAddress for the rejected Peer.

func (ErrRejected) Error

func (e ErrRejected) Error() string

func (ErrRejected) IsAuthFailure

func (e ErrRejected) IsAuthFailure() bool

IsAuthFailure when Peer authentication was unsuccessful.

func (ErrRejected) IsDuplicate

func (e ErrRejected) IsDuplicate() bool

IsDuplicate when Peer ID or IP are present already.

func (ErrRejected) IsFiltered

func (e ErrRejected) IsFiltered() bool

IsFiltered when Peer ID or IP was filtered.

func (ErrRejected) IsIncompatible

func (e ErrRejected) IsIncompatible() bool

IsIncompatible when Peer NodeInfo is not compatible with our own.

func (ErrRejected) IsNodeInfoInvalid

func (e ErrRejected) IsNodeInfoInvalid() bool

IsNodeInfoInvalid when the sent NodeInfo is not valid.

func (ErrRejected) IsSelf

func (e ErrRejected) IsSelf() bool

IsSelf when Peer is our own node.

type ErrSwitchAuthenticationFailure

type ErrSwitchAuthenticationFailure struct {
	Dialed *p2p.NetAddress
	Got    p2p.ID
}

func (ErrSwitchAuthenticationFailure) Error

type ErrSwitchConnectToSelf

type ErrSwitchConnectToSelf struct {
	Addr *p2p.NetAddress
}

ErrSwitchConnectToSelf to be raised when trying to connect to itself.

func (ErrSwitchConnectToSelf) Error

func (e ErrSwitchConnectToSelf) Error() string

type ErrSwitchDuplicatePeerID

type ErrSwitchDuplicatePeerID struct {
	ID p2p.ID
}

ErrSwitchDuplicatePeerID to be raised when a peer is connecting with a known ID.

func (ErrSwitchDuplicatePeerID) Error

func (e ErrSwitchDuplicatePeerID) Error() string

type ErrSwitchDuplicatePeerIP

type ErrSwitchDuplicatePeerIP struct {
	IP net.IP
}

ErrSwitchDuplicatePeerIP to be raised whena a peer is connecting with a known IP.

func (ErrSwitchDuplicatePeerIP) Error

func (e ErrSwitchDuplicatePeerIP) Error() string

type ErrTransportClosed

type ErrTransportClosed struct{}

ErrTransportClosed is raised when the Transport has been closed.

func (ErrTransportClosed) Error

func (e ErrTransportClosed) Error() string

type IPResolver

type IPResolver interface {
	LookupIPAddr(context.Context, string) ([]net.IPAddr, error)
}

IPResolver is a behaviour subset of net.Resolver.

type MultiplexTransport

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

MultiplexTransport accepts and dials tcp connections and upgrades them to multiplexed peers.

func NewMultiplexTransport

func NewMultiplexTransport(
	nodeInfo p2p.NodeInfo,
	nodeKey p2p.NodeKey,
	mConfig conn.MConnConfig,
) *MultiplexTransport

NewMultiplexTransport returns a tcp connected multiplexed peer.

func (*MultiplexTransport) Accept

func (mt *MultiplexTransport) Accept(cfg PeerConfig) (p2p.Peer, error)

Accept implements Transport.

func (*MultiplexTransport) AddChannel

func (mt *MultiplexTransport) AddChannel(chID byte)

AddChannel registers a channel to nodeInfo. NOTE: NodeInfo must be of type DefaultNodeInfo else channels won't be updated This is a bit messy at the moment but is cleaned up in the following version when NodeInfo changes from an interface to a concrete type

func (*MultiplexTransport) Cleanup

func (mt *MultiplexTransport) Cleanup(p p2p.Peer)

Cleanup removes the given address from the connections set and closes the connection.

func (*MultiplexTransport) Close

func (mt *MultiplexTransport) Close() error

Close implements transportLifecycle.

func (*MultiplexTransport) Dial

func (mt *MultiplexTransport) Dial(
	addr p2p.NetAddress,
	cfg PeerConfig,
) (p2p.Peer, error)

Dial implements Transport.

func (*MultiplexTransport) Listen

func (mt *MultiplexTransport) Listen(addr p2p.NetAddress) error

Listen implements transportLifecycle.

func (*MultiplexTransport) NetAddress

func (mt *MultiplexTransport) NetAddress() p2p.NetAddress

NetAddress implements Transport.

type MultiplexTransportOption

type MultiplexTransportOption func(*MultiplexTransport)

MultiplexTransportOption sets an optional parameter on the MultiplexTransport.

func MultiplexTransportConnFilters

func MultiplexTransportConnFilters(
	filters ...ConnFilterFunc,
) MultiplexTransportOption

MultiplexTransportConnFilters sets the filters for rejection new connections.

func MultiplexTransportFilterTimeout

func MultiplexTransportFilterTimeout(
	timeout time.Duration,
) MultiplexTransportOption

MultiplexTransportFilterTimeout sets the timeout waited for filter calls to return.

func MultiplexTransportMaxIncomingConnections

func MultiplexTransportMaxIncomingConnections(n int) MultiplexTransportOption

MultiplexTransportMaxIncomingConnections sets the maximum number of simultaneous connections (incoming). Default: 0 (unlimited)

func MultiplexTransportResolver

func MultiplexTransportResolver(resolver IPResolver) MultiplexTransportOption

MultiplexTransportResolver sets the Resolver used for ip lokkups, defaults to net.DefaultResolver.

type PeerConfig

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

PeerConfig is used to bundle data we need to fully setup a Peer with an MConn, provided by the caller of Accept and Dial (currently the Switch). This a temporary measure until reactor setup is less dynamic and we introduce the concept of PeerBehaviour to communicate about significant Peer lifecycle events. TODO(xla): Refactor out with more static Reactor setup and PeerBehaviour.

type PeerOption

type PeerOption func(*peer)

func PeerMetrics

func PeerMetrics(metrics *p2p.Metrics) PeerOption

type Transport

type Transport interface {
	// Listening address.
	NetAddress() p2p.NetAddress

	// Accept returns a newly connected Peer.
	Accept(PeerConfig) (p2p.Peer, error)

	// Dial connects to the Peer for the address.
	Dial(p2p.NetAddress, PeerConfig) (p2p.Peer, error)

	// Cleanup any resources associated with Peer.
	Cleanup(p2p.Peer)
}

Transport emits and connects to Peers. The implementation of Peer is left to the transport. Each transport is also responsible to filter establishing peers specific to its domain.

Jump to

Keyboard shortcuts

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