rpc

package
v0.0.0-...-5f226fc Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 29 Imported by: 49

Documentation

Overview

Package rpc implements dialing on Storj Network.

Index

Constants

View Source
const (
	// IsDRPC is true if drpc is being used.
	IsDRPC = true
)
View Source
const TCPConnectorPriority = 10

TCPConnectorPriority is the priority TCP is registered with by default for RegisterCandidateConnectorType. This is useful if you want to override TCP dialing settings for a specific HybridConnector using AddCandidateConnector.

Variables

View Source
var Error = errs.Class("rpc")

Error wraps all of the errors returned by this package.

Functions

func KnownNodeID

func KnownNodeID(address string) (id storj.NodeID, known bool)

KnownNodeID looks for a well-known node id for a given address.

func LookupNodeAddress

func LookupNodeAddress(ctx context.Context, nodeAddress string) string

LookupNodeAddress resolves a storage node address to the first IP address resolved. If an IP address is accidentally provided it is returned back. This function is used to resolve storage node IP addresses so that uplinks can use IP addresses directly without resolving many hosts.

func NewDefaultConnectionPool

func NewDefaultConnectionPool() *rpcpool.Pool

NewDefaultConnectionPool returns a rpc Pool with default options set.

func NewDefaultManagerOptions

func NewDefaultManagerOptions() drpcmanager.Options

NewDefaultManagerOptions returns the default options we use for drpc managers.

func QUICRolloutPercent

func QUICRolloutPercent(ctx context.Context) int

QUICRolloutPercent returns the currently configured QUIC rollout percent for the given context.

func RegisterCandidateConnectorType

func RegisterCandidateConnectorType(name string, connectorType func() Connector, priority int)

RegisterCandidateConnectorType registers a type of connector for use with all HybridConnector instances created in the future. If the new connector type has the same name as one that is already registered, it will replace the preexisting entry.

func WithForcedKind

func WithForcedKind(ctx context.Context, kind string) context.Context

WithForcedKind can force to use one specific type of connection (for example tcp or quic).

func WithQUICRolloutPercent

func WithQUICRolloutPercent(ctx context.Context, percent int) context.Context

WithQUICRolloutPercent sets the QUIC rollout percent for any dials that use the returned context.

Types

type Conn

type Conn struct {
	rpcpool.Conn
}

Conn is a wrapper around a drpc client connection.

func (*Conn) PeerIdentity

func (c *Conn) PeerIdentity() (*identity.PeerIdentity, error)

PeerIdentity returns the peer identity on the other end of the connection.

type Connector

type Connector interface {
	// DialContext is called to establish a encrypted connection using tls.
	DialContext(ctx context.Context, tlsconfig *tls.Config, address string) (ConnectorConn, error)
}

Connector is a type that creates a ConnectorConn, given an address and a tls configuration.

type ConnectorConn

type ConnectorConn interface {
	net.Conn
	ConnectionState() tls.ConnectionState
}

ConnectorConn is a type that creates a connection and establishes a tls session.

type DialFunc

type DialFunc func(ctx context.Context, network, address string) (net.Conn, error)

DialFunc represents a dialer that can establish a net.Conn.

type DialOptions

type DialOptions struct {
	ReplaySafe bool

	// ForceTCPFastOpenMultidialSupport, if true, tells the dialer that TCP_FASTOPEN
	// multidialing should be considered for this node, even if the nodeURL doesn't
	// have a debounce limit set. This does not mean that TCP_FASTOPEN or multidialing
	// will definitely be used, but it will be considered.
	ForceTCPFastOpenMultidialSupport bool
}

DialOptions provides a set of options around how to contact nodes.

type Dialer

