signaling_rpc_client

package
v0.30.6 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigID = ControllerID

ConfigID is the string used to identify this config object.

View Source
const ControllerID = "bifrost/signaling/rpc/client"

ControllerID is the ID of the controller.

Variables

View Source
var Version = semver.MustParse("0.0.1")

Version is the version of the controller implementation.

Functions

This section is empty.

Types

type Client

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

Client implements a signaling service client. Tracks a set of ongoing Session RPCs. Manages backpressure on senders across the signaling channel. Manages validating and signing messages with the peer private key.

func NewClient

func NewClient(
	le *logrus.Entry,
	c signaling_rpc.SRPCSignalingClient,
	privKey crypto.PrivKey,
	backoffConf *backoff.Backoff,
) (*Client, error)

NewClient constructs a new client.

func NewClientWithBus

func NewClientWithBus(
	le *logrus.Entry,
	b bus.Bus,
	privKey crypto.PrivKey,
	clientConf *stream_srpc_client.Config,
	protocolID protocol.ID,
	serviceID string,
) (*Client, error)

NewClientWithBus constructs a new client that contacts the server via a Bifrost stream.

If protocolID is empty, uses the default signaling protocol id. If serviceID is empty, uses the default signaling service id.

func (*Client) AddPeerRef

func (c *Client) AddPeerRef(remotePeerID string) *ClientPeerRef

AddPeerRef adds a reference to a remote peer. Initiates a session with the remote peer that can send/recv messages. Be sure to release the ref when done with it.

func (*Client) ClearContext

func (c *Client) ClearContext()

ClearContext clears the context for the client.

func (*Client) SetContext

func (c *Client) SetContext(ctx context.Context)

SetContext sets the context for the client. Until this is called, the client will do nothing.

func (*Client) SetListenHandler

func (c *Client) SetListenHandler(listenHandler ClientListenHandler)

SetListenHandler sets the handler to call when the Listen RPC returns a peer to contact. If nil, disables the Listen RPC.

listenHandler: if set, calls Listen and updates the handler when the list of remote peers that want a session with the local peer changes.

listenHandler is called with reset=true when the list is cleared.

SetContext must also be called to start the Listen RPC routine.

type ClientListenHandler

type ClientListenHandler func(ctx context.Context, reset, added bool, pid string)

ClientListenHandler is a function to handle when the incoming sessions list changes.

pid is the peer id in string format.

type ClientPeerRef

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

ClientPeerRef is a reference to a client peer.

func (*ClientPeerRef) GetLocalPeerID

func (r *ClientPeerRef) GetLocalPeerID() peer.ID

GetLocalPeerID returns the local peer ID.

func (*ClientPeerRef) GetRemotePeerID

func (r *ClientPeerRef) GetRemotePeerID() peer.ID

GetRemotePeerID returns the remote peer ID.

func (*ClientPeerRef) Recv

func (r *ClientPeerRef) Recv(ctx context.Context) (*peer.SignedMsg, error)

Recv waits for and acks an incoming message from a remote peer.

func (*ClientPeerRef) Release

func (r *ClientPeerRef) Release()

Release releases the peer reference.

func (*ClientPeerRef) Send

func (r *ClientPeerRef) Send(ctx context.Context, msg []byte) (_ *peer.SignedMsg, outErr error)

Send attempts to sign and send a message to the remote peer.

Encodes & signs the data with the peer private key Waits for the remote buffer to be empty Sends the message Waits for the message to be acked

If context is canceled the message will also be canceled.

type Config

type Config struct {

	// SignalingId is the signaling channel ID.
	// Filters which SignalPeer directives will be handled.
	SignalingId string `protobuf:"bytes,1,opt,name=signaling_id,json=signalingId,proto3" json:"signalingId,omitempty"`
	// PeerId is the local peer id to use for the client.
	// Can be empty to use any local peer.
	PeerId string `protobuf:"bytes,2,opt,name=peer_id,json=peerId,proto3" json:"peerId,omitempty"`
	// Client contains srpc.client configuration for the signaling RPC client.
	// The local peer ID is overridden with the peer ID of the looked-up peer.
	Client *client.Config `protobuf:"bytes,3,opt,name=client,proto3" json:"client,omitempty"`
	// ProtocolId overrides the default protocol id for the signaling client.
	// Default: bifrost/signaling
	ProtocolId string `protobuf:"bytes,4,opt,name=protocol_id,json=protocolId,proto3" json:"protocolId,omitempty"`
	// ServiceId overrides the default service id for the signaling client.
	// Default: signaling.rpc.Signaling
	ServiceId string `protobuf:"bytes,5,opt,name=service_id,json=serviceId,proto3" json:"serviceId,omitempty"`
	// Backoff is the backoff config for connecting to the service.
	// If unset, defaults to reasonable defaults.
	Backoff *backoff.Backoff `protobuf:"bytes,6,opt,name=backoff,proto3" json:"backoff,omitempty"`
	// DisableListen disables listening for incoming sessions.
	// If set, we will only call out, not accept incoming sessions.
	// If false, client will emit HandleSignalPeer directives for incoming sessions.
	DisableListen bool `protobuf:"varint,7,opt,name=disable_listen,json=disableListen,proto3" json:"disableListen,omitempty"`
	// contains filtered or unexported fields
}

Config configures a client for the Signaling SRPC service.

func (*Config) CloneMessageVT

func (m *Config) CloneMessageVT() protobuf_go_lite.CloneMessage

func (*Config) CloneVT

func (m *Config) CloneVT() *Config

func (*Config) EqualMessageVT

