Documentation
¶
Index ¶
- type AckError
- type ConnKeeper
- type ConnKeeperCfg
- type ErrRVAlreadySubscribed
- type ErrRVAlreadyUnsubscribed
- type OutboundRM
- type RMQ
- type RVBlob
- type RVHandler
- type RVID
- type RVManager
- func (rmgr *RVManager) BindToSession(sess clientintf.ServerSessionIntf)
- func (rmgr *RVManager) HandlePushedRMs(prm *rpc.PushRoutedMessage) error
- func (rmgr *RVManager) IsUpToDate() bool
- func (rmgr *RVManager) Run(ctx context.Context) error
- func (rmgr *RVManager) Sub(rdzv RVID, handler RVHandler, subPaid SubPaidHandler) error
- func (rmgr *RVManager) Unsub(rdzv RVID) error
- type RVManagerDB
- type SubPaidHandler
- type UnwelcomeError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AckError ¶
AckError is an error generated when the server sends an Acknowledge message with an embedded Error message.
Is is also used in client code to signal a given pushed message was processed with an error.
func (AckError) ToAck ¶
func (err AckError) ToAck(ack *rpc.Acknowledge)
ToAck copies this error to the given Acknowledge msg.
type ConnKeeper ¶
type ConnKeeper struct {
// contains filtered or unexported fields
}
ConnKeeper maintains an open connection to a server. Whenever the connection to the server closes, it attempts to re-connect. Only a single connection is kept online at any one time.
Fully kx'd server sessions are emitted via NextSession().
func NewConnKeeper ¶
func NewConnKeeper(cfg ConnKeeperCfg) *ConnKeeper
func (*ConnKeeper) GoOnline ¶
func (ck *ConnKeeper) GoOnline()
GoOnline instructs the ConnKeeper to keep attempting connections to the server.
func (*ConnKeeper) NextSession ¶
func (ck *ConnKeeper) NextSession(ctx context.Context) clientintf.ServerSessionIntf
NextSession blocks until a session is available or the context is canceled. Note this returns nil in two situations: if the last session failed and is now offline or if the context is canceled.
func (*ConnKeeper) RemainOffline ¶
func (ck *ConnKeeper) RemainOffline()
RemainOffline asks the ConnKeeper to disconnect from the current session (if there is one) and to remain offline until GoOnline() is called.
func (*ConnKeeper) Run ¶
func (ck *ConnKeeper) Run(ctx context.Context) error
Run runs the services of this conn keeper.
func (*ConnKeeper) SetKnownServerID ¶
func (ck *ConnKeeper) SetKnownServerID(tlsCert []byte, spid zkidentity.PublicIdentity)
SetKnownServerID sets the known server certs as the passed ones. Whenever we connect to the server and the certs are different then these, we request confirmation from the user.
type ConnKeeperCfg ¶
type ConnKeeperCfg struct {
PC clientintf.PaymentClient
Dialer clientintf.Dialer
CertConf clientintf.CertConfirmer
PingInterval time.Duration
ReconnectDelay time.Duration
Log slog.Logger
LogPings bool
// Passed to created serverSession instances (see there for reference).
PushedRoutedMsgsHandler func(msg *rpc.PushRoutedMessage) error
}
type ErrRVAlreadySubscribed ¶
type ErrRVAlreadySubscribed struct {
// contains filtered or unexported fields
}
func (ErrRVAlreadySubscribed) Error ¶
func (err ErrRVAlreadySubscribed) Error() string
func (ErrRVAlreadySubscribed) Is ¶
func (err ErrRVAlreadySubscribed) Is(target error) bool
type ErrRVAlreadyUnsubscribed ¶
type ErrRVAlreadyUnsubscribed struct {
// contains filtered or unexported fields
}
func (ErrRVAlreadyUnsubscribed) Error ¶
func (err ErrRVAlreadyUnsubscribed) Error() string
func (ErrRVAlreadyUnsubscribed) Is ¶
func (err ErrRVAlreadyUnsubscribed) Is(target error) bool
type OutboundRM ¶
type OutboundRM interface {
EncryptedLen() uint32
EncryptedMsg() (RVID, []byte, error)
Priority() uint
PaidForRM(int64, int64)
}
OutboundRM is the interface for sending routed messages via the rmq.
type RMQ ¶
type RMQ struct {
// contains filtered or unexported fields
}
RMQ is a queue for sending RoutedMessages (RMs) to the server. The rmq supports a flickering server connection: any unsent RMs are queued (FIFO style) until a new server session is bound via `bindToSession`.
Sending an RM only fails when the rmq is shutting down or the rm failed to encrypt itself.
func NewRMQ ¶
func NewRMQ(log slog.Logger, payClient clientintf.PaymentClient, localID *zkidentity.FullIdentity) *RMQ
func (*RMQ) BindToSession ¶
func (q *RMQ) BindToSession(sess clientintf.ServerSessionIntf)
BindToSession binds the rmq to the specified server session. Queued and new messages will be sent via this server until it is removed or the rmq stops.
func (*RMQ) QueueRM ¶
func (q *RMQ) QueueRM(orm OutboundRM, replyChan chan error) error
QueueRM enqueues the given RM to be sent to the server as soon as possible. Returns when the rm has been queued to be sent.
replyChan is written to when the RM has been received by server (which is determined when the RMQ receives the corresponding server ack) or if the rmq is stopping.
func (*RMQ) SendRM ¶
func (q *RMQ) SendRM(orm OutboundRM) error
SendRM sends the given routed message to the server whenever possible. It returns when the RM has been successfully written and acknowledged as received by the server.
type RVManager ¶
type RVManager struct {
// contains filtered or unexported fields
}
RVManager keeps track of the various rendezvous points that should be registered on a remote server and what to do when RoutedMessages are received on the registered points.
Values should not be reused once their run() method returns.
func NewRVManager ¶
func (*RVManager) BindToSession ¶
func (rmgr *RVManager) BindToSession(sess clientintf.ServerSessionIntf)
BindToSession binds the rendezvous manager to the specified server session.
Note: the rendezvous manager assumes the given session has been setup such that its `pushedRoutedMsgsHandler` calls the manager's `handlePushedRMs`.
func (*RVManager) HandlePushedRMs ¶
func (rmgr *RVManager) HandlePushedRMs(prm *rpc.PushRoutedMessage) error
HandlePushedRMs is called via a bound session's `pushedRoutedMsgsHandler` whenever routed messages are pushed from server to client.
func (*RVManager) IsUpToDate ¶
IsUpToDate returns true if the the manager has sent all updates to the remote server and the server has ack'd them.
func (*RVManager) Run ¶
Run runs the rendezvous manager services. A given RVManager instance should not be reused once its run method returns.
func (*RVManager) Sub ¶
func (rmgr *RVManager) Sub(rdzv RVID, handler RVHandler, subPaid SubPaidHandler) error
Sub informs the manager to subscribe to the given rendezvous point and to call handler once a message is received in the given point.
Note that handler might never be called if the manager is stopped and it might be called multiple times if the rendezvous is registered and pushed multiple times.
type RVManagerDB ¶
type RVManagerDB interface {
// UnpaidRVs filters the list of RVs, returning the ones that haven't
// been paid yet.
UnpaidRVs(rvs []RVID, expirationDays int) ([]RVID, error)
// SavePaidRVs saves the specified list of RVs as paid.
SavePaidRVs(rvs []RVID) error
// MarkRVUnpaid marks the specified RV as unpaid in the DB.
MarkRVUnpaid(rv RVID) error
}
RVManagerDB abstracts the necessary functions that the RV manager needs from the DB.
type SubPaidHandler ¶
type SubPaidHandler func(amount, fees int64)
SubPaidHandler is a callback type for tracking payment for subscribing to an RV.
type UnwelcomeError ¶
type UnwelcomeError struct {
Reason string
}
UnwelcomeError is an error generated when the server responds with an Unwelcome message during the welcome stage of connection setup.
func (UnwelcomeError) Error ¶
func (err UnwelcomeError) Error() string
func (UnwelcomeError) Is ¶
func (err UnwelcomeError) Is(target error) bool