connection

package
v0.0.0-...-c97221a Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: GPL-3.0 Imports: 29 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// DNSOptionAuto (default) tries the following with fallbacks: provider's DNS -> client's system DNS -> public DNS
	DNSOptionAuto = DNSOption("auto")
	// DNSOptionProvider uses DNS servers from provider's system configuration
	DNSOptionProvider = DNSOption("provider")
	// DNSOptionSystem uses DNS servers from client's system configuration
	DNSOptionSystem = DNSOption("system")
)

Variables

View Source
var (
	// ErrNoConnection error indicates that action applied to manager expects active connection (i.e. disconnect)
	ErrNoConnection = errors.New("no connection exists")
	// ErrAlreadyExists error indicates that action applied to manager expects no active connection (i.e. connect)
	ErrAlreadyExists = errors.New("connection already exists")
	// ErrConnectionCancelled indicates that connection in progress was cancelled by request of api user
	ErrConnectionCancelled = errors.New("connection was cancelled")
	// ErrConnectionFailed indicates that Connect method didn't reach "Connected" phase due to connection error
	ErrConnectionFailed = errors.New("connection has failed")
	// ErrUnsupportedServiceType indicates that target proposal contains unsupported service type
	ErrUnsupportedServiceType = errors.New("unsupported service type in proposal")
	// ErrInsufficientBalance indicates consumer has insufficient balance to connect to selected proposal
	ErrInsufficientBalance = errors.New("insufficient balance")
	// ErrUnlockRequired indicates that the consumer identity has not been unlocked yet
	ErrUnlockRequired = errors.New("unlock required")
)

Functions

func FilteredProposals

func FilteredProposals(f *proposal.Filter, sortBy string, repo proposalRepository) func() (*proposal.PricedServiceProposal, error)

FilteredProposals create an function to keep getting proposals from the discovery based on the provided filters.

func NewManager

func NewManager(
	paymentEngineFactory PaymentEngineFactory,
	connectionCreator Creator,
	eventBus eventbus.EventBus,
	ipResolver ip.Resolver,
	locationResolver location.OriginResolver,
	config Config,
	statsReportInterval time.Duration,
	validator validator,
	p2pDialer p2p.Dialer,
	preReconnect, postReconnect func(),
) *connectionManager

NewManager creates connection manager with given dependencies

func NewMultiConnectionManager

func NewMultiConnectionManager(newConnectionManager func() Manager) *multiConnectionManager

NewMultiConnectionManager create a wrapper around connection manager to support multiple connections.

Types

type Config

type Config struct {
	IPCheck   IPCheckConfig
	KeepAlive KeepAliveConfig
}

Config contains common configuration options for connection manager.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns default params.

type ConnectOptions

type ConnectOptions struct {
	ConsumerID      identity.Identity
	Proposal        proposal.PricedServiceProposal
	ProposalLookup  ProposalLookup
	SessionID       session.ID
	Params          ConnectParams
	SessionConfig   []byte
	ProviderNATConn *net.UDPConn
	ChannelConn     *net.UDPConn
	HermesID        common.Address
}

ConnectOptions represents the params we need to ensure a successful connection

type ConnectParams

type ConnectParams struct {
	// kill switch option restricting communication only through VPN
	DisableKillSwitch bool
	// DNS servers to use
	DNS DNSOption

	ProxyPort int
}

ConnectParams holds plugin specific params

type Connection

type Connection interface {
	Start(context.Context, ConnectOptions) error
	Reconnect(context.Context, ConnectOptions) error
	Stop()
	GetConfig() (ConsumerConfig, error)
	State() <-chan connectionstate.State
	Statistics() (connectionstate.Statistics, error)
}

Connection represents a connection

type ConnectionStart

type ConnectionStart func(context.Context, ConnectOptions) error

ConnectionStart start new connection with a given options.

type ConsumerConfig

type ConsumerConfig interface{}

ConsumerConfig are the parameters used for the initiation of connection

type Creator

type Creator func(serviceType string) (Connection, error)

Creator creates new connection by given options and uses state channel to report state changes

type DNSOption

type DNSOption string

DNSOption defines DNS server selection strategy for consumer

func NewDNSOption

func NewDNSOption(str string) (DNSOption, error)

