clientintf

package
v0.1.6-rc1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: ISC Imports: 17 Imported by: 0

Documentation

Overview

Package clientintf holds client-global interfaces and helper functions.

This works as the root for client types.

Index

Constants

View Source
const LockFileName = "app.lock"

Variables

View Source
var (
	ErrSubsysExiting             = errors.New("subsys exiting")
	ErrInvoiceInsufficientlyPaid = errors.New("invoice insufficiently paid")
)

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 EstimatePostSize

func EstimatePostSize(content, descr string) (uint64, error)

EstimatePostSize estimates the final size of a post share message, given the specified contents of the post.

func EstimateUploadCost

func EstimateUploadCost(size int64, feeRate uint64) (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 NewProxiedDialer

func NewProxiedDialer(cfg ProxyDialerConfig) func(context.Context) (Conn, *tls.ConnectionState, error)

NewProxiedDialer creates a client dialer function when a SOCKS proxy connection is necessary.

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

CertConfirmer is a functiion that can be called to confirm whether a given server is safe.

type Conn

type Conn interface {
	io.Reader
	io.Writer
	io.Closer
	RemoteAddr() net.Addr
}

Conn represents the required functions for a remote connection to a server.

type DecodedInvoice

type DecodedInvoice struct {
	ID         []byte
	MAtoms     int64
	ExpiryTime time.Time
}

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 Dialer

type Dialer func(context.Context) (Conn, *tls.ConnectionState, error)

Dialer is a function that can generate new connections to a server.

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 (pc FreePaymentClient) GetInvoice(ctx context.Context, mat int64, cb func(int64)) (string, error)

func (FreePaymentClient) IsInvoicePaid

func (pc FreePaymentClient) IsInvoicePaid(context.Context, int64, string) error

func (FreePaymentClient) IsPaymentCompleted added in v0.1.4

func (pc FreePaymentClient) IsPaymentCompleted(context.Context, string) error

func (FreePaymentClient) PayInvoice

func (pc FreePaymentClient) PayInvoice(context.Context, string) (int64, error)

func (FreePaymentClient) PayInvoiceAmount

func (pc FreePaymentClient) PayInvoiceAmount(context.Context, string, int64) (int64, error)

func (FreePaymentClient) PayScheme

func (pc FreePaymentClient) PayScheme() string

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.

func RandomID

func RandomID() ID

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
	IsPaymentCompleted(context.Context, string) error
}

PaymentClient is the interface for clients that can pay for invoices.

type PostID

type PostID = ID

type ProxyDialerConfig

type ProxyDialerConfig struct {
	ServerAddr   string
	ProxyAddr    string
	ProxyUser    string
	ProxyPass    string
	TorIsolation bool
	CircuitLimit uint32
	Log          slog.Logger
}

ProxyDialerConfig holds config fields for dialing to the server using a proxy.

type RawRVID

type RawRVID = ID

type ServerPolicy added in v0.1.4

type ServerPolicy struct {
	PushPaymentLifetime time.Duration
	MaxPushInvoices     int
}

ServerPolicy is the policy for a given server session.

type ServerSessionIntf

type ServerSessionIntf interface {
	SendPRPC(msg rpc.Message, payload interface{}, reply chan<- interface{}) error
	RequestClose(err error)
	PayClient() PaymentClient
	PaymentRates() (uint64, uint64)
	ExpirationDays() int
	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.

type UserID

type UserID = ID

Jump to

Keyboard shortcuts

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