2020-03-11 01:57:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-03-11 05:49:17 +00:00
|
|
|
"net/http"
|
|
|
|
"sort"
|
2020-03-11 01:57:52 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-sectorbuilder"
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
2020-03-11 07:22:21 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sealmgr/sectorutil"
|
2020-03-11 01:57:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type workerStorage struct {
|
|
|
|
path string // TODO: multi-path support
|
2020-03-11 05:49:17 +00:00
|
|
|
mid abi.ActorID
|
2020-03-11 01:57:52 +00:00
|
|
|
|
2020-03-11 05:49:17 +00:00
|
|
|
auth http.Header
|
2020-03-11 01:57:52 +00:00
|
|
|
api api.StorageMiner
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *workerStorage) AcquireSector(ctx context.Context, id abi.SectorNumber, existing sectorbuilder.SectorFileType, allocate sectorbuilder.SectorFileType, sealing bool) (sectorbuilder.SectorPaths, func(), error) {
|
2020-03-11 05:49:17 +00:00
|
|
|
asid := abi.SectorID{
|
|
|
|
Miner: w.mid,
|
|
|
|
Number: id,
|
|
|
|
}
|
|
|
|
|
|
|
|
// extract local storage; prefer
|
|
|
|
|
|
|
|
si, err := w.api.WorkerFindSector(ctx, asid, existing)
|
|
|
|
if err != nil {
|
|
|
|
return sectorbuilder.SectorPaths{}, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(si, func(i, j int) bool {
|
|
|
|
return si[i].Cost < si[j].Cost
|
|
|
|
})
|
|
|
|
|
|
|
|
best := si[0].URLs // TODO: not necessarily true
|
|
|
|
|
2020-03-11 07:22:21 +00:00
|
|
|
sname := sectorutil.SectorName(abi.SectorID{
|
|
|
|
Miner: w.mid,
|
|
|
|
Number: id,
|
|
|
|
})
|
|
|
|
|
2020-03-11 05:49:17 +00:00
|
|
|
w.fetch(best, )
|
2020-03-11 01:57:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ sectorbuilder.SectorProvider = &workerStorage{}
|