Documentation
¶
Index ¶
- Variables
- type Cleaner
- type Config
- type ConfigParams
- type ConfigProvider
- type DestroyCallback
- type Discovery
- type DiscoveryFactory
- type FindOpts
- type ID
- type IDGenerator
- type Instance
- type KeepAliveConfig
- type Manager
- func (manager *Manager) Kill() error
- func (manager *Manager) List(includeAll bool) []*Instance
- func (manager *Manager) Service(id ID) *Instance
- func (manager *Manager) Start(providerID identity.Identity, serviceType string, policyIDs []string, ...) (id ID, err error)
- func (manager *Manager) Stop(id ID) error
- type NATEventGetter
- type Options
- type PaymentEngine
- type PaymentEngineFactory
- type Pool
- type PriceValidator
- type PromiseProcessor
- type Publisher
- type Registry
- type RegistryFactory
- type Service
- type ServiceConfiguration
- type Session
- type SessionManager
- type SessionPool
- func (sp *SessionPool) Add(instance *Session)
- func (sp *SessionPool) Find(id session.ID) (*Session, bool)
- func (sp *SessionPool) FindBy(opts FindOpts) (*Session, bool)
- func (sp *SessionPool) GetAll() []*Session
- func (sp *SessionPool) Remove(id session.ID)
- func (sp *SessionPool) RemoveForService(serviceID string)
- type SessionStorage
- type WaitForNATHole
Constants ¶
This section is empty.
Variables ¶
var ( // ErrorLocation error indicates that action (i.e. disconnect) ErrorLocation = errors.New("failed to detect service location") // ErrUnsupportedServiceType indicates that manager tried to create an unsupported service type ErrUnsupportedServiceType = errors.New("unsupported service type") // ErrUnsupportedAccessPolicy indicates that manager tried to create service with unsupported access policy ErrUnsupportedAccessPolicy = errors.New("unsupported access policy") )
var ( // ErrorInvalidProposal is validation error then invalid proposal requested for session creation ErrorInvalidProposal = errors.New("proposal does not exist") // ErrorSessionNotExists returned when consumer tries to destroy session that does not exists ErrorSessionNotExists = errors.New("session does not exists") // ErrorWrongSessionOwner returned when consumer tries to destroy session that does not belongs to him ErrorWrongSessionOwner = errors.New("wrong session owner") )
var ErrNoSuchInstance = errors.New("no such instance")
ErrNoSuchInstance represents the error when we're stopping an instance that does not exist
Functions ¶
This section is empty.
Types ¶
type Cleaner ¶
type Cleaner struct {
SessionStorage SessionStorage
}
Cleaner cleans up when service is stopped
func (*Cleaner) HandleServiceStatus ¶
func (cleaner *Cleaner) HandleServiceStatus(event servicestate.AppEventServiceStatus)
HandleServiceStatus removes sessions of stopped service
type Config ¶
type Config struct {
KeepAlive KeepAliveConfig
}
Config contains common configuration options for session manager.
type ConfigParams ¶
type ConfigParams struct { SessionServiceConfig ServiceConfiguration SessionDestroyCallback DestroyCallback }
ConfigParams session configuration parameters
type ConfigProvider ¶
type ConfigProvider interface {
ProvideConfig(sessionID string, sessionConfig json.RawMessage, conn *net.UDPConn) (*ConfigParams, error)
}
ConfigProvider is able to handle config negotiations
type Discovery ¶
type Discovery interface { Start(ownIdentity identity.Identity, proposal func() market.ServiceProposal) Stop() Wait() }
Discovery registers the service to the discovery api periodically
type DiscoveryFactory ¶
type DiscoveryFactory func() Discovery
DiscoveryFactory initiates instance which is able announce service discoverability
type IDGenerator ¶
IDGenerator defines method for session id generation
type Instance ¶
type Instance struct { ID ID ProviderID identity.Identity Type string Options Options Proposal market.ServiceProposal // contains filtered or unexported fields }
Instance represents a run service
func NewInstance ¶
func NewInstance( providerID identity.Identity, serviceType string, options Options, proposal market.ServiceProposal, state servicestate.State, service Service, policyProvider policy.Provider, discovery Discovery, ) *Instance
NewInstance creates new instance of the service.
func (*Instance) CopyProposal ¶
func (i *Instance) CopyProposal() market.ServiceProposal
CopyProposal returns a copy of Proposal
func (*Instance) PolicyProvider ¶
PolicyProvider returns policy provider implementation.
func (*Instance) State ¶
func (i *Instance) State() servicestate.State
State returns the service instance state.
type KeepAliveConfig ¶
type KeepAliveConfig struct { SendInterval time.Duration SendTimeout time.Duration MaxSendErrCount int }
KeepAliveConfig contains keep alive options.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager entrypoint which knows how to start pluggable Mysterium instances
func NewManager ¶
func NewManager( serviceRegistry *Registry, discoveryFactory DiscoveryFactory, eventPublisher Publisher, policyOracle *localcopy.Oracle, policyProvider policy.Provider, p2pListener p2p.Listener, sessionManager func(service *Instance, channel p2p.Channel) *SessionManager, statusStorage connectivity.StatusStorage, location locationResolver, ) *Manager
NewManager creates new instance of pluggable instances manager
func (*Manager) Start ¶
func (manager *Manager) Start(providerID identity.Identity, serviceType string, policyIDs []string, options Options) (id ID, err error)
Start starts an instance of the given service type if knows one in service registry. It passes the options to the start method of the service. If an error occurs in the underlying service, the error is then returned.
type NATEventGetter ¶
NATEventGetter lets us access the last known traversal event
type Options ¶
type Options interface{}
Options represents any type of options for pluggable service
type PaymentEngine ¶
PaymentEngine is responsible for interacting with the consumer in regard to payments.
type PaymentEngineFactory ¶
type PaymentEngineFactory func(providerID, consumerID identity.Identity, chainID int64, hermesID common.Address, sessionID string, exchangeChan chan crypto.ExchangeMessage, price market.Price) (PaymentEngine, error)
PaymentEngineFactory creates a new instance of payment engine
type Pool ¶
Pool is responsible for supervising running instances
type PriceValidator ¶
type PriceValidator interface {
IsPriceValid(in market.Price, nodeType string, country string, serviceType string) bool
}
PriceValidator allows to validate prices against those in discovery.
type PromiseProcessor ¶
type PromiseProcessor interface { Start(proposal market.ServiceProposal) error Stop() error }
PromiseProcessor processes promises at provider side. Provider checks promises from consumer and signs them also. Provider clears promises from consumer.
type Publisher ¶
type Publisher interface {
Publish(topic string, data interface{})
}
Publisher is responsible for publishing given events
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds all pluggable services
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates a registry of pluggable services
func (*Registry) Register ¶
func (registry *Registry) Register(serviceType string, creator RegistryFactory)
Register registers a new pluggable service
type RegistryFactory ¶
RegistryFactory initiates instance which is able to serve
type Service ¶
type Service interface { Serve(instance *Instance) error Stop() error ConfigProvider }
Service interface represents pluggable Mysterium service
type ServiceConfiguration ¶
type ServiceConfiguration interface{}
ServiceConfiguration defines service configuration from underlying transport mechanism to be passed to remote party should be serializable to json format.
type Session ¶
type Session struct { ID session.ID ConsumerID identity.Identity ConsumerLocation market.Location HermesID common.Address Proposal market.ServiceProposal ServiceID string CreatedAt time.Time // contains filtered or unexported fields }
Session structure holds all required information about current session between service consumer and provider.
func NewSession ¶
func NewSession(service *Instance, request *pb.SessionRequest, tracer *trace.Tracer) (*Session, error)
NewSession creates a blank new session with an ID.
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager knows how to start and provision session
func NewSessionManager ¶
func NewSessionManager( service *Instance, sessionStorage *SessionPool, paymentEngineFactory PaymentEngineFactory, publisher publisher, channel p2p.Channel, config Config, priceValidator PriceValidator, ) *SessionManager
NewSessionManager returns new session SessionManager
func (*SessionManager) Acknowledge ¶
func (manager *SessionManager) Acknowledge(consumerID identity.Identity, sessionID string) error
Acknowledge marks the session as successfully established as far as the consumer is concerned.
func (*SessionManager) Destroy ¶
func (manager *SessionManager) Destroy(consumerID identity.Identity, sessionID string) error
Destroy destroys session by given sessionID
func (*SessionManager) Start ¶
func (manager *SessionManager) Start(request *pb.SessionRequest) (_ pb.SessionResponse, err error)
Start starts a session on the provider side for the given consumer. Multiple sessions per peerID is possible in case different services are used
type SessionPool ¶
type SessionPool struct {
// contains filtered or unexported fields
}
SessionPool maintains all current sessions in memory
func NewSessionPool ¶
func NewSessionPool(publisher publisher) *SessionPool
NewSessionPool initiates new session storage
func (*SessionPool) Add ¶
func (sp *SessionPool) Add(instance *Session)
Add puts given session to storage and publishes a creation event. Multiple sessions per peerID is possible in case different services are used
func (*SessionPool) Find ¶
func (sp *SessionPool) Find(id session.ID) (*Session, bool)
Find returns underlying session instance
func (*SessionPool) FindBy ¶
func (sp *SessionPool) FindBy(opts FindOpts) (*Session, bool)
FindBy returns a session by find options.
func (*SessionPool) GetAll ¶
func (sp *SessionPool) GetAll() []*Session
GetAll returns all sessions in storage
func (*SessionPool) Remove ¶
func (sp *SessionPool) Remove(id session.ID)
Remove removes given session from underlying storage
func (*SessionPool) RemoveForService ¶
func (sp *SessionPool) RemoveForService(serviceID string)
RemoveForService removes all sessions which belong to given service
type SessionStorage ¶
type SessionStorage interface {
RemoveForService(serviceID string)
}
SessionStorage keeps sessions and allows removing them by proposal id
type WaitForNATHole ¶
type WaitForNATHole func() error
WaitForNATHole blocks until NAT hole is punched towards consumer through local NAT or until hole punching failed