view

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: Apache-2.0 Imports: 18 Imported by: 9

Documentation

Index

Constants

View Source
const (
	SuccessLabel       tracing.LabelName = "success"
	ViewLabel          tracing.LabelName = "view"
	InitiatorViewLabel tracing.LabelName = "initiator_view"
)

Variables

View Source
var (
	ServiceNotFound = errors.New("service not found")
)

Functions

func AsInitiatorCall

func AsInitiatorCall(context view.Context, initiator View, v func(context view.Context) (interface{}, error)) (interface{}, error)

AsInitiatorCall can be used by a responder to behave temporarily as an initiator. Recall that an initiator is characterized by having an initiator (`context.Initiator()`) set when the initiator is instantiated. AsInitiatorCall sets context.Initiator() to the passed initiator, and executes the passed view call. TODO: what happens to the sessions already openend with a different initiator (maybe an empty one)?

func AsInitiatorView

func AsInitiatorView(context view.Context, initiator View) (interface{}, error)

AsInitiatorView can be used by a responder to behave temporarily as an initiator. Recall that an initiator is characterized by having an initiator (`context.Initiator()`) set when the initiator is instantiated. AsInitiatorView sets context.Initiator() to the passed initiator, and executes it.

func AsResponder

func AsResponder(context view.Context, session view.Session, v func(context view.Context) (interface{}, error)) (interface{}, error)

AsResponder can be used by an initiator to behave temporarily as a responder. Recall that a responder is characterized by having a default session (`context.Session()`) established by an initiator.

func GetIdentifier added in v0.4.1

func GetIdentifier(f view.View) string

func GetName added in v0.4.1

func GetName(f view.View) string

func Initiate

func Initiate(context view.Context, initiator View) (interface{}, error)

Initiate initiates a new protocol whose initiator's view is the passed one. The execution happens in a freshly created context. This is a shortcut for `view.GetManager(context).InitiateView(initiator)`.

func RunCall

func RunCall(context view.Context, v func(context view.Context) (interface{}, error)) (interface{}, error)

RunCall is a shortcut for `context.RunView(nil, view.WithViewCall(v))` and can be used to run a view call in a given context.

func RunView added in v0.3.0

func RunView(context view.Context, view View, opts ...view.RunViewOption)

RunView runs passed view within the passed context and using the passed options in a separate goroutine

func RunViewNow added in v0.7.0

func RunViewNow(parent ParentContext, v View, opts ...view.RunViewOption) (res interface{}, err error)

RunViewNow invokes the Call function of the given view. The view context used to the run view is either ctx or the one extracted from the options (see view.WithContext), if present.

Types

type ChildContext added in v0.7.0

type ChildContext struct {
	Parent ParentContext
	// contains filtered or unexported fields
}

ChildContext is a view context with a parent. It allows the developer to override session and initiator. It also supports error callbacks.

func NewChildContext added in v0.7.0

func NewChildContext(parentContext ParentContext, session view.Session, initiator view.View, errorCallbackFuncs ...func()) *ChildContext

NewChildContext return a new ChildContext from the given arguments

func NewChildContextFromParent added in v0.7.0

func NewChildContextFromParent(parentContext ParentContext) *ChildContext

NewChildContextFromParent return a new ChildContext from the given parent

func NewChildContextFromParentAndInitiator added in v0.7.0

func NewChildContextFromParentAndInitiator(parentContext ParentContext, initiator view.View) *ChildContext

NewChildContextFromParentAndInitiator return a new ChildContext from the given parent and initiator view

func NewChildContextFromParentAndSession added in v0.7.0

func NewChildContextFromParentAndSession(parentContext ParentContext, session view.Session) *ChildContext

NewChildContextFromParentAndSession return a new ChildContext from the given parent and session

func (*ChildContext) Cleanup added in v0.7.0

func (w *ChildContext) Cleanup()

func (*ChildContext) Context added in v0.7.0

func (w *ChildContext) Context() context.Context

func (*ChildContext) Dispose added in v0.7.0

func (w *ChildContext) Dispose()

func (*ChildContext) GetService added in v0.7.0

func (w *ChildContext) GetService(v interface{}) (interface{}, error)

func (*ChildContext) GetSession added in v0.7.0

func (w *ChildContext) GetSession(caller view.View, party view.Identity, boundToViews ...view.View) (view.Session, error)

func (*ChildContext) GetSessionByID added in v0.7.0

func (w *ChildContext) GetSessionByID(id string, party view.Identity) (view.Session, error)

func (*ChildContext) ID added in v0.7.0

func (w *ChildContext) ID() string

func (*ChildContext) Initiator added in v0.7.0

func (w *ChildContext) Initiator() view.View

