client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: ISC Imports: 41 Imported by: 1

README

FR Client Library

Testing

E2E testing requires a running server configured with ln payments. It assumes the dcrlnd three-node tmux environment is running.

$ go run ./brserver -cfg client/e2e-legacy-ln-server.conf
$ go test -count=1 -run TestE2E -tags e2elegacylntest -v ./client/ | tee /tmp/out.txt

Architecture

The diagram below shows the major layers of the client. Depicted is Alice sending a message while Bob is receiving it.

                                                                                                                                                
                            Alice                      server                        Bob        
                                                                                                
                                                                                                
                        +----------+                                              +----------+  
                        |  Client  |                                              |  Client  |  
                        +----------+                                              +----------+  
                              |                                                         |       
                              |                                                         |       
                              |                                                         |       
                       +------------+                                            +------------+ 
                       | RemoteUser | . . . . . . . . . . . . . . . . . . . . .  | RemoteUser | 
                       +------------+                                            +------------+ 
                              |                                                         |       
                              |                                                         |       
                              |                                                         |       
                         +---------+             +-----------------+           +---------------+
                         |   rmq   | . . . . . . |  subscriptions  |. . . . . .   rdzvManager  |
                         +---------+             +-----------------+           +---------------+
                              |                           |                             |       
                              |                           |                             |       
                              |                           |                             |       
                     +-----------------+         +------------------+         +---------|-------+
          ---------->|  serverSession  | . . . . |  client session  | . . . . |  serverSession  |
         /           +-----------------+         +------------------+         +-----------------+
        /               /     |                           |                             |    
+-------------+        /      |                           |                             |    
| connKeeper  |<-------       |                           |                             |    
+-------------+           +-------+                   +-------+                     +-------+
                          |  net  |-------------------|  net  |-------------------- |  net  |
                          +-------+                   +-------+                     +-------+

Each layer has certain specific responsibilities and attempts to maintain certain invariants for the other layers:

  • net: Lower-level network connection (currently TLS)
  • connKeeper: Attempts to keep an open connection to the server. Whenever a new connection is made, a new instance of serverSession is created
  • serverSession: Maintains the tag stack invariant (max inflight, non-acked messages to the server), encrypts/decrypts the wire msgs w/ the per-session key
  • rmq: outbound RoutedMessages queue; pays for each outbound RM before sending it, encrypts each RM according to its type (clear text, kx, ratchet)
  • rdzvManager: Rendezvous Manager, is the inbound RM queue; ensures the client is subscribed to the appropriate RV points in the server as needed and decides which remoteUser to call for every pushed RM
  • RemoteUser: holds the ratchet state for each user the client has completed a kx flow with and progresses it as RMs are sent and received. Also implements per-user higher level calls (send/receive PMs, files, etc)

Each layer is tipically implemented as a runnable state machine, where its API is (usually) synchronous and concurrent-safe and actions are performed in its run() call.

The main public-facing structures of this package are Config and Client. Consumers (e.g. a GUI or CLI client app) setup a Config instance as needed, create a new client instance and run it. The client will maintain its operations until one of its subsystems fail (in which case Run() returns with an error) or the context is canceled.

Documentation

Overview

Package client implements a CR complient client.

The diagram below shows the major layers of the client. Depicted is Alice sending a message while Bob is receiving it.

                            Alice                      server                        Bob

                        +----------+                                              +----------+
                        |  Client  |                                              |  Client  |
                        +----------+                                              +----------+
                              |                                                         |
                              |                                                         |
                              |                                                         |
                       +------------+                                            +------------+
                       | RemoteUser | . . . . . . . . . . . . . . . . . . . . .  | RemoteUser |
                       +------------+                                            +------------+
                              |                                                         |
                              |                                                         |
                              |                                                         |
                         +---------+             +-----------------+           +---------------+
                         |   rmq   | . . . . . . |  subscriptions  |. . . . . .|  rdzvManager  |
                         +---------+             +-----------------+           +---------------+
                              |                           |                             |
                              |                           |                             |
                              |                           |                             |
                     +-----------------+         +------------------+         +-----------------+
          ---------->|  serverSession  | . . . . |  client session  | . . . . |  serverSession  |
         /           +-----------------+         +------------------+         +-----------------+
        /               /     |                           |                             |
