transport

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2019 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	//Error is the errs class of standard Transport Client errors
	Error = errs.Class("transport error")
)

Functions

func DialAddressInsecure

func DialAddressInsecure(ctx context.Context, address string, opts ...grpc.DialOption) (conn *grpc.ClientConn, err error)

DialAddressInsecure returns an insecure grpc connection without tls to a node.

Use this method for communication with localhost. For example, with the inspector or debugging services. Otherwise in most cases DialNode should be used for communicating with nodes since it is secure.

Types

type Client

type Client interface {
	DialNode(ctx context.Context, node *pb.Node, opts ...grpc.DialOption) (*grpc.ClientConn, error)
	DialAddress(ctx context.Context, address string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
	Identity() *identity.FullIdentity
	WithObservers(obs ...Observer) Client
}

Client defines the interface to an transport client.

func NewClient

func NewClient(tlsOpts *tlsopts.Options, obs ...Observer) Client

NewClient returns a transport client with a default timeout for requests

func NewClientWithTimeout

func NewClientWithTimeout(tlsOpts *tlsopts.Options, requestTimeout time.Duration, obs ...Observer) Client

NewClientWithTimeout returns a transport client with a specified timeout for requests

type InvokeTimeout

type InvokeTimeout struct {
	Timeout time.Duration
}

InvokeTimeout enables timeouts for requests that take too long

func (InvokeTimeout) Intercept

func (it InvokeTimeout) Intercept(ctx context.Context, method string, req interface{}, reply interface{},
	cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error

Intercept adds a context timeout to a method call

type Observer

type Observer interface {
	ConnSuccess(ctx context.Context, node *pb.Node)
	ConnFailure(ctx context.Context, node *pb.Node, err error)
}

Observer implements the ConnSuccess and ConnFailure methods for Discovery and other services to use

type SimulatedNetwork

type SimulatedNetwork struct {
	DialLatency    time.Duration
	BytesPerSecond memory.Size
}

SimulatedNetwork allows creating connections that try to simulated realistic network conditions.

func (*SimulatedNetwork) DialOptions

func (network *SimulatedNetwork) DialOptions() []grpc.DialOption

DialOptions returns options such that it will use simulated network parameters

func (*SimulatedNetwork) GRPCDialContext

func (network *SimulatedNetwork) GRPCDialContext(ctx context.Context, address string) (net.Conn, error)

GRPCDialContext implements DialContext that is suitable for `grpc.WithContextDialer`

func (*SimulatedNetwork) NewClient

func (network *SimulatedNetwork) NewClient(client Client) Client

NewClient wraps an exiting client with the simulated network params.

type Transport

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

Transport interface structure

func (*Transport) DialAddress

func (transport *Transport) DialAddress(ctx context.Context, address string, opts ...grpc.DialOption) (conn *grpc.ClientConn, err error)

DialAddress returns a grpc connection with tls to an IP address.

Do not use this method unless having a good reason. In most cases DialNode should be used for communicating with nodes as it is more secure than DialAddress.

func (*Transport) DialNode

func (transport *Transport) DialNode(ctx context.Context, node *pb.Node, opts ...grpc.DialOption) (conn *grpc.ClientConn, err error)

DialNode returns a grpc connection with tls to a node.

Use this method for communicating with nodes as it is more secure than DialAddress. The connection will be established successfully only if the target node has the private key for the requested node ID.

func (*Transport) Identity

func (transport *Transport) Identity() *identity.FullIdentity

Identity is a getter for the transport's identity

func (*Transport) WithObservers

func (transport *Transport) WithObservers(obs ...Observer) Client

WithObservers returns a new transport including the listed observers.

Jump to

Keyboard shortcuts

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