lotus/node/impl/remoteworker.go

50 lines
1.2 KiB
Go
Raw Normal View History

package impl
2020-03-11 01:57:52 +00:00
import (
"context"
"net/http"
"golang.org/x/xerrors"
2020-05-20 18:23:51 +00:00
"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/go-jsonrpc/auth"
2020-03-11 01:57:52 +00:00
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/client"
2020-08-17 13:39:33 +00:00
sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage"
2020-03-11 01:57:52 +00:00
)
type remoteWorker struct {
api.WorkerAPI
2020-03-24 23:49:45 +00:00
closer jsonrpc.ClientCloser
2020-03-11 01:57:52 +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")
}
func connectRemoteWorker(ctx context.Context, fa api.Common, url string) (*remoteWorker, error) {
2020-05-20 18:23:51 +00:00
token, err := fa.AuthNew(ctx, []auth.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)
}
return &remoteWorker{wapi, closer}, nil
2020-03-24 23:49:45 +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
}
var _ sectorstorage.Worker = &remoteWorker{}