+-------------+        /      |                           |                             |
| connKeeper  |<-------       |                           |                             |
+-------------+           +-------+                   +-------+                     +-------+
                          |  net  |-------------------|  net  |-------------------- |  net  |
                          +-------+                   +-------+                     +-------+

Each layer has certain specific responsibilities and attempts to maintain certain invariants for the other layers:

  • `net`: Lower-level network connection (currently TLS)

  • `connKeeper`: Attempts to keep an open connection to the server. Whenever a new connection is made, a new instance of `serverSession` is created

  • `serverSession`: Maintains the tag stack invariant (max inflight, non-acked messages to the server), encrypts/decrypts the wire msgs w/ the per-session key

  • `rmq`: outbound RoutedMessages queue; pays for each outbound RM before sending it, encrypts each RM according to its type (clear text, kx, ratchet)

  • `rdzvManager`: Rendezvous Manager, is the inbound RM queue; ensures the client is subscribed to the appropriate RV points in the server as needed and decides which `remoteUser` to call for every pushed RM

  • `RemoteUser`: holds the ratchet state for each user the client has completed a kx flow with and progresses it as RMs are sent and received. Also implements per-user higher level calls (send/receive PMs, files, etc)

Each layer is tipically implemented as a runnable state machine, where its API is (usually) synchronous and concurrent-safe and actions are performed in its `run()` call.

The main public-facing structures of this package are `Config` and `Client`. Consumers (e.g. a GUI or CLI client app) setup a `Config` instance as needed, create a new client instance and run it. The client will maintain its operations until one of its subsystems fail (in which case `Run()` returns with an error) or the context is canceled.

Index

Constants

View Source
const (
	TEMediateID      = "mediate identity"
	TERequestInvite  = "request invite"
	TEReceivedInvite = "received invite"
	TEMsgForward     = "message forward"
	TEResetRequest   = "reset request"
	TEResetReply     = "reset reply"
)
View Source
const (
	ErrUnableToQueryNode  = WalletUsableErrorKind("ErrUnableToQueryNode")
	ErrNoPeers            = WalletUsableErrorKind("ErrNoPeers")
	ErrLowOutboundBalance = WalletUsableErrorKind("ErrLowOutboundBalance")
	ErrTooOldBlockchain   = WalletUsableErrorKind("ErrTooOldBlockchain")
	ErrNoActiveChannels   = WalletUsableErrorKind("ErrNoActiveChannels")
	ErrNoRouteToServer    = WalletUsableErrorKind("ErrNoRouteToServer")
	ErrUnableToPingPeers  = WalletUsableErrorKind("ErrUnableToPingPeers")
)

Variables

This section is empty.

Functions

func CheckLNWalletUsable

func CheckLNWalletUsable(ctx context.Context, lc lnrpc.LightningClient, svrNode string) error

CheckLNWalletUsable checks whether the given ln wallet is synced and is usable for sending payments to the given server LN node.

func PaymentFeeLimit

func PaymentFeeLimit(amountMAtoms uint64) *lnrpc.FeeLimit

PaymentFeeLimit returns the fee limit to use when making a payment for BR nodes of the specified size.

Types

type AddressBookEntry

type AddressBookEntry struct {
	ID      UserID `json:"id"`
	Nick    string `json:"nick"`
	Name    string `json:"name"`
	Ignored bool   `json:"ignored"`
}

type Client

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

Client is the main state manager for a CR client connection. It attempts to maintain an active connection to a CR server and manages the internal state of a client, including remote users it's connected to.

func New

func New(cfg Config) (*Client, error)

New creates a new CR client with the given config.

func (*Client) AcceptGroupChatInvite

func (c *Client) AcceptGroupChatInvite(iid uint64) error

