2020-03-27 20:08:06 +00:00
|
|
|
package impl
|
2020-03-11 01:57:52 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
|
2020-03-27 20:08:06 +00:00
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2020-03-11 01:57:52 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
|
|
|
storage2 "github.com/filecoin-project/specs-storage/storage"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
|
|
"github.com/filecoin-project/lotus/api/client"
|
2020-03-24 23:49:45 +00:00
|
|
|
"github.com/filecoin-project/lotus/lib/jsonrpc"
|
2020-03-27 23:00:21 +00:00
|
|
|
"github.com/filecoin-project/sector-storage"
|
2020-03-11 01:57:52 +00:00
|
|
|
)
|
|
|
|
|
2020-03-27 20:08:06 +00:00
|
|
|
type remoteWorker struct {
|
2020-03-11 01:57:52 +00:00
|
|
|
api.WorkerApi
|
2020-03-24 23:49:45 +00:00
|
|
|
closer jsonrpc.ClientCloser
|
2020-03-11 01:57:52 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 20:08:06 +00:00
|
|
|
func (r *remoteWorker) NewSector(ctx context.Context, sector abi.SectorID) error {
|
2020-03-17 20:19:52 +00:00
|
|
|
return xerrors.New("unsupported")
|
|
|
|
}
|
|
|
|
|
2020-03-27 20:08:06 +00:00
|
|
|
func (r *remoteWorker) AddPiece(ctx context.Context, sector abi.SectorID, pieceSizes []abi.UnpaddedPieceSize, newPieceSize abi.UnpaddedPieceSize, pieceData storage2.Data) (abi.PieceInfo, error) {
|
2020-03-13 11:59:19 +00:00
|
|
|
return abi.PieceInfo{}, xerrors.New("unsupported")
|
2020-03-11 01:57:52 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 20:08:06 +00:00
|
|
|
func connectRemoteWorker(ctx context.Context, fa api.Common, url string) (*remoteWorker, error) {
|
2020-03-11 05:49:17 +00:00
|
|
|
token, err := fa.AuthNew(ctx, []api.Permission{"admin"})
|
2020-03-11 01:57:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("creating auth token for remote connection: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
headers := http.Header{}
|
|
|
|
headers.Add("Authorization", "Bearer "+string(token))
|
|
|
|
|
2020-03-24 23:49:45 +00:00
|
|
|
wapi, closer, err := client.NewWorkerRPC(url, headers)
|
2020-03-11 01:57:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("creating jsonrpc client: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-03-27 20:08:06 +00:00
|
|
|
return &remoteWorker{wapi, closer}, nil
|
2020-03-24 23:49:45 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 20:08:06 +00:00
|
|
|
func (r *remoteWorker) Close() error {
|
2020-03-24 23:49:45 +00:00
|
|
|
r.closer()
|
|
|
|
return nil
|
2020-03-11 01:57:52 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 20:08:06 +00:00
|
|
|
var _ sectorstorage.Worker = &remoteWorker{}
|