[#193] getsvc: Edit request forwarder signature
Pass context to forwarder direct, without closure. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
6c7b708a98
commit
89924071cd
6 changed files with 11 additions and 17 deletions
|
@ -59,7 +59,7 @@ type RangeHashPrm struct {
|
|||
salt []byte
|
||||
}
|
||||
|
||||
type RequestForwarder func(coreclient.NodeInfo, coreclient.MultiAddressClient) (*object.Object, error)
|
||||
type RequestForwarder func(context.Context, coreclient.NodeInfo, coreclient.MultiAddressClient) (*object.Object, error)
|
||||
|
||||
// HeadPrm groups parameters of Head service call.
|
||||
type HeadPrm struct {
|
||||
|
|
|
@ -89,7 +89,7 @@ func (c *clientCacheWrapper) get(info coreclient.NodeInfo) (getClient, error) {
|
|||
|
||||
func (c *clientWrapper) getObject(ctx context.Context, exec *execCtx, info coreclient.NodeInfo) (*object.Object, error) {
|
||||
if exec.isForwardingEnabled() {
|
||||
return exec.prm.forwarder(info, c.client)
|
||||
return exec.prm.forwarder(ctx, info, c.client)
|
||||
}
|
||||
|
||||
key, err := exec.key()
|
||||
|
|
|
@ -29,7 +29,7 @@ type getRequestForwarder struct {
|
|||
Stream *streamObjectWriter
|
||||
}
|
||||
|
||||
func (f *getRequestForwarder) forward(ctx context.Context, addr network.Address, c client.MultiAddressClient, pubkey []byte) (*object.Object, error) {
|
||||
func (f *getRequestForwarder) forwardRequestToNode(ctx context.Context, addr network.Address, c client.MultiAddressClient, pubkey []byte) (*object.Object, error) {
|
||||
key, err := f.KeyStorage.GetKey(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -28,7 +28,7 @@ type getRangeRequestForwarder struct {
|
|||
Stream *streamObjectRangeWriter
|
||||
}
|
||||
|
||||
func (f *getRangeRequestForwarder) forward(ctx context.Context, addr network.Address, c client.MultiAddressClient, pubkey []byte) (*object.Object, error) {
|
||||
func (f *getRangeRequestForwarder) forwardRequestToNode(ctx context.Context, addr network.Address, c client.MultiAddressClient, pubkey []byte) (*object.Object, error) {
|
||||
key, err := f.KeyStorage.GetKey(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -29,7 +29,7 @@ type headRequestForwarder struct {
|
|||
KeyStorage *util.KeyStorage
|
||||
}
|
||||
|
||||
func (f *headRequestForwarder) forward(ctx context.Context, addr network.Address, c client.MultiAddressClient, pubkey []byte) (*object.Object, error) {
|
||||
func (f *headRequestForwarder) forwardRequestToNode(ctx context.Context, addr network.Address, c client.MultiAddressClient, pubkey []byte) (*object.Object, error) {
|
||||
var err error
|
||||
|
||||
key, err := f.KeyStorage.GetKey(nil)
|
||||
|
|
|
@ -65,9 +65,7 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre
|
|||
Stream: streamWrapper,
|
||||
}
|
||||
|
||||
p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.MultiAddressClient, pubkey []byte) (*object.Object, error) {
|
||||
return forwarder.forward(stream.Context(), addr, c, pubkey)
|
||||
}))
|
||||
p.SetRequestForwarder(groupAddressRequestForwarder(forwarder.forwardRequestToNode))
|
||||
}
|
||||
|
||||
return p, nil
|
||||
|
@ -117,9 +115,7 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get
|
|||
Stream: streamWrapper,
|
||||
}
|
||||
|
||||
p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.MultiAddressClient, pubkey []byte) (*object.Object, error) {
|
||||
return forwarder.forward(stream.Context(), addr, c, pubkey)
|
||||
}))
|
||||
p.SetRequestForwarder(groupAddressRequestForwarder(forwarder.forwardRequestToNode))
|
||||
}
|
||||
|
||||
return p, nil
|
||||
|
@ -251,9 +247,7 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp
|
|||
KeyStorage: s.keyStorage,
|
||||
}
|
||||
|
||||
p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.MultiAddressClient, pubkey []byte) (*object.Object, error) {
|
||||
return forwarder.forward(ctx, addr, c, pubkey)
|
||||
}))
|
||||
p.SetRequestForwarder(groupAddressRequestForwarder(forwarder.forwardRequestToNode))
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
@ -321,8 +315,8 @@ func toShortObjectHeader(hdr *object.Object) objectV2.GetHeaderPart {
|
|||
return sh
|
||||
}
|
||||
|
||||
func groupAddressRequestForwarder(f func(network.Address, client.MultiAddressClient, []byte) (*object.Object, error)) getsvc.RequestForwarder {
|
||||
return func(info client.NodeInfo, c client.MultiAddressClient) (*object.Object, error) {
|
||||
func groupAddressRequestForwarder(f func(context.Context, network.Address, client.MultiAddressClient, []byte) (*object.Object, error)) getsvc.RequestForwarder {
|
||||
return func(ctx context.Context, info client.NodeInfo, c client.MultiAddressClient) (*object.Object, error) {
|
||||
var (
|
||||
firstErr error
|
||||
res *object.Object
|
||||
|
@ -343,7 +337,7 @@ func groupAddressRequestForwarder(f func(network.Address, client.MultiAddressCli
|
|||
// would be nice to log otherwise
|
||||
}()
|
||||
|
||||
res, err = f(addr, c, key)
|
||||
res, err = f(ctx, addr, c, key)
|
||||
|
||||
return
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue