transport

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package transport defines the interfaces needed for various mesh operations.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyBootstrapped = raft.ErrCantBootstrap

ErrAlreadyBootstrapped is returned when a node believes the cluster to be already bootstrapped.

View Source
var ErrSignalTransportClosed = fmt.Errorf("signal transport closed")

ErrSignalTransportClosed is returned when a signal transport is closed by either side of the connection.

Functions

func IsSignalTransportClosed added in v0.4.0

func IsSignalTransportClosed(err error) bool

IsSignalTransportClosed returns true if the given error is ErrSignalTransportClosed.

Types

type BootstrapTransport added in v0.3.1

type BootstrapTransport interface {
	// LeaderElect should perform an initial leader election. It returns
	// true is this node was elected leader, or otherwise a JoinRoundTripper
	// for contacting the elected leader. If one or more nodes believe
	// the cluster to be already bootstrapped, then ErrAlreadyBootstrapped
	// should be returned with an optional JoinRoundTripper to nodes who are
	// already bootstrapped.
	LeaderElect(ctx context.Context) (isLeader bool, rt JoinRoundTripper, err error)
}

BootstrapTransport is the interface for dialing other peers to bootstrap a new mesh.

func NewNullBootstrapTransport added in v0.3.1

func NewNullBootstrapTransport() BootstrapTransport

NewNullBootstrapTransport returns a BootstrapTransport that always returns true for LeaderElect and nil for JoinRoundTripper. This is useful for testing and when no bootstrap transport is needed.

type BootstrapTransportFunc added in v0.3.1

type BootstrapTransportFunc func(ctx context.Context) (isLeader bool, rt JoinRoundTripper, err error)

BootstrapTransportFunc is a function that implements BootstrapTransport.

func (BootstrapTransportFunc) LeaderElect added in v0.3.1

func (f BootstrapTransportFunc) LeaderElect(ctx context.Context) (isLeader bool, rt JoinRoundTripper, err error)

LeaderElect implements BootstrapTransport.

type FeatureResolver added in v0.4.0

type FeatureResolver = Resolver[v1.Feature]

FeatureResolver is a resolver that resolves node addresses by feature.

type FeatureResolverFunc added in v0.4.0

type FeatureResolverFunc = ResolverFunc[v1.Feature]

FeatureResolverFunc is a function that implements FeatureResolver.

type JoinRoundTripper added in v0.3.1

type JoinRoundTripper = RoundTripper[v1.JoinRequest, v1.JoinResponse]

JoinRoundTripper is the interface for joining a cluster.

type JoinRoundTripperFunc added in v0.3.1

type JoinRoundTripperFunc = RoundTripperFunc[v1.JoinRequest, v1.JoinResponse]

JoinRoundTripperFunc is a function that implements JoinRoundTripper.

type JoinServer added in v0.3.1

type JoinServer = UnaryServer[v1.JoinRequest, v1.JoinResponse]

JoinServer is the interface for handling requests to join a cluster.

type JoinServerFunc added in v0.3.1

type JoinServerFunc = UnaryServerFunc[v1.JoinRequest, v1.JoinResponse]

JoinServerFunc is a function that implements JoinServer.

type LeaderDialer

type LeaderDialer interface {
	// DialLeader opens a gRPC connection to the current leader.
	DialLeader(ctx context.Context) (*grpc.ClientConn, error)
}

LeaderDialer is the interface for dialing the current leader.

type LeaderDialerFunc

type LeaderDialerFunc func(ctx context.Context) (*grpc.ClientConn, error)

LeaderDialerFunc is a function that implements LeaderDialer.

func (LeaderDialerFunc) DialLeader

func (f LeaderDialerFunc) DialLeader(ctx context.Context) (*grpc.ClientConn, error)

DialLeader implements LeaderDialer.

type NodeDialer

type NodeDialer interface {
	Dial(ctx context.Context, id string) (*grpc.ClientConn, error)
}

NodeDialer is an interface for dialing an arbitrary node. The node ID is optional and if empty, implementations can choose the node to dial.

type NodeDialerFunc

type NodeDialerFunc func(ctx context.Context, id string) (*grpc.ClientConn, error)

NodeDialerFunc is the function signature for dialing an arbitrary node. It is supplied by the mesh during startup. It can be used as an alternative to the NodeDialer interface.

func (NodeDialerFunc) Dial

Dial implements NodeDialer.

type NodeIDResolver added in v0.4.0

