Documentation ¶
Overview ¶
Package proto implements the renter side of the Sia renter-host protocol.
Index ¶
- Variables
- func SubmitContractRevision(c ContractRevision, w Wallet, tpool TransactionPool) (err error)
- type ContractRevision
- func (c ContractRevision) EndHeight() types.BlockHeight
- func (c ContractRevision) HostKey() hostdb.HostPublicKey
- func (c ContractRevision) ID() types.FileContractID
- func (c ContractRevision) IsValid() bool
- func (c ContractRevision) NumSectors() int
- func (c ContractRevision) RenterFunds() types.Currency
- type Session
- func (s *Session) Append(sector *[renterhost.SectorSize]byte) (crypto.Hash, error)
- func (s *Session) Close() (err error)
- func (s *Session) DeleteSectors(roots []crypto.Hash) error
- func (s *Session) FormContract(w Wallet, tpool TransactionPool, key ed25519.PrivateKey, ...) (_ ContractRevision, _ []types.Transaction, err error)
- func (s *Session) HostKey() hostdb.HostPublicKey
- func (s *Session) IsClosed() bool
- func (s *Session) Lock(id types.FileContractID, key ed25519.PrivateKey) (err error)
- func (s *Session) Read(w io.Writer, sections []renterhost.RPCReadRequestSection) (err error)
- func (s *Session) RenewAndClearContract(w Wallet, tpool TransactionPool, renterPayout types.Currency, ...) (_ ContractRevision, _ []types.Transaction, err error)
- func (s *Session) RenewContract(w Wallet, tpool TransactionPool, renterPayout types.Currency, ...) (_ ContractRevision, _ []types.Transaction, err error)
- func (s *Session) Revision() ContractRevision
- func (s *Session) SectorRoots(offset, n int) (_ []crypto.Hash, err error)
- func (s *Session) SetLatency(d time.Duration)
- func (s *Session) SetReadDeadline(d time.Duration)
- func (s *Session) SetWriteDeadline(d time.Duration)
- func (s *Session) Settings() (_ hostdb.HostSettings, err error)
- func (s *Session) Unlock() (err error)
- func (s *Session) Write(actions []renterhost.RPCWriteAction) (err error)
- type TransactionPool
- type Wallet
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidMerkleProof is returned by various RPCs when the host supplies // an invalid Merkle proof. ErrInvalidMerkleProof = errors.New("host supplied invalid Merkle proof") // ErrContractLocked is returned by the Lock RPC when the contract in // question is already locked by another party. This is a transient error; // the caller should retry later. ErrContractLocked = errors.New("contract is locked by another party") // ErrContractFinalized is returned by the Lock RPC when the contract in // question has reached its maximum revision number, meaning the contract // can no longer be revised. ErrContractFinalized = errors.New("contract cannot be revised further") )
Functions ¶
func SubmitContractRevision ¶ added in v0.2.0
func SubmitContractRevision(c ContractRevision, w Wallet, tpool TransactionPool) (err error)
SubmitContractRevision submits the latest revision of a contract to the blockchain, finalizing the renter and host payouts as they stand in the revision. Submitting a revision with a higher revision number will replace the previously-submitted revision.
Submitting revision transactions is a way for the renter to punish the host. If the host is well-behaved, there is no incentive for the renter to submit revision transactions. But if the host misbehaves, submitting the revision ensures that the host will lose the collateral it committed.
Types ¶
type ContractRevision ¶ added in v0.2.0
type ContractRevision struct { Revision types.FileContractRevision Signatures [2]types.TransactionSignature }
A ContractRevision contains the most recent revision to a file contract and its signatures.
func FormContract ¶
func FormContract(w Wallet, tpool TransactionPool, key ed25519.PrivateKey, host hostdb.ScannedHost, renterPayout types.Currency, startHeight, endHeight types.BlockHeight) (ContractRevision, []types.Transaction, error)
FormContract forms a contract with a host. The resulting contract will have renterPayout coins in the renter output.
func RenewContract ¶
func RenewContract(w Wallet, tpool TransactionPool, id types.FileContractID, key ed25519.PrivateKey, host hostdb.ScannedHost, renterPayout types.Currency, startHeight, endHeight types.BlockHeight) (ContractRevision, []types.Transaction, error)
RenewContract negotiates a new file contract and initial revision for data already stored with a host.
func (ContractRevision) EndHeight ¶ added in v0.2.0
func (c ContractRevision) EndHeight() types.BlockHeight
EndHeight returns the height at which the host is no longer obligated to store contract data.
func (ContractRevision) HostKey ¶ added in v0.2.0
func (c ContractRevision) HostKey() hostdb.HostPublicKey
HostKey returns the public key of the host.
func (ContractRevision) ID ¶ added in v0.2.0
func (c ContractRevision) ID() types.FileContractID
ID returns the ID of the original FileContract.
func (ContractRevision) IsValid ¶ added in v0.2.0
func (c ContractRevision) IsValid() bool
IsValid returns false if the ContractRevision has the wrong number of public keys or outputs.
func (ContractRevision) NumSectors ¶ added in v0.5.0
func (c ContractRevision) NumSectors() int
NumSectors returns the number of sectors covered by the contract.
func (ContractRevision) RenterFunds ¶ added in v0.2.0
func (c ContractRevision) RenterFunds() types.Currency
RenterFunds returns the funds remaining in the contract's Renter payout.
type Session ¶ added in v0.2.0
type Session struct {
// contains filtered or unexported fields
}
A Session is an ongoing exchange of RPCs via the renter-host protocol.
func NewSession ¶ added in v0.2.0
func NewSession(hostIP modules.NetAddress, hostKey hostdb.HostPublicKey, id types.FileContractID, key ed25519.PrivateKey, currentHeight types.BlockHeight) (_ *Session, err error)
NewSession initiates a new renter-host protocol session with the specified host. The supplied contract will be locked and synchronized with the host. The host's settings will also be requested.
func NewUnlockedSession ¶ added in v0.2.0
func NewUnlockedSession(hostIP modules.NetAddress, hostKey hostdb.HostPublicKey, currentHeight types.BlockHeight) (_ *Session, err error)
NewUnlockedSession initiates a new renter-host protocol session with the specified host, without locking an associated contract or requesting the host's settings.
func (*Session) Append ¶ added in v0.12.0
func (s *Session) Append(sector *[renterhost.SectorSize]byte) (crypto.Hash, error)
Append calls the Write RPC with a single action, appending the provided sector. It returns the Merkle root of the sector.
func (*Session) Close ¶ added in v0.2.0
Close gracefully terminates the session and closes the underlying connection.
func (*Session) DeleteSectors ¶ added in v0.13.0
DeleteSectors calls the Write RPC with a set of Swap and Trim actions that delete the specified sectors.
func (*Session) FormContract ¶ added in v0.2.0
func (s *Session) FormContract(w Wallet, tpool TransactionPool, key ed25519.PrivateKey, renterPayout types.Currency, startHeight, endHeight types.BlockHeight) (_ ContractRevision, _ []types.Transaction, err error)
FormContract forms a contract with a host. The resulting contract will have renterPayout coins in the renter output.
func (*Session) HostKey ¶ added in v0.2.0
func (s *Session) HostKey() hostdb.HostPublicKey
HostKey returns the public key of the host.
func (*Session) Lock ¶ added in v0.2.0
func (s *Session) Lock(id types.FileContractID, key ed25519.PrivateKey) (err error)
Lock calls the Lock RPC, locking the supplied contract and synchronizing its state with the host's most recent revision.
Lock returns ErrContractFinalized if the contract can no longer be revised. The contract will still be available via the Revision method, but invoking other RPCs may result in errors or panics.
func (*Session) Read ¶ added in v0.2.0
func (s *Session) Read(w io.Writer, sections []renterhost.RPCReadRequestSection) (err error)
Read calls the Read RPC, writing the requested sections of sector data to w. Merkle proofs are always requested.
Note that sector data is streamed to w before it has been validated. Callers MUST check the returned error, and discard any data written to w if the error is non-nil. Failure to do so may allow an attacker to inject malicious data.
func (*Session) RenewAndClearContract ¶ added in v0.15.0
func (s *Session) RenewAndClearContract(w Wallet, tpool TransactionPool, renterPayout types.Currency, startHeight, endHeight types.BlockHeight) (_ ContractRevision, _ []types.Transaction, err error)
RenewAndClearContract negotiates a new file contract and initial revision for data already stored with a host. The old contract is "cleared," reverting its filesize to zero.
func (*Session) RenewContract ¶ added in v0.2.0
func (s *Session) RenewContract(w Wallet, tpool TransactionPool, renterPayout types.Currency, startHeight, endHeight types.BlockHeight) (_ ContractRevision, _ []types.Transaction, err error)
RenewContract negotiates a new file contract and initial revision for data already stored with a host.
func (*Session) Revision ¶ added in v0.10.0
func (s *Session) Revision() ContractRevision
Revision returns the most recent revision of the locked contract.
func (*Session) SectorRoots ¶ added in v0.2.0
SectorRoots calls the SectorRoots RPC, returning the requested range of sector Merkle roots of the currently-locked contract.
func (*Session) SetLatency ¶ added in v0.14.4
SetLatency sets the latency deadline for RPCs.
func (*Session) SetReadDeadline ¶ added in v0.14.3
SetReadDeadline sets the per-byte read deadline for RPCs. For example, to time out after 1 minute when downloading a sector, set the per-byte deadline to time.Minute / renterhost.SectorSize.
func (*Session) SetWriteDeadline ¶ added in v0.14.3
SetWriteDeadline sets the per-byte write deadline for RPCs. For example, to time out after 1 minute when uploading a sector, set the per-byte deadline to time.Minute / renterhost.SectorSize.
func (*Session) Settings ¶ added in v0.2.0
func (s *Session) Settings() (_ hostdb.HostSettings, err error)
Settings calls the Settings RPC, returning the host's reported settings.
func (*Session) Unlock ¶ added in v0.2.0
Unlock calls the Unlock RPC, unlocking the currently-locked contract.
It is typically not necessary to manually unlock a contract, as the host will automatically unlock any locked contracts when the connection closes.
func (*Session) Write ¶ added in v0.2.0
func (s *Session) Write(actions []renterhost.RPCWriteAction) (err error)
Write implements the Write RPC, except for ActionUpdate. A Merkle proof is always requested.
type TransactionPool ¶
type TransactionPool interface { AcceptTransactionSet([]types.Transaction) error FeeEstimate() (min types.Currency, max types.Currency, err error) }
A TransactionPool can broadcast transactions and estimate transaction fees.
type Wallet ¶
type Wallet interface { NewWalletAddress() (types.UnlockHash, error) SignTransaction(txn *types.Transaction, toSign []crypto.Hash) error UnspentOutputs(limbo bool) ([]modules.UnspentOutput, error) UnconfirmedParents(txn types.Transaction) ([]types.Transaction, error) UnlockConditions(addr types.UnlockHash) (types.UnlockConditions, error) }
A Wallet provides addresses and outputs, and can sign transactions.