AcceptGroupChatInvite accepts the given invitation, previously received from some user.

func (*Client) AcceptInvite

func (c *Client) AcceptInvite(invite rpc.OOBPublicIdentityInvite) error

AcceptInvite blocks until the remote party reponds with us accepting the remote party's invitation. The invite should've been created by ReadInvite.

func (*Client) AddToGCBlockList

func (c *Client) AddToGCBlockList(gcid zkidentity.ShortID, uid UserID) error

AddToGCBlockList adds the user to the block list of the specified GC. This user will no longer be sent messages from the local client in the given GC and messages from this user will not generate GCMessage events.

func (*Client) AddressBook

func (c *Client) AddressBook() []*AddressBookEntry

func (*Client) AliasGC

func (c *Client) AliasGC(gcID zkidentity.ShortID, newAlias string) error

AliasGC replaces the local alias of a GC for a new one.

func (*Client) Block

func (c *Client) Block(uid UserID) error

Block blocks a uid.

func (*Client) ClearPayStats

func (c *Client) ClearPayStats(uid *UserID) error

ClearPayStats removes the payment stats associated with the given user. If nil is passed, then the payment stats for all users are cleared.

func (*Client) CommentPost

func (c *Client) CommentPost(postFrom clientintf.UserID, pid clientintf.PostID,
	comment string, parent *clientintf.ID) error

CommentPost sends a comment status update on the received post.

func (*Client) CreatePost

func (c *Client) CreatePost(post, descr string) (clientdb.PostSummary, error)

CreatePost creates a new post and shares it with all current subscribers.

func (*Client) FindSharedFileID

func (c *Client) FindSharedFileID(fname string) (clientdb.FileID, error)

FindSharedFileID finds the file ID of a shared file with the given filename.

func (*Client) GCIDByName

func (c *Client) GCIDByName(name string) (zkidentity.ShortID, error)

GCIDByName returns the GC ID of the local GC with the given name. The name can be either a local GC alias or a full hex GC ID.

func (*Client) GCKick

func (c *Client) GCKick(gcID zkidentity.ShortID, uid UserID, reason string) error

GCKick kicks the given user from the GC. This only works if we're the gc admin.

func (*Client) GCMessage

func (c *Client) GCMessage(gcID zkidentity.ShortID, msg string, mode rpc.MessageMode,
	progressChan chan SendProgress) error

GCMessage sends a message to the given GC. If progressChan is not nil, events are sent to it as the sending process progresses. Writes to progressChan are serial, so it's important that it not block indefinitely.

func (*Client) GetGC

GetGC returns information about the given gc the local user participates in.

func (*Client) GetGCAlias

func (c *Client) GetGCAlias(gcID zkidentity.ShortID) (string, error)

GetGCAlias returns the local alias for the specified GC.

func (*Client) GetGCBlockList

func (c *Client) GetGCBlockList(gcID zkidentity.ShortID) (clientdb.GCBlockList, error)

GetGCBlockList returns the blocklist of the given GC.

func (*Client) GetKXSearch

func (c *Client) GetKXSearch(targetID UserID) (clientdb.KXSearch, error)

GetKXSearch returns the KX search status for the given target.

func (*Client) GetUserContent

func (c *Client) GetUserContent(uid UserID, fid clientdb.FileID) error

GetUserContent starts the process to fetch the given file from the remote user.

func (*Client) GetUserPost

func (c *Client) GetUserPost(from UserID, pid clientintf.PostID, includeStatus bool) error

GetUserPost attempts to fetch the given post from the specified user. The post will be supplied in the PostReceived event of the client.

The includeStatus flag dictates whether to also request the associated status updates (comments, etc).

func (*Client) GoOnline

func (c *Client) GoOnline()

GoOnline requests the client to connect to the server (if not yet connected) and to remain connected as long as possible (including by attempting to re-connect if the connection closes).

func (*Client) HasDownloadedFile

func (c *Client) HasDownloadedFile(fid zkidentity.ShortID) (bool, error)

func (*Client) HasPostSubscribers

