Skip to content

Commit

Permalink
WIP: Support once-encoded messages with the replicated objects
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Dec 14, 2023
1 parent 01bd9e5 commit e600b99
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions client/object_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"math"
"os"
"sync"

"github.com/nspcc-dev/neofs-api-go/v2/acl"
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
Expand Down Expand Up @@ -402,7 +403,45 @@ func (c *Client) ReplicateObject(ctx context.Context, src io.ReadSeeker, signer
return resp.err
}

func ShareReplicatedObject(src io.ReadSeeker) io.ReadSeeker {
return &sharedReplicationMessage{
rs: src,
}
}

type sharedReplicationMessage struct {
rs io.ReadSeeker

mtx sync.Mutex
msg []byte
err error
}

func (x *sharedReplicationMessage) Read(p []byte) (n int, err error) {
return x.rs.Read(p)
}

func (x *sharedReplicationMessage) Seek(offset int64, whence int) (int64, error) {
return x.rs.Seek(offset, whence)
}

func prepareReplicateMessage(src io.ReadSeeker, signer neofscrypto.Signer) ([]byte, error) {
srm, ok := src.(*sharedReplicationMessage)
if !ok {
return newReplicateMessage(src, signer)
}

srm.mtx.Lock()
defer srm.mtx.Unlock()

if srm.msg == nil && srm.err == nil {
srm.msg, srm.err = newReplicateMessage(src, signer)
}

return srm.msg, srm.err
}

func newReplicateMessage(src io.ReadSeeker, signer neofscrypto.Signer) ([]byte, error) {
var objSize int64
var err error
switch v := src.(type) {
Expand Down

0 comments on commit e600b99

Please sign in to comment.