diff --git a/pkg/bee/api/act.go b/pkg/bee/api/act.go index 5b001bfdc..eac830b0e 100644 --- a/pkg/bee/api/act.go +++ b/pkg/bee/api/act.go @@ -28,7 +28,7 @@ func (a *ActService) Download(ctx context.Context, addr swarm.Address, opts *Dow func (a *ActService) Upload(ctx context.Context, name string, data io.Reader, o UploadOptions) (ActUploadResponse, error) { var resp ActUploadResponse h := http.Header{} - h.Add("swarm-postage-batch-id", o.BatchID) + h.Add(postageStampBatchHeader, o.BatchID) h.Add("swarm-deferred-upload", "true") h.Add("content-type", "application/octet-stream") h.Add("Swarm-Act", "true") @@ -43,7 +43,8 @@ func (a *ActService) Upload(ctx context.Context, name string, data io.Reader, o func (a *ActService) AddGrantees(ctx context.Context, name string, data io.Reader, o UploadOptions) (ActGranteesResponse, error) { var resp ActGranteesResponse h := http.Header{} - h.Add("swarm-postage-batch-id", o.BatchID) + h.Add(postageStampBatchHeader, o.BatchID) + h.Add(swarmActHistoryAddress, o.ActHistoryAddress.String()) err := a.client.requestWithHeader(ctx, http.MethodPost, "/"+apiVersion+"/grantee", h, data, &resp) return resp, err } diff --git a/pkg/bee/api/api.go b/pkg/bee/api/api.go index 7d5829a8c..4a86d5e5e 100644 --- a/pkg/bee/api/api.go +++ b/pkg/bee/api/api.go @@ -208,7 +208,6 @@ func (c *Client) requestData(ctx context.Context, method, path string, body io.R if opts != nil && opts.RedundancyFallbackMode != nil { req.Header.Set(swarmRedundancyFallbackMode, strconv.FormatBool(*opts.RedundancyFallbackMode)) } - r, err := c.httpClient.Do(req) if err != nil { return nil, err @@ -313,11 +312,12 @@ func (f roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) { } type UploadOptions struct { - Act bool - Pin bool - Tag uint64 - BatchID string - Direct bool + Act bool + Pin bool + Tag uint64 + BatchID string + Direct bool + ActHistoryAddress swarm.Address } type DownloadOptions struct { diff --git a/pkg/bee/client.go b/pkg/bee/client.go index 9323e1f46..a3114aedd 100644 --- a/pkg/bee/client.go +++ b/pkg/bee/client.go @@ -812,6 +812,7 @@ func (c *Client) PatchActGrantees(ctx context.Context, pf *File, addr swarm.Addr } pf.SetAddress(r.Reference) + pf.SetHistroryAddress(r.HistoryAddress) return nil } diff --git a/pkg/check/act/act.go b/pkg/check/act/act.go index 81ee928b6..fb93da06d 100644 --- a/pkg/check/act/act.go +++ b/pkg/check/act/act.go @@ -32,7 +32,7 @@ func NewDefaultOptions() Options { FileName: "act", FileSize: 1 * 1024, PostageAmount: 420000000, - PostageDepth: 17, + PostageDepth: 20, PostageLabel: "act-label", Seed: 0, } @@ -66,12 +66,43 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int return err } - sortedNodes := cluster.NodeNames() - upNodeName := sortedNodes[0] + for name, node := range cluster.Nodes() { + c.logger.Infof("Node %s: %+v", name, node.Config()) + c.logger.Info("-------------------") + cl := node.Client() + t, _ := cl.Topology(ctx) + c.logger.Infof("Node %s: %+v", name, t) + c.logger.Info("=====================================") + } + + fullNodes := cluster.FullNodeNames() + lightNodes := cluster.LightNodeNames() + + //sortedNodes := cluster.NodeNames() + //upNodeName := sortedNodes[0] + upNodeName := lightNodes[0] upClient := clients[upNodeName] addr, _ := upClient.Addresses(ctx) publisher, _ := swarm.ParseHexAddress(addr.PublicKey) + //nodeName1 := sortedNodes[1] + nodeName1 := fullNodes[0] + client1 := clients[nodeName1] + addr1, _ := client1.Addresses(ctx) + pubk1, _ := swarm.ParseHexAddress(addr1.PublicKey) + + //nodeName2 := sortedNodes[2] + nodeName2 := fullNodes[1] + client2 := clients[nodeName2] + addr2, _ := client2.Addresses(ctx) + pubk2, _ := swarm.ParseHexAddress(addr2.PublicKey) + + //odeName3 := sortedNodes[3] + nodeName3 := fullNodes[2] + client3 := clients[nodeName3] + addr3, _ := client3.Addresses(ctx) + pubk3, _ := swarm.ParseHexAddress(addr3.PublicKey) + rnds := random.PseudoGenerators(o.Seed, 1) fileName := fmt.Sprintf("%s-%s-%d", o.FileName, upNodeName, rnds[0].Int()) @@ -91,50 +122,52 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int } c.logger.Info("ACT file uploaded") - time.Sleep(3 * time.Second) + time.Sleep(5 * time.Second) act := true + fileAddress := file.Address() history := file.HistroryAddress() - timestamp := uint64(2) - // download act file - size, hash, err := upClient.DownloadActFile(ctx, file.Address(), &api.DownloadOptions{Act: &act, ActPublicKey: &publisher, ActHistoryAddress: &history, ActTimestamp: ×tamp}) + size, hash, err := upClient.DownloadActFile(ctx, fileAddress, &api.DownloadOptions{Act: &act, ActPublicKey: &publisher, ActHistoryAddress: &history}) if err != nil { return fmt.Errorf("node %s: %w", upNodeName, err) } if !bytes.Equal(file.Hash(), hash) { - c.logger.Infof("Node %s. ACT file hash not equal. Uploaded size: %d Downloaded size: %d File: %s", upNodeName, file.Size(), size, file.Address().String()) + c.logger.Infof("Node %s. ACT file hash not equal. Uploaded size: %d Downloaded size: %d File: %s", upNodeName, file.Size(), size, fileAddress.String()) return errors.New("ACT file retrieval - hash error") } c.logger.Info("ACT file downloaded") + time.Sleep(5 * time.Second) // download act file with wrong public key - notPublisher, _ := swarm.ParseHexAddress("010101010101010101010101010101010101010101010101010101010101010101") - _, _, notPErr := upClient.DownloadActFile(ctx, file.Address(), &api.DownloadOptions{Act: &act, ActPublicKey: ¬Publisher, ActHistoryAddress: &history, ActTimestamp: ×tamp}) + notPublisher := pubk1 + _, _, notPErr := upClient.DownloadActFile(ctx, file.Address(), &api.DownloadOptions{Act: &act, ActPublicKey: ¬Publisher, ActHistoryAddress: &history}) if notPErr == nil { return fmt.Errorf("node %s: File downloaded with wrong public key successfully - this is an error", upNodeName) } c.logger.Info("ACT Access denied with incorrect public key") + time.Sleep(5 * time.Second) // add grantees list gFile := bee.NewBufferFile("grantees.json", bytes.NewBuffer([]byte(`{ "grantees": [ - "02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12e8", - "02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12e9", - "02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12ee" - ] + "`+pubk2.String()+`", + "`+pubk3.String()+`" + ] }`))) - err = upClient.AddActGrantees(ctx, &gFile, api.UploadOptions{BatchID: batchID}) + fileHis := file.HistroryAddress() + err = upClient.AddActGrantees(ctx, &gFile, api.UploadOptions{BatchID: batchID, ActHistoryAddress: fileHis}) if err != nil { return fmt.Errorf("node %s: add grantees error: %w", upNodeName, err) } c.logger.Info("ACT grantees added") + time.Sleep(5 * time.Second) - time.Sleep(3 * time.Second) + time.Sleep(1 * time.Second) // list grantees addresses, gErr := upClient.GetActGrantees(ctx, gFile.Address()) @@ -144,66 +177,64 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int if addresses == nil { return fmt.Errorf("node %s: GetActGrantees: addresses is nil", upNodeName) } - if len(addresses) != 3 { - return fmt.Errorf("node %s: GetActGrantees: addresses length is not 3", upNodeName) + if len(addresses) != 2 { + return fmt.Errorf("node %s: GetActGrantees: addresses length is not 2", upNodeName) } c.logger.Info("ACT grantees listed") + time.Sleep(5 * time.Second) - // download act file with added grantees - grantees := []string{"02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12e8", - "02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12e9", - "02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12ee"} - - for _, str := range grantees { - gPublisher, _ := swarm.ParseHexAddress(str) - history := file.HistroryAddress() - gSize, gHash, gPErr := upClient.DownloadActFile(ctx, file.Address(), &api.DownloadOptions{Act: &act, ActPublicKey: &gPublisher, ActHistoryAddress: &history, ActTimestamp: ×tamp}) - if gPErr != nil { - return fmt.Errorf("node %s: %w", upNodeName, gPErr) - } - - if !bytes.Equal(file.Hash(), gHash) { - c.logger.Infof("Node %s. ACT file with new grantee hash not equal. Uploaded size: %d Downloaded size: %d File: %s", upNodeName, file.Size(), gSize, file.Address().String()) - return errors.New("ACT file retrieval with new grantee - hash error") + // patch grantees + /* + pFile := bee.NewBufferFile("grantees-patch.json", bytes.NewBuffer([]byte(`{ + "add": [ + "`+pubk1.String()+`" + ], + "revoke": [ + "`+pubk2.String()+`", + "`+pubk3.String()+`" + ] + }`))) + + pErr := upClient.PatchActGrantees(ctx, &pFile, gFile.Address(), gFile.HistroryAddress(), batchID) + if pErr != nil { + return fmt.Errorf("node %s: PatchActGrantees: %w", upNodeName, pErr) } - } - c.logger.Info("ACT file downloaded with new grantees") + c.logger.Info("ACT grantees patched") - // patch grantees - pFile := bee.NewBufferFile("grantees-patch.json", bytes.NewBuffer([]byte(`{ - "add": [ - "02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12e7" - ], - "revoke": [ - "02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12e9", - "02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12ee" - ] - }`))) - - pErr := upClient.PatchActGrantees(ctx, &pFile, gFile.Address(), gFile.HistroryAddress(), batchID) - if pErr != nil { - return fmt.Errorf("node %s: PatchActGrantees: %w", upNodeName, pErr) + // list grantees after patch + patchAddresses, patchErr := upClient.GetActGrantees(ctx, pFile.Address()) + if patchErr != nil { + return fmt.Errorf("node %s: GetActGrantees after patch: %w", upNodeName, patchErr) + } + if patchAddresses == nil { + return fmt.Errorf("node %s: GetActGrantees after patch: addresses is nil", upNodeName) + } + if len(patchAddresses) != 1 { + return fmt.Errorf("node %s: GetActGrantees after patch: addresses length is not 1", upNodeName) + } + c.logger.Info("ACT grantees listed after patch") + */ + // download act file + his := gFile.HistroryAddress() + c.logger.Infof("ACT file download started: %s", fileAddress.String()) + _, _, err1 := client2.DownloadActFile(ctx, fileAddress, &api.DownloadOptions{Act: &act, ActPublicKey: &publisher, ActHistoryAddress: &his}) + if err1 != nil { + return fmt.Errorf("node %s: %w", nodeName1, err1) } - c.logger.Info("ACT grantees patched") - - time.Sleep(3 * time.Second) + return errors.New("ACT file retrieval - hash error") + /* + if !bytes.Equal(file.Hash(), hash1) { + c.logger.Infof("Node %s. ACT file hash not equal. Uploaded size: %d Downloaded size: %d File: %s", nodeName1, file.Size(), size1, file.Address().String()) + return errors.New("ACT file retrieval - hash error") + } - // list grantees after patch - patchAddresses, patchErr := upClient.GetActGrantees(ctx, pFile.Address()) - if patchErr != nil { - return fmt.Errorf("node %s: GetActGrantees after patch: %w", upNodeName, patchErr) - } - if patchAddresses == nil { - return fmt.Errorf("node %s: GetActGrantees after patch: addresses is nil", upNodeName) - } - if len(patchAddresses) != 2 { - return fmt.Errorf("node %s: GetActGrantees after patch: addresses length is not 2", upNodeName) - } + c.logger.Info("ACT file downloaded with grantee") - c.logger.Info("ACT test completed") + c.logger.Info("ACT test completed") - return + return + */ }