2020-10-22 11:04:46 +00:00
|
|
|
package response
|
|
|
|
|
|
|
|
import (
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/refs"
|
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/session"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/core/netmap"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/services/util"
|
|
|
|
"github.com/TrueCloudLab/frostfs-sdk-go/version"
|
2020-10-22 11:04:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Service represents universal v2 service
|
|
|
|
// that sets response meta header values.
|
|
|
|
type Service struct {
|
2022-05-11 14:58:52 +00:00
|
|
|
version refs.Version
|
2020-10-22 11:04:46 +00:00
|
|
|
|
2020-10-22 11:22:23 +00:00
|
|
|
state netmap.State
|
2020-10-22 11:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewService creates, initializes and returns Service instance.
|
2022-12-30 15:04:24 +00:00
|
|
|
func NewService(nmState netmap.State) *Service {
|
|
|
|
s := &Service{state: nmState}
|
|
|
|
version.Current().WriteToV2(&s.version)
|
|
|
|
return s
|
2020-10-22 11:04:46 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 14:48:50 +00:00
|
|
|
// SetMeta sets adds meta-header to resp.
|
|
|
|
func (s *Service) SetMeta(resp util.ResponseMessage) {
|
2020-10-22 11:04:46 +00:00
|
|
|
meta := new(session.ResponseMetaHeader)
|
2022-12-30 15:04:24 +00:00
|
|
|
meta.SetVersion(&s.version)
|
2022-02-07 13:34:02 +00:00
|
|
|
meta.SetTTL(1) // FIXME: #1160 TTL must be calculated
|
2022-12-30 15:04:24 +00:00
|
|
|
meta.SetEpoch(s.state.CurrentEpoch())
|
2020-10-22 11:04:46 +00:00
|
|
|
|
|
|
|
if origin := resp.GetMetaHeader(); origin != nil {
|
2022-02-07 13:34:02 +00:00
|
|
|
// FIXME: #1160 what if origin is set by local server?
|
2020-10-22 11:04:46 +00:00
|
|
|
meta.SetOrigin(origin)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.SetMetaHeader(meta)
|
|
|
|
}
|