Commit 337fc7ae authored by Luke Champine's avatar Luke Champine

expose ResolveID method

parent 3281a84b
......@@ -117,10 +117,10 @@ func (c *Contractor) CurrentPeriod() types.BlockHeight {
return c.currentPeriod
}
// resolveID returns the ID of the most recent renewal of id.
func (c *Contractor) resolveID(id types.FileContractID) types.FileContractID {
// ResolveID returns the ID of the most recent renewal of id.
func (c *Contractor) ResolveID(id types.FileContractID) types.FileContractID {
if newID, ok := c.renewedIDs[id]; ok && newID != id {
return c.resolveID(newID)
return c.ResolveID(newID)
}
return id
}
......
......@@ -141,7 +141,7 @@ func TestContracts(t *testing.T) {
}
}
// TestResolveID tests the resolveID method.
// TestResolveID tests the ResolveID method.
func TestResolveID(t *testing.T) {
c := &Contractor{
renewedIDs: map[types.FileContractID]types.FileContractID{
......@@ -163,7 +163,7 @@ func TestResolveID(t *testing.T) {
{types.FileContractID{5}, types.FileContractID{6}},
}
for _, test := range tests {
if r := c.resolveID(test.id); r != test.resolved {
if r := c.ResolveID(test.id); r != test.resolved {
t.Errorf("expected %v -> %v, got %v", test.id, test.resolved, r)
}
}
......
......@@ -107,7 +107,7 @@ func (hd *hostDownloader) Close() error {
// from a host.
func (c *Contractor) Downloader(id types.FileContractID) (_ Downloader, err error) {
c.mu.RLock()
id = c.resolveID(id)
id = c.ResolveID(id)
cachedDownloader, haveDownloader := c.downloaders[id]
height := c.blockHeight
contract, haveContract := c.contracts[id]
......
......@@ -166,7 +166,7 @@ func (he *hostEditor) Modify(oldRoot, newRoot crypto.Hash, offset uint64, newDat
// delete sectors on a host.
func (c *Contractor) Editor(id types.FileContractID) (_ Editor, err error) {
c.mu.RLock()
id = c.resolveID(id)
id = c.ResolveID(id)
cachedEditor, haveEditor := c.editors[id]
height := c.blockHeight
contract, haveContract := c.contracts[id]
......
......@@ -117,7 +117,7 @@ type (
)
// newDownload initializes and returns a download object.
func newDownload(f *file, destination string, currentContracts map[modules.NetAddress]types.FileContractID) *download {
func (r *Renter) newDownload(f *file, destination string, currentContracts map[modules.NetAddress]types.FileContractID) *download {
d := &download{
finishedChunks: make([]bool, f.numChunks()),
......@@ -150,7 +150,11 @@ func newDownload(f *file, destination string, currentContracts map[modules.NetAd
// get latest contract ID
id, ok := currentContracts[contract.IP]
if !ok {
continue
// no matching NetAddress; try using a revised ID
id = r.hostContractor.ResolveID(contract.ID)
if id == contract.ID {
continue
}
}
for i := range contract.Pieces {
d.pieceSet[contract.Pieces[i].Chunk][id] = contract.Pieces[i]
......
......@@ -26,7 +26,7 @@ func (r *Renter) Download(path, destination string) error {
}
// Create the download object and add it to the queue.
d := newDownload(file, destination, currentContracts)
d := r.newDownload(file, destination, currentContracts)
lockID = r.mu.Lock()
r.downloadQueue = append(r.downloadQueue, d)
r.mu.Unlock(lockID)
......
......@@ -100,6 +100,9 @@ type hostContractor interface {
// Downloader creates a Downloader from the specified contract ID,
// allowing the retrieval of sectors.
Downloader(types.FileContractID) (contractor.Downloader, error)
// ResolveID returns the most recent renewal of the specified ID.
ResolveID(types.FileContractID) types.FileContractID
}
// A trackedFile contains metadata about files being tracked by the Renter.
......
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