func (*ChildContext) IsMe added in v0.7.0

func (w *ChildContext) IsMe(id view.Identity) bool

func (*ChildContext) Me added in v0.7.0

func (w *ChildContext) Me() view.Identity

func (*ChildContext) OnError added in v0.7.0

func (w *ChildContext) OnError(f func())

func (*ChildContext) PutService added in v0.7.0

func (w *ChildContext) PutService(v interface{}) error

func (*ChildContext) PutSession added in v0.7.0

func (w *ChildContext) PutSession(caller view.View, party view.Identity, session view.Session) error

func (*ChildContext) ResetSessions added in v0.7.0

func (w *ChildContext) ResetSessions() error

func (*ChildContext) RunView added in v0.7.0

func (w *ChildContext) RunView(v view.View, opts ...view.RunViewOption) (res interface{}, err error)

func (*ChildContext) Session added in v0.7.0

func (w *ChildContext) Session() view.Session

func (*ChildContext) StartSpanFrom added in v0.7.0

func (w *ChildContext) StartSpanFrom(c context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

type CommLayer added in v0.4.1

type CommLayer interface {
	NewSessionWithID(sessionID, contextID, endpoint string, pkid []byte, caller view.Identity, msg *view.Message) (view.Session, error)

	NewSession(caller string, contextID string, endpoint string, pkid []byte) (view.Session, error)

	MasterSession() (view.Session, error)

	DeleteSessions(ctx context.Context, sessionID string)
}

func GetCommLayer added in v0.4.1

func GetCommLayer(sp services.Provider) CommLayer

type Context added in v0.7.0

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

Context implements the view.Context interface

func NewContext added in v0.4.1

func NewContext(
	context context.Context,
	sp services.Provider,
	contextID string,
	sessionFactory SessionFactory,
	resolver EndpointService,
	idProvider IdentityProvider,
	party view.Identity,
	session view.Session,
	caller view.Identity,
	tracer trace.Tracer,
	localIdentityChecker LocalIdentityChecker,
) (*Context, error)

NewContext returns a new Context

func NewContextForInitiator added in v0.4.1

func NewContextForInitiator(
	contextID string,
	context context.Context,
	sp services.Provider,
	sessionFactory SessionFactory,
	resolver EndpointService,
	idProvider IdentityProvider,
	party view.Identity,
	initiator view.View,
	tracer trace.Tracer,
	localIdentityChecker LocalIdentityChecker,
) (*Context, error)

NewContextForInitiator returns a new Context for an initiator view

func (*Context) Caller added in v0.7.0

func (c *Context) Caller() view.Identity

func (*Context) Cleanup added in v0.7.0

func (c *Context) Cleanup()

func (*Context) Context added in v0.7.0

func (c *Context) Context() context.Context

func (*Context) Dispose added in v0.7.0

func (c *Context) Dispose()

func (*Context) GetService added in v0.7.0

func (c *Context) GetService(v interface{}) (interface{}, error)

func (*Context) GetSession added in v0.7.0

func (c *Context) GetSession(caller view.View, party view.Identity, boundToViews ...view.View) (view.Session, error)

func (*Context) GetSessionByID added in v0.7.0

func (c *Context) GetSessionByID(id string, party view.Identity) (view.Session, error)

func (*Context) ID added in v0.7.0

func (c *Context) ID() string

func (*Context) Identity added in v0.7.0

func (c *Context) Identity(ref string) (view.Identity, error)

Identity returns the identity matching the passed argument

func (*Context) Initiator added in v0.7.0

func (c *Context) Initiator() view.View

func (*Context) IsMe added in v0.7.0

func (c *Context) IsMe(id view.Identity) bool

func (*Context) Me added in v0.7.0

func (c *Context) Me() view.Identity

func (*Context) OnError added in v0.7.0

func (c *Context) OnError(callback func())

func (*Context) PutService added in v0.7.0

func (c *Context) PutService(service interface{}) error

func (*Context) PutSession added in v0.7.0

func (c *Context) PutSession(caller view.View, party view.Identity, session view.Session) error

func (*Context) ResetSessions added in v0.7.0

func (c *Context) ResetSessions() error

func (*Context) RunView added in v0.7.0

func (c *Context) RunView(v view.View, opts ...view.RunViewOption) (res interface{}, err error)

func (*Context) Session added in v0.7.0

func (c *Context) Session() view.Session

func (*Context) StartSpan added in v0.7.0

func (c *Context) StartSpan(name string, opts ...trace.SpanStartOption) trace.Span

func (*Context) StartSpanFrom added in v0.7.0

func (c *Context) StartSpanFrom(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

type DisposableContext added in v0.7.0

type DisposableContext interface {
	view.Context
	Dispose()
}

DisposableContext extends view.Context with additional functions

type EndpointService added in v0.4.1

type EndpointService interface {
	GetIdentity(endpoint string, pkID []byte) (view.Identity, error)
	Resolver(ctx context.Context, party view.Identity) (*endpoint.Resolver, []byte, error)
}

EndpointService models the dependency to the view-sdk's endpoint service

type Factory added in v0.4.1

type Factory interface {
	// NewView returns an instance of the View interface build using the passed argument.
	NewView(in []byte) (view.View, error)
}

Factory is used to create instances of the View interface

type IdentityProvider added in v0.4.1

type IdentityProvider interface {
	Identity(string) view.Identity
	DefaultIdentity() view.Identity
}

IdentityProvider models the dependency to the view-sdk's identity provider

type LocalIdentityChecker added in v0.4.1

type LocalIdentityChecker interface {
	IsMe(ctx context.Context, id view.Identity) bool
}

LocalIdentityChecker models the dependency to the view-sdk's sig service

type Manager added in v0.4.1

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

func GetManager added in v0.4.1

func GetManager(sp services.Provider) (*Manager, error)

GetManager returns an instance of *Manager, if available, an error otherwise

func NewManager added in v0.4.1

func NewManager(
	serviceProvider services.Provider,
	commLayer CommLayer,
	endpointService EndpointService,
	identityProvider IdentityProvider,
	registry *Registry,
	tracerProvider tracing.Provider,
	metricsProvider metrics.Provider,
	localIdentityChecker LocalIdentityChecker,
) *Manager

func (*Manager) Context added in v0.4.1

func (cm *Manager) Context(contextID string) (view.Context, error)

Context returns a view.Context for a given contextID. If the context does not exist, an error is returned.

func (*Manager) ExistResponderForCaller added in v0.4.1

func (cm *Manager) ExistResponderForCaller(caller string) (view.View, view.Identity, error)

func (*Manager) GetIdentifier added in v0.4.1

func (cm *Manager) GetIdentifier(f view.View) string

func (*Manager) GetResponder added in v0.4.1

func (cm *Manager) GetResponder(initiatedBy interface{}) (view.View, error)

func (*Manager) GetService added in v0.4.1

func (cm *Manager) GetService(typ reflect.Type) (interface{}, error)

func (*Manager) Initiate added in v0.4.1

func (cm *Manager) Initiate(id string, ctx context.Context) (interface{}, error)

func (*Manager) InitiateContext added in v0.4.1

func (cm *Manager) InitiateContext(view view.View) (view.Context, error)

func (*Manager) InitiateContextFrom added in v0.4.1

func (cm *Manager) InitiateContextFrom(ctx context.Context, view view.View, id view.Identity, contextID string) (view.Context, error)

func (*Manager) InitiateContextWithIdentity added in v0.4.1

func (cm *Manager) InitiateContextWithIdentity(view view.View, id view.Identity) (view.Context, error)

func (*Manager) InitiateContextWithIdentityAndID added in v0.4.1

func (cm *Manager) InitiateContextWithIdentityAndID(view view.View, id view.Identity, contextID string) (view.Context, error)

func (*Manager) InitiateView added in v0.4.1

func (cm *Manager) InitiateView(view view.View, ctx context.Context) (interface{}, error)

func (*Manager) InitiateViewWithIdentity added in v0.4.1

func (cm *Manager) InitiateViewWithIdentity(view view.View, id view.Identity, ctx context.Context) (interface{}, error)

func (*Manager) NewView added in v0.4.1

func (cm *Manager) NewView(id string, in []byte) (f view.View, err error)

func (*Manager) RegisterFactory added in v0.4.1

func (cm *Manager) RegisterFactory(id string, factory Factory) error

func (*Manager) RegisterResponder added in v0.4.1

func (cm *Manager) RegisterResponder(responder view.View, initiatedBy interface{}) error

func (*Manager) RegisterResponderWithIdentity added in v0.4.1

func (cm *Manager) RegisterResponderWithIdentity(responder view.View, id view.Identity, initiatedBy interface{}) error

func (*Manager) ResolveIdentities added in v0.4.1

func (cm *Manager) ResolveIdentities(endpoints ...string) ([]view.Identity, error)

func (*Manager) Start added in v0.4.1

func (cm *Manager) Start(ctx context.Context)

type Metrics added in v0.4.1

type Metrics struct {
	Contexts metrics.Gauge
}

type ParentContext added in v0.7.0

type ParentContext interface {
	DisposableContext
	Cleanup()
	PutSession(caller view.View, party view.Identity, session view.Session) error
}

type Registry added in v0.4.1

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

func GetRegistry added in v0.4.1

func GetRegistry(sp services.Provider) *Registry

GetRegistry returns an instance of the view registry. It panics, if no instance is found.

func NewRegistry added in v0.4.1

func NewRegistry() *Registry

func (*Registry) ExistResponderForCaller added in v0.4.1

func (cm *Registry) ExistResponderForCaller(caller string) (view.View, view.Identity, error)

func (*Registry) GetIdentifier added in v0.4.1

func (cm *Registry) GetIdentifier(f view.View) string

func (*Registry) GetResponder added in v0.4.1

func (cm *Registry) GetResponder(initiatedBy interface{}) (view.View, error)

func (*Registry) GetView added in v0.4.1

func (cm *Registry) GetView(id string) (view.View, error)

func (*Registry) NewView added in v0.4.1

func (cm *Registry) NewView(id string, in []byte) (f view.View, err error)

func (*Registry) RegisterFactory added in v0.4.1

func (cm *Registry) RegisterFactory(id string, factory Factory) error

func (*Registry) RegisterResponder added in v0.4.1

func (cm *Registry) RegisterResponder(responder view.View, initiatedBy interface{}) error

func (*Registry) RegisterResponderFactory added in v0.4.1

func (cm *Registry) RegisterResponderFactory(factory Factory, initiatedBy interface{}) error

func (*Registry) RegisterResponderWithIdentity added in v0.4.1

func (cm *Registry) RegisterResponderWithIdentity(responder view.View, id view.Identity, initiatedBy interface{}) error

type ServiceProvider added in v0.4.1

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

func NewServiceProvider added in v0.4.1

func NewServiceProvider() *ServiceProvider

func (*ServiceProvider) GetService added in v0.4.1

func (sp *ServiceProvider) GetService(v interface{}) (interface{}, error)

func (*ServiceProvider) RegisterService added in v0.4.1

func (sp *ServiceProvider) RegisterService(service interface{}) error

func (*ServiceProvider) String added in v0.4.1

func (sp *ServiceProvider) String() string

type Session added in v0.4.1

type Session = view.Session

Session encapsulates a communication channel to an endpoint

type SessionFactory added in v0.4.1

type SessionFactory interface {
	NewSessionWithID(sessionID, contextID, endpoint string, pkid []byte, caller view.Identity, msg *view.Message) (view.Session, error)

	NewSession(caller string, contextID string, endpoint string, pkid []byte) (view.Session, error)

	DeleteSessions(ctx context.Context, sessionID string)
}

SessionFactory is used to create new communication sessions

type Sessions added in v0.4.1

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

func (*Sessions) Delete added in v0.4.1

func (s *Sessions) Delete(viewId string, party view.Identity)

func (*Sessions) Get added in v0.4.1

func (s *Sessions) Get(viewId string, party view.Identity) view.Session

func (*Sessions) GetFirstOpen added in v0.4.1

func (s *Sessions) GetFirstOpen(viewId string, parties iterators.Iterator[view.Identity]) (view.Session, view.Identity)

func (*Sessions) GetSessionIDs added in v0.4.1

func (s *Sessions) GetSessionIDs() []string

func (*Sessions) Lock added in v0.4.1

func (s *Sessions) Lock()

func (*Sessions) Put added in v0.4.1

func (s *Sessions) Put(viewId string, party view.Identity, session view.Session)

func (*Sessions) PutDefault added in v0.4.1

func (s *Sessions) PutDefault(party view.Identity, session view.Session)

func (*Sessions) Reset added in v0.4.1

func (s *Sessions) Reset()

func (*Sessions) Unlock added in v0.4.1

func (s *Sessions) Unlock()

type Stream added in v0.3.0

type Stream interface {
	Recv(m interface{}) error
	Send(m interface{}) error
}

func GetStream added in v0.3.0

func GetStream(sp services.Provider) Stream

func GetStreamIfExists added in v0.3.0

func GetStreamIfExists(sp services.Provider) (Stream, error)

type View added in v0.7.0

type View = view.View

View is an alias for View

type ViewContext added in v0.7.0

type ViewContext = view.Context

ViewContext is an alias for view.Context

type WrappedContext added in v0.7.0

type WrappedContext struct {
	ParentContext
	// contains filtered or unexported fields
}

WrappedContext wraps an existing view context to provider a different context.Context

func WrapContext added in v0.7.0

func WrapContext(parent ParentContext, ctx context.Context) *WrappedContext

WrapContext returns a new WrappedContext for the given arguments

func (*WrappedContext) Context added in v0.7.0

func (c *WrappedContext) Context() context.Context

Context returns the overrode go context

Directories

Path Synopsis
grpc
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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