func (c *Client) HasPostSubscribers() (bool, error)

HasPostSubscribers returns true if the local client has subscribers to our posts.

func (*Client) HeartPost

func (c *Client) HeartPost(from clientintf.UserID, pid clientintf.PostID, heart bool) error

HeartPost sends a status update, either adding or removing the current user's heart on the given received post.

func (*Client) Ignore

func (c *Client) Ignore(uid UserID, ignore bool) error

Ignore changes the setting of the local ignore flag of the specified user.

func (*Client) InviteToGroupChat

func (c *Client) InviteToGroupChat(gcID zkidentity.ShortID, user UserID) error

InviteToGroupChat invites the given user to the given gc. The local user must be the admin of the group and the remote user must have been KX'd with.

func (*Client) IsIgnored

func (c *Client) IsIgnored(uid clientintf.UserID) (bool, error)

IsIgnored indicates whether the given client has the ignored flag set.

func (*Client) KXSearchPostAuthor

func (c *Client) KXSearchPostAuthor(postFrom UserID, post clientintf.PostID) error

KXSearchPostAuthor attempts to start a new kx search for the author of the specified post.

func (*Client) KillGroupChat

func (c *Client) KillGroupChat(gcID zkidentity.ShortID, reason string) error

KillGroupChat completely dissolves the group chat.

func (*Client) ListDownloads

func (c *Client) ListDownloads() ([]clientdb.FileDownload, error)

ListDownloads lists all outstanding downloads.

func (*Client) ListGCInvitesFor

func (c *Client) ListGCInvitesFor(gcName string) ([]*clientdb.GCInvite, error)

ListGCInvitesFor returns all GC invites received that were for the specified gc name.

func (*Client) ListGCs

func (c *Client) ListGCs() ([]clientdb.GCAddressBookEntry, error)

ListGCs lists all local GCs the user is participating in.

func (*Client) ListKXSearches

func (c *Client) ListKXSearches() ([]UserID, error)

ListKXSearches lists the IDs of all outstanding KX searches.

func (*Client) ListKXs

func (c *Client) ListKXs() ([]clientdb.KXData, error)

func (*Client) ListLocalSharedFiles

func (c *Client) ListLocalSharedFiles() ([]clientdb.SharedFileAndShares, error)

ListLocalSharedFiles lists all locally shared files.

func (*Client) ListMediateIDs

func (c *Client) ListMediateIDs() ([]clientdb.MediateIDRequest, error)

ListMediateIDs lists mediate id requests made by the local client.

func (*Client) ListPaymentStats

func (c *Client) ListPaymentStats() (map[UserID]clientdb.UserPayStats, error)

ListPaymentStats returns the general payment stats for all users.

func (*Client) ListPostStatusUpdates

func (c *Client) ListPostStatusUpdates(from UserID, pid clientintf.PostID) ([]rpc.PostMetadataStatus, error)

ListPostStatusUpdates lists the status updates of the specified post.

func (*Client) ListPostSubscribers

func (c *Client) ListPostSubscribers() ([]clientintf.UserID, error)

ListPostSubscribers lists the subscribers to the local client's posts.

func (*Client) ListPostSubscriptions

func (c *Client) ListPostSubscriptions() ([]clientdb.PostSubscription, error)

ListPostSubscriptions lists remote users whose posts we are subscribed to.

func (*Client) ListPosts

func (c *Client) ListPosts() ([]clientdb.PostSummary, error)

ListReceivedPosts lists all posts created or received by the local client.

func (*Client) ListUserContent

func (c *Client) ListUserContent(uid UserID, dirs []string, filter string) error

ListUserContent lists the content shared by the given remote user. Dirs must be one of the supported dirs (rpc.RMFTDGlobal or rpc.RMFTDShared).

func (*Client) ListUserPosts

func (c *Client) ListUserPosts(uid UserID) error

ListUserPosts lists the posts made by the specified user.

func (*Client) LocalNick

func (c *Client) LocalNick() string

LocalNick is the nick of this client.

