rhp

package
v1.0.3-beta.2 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	SessionEventTypeStart    = "sessionStart"
	SessionEventTypeEnd      = "sessionEnd"
	SessionEventTypeRPCStart = "rpcStart"
	SessionEventTypeRPCEnd   = "rpcEnd"
)

SessionEventType is the type of a session event.

View Source
const (
	SessionProtocolTCP = "tcp"
	SessionProtocolWS  = "websocket"
)

SessionProtocol is the protocol used by a session.

Variables

This section is empty.

Functions

func ClearingRevision

func ClearingRevision(revision types.FileContractRevision, outputValues []types.Currency) (types.FileContractRevision, error)

ClearingRevision returns a revision that locks a contract and sets the missed proof outputs to the valid proof outputs.

func HashRevision

func HashRevision(rev types.FileContractRevision) types.Hash256

HashRevision returns the hash of rev.

func InitialRevision

func InitialRevision(formationTxn *types.Transaction, hostPubKey, renterPubKey types.UnlockKey) types.FileContractRevision

InitialRevision returns the first revision of a file contract formation transaction.

func Revise

func Revise(revision types.FileContractRevision, revisionNumber uint64, validOutputs, missedOutputs []types.Currency) (types.FileContractRevision, error)

Revise updates the contract revision with the provided values.

func ValidateClearingRevision

func ValidateClearingRevision(current, final types.FileContractRevision, finalPayment types.Currency) (types.Currency, error)

ValidateClearingRevision verifies that the revision locks the current contract by setting its revision number to the maximum value and the valid and missed proof outputs are the same.

func ValidatePaymentRevision

func ValidatePaymentRevision(current, revision types.FileContractRevision, payment types.Currency) error

ValidatePaymentRevision verifies that a payment revision is valid and the amount is properly deducted from both renter outputs and added to both host outputs. Signatures are not validated.

func ValidateProgramRevision

func ValidateProgramRevision(current, revision types.FileContractRevision, storage, collateral types.Currency) (burn types.Currency, _ error)

ValidateProgramRevision verifies that a contract program revision is valid and only the missed host value and burn value are modified by the expected burn amount. All other usage will have been paid for by the RPC budget.

func ValidateRevision

func ValidateRevision(current, revision types.FileContractRevision, payment, collateral types.Currency) (transfer, burn types.Currency, err error)

ValidateRevision verifies that a new revision is valid given the current revision. Only the revision number and proof output values are allowed to change

Types

type Conn

type Conn struct {
	net.Conn
	// contains filtered or unexported fields
}

An Conn wraps a net.Conn to track the amount of data read and written and limit bandwidth usage.

func NewConn

func NewConn(c net.Conn, m DataMonitor, rl, wl *rate.Limiter) *Conn

NewConn initializes a new RPC conn wrapper.

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

Read implements io.Reader

func (*Conn) Usage

func (c *Conn) Usage() (read, written uint64)

Usage returns the amount of data read and written by the connection.

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

Write implements io.Writer

type DataMonitor

type DataMonitor interface {
	ReadBytes(n int)
	WriteBytes(n int)
}

A DataMonitor records the amount of data read and written across all connections.

type DataRecorder

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

A DataRecorder records the amount of data read and written across connections.

func NewDataRecorder

func NewDataRecorder(store DataRecorderStore, log *zap.Logger) *DataRecorder

NewDataRecorder initializes a new DataRecorder

func (*DataRecorder) Close

func (dr *DataRecorder) Close() error

Close persists any remaining usage and returns nil

func (*DataRecorder) ReadBytes

func (dr *DataRecorder) ReadBytes(n int)

ReadBytes increments the number of bytes read by n.

func (*DataRecorder) Usage

func (dr *DataRecorder) Usage() (read, written uint64)

Usage returns the number of bytes read and written

func (*DataRecorder) WriteBytes

func (dr *DataRecorder) WriteBytes(n int)

WriteBytes increments the number of bytes written by n.

type DataRecorderStore

type DataRecorderStore interface {
	IncrementRHPDataUsage(ingress, egress uint64) error
}

A DataRecorderStore persists data usage

type RPC added in v0.2.0

type RPC struct {
	ID        UID             `json:"id"`
	SessionID UID             `json:"sessionID"`
	RPC       types.Specifier `json:"rpc"`
	Usage     contracts.Usage `json:"usage"`
	Error     error           `json:"error,omitempty"`
	Elapsed   time.Duration   `json:"timestamp"`
}

An RPC is an RPC call made by a renter to a host.

type Session added in v0.2.0

type Session struct {
	ID          UID             `json:"id"`
	Protocol    string          `json:"protocol"`
	RHPVersion  int             `json:"rhpVersion"`
	PeerAddress string          `json:"peerAddress"`
	Ingress     uint64          `json:"ingress"`
	Egress      uint64          `json:"egress"`
	Usage       contracts.Usage `json:"usage"`

	Timestamp time.Time `json:"timestamp"`
	// contains filtered or unexported fields
}

A Session is an open connection between a host and a renter.

type SessionEvent added in v0.2.0

type SessionEvent struct {
	Type    string  `json:"type"`
	Session Session `json:"session"`
	RPC     any     `json:"rpc,omitempty"`
}

A SessionEvent is an event that occurs during a session.

type SessionReporter added in v0.2.0

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

A SessionReporter manages open sessions and reports session events to subscribers.

func NewSessionReporter added in v0.2.0

func NewSessionReporter() *SessionReporter

NewSessionReporter returns a new SessionReporter.

func (*SessionReporter) Active added in v0.2.0

func (sr *SessionReporter) Active() []Session

Active returns a snapshot of the currently active sessions.

func (*SessionReporter) StartRPC added in v0.2.0

func (sr *SessionReporter) StartRPC(sessionID UID, rpc types.Specifier) (rpcID UID, end func(contracts.Usage, error))

StartRPC starts a new RPC and returns a function that should be called when the RPC ends.

func (*SessionReporter) StartSession added in v0.2.0

func (sr *SessionReporter) StartSession(conn *Conn, proto string, version int) (sessionID UID, end func())

StartSession starts a new session and returns a function that should be called when the session ends.

func (*SessionReporter) Subscribe added in v0.2.0

func (sr *SessionReporter) Subscribe(sub SessionSubscriber)

Subscribe subscribes to session events.

func (*SessionReporter) Unsubscribe added in v0.2.0

func (sr *SessionReporter) Unsubscribe(sub SessionSubscriber)

Unsubscribe unsubscribes from session events.

type SessionSubscriber added in v0.2.0

type SessionSubscriber interface {
	ReceiveSessionEvent(SessionEvent)
}

A SessionSubscriber receives session events.

type UID added in v0.2.0

type UID [8]byte

UID is a unique identifier for a session or RPC.

func (UID) String added in v0.2.0

func (u UID) String() string

String returns the hex-encoded string representation of the UID.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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