Documentation
¶
Overview ¶
Package clientintf holds client-global interfaces and helper functions.
This works as the root for client types.
Index ¶
- Constants
- Variables
- func ChunkIndexMatches(fm *rpc.FileMetadata, index int, hash []byte) bool
- func EstimatePMCost(msg string, policy *ServerPolicy) (uint64, error)
- func EstimatePostSize(content, descr string) (uint64, error)
- func EstimateUploadCost(size int64, policy *ServerPolicy) (uint64, error)
- func FileChunkMAtoms(chunkIdx int, fm *rpc.FileMetadata) uint64
- func NetDialer(addr string, log slog.Logger) func(context.Context) (Conn, *tls.ConnectionState, error)
- func PostTitle(pm *rpc.PostMetadata) string
- func WithDialer(addr string, log slog.Logger, dialFunc DialFunc) func(context.Context) (Conn, *tls.ConnectionState, error)
- func WithSeeder(addr string, log slog.Logger, dialFunc DialFunc) func(context.Context) (Conn, *tls.ConnectionState, error)
- type CertConfirmer
- type Conn
- type DecodedInvoice
- type DialFunc
- type Dialer
- type FileID
- type FreePaymentClient
- func (pc FreePaymentClient) DecodeInvoice(_ context.Context, invoice string) (DecodedInvoice, error)
- func (pc FreePaymentClient) GetInvoice(ctx context.Context, mat int64, cb func(int64)) (string, error)
- func (pc FreePaymentClient) IsInvoicePaid(context.Context, int64, string) error
- func (pc FreePaymentClient) IsPaymentCompleted(context.Context, string) (int64, error)
- func (pc FreePaymentClient) PayInvoice(context.Context, string) (int64, error)
- func (pc FreePaymentClient) PayInvoiceAmount(context.Context, string, int64) (int64, error)
- func (pc FreePaymentClient) PayScheme() string
- func (pc FreePaymentClient) TrackInvoice(ctx context.Context, inv string, minMAtoms int64) (int64, error)
- type ID
- type OnboardStage
- type OnboardState
- type PagesSessionID
- type PaidInviteKey
- func (pik *PaidInviteKey) Decode(s string) error
- func (pik PaidInviteKey) Decrypt(box []byte) ([]byte, error)
- func (pik PaidInviteKey) Encode() (string, error)
- func (pik PaidInviteKey) Encrypt(message []byte) ([]byte, error)
- func (pik PaidInviteKey) MarshalJSON() ([]byte, error)
- func (pik PaidInviteKey) RVPoint() ratchet.RVPoint
- func (pik PaidInviteKey) String() string
- func (pik *PaidInviteKey) UnmarshalJSON(b []byte) error
- type PaymentClient
- type PostID
- type RawRVID
- type ReceivedGCMsg
- type ServerPolicy
- type ServerSessionIntf
- type UserID
Constants ¶
const LockFileName = "app.lock"
Variables ¶
var ( ErrSubsysExiting = errors.New("subsys exiting") ErrInvoiceInsufficientlyPaid = errors.New("invoice insufficiently paid") ErrInvoiceExpired = errors.New("invoice expired") ErrOnboardNoFunds = errors.New("onboarding invite does not have any funds") ErrRetriablePayment = errors.New("retriable payment error") )
Functions ¶
func ChunkIndexMatches ¶
func ChunkIndexMatches(fm *rpc.FileMetadata, index int, hash []byte) bool
ChunkIndexMatches returns true if the hash of the manifest file at the specified index matches the given hash.
func EstimatePMCost ¶ added in v0.2.3
func EstimatePMCost(msg string, policy *ServerPolicy) (uint64, error)
Returns the estimate cost (in milliatoms) to send the given PM message to a remote user. The feeRate must be specified in milliatoms/byte.
func EstimatePostSize ¶
EstimatePostSize estimates the final size of a post share message, given the specified contents of the post.
func EstimateUploadCost ¶
func EstimateUploadCost(size int64, policy *ServerPolicy) (uint64, error)
Returns the estimate cost (in milliatoms) to upload a file of the given size to a remote user. The feeRate must be specified in milliatoms/byte.
func FileChunkMAtoms ¶
func FileChunkMAtoms(chunkIdx int, fm *rpc.FileMetadata) uint64
FileChunkMAtoms returns the cost to download the specified chunk from the file.
func NetDialer ¶
func NetDialer(addr string, log slog.Logger) func(context.Context) (Conn, *tls.ConnectionState, error)
NetDialer returns a client dialer function that always connects to a specific server address.
func PostTitle ¶
func PostTitle(pm *rpc.PostMetadata) string
PostTitle returns a suggested title for a given post. It fetches from the "title" attribute (if it exists) or from the first non-empty line of the main post content.
Types ¶
type CertConfirmer ¶
type CertConfirmer func(context.Context, *tls.ConnectionState, *zkidentity.PublicIdentity) error
CertConfirmer is a functiion that can be called to confirm whether a given server is safe.
type DecodedInvoice ¶
DecodedInvoice represents an invoice that was successfully decoded by the PaymentClient
func (*DecodedInvoice) IsExpired ¶
func (inv *DecodedInvoice) IsExpired(affordance time.Duration) bool
IsExpired returns whether this invoice has expired taking into account the specified affordance. In other words, it returns true if the expiration time of the invoice is before time.Now().Add(affordance).
type FreePaymentClient ¶
type FreePaymentClient struct{}
FreePaymentClient implements the PaymentClient interface for servers that offer the "free" payment scheme: namely, invoices are requested but there is nothing to pay for.
func (FreePaymentClient) DecodeInvoice ¶
func (pc FreePaymentClient) DecodeInvoice(_ context.Context, invoice string) (DecodedInvoice, error)
func (FreePaymentClient) GetInvoice ¶
func (FreePaymentClient) IsInvoicePaid ¶
func (FreePaymentClient) IsPaymentCompleted ¶ added in v0.1.4
func (FreePaymentClient) PayInvoice ¶
func (FreePaymentClient) PayInvoiceAmount ¶
func (FreePaymentClient) PayScheme ¶
func (pc FreePaymentClient) PayScheme() string
func (FreePaymentClient) TrackInvoice ¶ added in v0.1.8
type ID ¶
type ID = zkidentity.ShortID
ID is a 32-byte global ID. This is used as an alias for all 32-byte arrays that are interpreted as unique IDs.
type OnboardStage ¶ added in v0.1.7
type OnboardStage string
OnboardStage tracks stages of the client onboarding process.
const ( StageFetchingInvite OnboardStage = "fetching_invite" StageInviteUnpaid OnboardStage = "invite_unpaid" StageInviteFetchTimeout OnboardStage = "invite_fetch_timeout" StageInviteNoFunds OnboardStage = "invite_no_funds" StageRedeemingFunds OnboardStage = "redeeming_funds" StageWaitingFundsConfirm OnboardStage = "waiting_funds_confirm" StageOpeningOutbound OnboardStage = "opening_outbound" StageWaitingOutMined OnboardStage = "waiting_out_mined" StageWaitingOutConfirm OnboardStage = "waiting_out_confirm" StageOpeningInbound OnboardStage = "opening_inbound" StageInitialKX OnboardStage = "initial_kx" StageOnboardDone OnboardStage = "done" )
type OnboardState ¶ added in v0.1.7
type OnboardState struct {
Stage OnboardStage `json:"stage"`
Key *PaidInviteKey `json:"key"`
Invite *rpc.OOBPublicIdentityInvite `json:"invite"`
RedeemTx *chainhash.Hash `json:"redeem_tx"`
RedeemAmount dcrutil.Amount `json:"redeem_amount"`
OutChannelID string `json:"out_channel_id"`
InChannelID string `json:"in_channel_id"`
OutChannelHeightHint uint32 `json:"out_channel_height_hint"`
OutChannelMinedHeight uint32 `json:"out_channel_mined_height"`
OutChannelConfsLeft int32 `json:"out_channel_confs_left"`
}
OnboardState tracks a state of the client onboarding process.
type PagesSessionID ¶ added in v0.1.8
type PagesSessionID uint64
PagesSessionID is a type that represents a page navigation session.
func (PagesSessionID) String ¶ added in v0.1.8
func (id PagesSessionID) String() string
type PaidInviteKey ¶ added in v0.1.7
type PaidInviteKey struct {
// contains filtered or unexported fields
}
PaidInviteKey is the encryption key that is used in paid invites.
func DecodePaidInviteKey ¶ added in v0.1.7
func DecodePaidInviteKey(s string) (PaidInviteKey, error)
DecodePaidInviteKey decodes a given string as a PaidInviteKey.
func GeneratePaidInviteKey ¶ added in v0.1.7
func GeneratePaidInviteKey() PaidInviteKey
GeneratePaidInviteKey generates a new, cryptographically secure paid invite key.
func (*PaidInviteKey) Decode ¶ added in v0.1.7
func (pik *PaidInviteKey) Decode(s string) error
Decode the key from its string encoding.
func (PaidInviteKey) Decrypt ¶ added in v0.1.7
func (pik PaidInviteKey) Decrypt(box []byte) ([]byte, error)
Decrypt a message with this key.
func (PaidInviteKey) Encode ¶ added in v0.1.7
func (pik PaidInviteKey) Encode() (string, error)
Encode this key as a string.
func (PaidInviteKey) Encrypt ¶ added in v0.1.7
func (pik PaidInviteKey) Encrypt(message []byte) ([]byte, error)
Encrypt a message with this key.
func (PaidInviteKey) MarshalJSON ¶ added in v0.1.7
func (pik PaidInviteKey) MarshalJSON() ([]byte, error)
MarshalJSON marshals the id into a json string.
func (PaidInviteKey) RVPoint ¶ added in v0.1.7
func (pik PaidInviteKey) RVPoint() ratchet.RVPoint
RVPoint calculates the RV point that corresponds to this key.
func (PaidInviteKey) String ¶ added in v0.1.7
func (pik PaidInviteKey) String() string
String returns the encoded paid invite key or an error string.
func (*PaidInviteKey) UnmarshalJSON ¶ added in v0.1.7
func (pik *PaidInviteKey) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals the json representation of a ShortID.
type PaymentClient ¶
type PaymentClient interface {
PayScheme() string
PayInvoice(context.Context, string) (int64, error)
PayInvoiceAmount(context.Context, string, int64) (int64, error)
GetInvoice(context.Context, int64, func(int64)) (string, error)
DecodeInvoice(context.Context, string) (DecodedInvoice, error)
IsInvoicePaid(context.Context, int64, string) error
TrackInvoice(context.Context, string, int64) (int64, error)
IsPaymentCompleted(context.Context, string) (int64, error)
}
PaymentClient is the interface for clients that can pay for invoices.
type ReceivedGCMsg ¶ added in v0.1.8
type ReceivedGCMsg struct {
MsgID zkidentity.ShortID `json:"msg_id"`
UID UserID `json:"uid"`
GCM rpc.RMGroupMessage `json:"gcm"`
TS time.Time `json:"ts"`
GCAlias string `json:"gc_alias"`
}
ReceivedGCMsg is an individual GC message received by a local client.
type ServerPolicy ¶ added in v0.1.4
type ServerPolicy struct {
PushPaymentLifetime time.Duration `json:"push_payment_lifetime"`
MaxPushInvoices int `json:"max_push_invoices"`
// MaxMsgSizeVersion is the version of the max message size accepted
// by the server.
MaxMsgSizeVersion rpc.MaxMsgSizeVersion `json:"max_msg_size_version"`
// MaxMsgSize is the maximum message size accepted by the server.
MaxMsgSize uint `json:"max_msg_size"`
// ExpirationDays is the number of days after which data pushed to the server
// is removed if not fetched.
ExpirationDays int `json:"expiration_days"`
// PushPayRateMAtoms is the rate (in milli-atoms per PushPayRateBytes) to
// push data to the server.
PushPayRateMAtoms uint64 `json:"push_pay_rate_matoms"`
// PushPayRateBytes is the number of bytes used in calculating the final
// push pay rate.
PushPayRateBytes uint64 `json:"push_pay_rate_bytes"`
// PushPayRateMinMAtoms is the minimum payment amount (in MAtoms)
// independently of size.
PushPayRateMinMAtoms uint64 `json:"push_pay_rate_min_matoms"`
// SubPayRate is the rate (in milli-atoms) to subscribe to an RV point
// on the server.
SubPayRate uint64 `json:"sub_pay_rate"`
// PingLimit is the deadline for writing messages (including ping) to
// the server.
PingLimit time.Duration `json:"ping_limit"`
// ClientVersions is a list of server-provided client and versions
// suggested for use when connecting to this server. This can be used
// by the client to determine if it should be updated.
ClientVersions []rpc.SuggestedClientVersion `json:"client_versions"`
MilliAtomsPerRTSess uint64
MilliAtomsPerUserRTSess uint64
MilliAtomsGetCookie uint64
MilliAtomsPerUserCookie uint64
MilliAtomsRTJoin uint64
MilliAtomsRTPushRate uint64
RTPushRateMBytes uint64
}
ServerPolicy is the policy for a given server session.
func (*ServerPolicy) CalcPushCostMAtoms ¶ added in v0.2.3
func (sp *ServerPolicy) CalcPushCostMAtoms(msgSizeBytes int) (int64, error)
CalcPushCostMAtoms calculates the cost to push a message with the given size.
func (*ServerPolicy) CalcRTPushMAtoms ¶ added in v0.2.4
func (sp *ServerPolicy) CalcRTPushMAtoms(sessSize, pushMB uint32) (int64, error)
CalcRTPushMAtoms calculates how much to pay to push the given number of bytes in a session of the given size using the current server policy.
func (*ServerPolicy) MaxPayloadSize ¶ added in v0.2.3
func (sp *ServerPolicy) MaxPayloadSize() int
MaxPayloadSize returns the max payload size for the server policy.
func (*ServerPolicy) PushDcrPerGB ¶ added in v0.2.3
func (sp *ServerPolicy) PushDcrPerGB() float64
PushDcrPerGB returns the rate to push data to the server, in DCR/GB. Assumes the push policy rates are valid.
type ServerSessionIntf ¶
type ServerSessionIntf interface {
SendPRPC(msg rpc.Message, payload interface{}, reply chan<- interface{}) error
RequestClose(err error)
PayClient() PaymentClient
Policy() ServerPolicy
// Context returns a context that gets cancelled once this session stops
// running.
Context() context.Context
}
ServerSessionIntf is the interface available from serverSession to consumers.