func (*Client) NewGroupChat

func (c *Client) NewGroupChat(name string) (zkidentity.ShortID, error)

NewGroupChat creates a new gc with the local user as admin.

func (*Client) PM

func (c *Client) PM(uid UserID, msg string) error

PM sends a private message to the given user, identified by its public id. The user must have been already KX'd with for this to work.

func (*Client) PartFromGC

func (c *Client) PartFromGC(gcID zkidentity.ShortID, reason string) error

PartFromGC withdraws the local client from the given GC.

func (*Client) PublicID

func (c *Client) PublicID() UserID

PublicID is the public local identity of this client.

func (*Client) RMQLen

func (c *Client) RMQLen() int

RMQLen is the number of outstanding messages in the outbound routed messages queue.

func (*Client) RVsUpToDate

func (c *Client) RVsUpToDate() bool

RVsUpToDate returns true if the subscriptions to remote RVs are up to date in the server.

func (*Client) ReadInvite

func (c *Client) ReadInvite(r io.Reader) (rpc.OOBPublicIdentityInvite, error)

ReadInvite decodes an invite from the given reader. Note the invite is not acted upon until AcceptInvite is called.

func (*Client) ReadPost

func (c *Client) ReadPost(uid clientintf.UserID, pid clientintf.PostID) (rpc.PostMetadata, error)

ReadReceivedPost returns the post data for the given user/post.

func (*Client) RelayPost

func (c *Client) RelayPost(postFrom clientintf.UserID, pid clientintf.PostID,
	toUser clientintf.UserID) error

RelayPost sends the given post to the specified user.

func (*Client) RelayPostToSubscribers

func (c *Client) RelayPostToSubscribers(postFrom clientintf.UserID, pid clientintf.PostID) error

RelayPostToSubscribers relays the specified post to all current post subscribers.

func (*Client) RemainOffline

func (c *Client) RemainOffline()

RemainOffline requests the client to remain offline.

func (*Client) RemoveFromGCBlockList

func (c *Client) RemoveFromGCBlockList(gcid zkidentity.ShortID, uid UserID) error

AddToGCBlockList removes the user from the block list of the specified GC.

func (*Client) RenameUser

func (c *Client) RenameUser(uid UserID, newNick string) error

RenameUser modifies the nick for the specified user.

func (*Client) RequestMediateIdentity

func (c *Client) RequestMediateIdentity(mediator, target UserID) error

RequestMediateIdentity attempts to start a kx process with target by asking mediator for an introduction.

func (*Client) RequestTransitiveReset

func (c *Client) RequestTransitiveReset(mediator, target UserID) error

func (*Client) ResetRatchet

func (c *Client) ResetRatchet(uid UserID) error

ResetRatchet requests a ratchet reset with the given user.

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run runs all client goroutines until the given context is canceled.

Must only be called once.

func (*Client) SendFile

func (c *Client) SendFile(uid UserID, filepath string) error

SendFile sends a file to the given user without requesting a payment for it.

func (*Client) ServerLNNode

func (c *Client) ServerLNNode() string

ServerLNNode returns the LN Node ID of the server we're connected to. This can be empty if we're not connected to any servers.

func (*Client) ShareFile

func (c *Client) ShareFile(fname string, uid *UserID,
	cost uint64, isRef bool, descr string,
) (clientdb.SharedFile, rpc.FileMetadata, error)

ShareFile shares the given filename with the given user (or to all users if none is specified).

Cost is in atoms.

func (*Client) SubscribeToPosts

func (c *Client) SubscribeToPosts(uid UserID) error

SubscribeToPosts attempts to subscribe to the posts of the given user.

It returns when the remote user replies or the client exits.

func (*Client) SuggestKX

func (c *Client) SuggestKX(invitee, target UserID) error

SuggestKX sends a message to invitee suggesting they KX with target (through the local client).

func (*Client) SummarizeUserPayStats

func (c *Client) SummarizeUserPayStats(uid UserID) ([]clientdb.PayStatsSummary, error)

