accounting

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: BSD-3-Clause Imports: 12 Imported by: 2 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrOverdraft is the error returned if the expected debt in Reserve would exceed the payment thresholds
	ErrOverdraft = errors.New("attempted overdraft")
	// ErrDisconnectThresholdExceeded is the error returned if a peer has exceeded the disconnect threshold
	ErrDisconnectThresholdExceeded = errors.New("disconnect threshold exceeded")
	// ErrInvalidPaymentTolerance is the error returned if the payment tolerance is too high compared to the payment threshold
	ErrInvalidPaymentTolerance = errors.New("payment tolerance must be less than half the payment threshold")
)

Functions

This section is empty.

Types

type Accounting

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

Accounting is the main implementation of the accounting interface

func NewAccounting

func NewAccounting(o Options) (*Accounting, error)

NewAccounting creates a new Accounting instance with the provided options

func (*Accounting) Balance

func (a *Accounting) Balance(peer swarm.Address) (balance int64, err error)

Balance returns the current balance for the given peer

func (*Accounting) Balances

func (a *Accounting) Balances() (map[string]int64, error)

Balances gets balances for all peers from store

func (*Accounting) Credit

func (a *Accounting) Credit(peer swarm.Address, price uint64) error

Credit increases the amount of credit we have with the given peer (and decreases existing debt).

func (*Accounting) Debit

func (a *Accounting) Debit(peer swarm.Address, price uint64) error

Debit increases the amount of debt we have with the given peer (and decreases existing credit)

func (*Accounting) Metrics

func (a *Accounting) Metrics() []prometheus.Collector

func (*Accounting) NotifyPayment

func (a *Accounting) NotifyPayment(peer swarm.Address, amount uint64) error

NotifyPayment is called by Settlement when we received payment Implements the PaymentObserver interface

func (*Accounting) Release

func (a *Accounting) Release(peer swarm.Address, price uint64)

Release releases reserved funds

func (*Accounting) Reserve

func (a *Accounting) Reserve(peer swarm.Address, price uint64) error

Reserve reserves a portion of the balance for peer

type FixedPricer

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

func NewFixedPricer

func NewFixedPricer(overlay swarm.Address, poPrice uint64) *FixedPricer

func (*FixedPricer) PeerPrice

func (pricer *FixedPricer) PeerPrice(peer, chunk swarm.Address) uint64

func (*FixedPricer) Price

func (pricer *FixedPricer) Price(chunk swarm.Address) uint64

type Interface

type Interface interface {
	// Reserve reserves a portion of the balance for peer
	// It returns an error if the operation would risk exceeding the disconnect threshold
	// This should be called (always in combination with Release) before a Credit action to prevent overspending in case of concurrent requests
	Reserve(peer swarm.Address, price uint64) error
	// Release releases reserved funds
	Release(peer swarm.Address, price uint64)
	// Credit increases the balance the peer has with us (we "pay" the peer)
	Credit(peer swarm.Address, price uint64) error
	// Debit increases the balance we have with the peer (we get "paid")
	Debit(peer swarm.Address, price uint64) error
	// Balance returns the current balance for the given peer
	Balance(peer swarm.Address) (int64, error)
	// Balances returns balances for all known peers
	Balances() (map[string]int64, error)
}

Interface is the main interface for Accounting

type Options

type Options struct {
	PaymentThreshold uint64
	PaymentTolerance uint64
	Logger           logging.Logger
	Store            storage.StateStorer
	Settlement       settlement.Interface
}

Options for accounting

type Pricer

type Pricer interface {
	// PeerPrice is the price the peer charges for a given chunk hash
	PeerPrice(peer, chunk swarm.Address) uint64
	// Price is the price we charge for a given chunk hash
	Price(chunk swarm.Address) uint64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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