Register miner address from storageminer process
This commit is contained in:
+4
-2
@@ -80,6 +80,7 @@ const (
|
||||
// storage miner
|
||||
HandleDealsKey
|
||||
RunSectorServiceKey
|
||||
RegisterMinerKey
|
||||
|
||||
// daemon
|
||||
ExtractApiKey
|
||||
@@ -238,6 +239,7 @@ func Online() Option {
|
||||
Override(new(*deals.Handler), deals.NewHandler),
|
||||
Override(HandleDealsKey, modules.HandleDeals),
|
||||
Override(RunSectorServiceKey, modules.RunSectorService),
|
||||
Override(RegisterMinerKey, modules.RegisterMiner),
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -306,13 +308,13 @@ func Repo(r repo.Repo) Option {
|
||||
|
||||
Override(new(types.KeyStore), modules.KeyStore),
|
||||
|
||||
Override(new(*modules.APIAlg), modules.APISecret),
|
||||
Override(new(*dtypes.APIAlg), modules.APISecret),
|
||||
)
|
||||
}
|
||||
|
||||
func FullAPI(out *api.FullNode) Option {
|
||||
return func(s *Settings) error {
|
||||
resAPI := &impl.API{}
|
||||
resAPI := &impl.FullNodeAPI{}
|
||||
s.invokes[ExtractApiKey] = fx.Extract(resAPI)
|
||||
*out = resAPI
|
||||
return nil
|
||||
|
||||
+5
-5
@@ -3,6 +3,10 @@ package impl
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/filecoin-project/go-lotus/api"
|
||||
"github.com/filecoin-project/go-lotus/build"
|
||||
"github.com/filecoin-project/go-lotus/node/modules/dtypes"
|
||||
|
||||
"github.com/gbrlsnchs/jwt/v3"
|
||||
"github.com/libp2p/go-libp2p-core/host"
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
@@ -10,16 +14,12 @@ import (
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
"go.uber.org/fx"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-lotus/api"
|
||||
"github.com/filecoin-project/go-lotus/build"
|
||||
"github.com/filecoin-project/go-lotus/node/modules"
|
||||
)
|
||||
|
||||
type CommonAPI struct {
|
||||
fx.In
|
||||
|
||||
APISecret *modules.APIAlg
|
||||
APISecret *dtypes.APIAlg
|
||||
Host host.Host
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
var log = logging.Logger("node")
|
||||
|
||||
type API struct {
|
||||
type FullNodeAPI struct {
|
||||
CommonAPI
|
||||
full.ChainAPI
|
||||
full.ClientAPI
|
||||
@@ -24,8 +24,8 @@ type API struct {
|
||||
Miner *miner.Miner
|
||||
}
|
||||
|
||||
func (a *API) MinerRegister(ctx context.Context, addr address.Address) error {
|
||||
func (a *FullNodeAPI) MinerRegister(ctx context.Context, addr address.Address) error {
|
||||
return a.Miner.Register(addr)
|
||||
}
|
||||
|
||||
var _ api.FullNode = &API{}
|
||||
var _ api.FullNode = &FullNodeAPI{}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/filecoin-project/go-lotus/api"
|
||||
"github.com/filecoin-project/go-lotus/chain/types"
|
||||
"github.com/filecoin-project/go-lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/go-lotus/node/repo"
|
||||
)
|
||||
|
||||
@@ -29,13 +30,11 @@ func RecordValidator(ps peerstore.Peerstore) record.Validator {
|
||||
|
||||
const JWTSecretName = "auth-jwt-private"
|
||||
|
||||
type APIAlg jwt.HMACSHA
|
||||
|
||||
type jwtPayload struct {
|
||||
Allow []string
|
||||
}
|
||||
|
||||
func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*APIAlg, error) {
|
||||
func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*dtypes.APIAlg, error) {
|
||||
key, err := keystore.Get(JWTSecretName)
|
||||
if err != nil {
|
||||
log.Warn("Generating new API secret")
|
||||
@@ -69,5 +68,5 @@ func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*APIAlg, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return (*APIAlg)(jwt.NewHS256(key.PrivateKey)), nil
|
||||
return (*dtypes.APIAlg)(jwt.NewHS256(key.PrivateKey)), nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package dtypes
|
||||
|
||||
import "github.com/gbrlsnchs/jwt/v3"
|
||||
|
||||
type APIAlg jwt.HMACSHA
|
||||
@@ -125,3 +125,18 @@ func StagingDAG(mctx helpers.MetricsCtx, lc fx.Lifecycle, r repo.LockedRepo, rt
|
||||
|
||||
return dag, nil
|
||||
}
|
||||
|
||||
func RegisterMiner(lc fx.Lifecycle, ds dtypes.MetadataDS, api api.FullNode) error {
|
||||
minerAddr, err := minerAddrFromDS(ds)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
log.Infof("registering miner '%s' with full node", minerAddr)
|
||||
return api.MinerRegister(ctx, minerAddr)
|
||||
},
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user