diff --git a/api/api.go b/api/api.go index f959cb455..4b308520c 100644 --- a/api/api.go +++ b/api/api.go @@ -54,7 +54,6 @@ type Common interface { // Version provides information about API provider Version(context.Context) (Version, error) - } // FullNode API is a low-level interface to the Filecoin network full node @@ -111,6 +110,4 @@ type FullNode interface { // Full API is a low-level interface to the Filecoin network storage miner node type StorageMiner interface { Common - - } diff --git a/api/client/client.go b/api/client/client.go index d7b862d94..1bf04d6a2 100644 --- a/api/client/client.go +++ b/api/client/client.go @@ -29,4 +29,4 @@ func NewStorageMinerRPC(addr string, requestHeader http.Header) (api.StorageMine }, requestHeader) return &res, err -} \ No newline at end of file +} diff --git a/api/permissioned.go b/api/permissioned.go index 62603ea79..71c93f8e7 100644 --- a/api/permissioned.go +++ b/api/permissioned.go @@ -27,11 +27,23 @@ func WithPerm(ctx context.Context, perms []string) context.Context { return context.WithValue(ctx, permCtxKey, perms) } -func Permissioned(a FullNode) FullNode { - var out FullNodeStruct +func PermissionedStorMinerAPI(a StorageMiner) StorageMiner { + var out StorageMinerStruct + permissionedAny(a, &out.Internal) + permissionedAny(a, &out.CommonStruct.Internal) + return &out +} - rint := reflect.ValueOf(&out.Internal).Elem() - ra := reflect.ValueOf(a) +func PermissionedFullAPI(a FullNode) FullNode { + var out FullNodeStruct + permissionedAny(a, &out.Internal) + permissionedAny(a, &out.CommonStruct.Internal) + return &out +} + +func permissionedAny(in interface{}, out interface{}) { + rint := reflect.ValueOf(out).Elem() + ra := reflect.ValueOf(in) for f := 0; f < rint.NumField(); f++ { field := rint.Type().Field(f) @@ -81,6 +93,4 @@ func Permissioned(a FullNode) FullNode { })) } - - return &out } diff --git a/api/struct.go b/api/struct.go index 08f03e9f1..d9a629b35 100644 --- a/api/struct.go +++ b/api/struct.go @@ -15,7 +15,7 @@ import ( var _ = AllPermissions type CommonStruct struct { - Internal struct{ + Internal struct { AuthVerify func(ctx context.Context, token string) ([]string, error) `perm:"read"` AuthNew func(ctx context.Context, perms []string) ([]byte, error) `perm:"admin"` @@ -61,8 +61,7 @@ type FullNodeStruct struct { type StorageMinerStruct struct { CommonStruct - Internal struct{ - + Internal struct { } } diff --git a/cmd/lotus-storage-miner/run.go b/cmd/lotus-storage-miner/run.go index 29396b7d8..29f924689 100644 --- a/cmd/lotus-storage-miner/run.go +++ b/cmd/lotus-storage-miner/run.go @@ -68,7 +68,7 @@ var runCmd = &cli.Command{ log.Infof("Remote version %s", v) rpcServer := jsonrpc.NewServer() - rpcServer.Register("Filecoin", minerapi) + rpcServer.Register("Filecoin", api.PermissionedStorMinerAPI(minerapi)) http.Handle("/rpc/v0", rpcServer) return http.ListenAndServe("127.0.0.1:"+cctx.String("api"), http.DefaultServeMux) }, diff --git a/cmd/lotus/rpc.go b/cmd/lotus/rpc.go index 6d22e1f85..096b9b750 100644 --- a/cmd/lotus/rpc.go +++ b/cmd/lotus/rpc.go @@ -7,9 +7,9 @@ import ( "github.com/filecoin-project/go-lotus/lib/jsonrpc" ) -func serveRPC(api api.FullNode, addr string) error { +func serveRPC(a api.FullNode, addr string) error { rpcServer := jsonrpc.NewServer() - rpcServer.Register("Filecoin", api) + rpcServer.Register("Filecoin", api.PermissionedFullAPI(a)) http.Handle("/rpc/v0", rpcServer) return http.ListenAndServe(addr, http.DefaultServeMux) } diff --git a/node/fullapi.go b/node/fullapi.go index fea0f3689..5b79c5020 100644 --- a/node/fullapi.go +++ b/node/fullapi.go @@ -22,10 +22,10 @@ type FullNodeAPI struct { CommonAPI - Chain *chain.ChainStore - PubSub *pubsub.PubSub - Mpool *chain.MessagePool - Wallet *chain.Wallet + Chain *chain.ChainStore + PubSub *pubsub.PubSub + Mpool *chain.MessagePool + Wallet *chain.Wallet } func (a *FullNodeAPI) ChainSubmitBlock(ctx context.Context, blk *chain.BlockMsg) error {