type NodeIDResolver = Resolver[string]

NodeIDResolver is a resolver that resolves node addresses by node ID.

type NodeIDResolverFunc added in v0.4.0

type NodeIDResolverFunc = ResolverFunc[string]

NodeIDResolverFunc is a function that implements NodeIDResolver.

type RaftTransport

type RaftTransport interface {
	raft.Transport
	LeaderDialer

	// AddrPort returns the address and port the transport is listening on.
	AddrPort() netip.AddrPort

	// Close closes the transport.
	Close() error
}

RaftTransport defines the methods needed for raft consensus to function in a webmesh cluster.

type Resolver added in v0.4.0

type Resolver[T any] interface {
	// Resolve resolves the addresses for the given lookup parameters.
	Resolve(ctx context.Context, lookup T) ([]netip.AddrPort, error)
}

Resolver is the interface for resolving node addresses. Implementations can be pre-baked for specialized cases, such as resolving node addresses by a specific feature. The returned type is an AddrPort to support resolvers that need to return port numbers.

type ResolverFunc added in v0.4.0

type ResolverFunc[T any] func(ctx context.Context, lookup T) ([]netip.AddrPort, error)

ResolverFunc is a function that implements Resolver.

func (ResolverFunc[T]) Resolve added in v0.4.0

func (f ResolverFunc[T]) Resolve(ctx context.Context, lookup T) ([]netip.AddrPort, error)

Resolve implements Resolver.

type RoundTripper added in v0.3.1

type RoundTripper[REQ, RESP any] interface {
	RoundTrip(ctx context.Context, req *REQ) (*RESP, error)
}

RoundTripper is a generic interface for executing a request and returning a response.

type RoundTripperFunc added in v0.3.1

type RoundTripperFunc[REQ, RESP any] func(ctx context.Context, req *REQ) (*RESP, error)

RoundTripperFunc is a function that implements RoundTripper.

func (RoundTripperFunc[REQ, RESP]) RoundTrip added in v0.3.1

func (f RoundTripperFunc[REQ, RESP]) RoundTrip(ctx context.Context, req *REQ) (*RESP, error)

RoundTrip implements RoundTripper.

type UnaryServer added in v0.3.1

type UnaryServer[REQ, RESP any] interface {
	// Serve is executed when a unary request is received.
	Serve(ctx context.Context, req *REQ) (*RESP, error)
}

UnaryServer is the interface for handling unary requests.

type UnaryServerFunc added in v0.3.1

type UnaryServerFunc[REQ, RESP any] func(ctx context.Context, req *REQ) (*RESP, error)

UnaryServerFunc is a function that implements UnaryServer.

func (UnaryServerFunc[REQ, RESP]) Serve added in v0.3.1

func (f UnaryServerFunc[REQ, RESP]) Serve(ctx context.Context, req *REQ) (*RESP, error)

Serve implements UnaryServer.

type WebRTCSignalTransport added in v0.4.0

type WebRTCSignalTransport interface {
	// Start starts the transport. This will not return until a remote peer
	// has provided a session description.
	Start(ctx context.Context) error
	// TURNServers returns a list of TURN servers configured for the transport.
	TURNServers() []webrtc.ICEServer
	// SendDescription sends an SDP description to the remote peer.
	SendDescription(ctx context.Context, desc webrtc.SessionDescription) error
	// SendCandidate sends an ICE candidate to the remote peer.
	SendCandidate(ctx context.Context, candidate webrtc.ICECandidateInit) error
	// Candidates returns a channel of ICE candidates received from the remote peer.
	Candidates() <-chan webrtc.ICECandidateInit
	// RemoteDescription returns the SDP description received from the remote peer.
	RemoteDescription() webrtc.SessionDescription
	// Error returns a channel that receives any error encountered during signaling.
	// This channel will be closed when the transport is closed.
	Error() <-chan error
	// Close closes the transport.
	Close() error
}

WebRTCSignalTransport is the transport interface for providing WebRTC signaling between mesh nodes.

Directories

Path Synopsis
Package datachannels provides a WebRTC data channel API for port forwarding.
Package datachannels provides a WebRTC data channel API for port forwarding.
Package libp2p provides discovery mechanisms using Kademlia DHT.
Package libp2p provides discovery mechanisms using Kademlia DHT.
Package tcp provides TCP based transports.
Package tcp provides TCP based transports.

Jump to

Keyboard shortcuts

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