Documentation
¶
Index ¶
- Constants
- Variables
- func FilteredProposals(f *proposal.Filter, sortBy string, repo proposalRepository) func() (*proposal.PricedServiceProposal, error)
- func NewManager(paymentEngineFactory PaymentEngineFactory, connectionCreator Creator, ...) *connectionManager
- func NewMultiConnectionManager(newConnectionManager func() Manager) *multiConnectionManager
- type Config
- type ConnectOptions
- type ConnectParams
- type Connection
- type ConnectionStart
- type ConsumerConfig
- type Creator
- type DNSOption
- type Factory
- type IPCheckConfig
- type KeepAliveConfig
- type Manager
- type MultiManager
- type PaymentEngineFactory
- type PaymentIssuer
- type PriceGetter
- type ProposalLookup
- type Registry
- type StateChannel
- type TimeGetter
- type Validator
Constants ¶
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 ¶
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.
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 ¶
NewDNSOption creates and validates DNSOption
func (*DNSOption) ResolveIPs ¶
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 ¶
UnmarshalJSON parses JSON → DNSOption
type IPCheckConfig ¶
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 ¶
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
type StateChannel ¶
type StateChannel chan connectionstate.State
StateChannel is the channel we receive state change events on
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.