SummarizeUserPayStats reads the payment stats file of the given user and returns a summary of what the payments were made and received in relation to the specified user.

func (*Client) TipUser

func (c *Client) TipUser(uid UserID, dcrAmount float64) error

TipUser sends a tip with the given dcr amount to the remote user.

func (*Client) UIDByNick

func (c *Client) UIDByNick(nick string) (UserID, error)

UIDByNick returns the user ID associated with the given nick.

func (*Client) UnshareFile

func (c *Client) UnshareFile(fid clientdb.FileID, uid *UserID) error

UnshareFile stops sharing the given file with the given user (or all users if unspecified).

func (*Client) UnsubscribeToPosts

func (c *Client) UnsubscribeToPosts(uid UserID) error

UnsubscribeToPosts unsubscribes the local user to the posts made by the given remote user.

It returns when the remote user replies or when the client exits.

func (*Client) UserByID

func (c *Client) UserByID(uid UserID) (*RemoteUser, error)

UserByID returns the remote user of the given ID.

func (*Client) UserByNick

func (c *Client) UserByNick(nick string) (*RemoteUser, error)

UserByNick returns the user identified by the given nick. Nick may be the actual user nick or a prefix of the user's ID (to disambiguate between users with the same nick).

func (*Client) UserExists

func (c *Client) UserExists(id UserID) bool

func (*Client) UserNick

func (c *Client) UserNick(uid UserID) (string, error)

UserNick returns the nick of the given user.

func (*Client) WriteNewInvite

func (c *Client) WriteNewInvite(w io.Writer) (rpc.OOBPublicIdentityInvite, error)

WriteNewInvite creates a new invite and writes it to the given writer.

type Config