NewDNSOption creates and validates DNSOption

func (DNSOption) Exact

func (o DNSOption) Exact() (servers []string, ok bool)

Exact returns a slice of DNS server IPs, if they were set

func (*DNSOption) ResolveIPs

func (o *DNSOption) ResolveIPs(providerDNS string) ([]string, error)

ResolveIPs resolves DNS server IPs on the consumer side using self as the consumer preference and `providerDNS` argument as received from the provider

func (*DNSOption) UnmarshalJSON

func (o *DNSOption) UnmarshalJSON(data []byte) error

UnmarshalJSON parses JSON → DNSOption

type Factory

type Factory func() (Connection, error)

Factory represents a connection constructor

type IPCheckConfig

type IPCheckConfig struct {
	MaxAttempts             int
	SleepDurationAfterCheck time.Duration
}

IPCheckConfig contains common params for connection ip check.

type KeepAliveConfig

type KeepAliveConfig struct {
	SendInterval    time.Duration
	SendTimeout     time.Duration
	MaxSendErrCount int
}

KeepAliveConfig contains keep alive options.

type Manager

type Manager interface {
	// Connect creates new connection from given consumer to provider, reports error if connection already exists
	Connect(consumerID identity.Identity, hermesID common.Address, proposal ProposalLookup, params ConnectParams) error
	// Status queries current status of connection
	Status() connectionstate.Status
	// Stats provides connection statistics information.
	Stats() connectionstate.Statistics
	// Disconnect closes established connection, reports error if no connection
	Disconnect() error
	// CheckChannel checks if current session channel is alive, returns error on failed keep-alive ping
	CheckChannel(context.Context) error
	// Reconnect reconnects current session
	Reconnect()
}

Manager interface provides methods to manage connection

type MultiManager

type MultiManager interface {
	// Connect creates new connection from given consumer to provider, reports error if connection already exists
	Connect(consumerID identity.Identity, hermesID common.Address, proposal ProposalLookup, params ConnectParams) error
	// Status queries current status of connection
	Status(n int) connectionstate.Status
	// Stats provides connection statistics information.
	Stats(n int) connectionstate.Statistics
	// Disconnect closes established connection, reports error if no connection
	Disconnect(n int) error
	// CheckChannel checks if current session channel is alive, returns error on failed keep-alive ping
	CheckChannel(context.Context) error
	// Reconnect reconnects current session
	Reconnect(n int)
}

MultiManager interface provides methods to manage connection

type PaymentEngineFactory

type PaymentEngineFactory func(senderUUID string, channel p2p.Channel, consumer, provider identity.Identity, hermes common.Address, proposal proposal.PricedServiceProposal, price market.Price) (PaymentIssuer, error)

PaymentEngineFactory creates a new payment issuer from the given params

type PaymentIssuer

type PaymentIssuer interface {
	Start() error
	SetSessionID(string)
	Stop()
}

PaymentIssuer handles the payments for service

type PriceGetter

type PriceGetter interface {
	GetCurrentPrice(nodeType string, country string) (market.Price, error)
}

PriceGetter fetches the current price.

type ProposalLookup

type ProposalLookup func() (proposal *proposal.PricedServiceProposal, err error)

ProposalLookup returns a service proposal based on predefined conditions.

type Registry

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

Registry holds of all plugable connections

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates registry of plugable connections

func (*Registry) CreateConnection

func (registry *Registry) CreateConnection(serviceType string) (Connection, error)

CreateConnection create plugable connection

func (*Registry) Register

func (registry *Registry) Register(serviceType string, creator Factory)

Register new plugable connection

type StateChannel

type StateChannel chan connectionstate.State

StateChannel is the channel we receive state change events on

type TimeGetter

type TimeGetter func() time.Time

TimeGetter function returns current time

type Validator

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

Validator validates pre connection conditions.

func NewValidator

func NewValidator(consumerBalanceGetter consumerBalanceGetter, unlockChecker unlockChecker) *Validator

NewValidator returns a new instance of connection validator.

func (*Validator) Validate

func (v *Validator) Validate(chainID int64, consumerID identity.Identity, price market.Price) error

Validate checks whether the pre-connection conditions are fulfilled.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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