Documentation ¶
Index ¶
- Constants
- func ClearingRevision(revision types.FileContractRevision, outputValues []types.Currency) (types.FileContractRevision, error)
- func HashRevision(rev types.FileContractRevision) types.Hash256
- func InitialRevision(formationTxn *types.Transaction, hostPubKey, renterPubKey types.UnlockKey) types.FileContractRevision
- func Revise(revision types.FileContractRevision, revisionNumber uint64, ...) (types.FileContractRevision, error)
- func ValidateClearingRevision(current, final types.FileContractRevision, finalPayment types.Currency) (types.Currency, error)
- func ValidatePaymentRevision(current, revision types.FileContractRevision, payment types.Currency) error
- func ValidateProgramRevision(current, revision types.FileContractRevision, ...) (burn types.Currency, _ error)
- func ValidateRevision(current, revision types.FileContractRevision, ...) (transfer, burn types.Currency, err error)
- type Conn
- type DataMonitor
- type DataRecorder
- type DataRecorderStore
- type RPC
- type Session
- type SessionEvent
- type SessionReporter
- func (sr *SessionReporter) Active() []Session
- func (sr *SessionReporter) StartRPC(sessionID UID, rpc types.Specifier) (rpcID UID, end func(contracts.Usage, error))
- func (sr *SessionReporter) StartSession(conn *Conn, proto string, version int) (sessionID UID, end func())
- func (sr *SessionReporter) Subscribe(sub SessionSubscriber)
- func (sr *SessionReporter) Unsubscribe(sub SessionSubscriber)
- type SessionSubscriber
- type UID
Constants ¶
const ( SessionEventTypeStart = "sessionStart" SessionEventTypeEnd = "sessionEnd" SessionEventTypeRPCStart = "rpcStart" SessionEventTypeRPCEnd = "rpcEnd" )
SessionEventType is the type of a session event.
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 ¶
An Conn wraps a net.Conn to track the amount of data read and written and limit bandwidth usage.
type DataMonitor ¶
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 ¶
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.