type Config struct {
	// ReconnectDelay is how long to wait between attempts to reconnect to
	// the server.
	ReconnectDelay time.Duration

	// PayClient identifies which payment scheme the client is configured
	// to use.
	PayClient clientintf.PaymentClient

	// LocalIDIniter is called when the client needs a new local identity.
	LocalIDIniter func(ctx context.Context) (*zkidentity.FullIdentity, error)

	// Dialer connects to the server. TLS is required.
	Dialer clientintf.Dialer

	// CompressLevel is the zlib compression level to use to compress
	// routed messages. Zero means no compression.
	CompressLevel int

	// DB instace for client operations. The client will call the Run()
	// method of the DB instance itself.
	DB *clientdb.DB

	// CertConfirmer must return nil if the given TLS certificate (outer
	// cert) and public key (inner cert) are accepted or an error if it any
	// of them are rejected.
	CertConfirmer clientintf.CertConfirmer

	// Logger is a function that generates loggers for each of the client's
	// subsystems.
	Logger func(subsys string) slog.Logger

	// LogPings indicates whether to log messages related to pings between
	// the client and the server.
	LogPings bool

	// CheckServerSession is called after a server session is established
	// but before ServerSessionChanged is called and allows clients to check
	// whether the connection is acceptable or if other preconditions are
	// met before continuing to connect with the specified server.
	//
	// If this callback is non nil and returns an error, the connection
	// is dropped and another attempt at the connection is made.
	//
	// If the passed connCtx is canceled, this means the connection was
	// closed (either by the remote end or by the local end).
	CheckServerSession func(connCtx context.Context, lnNode string) error

	// ServerSessionChanged is called indicating that the connection to the
	// server changed to the specified state (either connected or not).
	//
	// The push and subscription rates are specified in milliatoms/byte.
	ServerSessionChanged func(connected bool, pushRate, subRate, expirationDays uint64)

	// PMHandler is called when a message from the specified user is
	// received.
	PMHandler func(user *RemoteUser, msg rpc.RMPrivateMessage, ts time.Time)

	// GCInviteHandler is called when the user received an invitation to
	// join a group chat from a remote user.
	GCInviteHandler func(user *RemoteUser, iid uint64, invite rpc.RMGroupInvite)

	// GCJoinHandler is called when a user has joined a GC we administer.
	GCJoinHandler func(user *RemoteUser, gc clientdb.GCAddressBookEntry)

	// GCListUpdated is called when we receive remote updates for a GC from
	// the GC admin.
	GCListUpdated func(gc clientdb.GCAddressBookEntry)

	// GCUserParted is called when a user was removed from a GC. Kicked
	// signals whether it was the user that left or whether the admin
	// kicked the user.
	GCUserParted func(gcid GCID, uid UserID, reason string, kicked bool)

	// GCKilled is called when the given GC is dissolved by its admin.
	GCKilled func(gcid GCID, reason string)

	// GCMsgHandler is called when a group chat message is received from
	// the specified user.
	GCMsgHandler func(user *RemoteUser, msg rpc.RMGroupMessage, ts time.Time)

	// GCWithUnkxdMember is called when an attempt to send a GC message
	// failed due to a GC member being unkxd with the local client.
	GCWithUnkxdMember func(gcid GCID, uid UserID)

	// KXCompleted is called when a KX processed completed with a remote
	// user.
	KXCompleted func(user *RemoteUser)

	// KXSuggestion is called when a remote user sends a suggestion to KX
	// with a new user.
	KXSuggestion func(user *RemoteUser, pii zkidentity.PublicIdentity)

	// PostsListReceived is called when we receive the list of posts from
	// a remote user.
	PostsListReceived func(user *RemoteUser, postList rpc.RMListPostsReply)

	// PostReceived is called when a new post is received from a remote
	// user.
	PostReceived func(user *RemoteUser, summary clientdb.PostSummary, post rpc.PostMetadata)

	// PostStatusReceived is called when we receive a status update for a
	// given post.
	//
	// Note: user may be nil if the status update is for a post made by the
	// local user. This can happen both for received status updates and
	// status updates made by the local client.
	PostStatusReceived func(user *RemoteUser, pid clientintf.PostID,
		statusFrom UserID, status rpc.PostMetadataStatus)

	TipReceived func(user *RemoteUser, amount float64)

	// SubscriptionChanged is called whenever the given user changes its
	// subscription status with the local client (either subscribed or
	// unsubscribed).
	SubscriptionChanged func(user *RemoteUser, subscribed bool)

	// ContentListReceived is called when the list of content of the user is
	// received.
	ContentListReceived func(user *RemoteUser, files []clientdb.RemoteFile, listErr error)

	// FileDownloadConfirmer is called to confirm the start of a file
	// download with the user.
	FileDownloadConfirmer func(user *RemoteUser, fm rpc.FileMetadata) bool

	// FileDownloadCompleted is called whenever a download of a file has
	// completed.
	FileDownloadCompleted func(user *RemoteUser, fm rpc.FileMetadata, diskPath string)

	// FileDownloadProgress is called reporting the progress of a file
	// download process.
	FileDownloadProgress func(user *RemoteUser, fm rpc.FileMetadata, nbMissingChunks int)

	// TransitiveEvent is called whenever a request is made by source for
	// the local client to forward a message to dst.
	TransitiveEvent func(src, dst UserID, event TransitiveEvent)

	// UserBlocked is called when we blocked the specified user due to their
	// request. Note that the passed user cannot be used for messaging
	// anymore.
	UserBlocked func(user *RemoteUser)

	// KXSearchCompleted is called when KX is completed with a user that
	// was the target of a KX search.
	KXSearchCompleted func(user *RemoteUser)

	// GCMInterMsgDelay is the time between GC messages received for
	// delaying delivering message events. This helps during reconnection
	// when multiple GC messages are received out of order.
	GCMInterMsgDelay time.Duration

	// GCMMaxDelay is the max delay after which GC messages are delivered
	// without any caching.
	GCMMaxDelay time.Duration
}

Config holds the necessary config for instantiating a CR client.

type DcrlnPaymentClient

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

DcrlnPaymentClient implements the PaymentClient interface for servers that offer the "dcrln" payment scheme.

func NewDcrlndPaymentClient

