transport

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: Apache-2.0 Imports: 5 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.

Functions

This section is empty.

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 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 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 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.

Directories

Path Synopsis
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