func (this *Config) EqualMessageVT(thatMsg any) bool

func (*Config) EqualVT

func (this *Config) EqualVT(that *Config) bool

func (*Config) EqualsConfig

func (c *Config) EqualsConfig(other config.Config) bool

EqualsConfig checks if the other config is equal.

func (*Config) GetBackoff

func (x *Config) GetBackoff() *backoff.Backoff

func (*Config) GetClient

func (x *Config) GetClient() *client.Config

func (*Config) GetConfigID

func (c *Config) GetConfigID() string

GetConfigID returns the unique string for this configuration type. This string is stored with the encoded config.

func (*Config) GetDebugVals

func (c *Config) GetDebugVals() config.DebugValues

GetDebugVals returns the directive arguments as key/value pairs. This should be something like param1="test", param2="test". This is not necessarily unique, and is primarily intended for display.

func (*Config) GetDisableListen

func (x *Config) GetDisableListen() bool

func (*Config) GetPeerId

func (x *Config) GetPeerId() string

func (*Config) GetProtocolId

func (x *Config) GetProtocolId() string

func (*Config) GetServiceId

func (x *Config) GetServiceId() string

func (*Config) GetSignalingId

func (x *Config) GetSignalingId() string

func (*Config) MarshalJSON added in v0.29.0

func (x *Config) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Config to JSON.

func (*Config) MarshalProtoJSON added in v0.29.0

func (x *Config) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the Config message to JSON.

func (*Config) MarshalProtoText added in v0.29.2

func (x *Config) MarshalProtoText() string

func (*Config) MarshalToSizedBufferVT

func (m *Config) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*Config) MarshalToVT

func (m *Config) MarshalToVT(dAtA []byte) (int, error)

func (*Config) MarshalVT

func (m *Config) MarshalVT() (dAtA []byte, err error)

func (*Config) ParsePeerID

func (c *Config) ParsePeerID() (peer.ID, error)

ParsePeerID parses the session peer ID.

func (*Config) ParseProtocolID

func (c *Config) ParseProtocolID() (protocol.ID, error)

ParseProtocolID parses the signaling protocol id if it is not empty.

func (*Config) ProtoMessage

func (*Config) ProtoMessage()

func (*Config) Reset

func (x *Config) Reset()

func (*Config) SizeVT

func (m *Config) SizeVT() (n int)

func (*Config) String

func (x *Config) String() string

func (*Config) UnmarshalJSON added in v0.29.0

func (x *Config) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the Config from JSON.

func (*Config) UnmarshalProtoJSON added in v0.29.0

func (x *Config) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the Config message from JSON.

func (*Config) UnmarshalVT

func (m *Config) UnmarshalVT(dAtA []byte) error

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration. This is a cursory validation to see if the values "look correct."

type Controller

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

Controller is the signaling client controller.

func NewController

func NewController(le *logrus.Entry, b bus.Bus, conf *Config) (*Controller, error)

NewController constructs a new signaling client controller.

func (*Controller) Close

func (c *Controller) Close() error

Close releases any resources used by the controller. Error indicates any issue encountered releasing.

func (*Controller) Execute

func (c *Controller) Execute(ctx context.Context) error

Execute executes the controller goroutine. Returning nil ends execution. Returning an error triggers a retry with backoff.

func (*Controller) GetControllerInfo

func (c *Controller) GetControllerInfo() *controller.Info

GetControllerInfo returns information about the controller.

func (*Controller) HandleDirective

func (c *Controller) HandleDirective(ctx context.Context, di directive.Instance) ([]directive.Resolver, error)

HandleDirective asks if the handler can resolve the directive. If it can, it returns resolver(s). If not, returns nil. It is safe to add a reference to the directive during this call. The passed context is canceled when the directive instance expires. NOTE: the passed context is not canceled when the handler is removed.

type Factory

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

Factory constructs a Signaling RPC Client.

func NewFactory

func NewFactory(bus bus.Bus) *Factory

NewFactory builds the factory.

func (*Factory) Construct

func (t *Factory) Construct(
	ctx context.Context,
	conf config.Config,
	opts controller.ConstructOpts,
) (controller.Controller, error)

Construct constructs the associated controller given configuration.

func (*Factory) ConstructConfig

func (t *Factory) ConstructConfig() config.Config

ConstructConfig constructs an instance of the controller configuration.

func (*Factory) GetConfigID

func (t *Factory) GetConfigID() string

GetConfigID returns the configuration ID for the controller.

func (*Factory) GetControllerID

func (t *Factory) GetControllerID() string

GetControllerID returns the unique ID for the controller.

func (*Factory) GetVersion

func (t *Factory) GetVersion() semver.Version

GetVersion returns the version of this controller.

type Session

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

Session implements signaling.Session.

func NewSessionWithRef

func NewSessionWithRef(ref *ClientPeerRef) *Session

NewSessionWithRef wraps a ClientPeerRef into a signaling.Session.

func (*Session) GetLocalPeerID

func (s *Session) GetLocalPeerID() peer.ID

GetLocalPeerID returns the local peer ID.

func (*Session) GetRemotePeerID

func (s *Session) GetRemotePeerID() peer.ID

GetRemotePeerID returns the remote peer ID.

func (*Session) Recv

func (s *Session) Recv(ctx context.Context) ([]byte, error)

Recv waits for and acknowledges an incoming message from the remote peer.

func (*Session) Send

func (s *Session) Send(ctx context.Context, msg []byte) error

Send transmits a message to the remote peer. Blocks until the context is canceled OR the message is acked.

Jump to

Keyboard shortcuts

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