func NewDcrlndPaymentClient(ctx context.Context, cfg DcrlnPaymentClientCfg) (*DcrlnPaymentClient, error)

NewDcrlndPaymentClient creates a new payment client that can send payments through dcrlnd.

func (*DcrlnPaymentClient) DecodeInvoice

func (pc *DcrlnPaymentClient) DecodeInvoice(ctx context.Context, invoice string) (clientintf.DecodedInvoice, error)

func (*DcrlnPaymentClient) GetInvoice

func (pc *DcrlnPaymentClient) GetInvoice(ctx context.Context, mat int64, cb func(int64)) (string, error)

func (*DcrlnPaymentClient) IsInvoicePaid

func (pc *DcrlnPaymentClient) IsInvoicePaid(ctx context.Context, minMatAmt int64, invoice string) error

func (*DcrlnPaymentClient) LNRPC

func (*DcrlnPaymentClient) PayInvoice

func (pc *DcrlnPaymentClient) PayInvoice(ctx context.Context, invoice string) (int64, error)

func (*DcrlnPaymentClient) PayInvoiceAmount

func (pc *DcrlnPaymentClient) PayInvoiceAmount(ctx context.Context, invoice string, amount int64) (int64, error)

func (*DcrlnPaymentClient) PayScheme

func (pc *DcrlnPaymentClient) PayScheme() string

func (*DcrlnPaymentClient) UnlockWallet

func (pc *DcrlnPaymentClient) UnlockWallet(ctx context.Context, pass string) error

type DcrlnPaymentClientCfg

type DcrlnPaymentClientCfg struct {
	TLSCertPath  string
	MacaroonPath string
	Address      string
	Log          slog.Logger
}

type GCID

type GCID = zkidentity.ShortID

type RemoteUser

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

RemoteUser tracks the state of a fully formed ratchet (that is, after kx completes) and offers services that can be performed on this remote user.

func (*RemoteUser) AddressBookEntry

func (ru *RemoteUser) AddressBookEntry() AddressBookEntry

func (*RemoteUser) ID

func (ru *RemoteUser) ID() UserID

func (*RemoteUser) IsIgnored

func (ru *RemoteUser) IsIgnored() bool

func (*RemoteUser) Nick

func (ru *RemoteUser) Nick() string

func (*RemoteUser) PublicIdentity

func (ru *RemoteUser) PublicIdentity() zkidentity.PublicIdentity

func (*RemoteUser) SetIgnored

func (ru *RemoteUser) SetIgnored(ignored bool)

func (*RemoteUser) String

func (ru *RemoteUser) String() string

type SendProgress

type SendProgress struct {
	Sent  int
	Total int
	Err   error
}

SendProgress is sent to track progress of messages that are sent to multiple remote users (for example, GC messages that are sent to all members).

type TransitiveEvent

type TransitiveEvent string

type UserID

type UserID = clientintf.UserID

func SortedUserPayStatsIDs

func SortedUserPayStatsIDs(stats map[UserID]clientdb.UserPayStats) []UserID

SortedUserPayStatsIDs returns a sorted list of IDs from the passed stats map, ordered by largest total payments.

func UserIDFromStr

func UserIDFromStr(s string) UserID

RemoteIDFromStr converts the given string to a UserID. Returns an empty uid if the string is not a valid UserID.

type WalletUsableError

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

WalletUsableError is a complex error type that wraps both one the type of error and an underlying error (if it exists)

func (WalletUsableError) Error

func (err WalletUsableError) Error() string

func (WalletUsableError) Unwrap

func (err WalletUsableError) Unwrap() error

type WalletUsableErrorKind

type WalletUsableErrorKind string

WalletUsableErrorKind holds the types of errors that may happen when checking if an LN wallet is usable for payments to the server.

func (WalletUsableErrorKind) Error

func (err WalletUsableErrorKind) Error() string

Directories

Path Synopsis
Package clientintf holds client-global interfaces and helper functions.
Package clientintf holds client-global interfaces and helper functions.
internal

Jump to

Keyboard shortcuts

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