use latest contract when downloading

parent d751c4a9
......@@ -117,7 +117,7 @@ type (
)
// newDownload initializes and returns a download object.
func newDownload(f *file, destination string) *download {
func newDownload(f *file, destination string, currentContracts map[modules.NetAddress]types.FileContractID) *download {
d := &download{
finishedChunks: make([]bool, f.numChunks()),
......@@ -147,8 +147,13 @@ func newDownload(f *file, destination string) *download {
}
f.mu.RLock()
for _, contract := range f.contracts {
// get latest contract ID
id, ok := currentContracts[contract.IP]
if !ok {
continue
}
for i := range contract.Pieces {
d.pieceSet[contract.Pieces[i].Chunk][contract.ID] = contract.Pieces[i]
d.pieceSet[contract.Pieces[i].Chunk][id] = contract.Pieces[i]
}
}
f.mu.RUnlock()
......
......@@ -5,6 +5,7 @@ import (
"sync/atomic"
"github.com/NebulousLabs/Sia/modules"
"github.com/NebulousLabs/Sia/types"
)
// Download downloads a file, identified by its path, to the destination
......@@ -18,8 +19,14 @@ func (r *Renter) Download(path, destination string) error {
return errors.New("no file with that path")
}
// Build current contracts map.
currentContracts := make(map[modules.NetAddress]types.FileContractID)
for _, contract := range r.hostContractor.Contracts() {
currentContracts[contract.NetAddress] = contract.ID
}
// Create the download object and add it to the queue.
d := newDownload(file, destination)
d := newDownload(file, destination, currentContracts)
lockID = r.mu.Lock()
r.downloadQueue = append(r.downloadQueue, d)
r.mu.Unlock(lockID)
......
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