Commit 72317011 authored by Luke Champine's avatar Luke Champine

minor tweaks

parent 5c49dfba
package host
import (
//"errors"
//"os"
//"path/filepath"
"errors"
"os"
"github.com/NebulousLabs/Sia/consensus"
//"github.com/NebulousLabs/Sia/hash"
"github.com/NebulousLabs/Sia/hash"
)
// ContractEntry houses a single contract with its id - you cannot derive the
......@@ -132,33 +131,27 @@ func (h *Host) threadedConsensusListen(updateChan chan struct{}) {
// Create a proof of storage for a contract, using the state height to
// determine the random seed. Create proof must be under a host and state lock.
func (h *Host) createStorageProof(entry ContractEntry, heightForProof consensus.BlockHeight) (sp consensus.StorageProof, err error) {
/*
// Get the file associated with the contract.
contractObligation, exists := h.contracts[entry.ID]
if !exists {
err = errors.New("no record of that file")
return
}
fullname := filepath.Join(h.hostDir, contractObligation.filename)
contractObligation, exists := h.contracts[entry.ID]
if !exists {
err = errors.New("no record of that file")
return
}
// Open the file.
file, err := os.Open(fullname)
if err != nil {
return
}
defer file.Close()
file, err := os.Open(contractObligation.path)
if err != nil {
return
}
defer file.Close()
// Build the proof using the hash library.
numSegments := hash.CalculateSegments(entry.Contract.FileSize)
segmentIndex, err := h.state.StorageProofSegment(entry.ID)
if err != nil {
return
}
base, hashSet, err := hash.BuildReaderProof(file, numSegments, segmentIndex)
if err != nil {
return
}
sp = consensus.StorageProof{entry.ID, base, hashSet}
*/
segmentIndex, err := h.state.StorageProofSegment(entry.ID)
if err != nil {
return
}
numSegments := hash.CalculateSegments(entry.Contract.FileSize)
base, hashSet, err := hash.BuildReaderProof(file, numSegments, segmentIndex)
if err != nil {
return
}
sp = consensus.StorageProof{entry.ID, base, hashSet}
return
}
......@@ -4,16 +4,14 @@ import (
"io"
"github.com/NebulousLabs/Sia/consensus"
"github.com/NebulousLabs/Sia/hash"
)
// TODO: embed ContractTerms?
type UploadParams struct {
Data io.ReadSeeker
Duration consensus.BlockHeight
Delay consensus.BlockHeight
FileSize uint64
MerkleRoot hash.Hash
Data io.ReadSeeker
Duration consensus.BlockHeight
Delay consensus.BlockHeight
FileSize uint64
// these fields are not seen by the host
Nickname string
......
......@@ -15,6 +15,8 @@ import (
const (
// TODO: ask wallet
minerFee = 10
defaultWindowSize = 100
)
func (r *Renter) createContractTransaction(host modules.HostEntry, terms modules.ContractTerms, merkleRoot hash.Hash) (txn consensus.Transaction, err error) {
......@@ -71,10 +73,10 @@ func (r *Renter) negotiateContract(host modules.HostEntry, up modules.UploadPara
terms := modules.ContractTerms{
FileSize: filesize,
StartHeight: height + up.Delay,
WindowSize: 0, // ??
NumWindows: 0, // ?? duration/windowsize + 1?
ClientPayout: 0, // ??
HostPayout: host.Price, // ??
WindowSize: defaultWindowSize,
NumWindows: (uint64(up.Duration) / defaultWindowSize) + 1,
Price: host.Price, // ??
Collateral: host.Collateral, // ??
ValidProofAddress: host.CoinAddress,
MissedProofAddress: consensus.ZeroAddress,
}
......
......@@ -80,7 +80,6 @@ func (r *Renter) downloadPiece(piece FilePiece, path string) error {
if _, err = encoding.WriteObject(conn, piece.ContractID); err != nil {
return
}
// TODO: read error
// create file
file, err := os.Create(path)
......@@ -93,6 +92,7 @@ func (r *Renter) downloadPiece(piece FilePiece, path string) error {
_, err = io.CopyN(file, conn, int64(piece.Contract.FileSize))
if err != nil {
os.Remove(path)
r.hostDB.FlagHost(piece.Host.IPAddress)
return
}
return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment