2020-09-22 06:51:47 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
2020-09-29 16:44:59 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
2020-09-22 06:51:47 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type remoteStream struct {
|
|
|
|
prm *Prm
|
|
|
|
|
2020-09-29 16:44:59 +00:00
|
|
|
keyStorage *util.KeyStorage
|
2020-09-22 06:51:47 +00:00
|
|
|
|
|
|
|
addr *network.Address
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *remoteStream) stream(ctx context.Context, ch chan<- []*object.ID) error {
|
2020-09-29 16:44:59 +00:00
|
|
|
key, err := s.keyStorage.GetKey(s.prm.common.SessionToken())
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "(%T) could not receive private key", s)
|
|
|
|
}
|
|
|
|
|
2020-09-24 08:27:14 +00:00
|
|
|
addr, err := s.addr.IPAddrString()
|
2020-09-24 07:37:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-09-22 06:51:47 +00:00
|
|
|
|
2020-09-29 16:44:59 +00:00
|
|
|
c, err := client.New(key,
|
2020-09-22 06:51:47 +00:00
|
|
|
client.WithAddress(addr),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "(%T) could not create SDK client %s", s, addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: add writer parameter to SDK client
|
|
|
|
id, err := c.SearchObject(ctx, new(client.SearchObjectParams).
|
|
|
|
WithContainerID(s.prm.cid).
|
|
|
|
WithSearchFilters(s.prm.query.ToSearchFilters()),
|
|
|
|
client.WithTTL(1), // FIXME: use constant
|
2020-09-29 16:44:59 +00:00
|
|
|
client.WithSession(s.prm.common.SessionToken()),
|
2020-09-22 06:51:47 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "(%T) could not search objects in %s", s, addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
ch <- id
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|