service

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: 36 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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")
)
View Source
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.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns default params.

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 DestroyCallback

type DestroyCallback func()

DestroyCallback cleanups session

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 FindOpts

type FindOpts struct {
	Peer        *identity.Identity
	ServiceType string
}

FindOpts provides fields to search sessions.

type ID

type ID string

ID represent unique identifier of the running service.

type IDGenerator

type IDGenerator func() (session.ID, error)

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

func (i *Instance) PolicyProvider() policy.Provider

PolicyProvider returns policy provider implementation.

func (*Instance) Service

func (i *Instance) Service() Service

Service returns the running service 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) Kill

func (manager *Manager) Kill() error

Kill stops all services.

func (*Manager) List

func (manager *Manager) List(includeAll bool) []*Instance

List returns array of service instances.

func (*Manager) Service

func (manager *Manager) Service(id ID) *Instance

Service returns a service instance by requested id.

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.

func (*Manager) Stop

func (manager *Manager) Stop(id ID) error

Stop stops the service.

type NATEventGetter

type NATEventGetter interface {
	LastEvent() *event.Event
}

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

type PaymentEngine interface {
	Start() error
	WaitFirstInvoice(time.Duration) error
	Stop()
}

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

type Pool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Pool is responsible for supervising running instances

func NewPool

func NewPool(eventPublisher Publisher) *Pool

NewPool returns a empty service pool

func (*Pool) Add

func (p *Pool) Add(instance *Instance)

Add registers a service to running instances pool

func (*Pool) Del

func (p *Pool) Del(id ID)

Del removes a service from running instances pool

func (*Pool) Instance

func (p *Pool) Instance(id ID) *Instance

Instance returns service instance by the requested id.

func (*Pool) List

func (p *Pool) List() []*Instance

List returns all running service instances.

func (*Pool) Stop

func (p *Pool) Stop(id ID) error

Stop kills all sub-resources of instance

func (*Pool) StopAll

func (p *Pool) StopAll() error

StopAll kills all 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) Create

func (registry *Registry) Create(serviceType string, options Options) (Service, error)

Create creates pluggable service

func (*Registry) Register

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

Register registers a new pluggable service

type RegistryFactory

type RegistryFactory func(options Options) (Service, error)

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.

func (*Session) Close

func (s *Session) Close()

Close ends session.

func (*Session) Done

func (s *Session) Done() <-chan struct{}

Done returns readonly done channel.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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