Skip to content

Commit

Permalink
neofs: Add maxObjectSize as parameter in constructor
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed Aug 11, 2023
1 parent 8ecf334 commit fe4f585
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
8 changes: 7 additions & 1 deletion cmd/s3-authmate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/nspcc-dev/neofs-s3-gw/internal/neofs"
"github.com/nspcc-dev/neofs-s3-gw/internal/version"
"github.com/nspcc-dev/neofs-s3-gw/internal/wallet"
"github.com/nspcc-dev/neofs-sdk-go/client"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/nspcc-dev/neofs-sdk-go/pool"
"github.com/nspcc-dev/neofs-sdk-go/user"
Expand Down Expand Up @@ -720,7 +721,12 @@ func createNeoFS(ctx context.Context, log *zap.Logger, cfg PoolConfig, anonSigne
return nil, fmt.Errorf("dial pool: %w", err)
}

neoFS := neofs.NewNeoFS(p, signer, anonSigner)
ni, err := p.NetworkInfo(ctx, client.PrmNetworkInfo{})
if err != nil {
return nil, fmt.Errorf("networkInfo: %w", err)
}

neoFS := neofs.NewNeoFS(p, signer, anonSigner, int64(ni.MaxObjectSize()))

return neofs.NewAuthmateNeoFS(neoFS), nil
}
15 changes: 13 additions & 2 deletions cmd/s3-gw/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/nspcc-dev/neofs-s3-gw/internal/neofs"
"github.com/nspcc-dev/neofs-s3-gw/internal/version"
"github.com/nspcc-dev/neofs-s3-gw/internal/wallet"
"github.com/nspcc-dev/neofs-sdk-go/client"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
"github.com/nspcc-dev/neofs-sdk-go/pool"
"github.com/nspcc-dev/neofs-sdk-go/stat"
Expand Down Expand Up @@ -100,7 +101,12 @@ func newApp(ctx context.Context, log *Logger, v *viper.Viper) *App {
anonSigner := user.NewAutoIDSignerRFC6979(anonKey.PrivateKey)
log.logger.Info("anonymous signer", zap.String("userID", anonSigner.UserID().String()))

neoFS := neofs.NewNeoFS(conns, signer, anonSigner)
ni, err := conns.NetworkInfo(ctx, client.PrmNetworkInfo{})
if err != nil {
log.logger.Fatal("newApp: networkInfo", zap.Error(err))
}

neoFS := neofs.NewNeoFS(conns, signer, anonSigner, int64(ni.MaxObjectSize()))

// prepare auth center
ctr := auth.New(neofs.NewAuthmateNeoFS(neoFS), key, v.GetStringSlice(cfgAllowedAccessKeyIDPrefixes), getAccessBoxCacheConfig(v, log.logger))
Expand Down Expand Up @@ -151,8 +157,13 @@ func (a *App) initLayer(ctx context.Context, anonSigner user.Signer) {

signer := user.NewAutoIDSignerRFC6979(a.gateKey.PrivateKey)

ni, err := a.pool.NetworkInfo(ctx, client.PrmNetworkInfo{})
if err != nil {
a.log.Fatal("initLayer: networkInfo", zap.Error(err))
}

// prepare object layer
a.obj = layer.NewLayer(a.log, neofs.NewNeoFS(a.pool, signer, anonSigner), layerCfg)
a.obj = layer.NewLayer(a.log, neofs.NewNeoFS(a.pool, signer, anonSigner, int64(ni.MaxObjectSize())), layerCfg)

if a.cfg.GetBool(cfgEnableNATS) {
nopts := getNotificationsOptions(a.cfg, a.log)
Expand Down
23 changes: 10 additions & 13 deletions internal/neofs/neofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ import (
// It is used to provide an interface to dependent packages
// which work with NeoFS.
type NeoFS struct {
pool *pool.Pool
gateSigner user.Signer
anonSigner user.Signer
pool *pool.Pool
gateSigner user.Signer
anonSigner user.Signer
maxObjectSize int64
}

// NewNeoFS creates new NeoFS using provided pool.Pool.
func NewNeoFS(p *pool.Pool, signer user.Signer, anonSigner user.Signer) *NeoFS {
func NewNeoFS(p *pool.Pool, signer user.Signer, anonSigner user.Signer, maxObjectSize int64) *NeoFS {

Check warning on line 44 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L44

Added line #L44 was not covered by tests
return &NeoFS{
pool: p,
gateSigner: signer,
anonSigner: anonSigner,
pool: p,
gateSigner: signer,
anonSigner: anonSigner,
maxObjectSize: maxObjectSize,
}

Check warning on line 50 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L46-L50

Added lines #L46 - L50 were not covered by tests
}

Expand Down Expand Up @@ -214,11 +216,6 @@ func (x *NeoFS) DeleteContainer(ctx context.Context, id cid.ID, token *session.C

// CreateObject implements neofs.NeoFS interface method.
func (x *NeoFS) CreateObject(ctx context.Context, prm layer.PrmObjectCreate) (oid.ID, error) {
ni, err := x.pool.NetworkInfo(ctx, client.PrmNetworkInfo{})
if err != nil {
return oid.ID{}, fmt.Errorf("networkInfo: %w", err)
}

attrNum := len(prm.Attributes) + 1 // + creation time

if prm.Filepath != "" {
Expand Down Expand Up @@ -284,7 +281,7 @@ func (x *NeoFS) CreateObject(ctx context.Context, prm layer.PrmObjectCreate) (oi
var idObj oid.ID

for {
_, err = io.CopyN(writer, prm.Payload, int64(ni.MaxObjectSize()))
_, err = io.CopyN(writer, prm.Payload, x.maxObjectSize)
if err == nil {
continue

Check warning on line 286 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L281-L286

Added lines #L281 - L286 were not covered by tests
}
Expand Down

0 comments on commit fe4f585

Please sign in to comment.