type Dialer struct {
	// TLSOptions controls the tls options for dialing with NodeID verification.
	// If it is nil, only insecure connections can be made.
	TLSOptions *tlsopts.Options

	// Override system TLS settings when using hostname verification
	HostnameTLSConfig *tls.Config

	// DialTimeout causes all the tcp dials to error if they take longer
	// than it if it is non-zero.
	DialTimeout time.Duration

	// DialLatency sleeps this amount if it is non-zero before every dial.
	// The timeout runs while the sleep is happening.
	DialLatency time.Duration

	// Pool is the shared connection pool for this dialer.
	Pool *rpcpool.Pool

	// ConnectionOptions controls the options that we pass to drpc connections.
	ConnectionOptions drpcconn.Options

	// AttemptBackgroundQoS controls whether QoS flags will be set on connection packets.
	AttemptBackgroundQoS bool

	// Connector is how sockets are opened. If nil, net.Dialer is used.
	Connector Connector
}

Dialer holds configuration for dialing.

func NewDefaultDialer

func NewDefaultDialer(tlsOptions *tlsopts.Options) Dialer

NewDefaultDialer returns a Dialer with default options set.

func NewDefaultPooledDialer

func NewDefaultPooledDialer(tlsOptions *tlsopts.Options) Dialer

NewDefaultPooledDialer returns a Dialer with default options set and a long lived dialer shared connection pool. This is appropriate for longer lived processes with more resources.

func (Dialer) DialAddressHostnameVerification

func (d Dialer) DialAddressHostnameVerification(ctx context.Context, address string) (_ *Conn, err error)

DialAddressHostnameVerification dials to the specified address and assumes that the server will valdiate their hostname with the system/browser CA, unless overridden. It ignores any TLSOptions set on the dialer.

func (Dialer) DialAddressInsecure

func (d Dialer) DialAddressInsecure(ctx context.Context, address string) (_ *Conn, err error)

DialAddressInsecure dials to the specified address and does not check the node id.

func (Dialer) DialAddressUnencrypted

func (d Dialer) DialAddressUnencrypted(ctx context.Context, address string) (_ *Conn, err error)

DialAddressUnencrypted dials to the specified address without tls.

func (Dialer) DialNode

func (d Dialer) DialNode(ctx context.Context, nodeURL storj.NodeURL, opts DialOptions) (_ *Conn, err error)

DialNode dials to the specified node url using the provided options and asserts it has the given node id.

func (Dialer) DialNodeURL

func (d Dialer) DialNodeURL(ctx context.Context, nodeURL storj.NodeURL) (_ *Conn, err error)

DialNodeURL dials to the specified node url and asserts it has the given node id.

type HybridConnector

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

HybridConnector implements a dialer that creates a connection using any of (potentially) multiple connector candidates. The fastest one is kept, and all others are closed and discarded.

func NewHybridConnector

func NewHybridConnector() HybridConnector

NewHybridConnector instantiates a new instance of HybridConnector with all registered connector types.

func (*HybridConnector) AddCandidateConnector

func (c *HybridConnector) AddCandidateConnector(name string, connector Connector, priority int)

AddCandidateConnector adds a candidate connector to this HybridConnector instance. (Other HybridConnector instances, both current and future, will not be affected by this call).

It is recommended that this be used before any connections are attempted with the HybridConnector, because no concurrency protection is built in to accesses to c.connectors.

This method now replaces any candidate connector with the same name, to match the behavior of RegisterCandidateConnectorType.

func (HybridConnector) DialContext

func (c HybridConnector) DialContext(ctx context.Context, tlsConfig *tls.Config, address string) (_ ConnectorConn, err error)

DialContext creates an encrypted connection using one of the candidate connectors. All connectors are started at the same time, and the first one to finish will have its connection returned (and other connectors will be canceled). If multiple connectors finish before they are canceled, the connection with the highest priority value is kept.

func (HybridConnector) DialContextUnencrypted

func (c HybridConnector) DialContextUnencrypted(ctx context.Context, address string) (net.Conn, error)

DialContextUnencrypted creates a raw connection using the first registered connector that has a DialContextUnencrypted method. Unless the tcp connector is unregistered, this will be the tcp connector.

func (HybridConnector) DialContextUnencryptedUnprefixed

func (c HybridConnector) DialContextUnencryptedUnprefixed(ctx context.Context, address string) (net.Conn, error)

DialContextUnencryptedUnprefixed creates a raw connection using the first registered connector that has a DialContextUnencryptedUnprefixed method. Unless the tcp connector is unregistered, this will be the tcp connector.

func (*HybridConnector) RemoveCandidateConnector

func (c *HybridConnector) RemoveCandidateConnector(name string)

RemoveCandidateConnector removes a candidate connector from this HybridConnector instance, if there is one with the given name.

It is recommended that this be used before any connections are attempted with the HybridConnector, because no concurrency protection is built in to accesses to c.connectors.

func (*HybridConnector) SetSendDRPCMuxHeader

func (c *HybridConnector) SetSendDRPCMuxHeader(send bool)

SetSendDRPCMuxHeader tells the underlying connector whether it should send the DRPC mux header.

func (*HybridConnector) SetTransferRate

func (c *HybridConnector) SetTransferRate(rate memory.Size)

SetTransferRate calls SetTransferRate with the given transfer rate on all of its candidate connectors (if they have a SetTransferRate method).

type TCPConnector

type TCPConnector struct {
	// TCPUserTimeout controls what setting to use for the TCP_USER_TIMEOUT
	// socket option on dialed connections. Only valid on linux. Only set
	// if positive.
	TCPUserTimeout time.Duration

	// TransferRate limits all read/write operations to go slower than
	// the size per second if it is non-zero.
	TransferRate memory.Size

	// SendDRPCMuxHeader caused the connector to send a preamble after TCP handshake
	// but before the TLS handshake.
	// This was used to migrate from gRPC to DRPC.
	// This needs to be false when connecting through a TLS termination proxy.
	SendDRPCMuxHeader bool
	// contains filtered or unexported fields
}

TCPConnector implements a dialer that creates an encrypted connection using tls.

func NewDefaultTCPConnector deprecated

func NewDefaultTCPConnector(dialer DialFunc) *TCPConnector

NewDefaultTCPConnector creates a new TCPConnector instance with provided tcp dialer. If no dialer is predefined, net.Dialer is used by default.

Deprecated: Use NewHybridConnector wherever possible instead.

func (*TCPConnector) DialContext

func (t *TCPConnector) DialContext(ctx context.Context, tlsConfig *tls.Config, address string) (_ ConnectorConn, err error)

DialContext creates a encrypted tcp connection using tls.

func (*TCPConnector) DialContextUnencrypted

func (t *TCPConnector) DialContextUnencrypted(ctx context.Context, address string) (_ net.Conn, err error)

DialContextUnencrypted creates a raw tcp connection.

func (*TCPConnector) DialContextUnencryptedUnprefixed

func (t *TCPConnector) DialContextUnencryptedUnprefixed(ctx context.Context, address string) (_ net.Conn, err error)

DialContextUnencryptedUnprefixed creates a raw TCP connection without any prefixes.

func (*TCPConnector) SetSendDRPCMuxHeader

func (t *TCPConnector) SetSendDRPCMuxHeader(send bool)

SetSendDRPCMuxHeader says whether we should send the DRPC mux header.

func (*TCPConnector) SetTransferRate

func (t *TCPConnector) SetTransferRate(rate memory.Size)

SetTransferRate sets the transfer rate member for this TCPConnector instance. This is mainly provided for interface compatibility with other connectors.

Directories

Path Synopsis
Package rpcpeer implements context.Context peer tagging.
Package rpcpeer implements context.Context peer tagging.
Package rpcpool implements connection pooling for rpc.
Package rpcpool implements connection pooling for rpc.
Package rpcstatus contains status code definitions for rpc.
Package rpcstatus contains status code definitions for rpc.
Package rpctest holds helpers for development/testing.
Package rpctest holds helpers for development/testing.
Package rpctimeout provides helpers to have timeouts on rpc streams.
Package rpctimeout provides helpers to have timeouts on rpc streams.
Package rpctracing implements tracing for rpc.
Package rpctracing implements tracing for rpc.

Jump to

Keyboard shortcuts

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