| 
									
										
										
										
											2017-04-14 10:29:00 +02:00
										 |  |  | // Copyright 2017 The go-ethereum Authors | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | // This file is part of the go-ethereum library. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // The go-ethereum library is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  | // it under the terms of the GNU Lesser General Public License as published by | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  | // (at your option) any later version. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // The go-ethereum library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
					
						
							|  |  |  | // GNU Lesser General Public License for more details. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // You should have received a copy of the GNU Lesser General Public License | 
					
						
							|  |  |  | // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package client | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 	"bytes" | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | 	"io/ioutil" | 
					
						
							|  |  |  | 	"os" | 
					
						
							|  |  |  | 	"path/filepath" | 
					
						
							|  |  |  | 	"reflect" | 
					
						
							|  |  |  | 	"sort" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | 	"github.com/ethereum/go-ethereum/swarm/storage" | 
					
						
							| 
									
										
										
										
											2018-10-03 09:15:17 +02:00
										 |  |  | 	"github.com/ethereum/go-ethereum/swarm/storage/feed/lookup" | 
					
						
							| 
									
										
											  
											
												Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID. 
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru:  Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
											
										 
											2018-09-28 12:07:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	"github.com/ethereum/go-ethereum/common" | 
					
						
							|  |  |  | 	"github.com/ethereum/go-ethereum/crypto" | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 	"github.com/ethereum/go-ethereum/swarm/api" | 
					
						
							| 
									
										
										
										
											2018-06-20 14:06:27 +02:00
										 |  |  | 	swarmhttp "github.com/ethereum/go-ethereum/swarm/api/http" | 
					
						
							| 
									
										
										
										
											2018-10-03 09:15:17 +02:00
										 |  |  | 	"github.com/ethereum/go-ethereum/swarm/storage/feed" | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 15:21:14 +07:00
										 |  |  | func serverFunc(api *api.API) swarmhttp.TestServer { | 
					
						
							| 
									
										
										
										
											2018-07-12 15:42:45 +02:00
										 |  |  | 	return swarmhttp.NewServer(api, "") | 
					
						
							| 
									
										
										
										
											2018-06-20 14:06:27 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | // TestClientUploadDownloadRaw test uploading and downloading raw data to swarm | 
					
						
							|  |  |  | func TestClientUploadDownloadRaw(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-06-20 14:06:27 +02:00
										 |  |  | 	testClientUploadDownloadRaw(false, t) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | func TestClientUploadDownloadRawEncrypted(t *testing.T) { | 
					
						
							|  |  |  | 	testClientUploadDownloadRaw(true, t) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func testClientUploadDownloadRaw(toEncrypt bool, t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-11-14 15:21:14 +07:00
										 |  |  | 	srv := swarmhttp.NewTestSwarmServer(t, serverFunc, nil) | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | 	defer srv.Close() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 	client := NewClient(srv.URL) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// upload some raw data | 
					
						
							|  |  |  | 	data := []byte("foo123") | 
					
						
							| 
									
										
										
										
											2018-06-20 14:06:27 +02:00
										 |  |  | 	hash, err := client.UploadRaw(bytes.NewReader(data), int64(len(data)), toEncrypt) | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// check we can download the same data | 
					
						
							| 
									
										
										
										
											2018-06-20 14:06:27 +02:00
										 |  |  | 	res, isEncrypted, err := client.DownloadRaw(hash) | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-20 14:06:27 +02:00
										 |  |  | 	if isEncrypted != toEncrypt { | 
					
						
							|  |  |  | 		t.Fatalf("Expected encyption status %v got %v", toEncrypt, isEncrypted) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 	defer res.Close() | 
					
						
							|  |  |  | 	gotData, err := ioutil.ReadAll(res) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if !bytes.Equal(gotData, data) { | 
					
						
							|  |  |  | 		t.Fatalf("expected downloaded data to be %q, got %q", data, gotData) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TestClientUploadDownloadFiles test uploading and downloading files to swarm | 
					
						
							|  |  |  | // manifests | 
					
						
							|  |  |  | func TestClientUploadDownloadFiles(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-06-20 14:06:27 +02:00
										 |  |  | 	testClientUploadDownloadFiles(false, t) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestClientUploadDownloadFilesEncrypted(t *testing.T) { | 
					
						
							|  |  |  | 	testClientUploadDownloadFiles(true, t) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func testClientUploadDownloadFiles(toEncrypt bool, t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-11-14 15:21:14 +07:00
										 |  |  | 	srv := swarmhttp.NewTestSwarmServer(t, serverFunc, nil) | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 	defer srv.Close() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	client := NewClient(srv.URL) | 
					
						
							|  |  |  | 	upload := func(manifest, path string, data []byte) string { | 
					
						
							|  |  |  | 		file := &File{ | 
					
						
							|  |  |  | 			ReadCloser: ioutil.NopCloser(bytes.NewReader(data)), | 
					
						
							|  |  |  | 			ManifestEntry: api.ManifestEntry{ | 
					
						
							|  |  |  | 				Path:        path, | 
					
						
							|  |  |  | 				ContentType: "text/plain", | 
					
						
							|  |  |  | 				Size:        int64(len(data)), | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-06-20 14:06:27 +02:00
										 |  |  | 		hash, err := client.Upload(file, manifest, toEncrypt) | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			t.Fatal(err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return hash | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	checkDownload := func(manifest, path string, expected []byte) { | 
					
						
							|  |  |  | 		file, err := client.Download(manifest, path) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			t.Fatal(err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		defer file.Close() | 
					
						
							|  |  |  | 		if file.Size != int64(len(expected)) { | 
					
						
							|  |  |  | 			t.Fatalf("expected downloaded file to be %d bytes, got %d", len(expected), file.Size) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-08-08 20:34:35 +03:00
										 |  |  | 		if file.ContentType != "text/plain" { | 
					
						
							|  |  |  | 			t.Fatalf("expected downloaded file to have type %q, got %q", "text/plain", file.ContentType) | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		data, err := ioutil.ReadAll(file) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			t.Fatal(err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if !bytes.Equal(data, expected) { | 
					
						
							|  |  |  | 			t.Fatalf("expected downloaded data to be %q, got %q", expected, data) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// upload a file to the root of a manifest | 
					
						
							|  |  |  | 	rootData := []byte("some-data") | 
					
						
							|  |  |  | 	rootHash := upload("", "", rootData) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// check we can download the root file | 
					
						
							|  |  |  | 	checkDownload(rootHash, "", rootData) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// upload another file to the same manifest | 
					
						
							|  |  |  | 	otherData := []byte("some-other-data") | 
					
						
							|  |  |  | 	newHash := upload(rootHash, "some/other/path", otherData) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// check we can download both files from the new manifest | 
					
						
							|  |  |  | 	checkDownload(newHash, "", rootData) | 
					
						
							|  |  |  | 	checkDownload(newHash, "some/other/path", otherData) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// replace the root file with different data | 
					
						
							|  |  |  | 	newHash = upload(newHash, "", otherData) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// check both files have the other data | 
					
						
							|  |  |  | 	checkDownload(newHash, "", otherData) | 
					
						
							|  |  |  | 	checkDownload(newHash, "some/other/path", otherData) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var testDirFiles = []string{ | 
					
						
							|  |  |  | 	"file1.txt", | 
					
						
							|  |  |  | 	"file2.txt", | 
					
						
							|  |  |  | 	"dir1/file3.txt", | 
					
						
							|  |  |  | 	"dir1/file4.txt", | 
					
						
							|  |  |  | 	"dir2/file5.txt", | 
					
						
							|  |  |  | 	"dir2/dir3/file6.txt", | 
					
						
							|  |  |  | 	"dir2/dir4/file7.txt", | 
					
						
							|  |  |  | 	"dir2/dir4/file8.txt", | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func newTestDirectory(t *testing.T) string { | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | 	dir, err := ioutil.TempDir("", "swarm-client-test") | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for _, file := range testDirFiles { | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | 		path := filepath.Join(dir, file) | 
					
						
							|  |  |  | 		if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil { | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 			os.RemoveAll(dir) | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | 			t.Fatalf("error creating dir for %s: %s", path, err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 		if err := ioutil.WriteFile(path, []byte(file), 0644); err != nil { | 
					
						
							|  |  |  | 			os.RemoveAll(dir) | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | 			t.Fatalf("error writing file %s: %s", path, err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 	return dir | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TestClientUploadDownloadDirectory tests uploading and downloading a | 
					
						
							|  |  |  | // directory of files to a swarm manifest | 
					
						
							|  |  |  | func TestClientUploadDownloadDirectory(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-11-14 15:21:14 +07:00
										 |  |  | 	srv := swarmhttp.NewTestSwarmServer(t, serverFunc, nil) | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 	defer srv.Close() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dir := newTestDirectory(t) | 
					
						
							|  |  |  | 	defer os.RemoveAll(dir) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// upload the directory | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | 	client := NewClient(srv.URL) | 
					
						
							| 
									
										
										
										
											2018-08-10 16:12:55 +02:00
										 |  |  | 	defaultPath := testDirFiles[0] | 
					
						
							| 
									
										
										
										
											2018-06-20 14:06:27 +02:00
										 |  |  | 	hash, err := client.UploadDirectory(dir, defaultPath, "", false) | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("error uploading directory: %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// check we can download the individual files | 
					
						
							|  |  |  | 	checkDownloadFile := func(path string, expected []byte) { | 
					
						
							|  |  |  | 		file, err := client.Download(hash, path) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			t.Fatal(err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		defer file.Close() | 
					
						
							|  |  |  | 		data, err := ioutil.ReadAll(file) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			t.Fatal(err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if !bytes.Equal(data, expected) { | 
					
						
							|  |  |  | 			t.Fatalf("expected data to be %q, got %q", expected, data) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	for _, file := range testDirFiles { | 
					
						
							|  |  |  | 		checkDownloadFile(file, []byte(file)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// check we can download the default path | 
					
						
							|  |  |  | 	checkDownloadFile("", []byte(testDirFiles[0])) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// check we can download the directory | 
					
						
							|  |  |  | 	tmp, err := ioutil.TempDir("", "swarm-client-test") | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	defer os.RemoveAll(tmp) | 
					
						
							| 
									
										
										
										
											2018-08-15 17:41:52 +02:00
										 |  |  | 	if err := client.DownloadDirectory(hash, "", tmp, ""); err != nil { | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	for _, file := range testDirFiles { | 
					
						
							|  |  |  | 		data, err := ioutil.ReadFile(filepath.Join(tmp, file)) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			t.Fatal(err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if !bytes.Equal(data, []byte(file)) { | 
					
						
							|  |  |  | 			t.Fatalf("expected data to be %q, got %q", file, data) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TestClientFileList tests listing files in a swarm manifest | 
					
						
							|  |  |  | func TestClientFileList(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-06-20 14:06:27 +02:00
										 |  |  | 	testClientFileList(false, t) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestClientFileListEncrypted(t *testing.T) { | 
					
						
							|  |  |  | 	testClientFileList(true, t) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func testClientFileList(toEncrypt bool, t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-11-14 15:21:14 +07:00
										 |  |  | 	srv := swarmhttp.NewTestSwarmServer(t, serverFunc, nil) | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 	defer srv.Close() | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 	dir := newTestDirectory(t) | 
					
						
							|  |  |  | 	defer os.RemoveAll(dir) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	client := NewClient(srv.URL) | 
					
						
							| 
									
										
										
										
											2018-06-20 14:06:27 +02:00
										 |  |  | 	hash, err := client.UploadDirectory(dir, "", "", toEncrypt) | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("error uploading directory: %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ls := func(prefix string) []string { | 
					
						
							| 
									
										
										
										
											2018-08-15 17:41:52 +02:00
										 |  |  | 		list, err := client.List(hash, prefix, "") | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			t.Fatal(err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 		paths := make([]string, 0, len(list.CommonPrefixes)+len(list.Entries)) | 
					
						
							| 
									
										
										
										
											2017-08-08 20:34:35 +03:00
										 |  |  | 		paths = append(paths, list.CommonPrefixes...) | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 		for _, entry := range list.Entries { | 
					
						
							|  |  |  | 			paths = append(paths, entry.Path) | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sort.Strings(paths) | 
					
						
							|  |  |  | 		return paths | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tests := map[string][]string{ | 
					
						
							| 
									
										
										
										
											2017-11-08 11:45:52 +01:00
										 |  |  | 		"":                    {"dir1/", "dir2/", "file1.txt", "file2.txt"}, | 
					
						
							|  |  |  | 		"file":                {"file1.txt", "file2.txt"}, | 
					
						
							|  |  |  | 		"file1":               {"file1.txt"}, | 
					
						
							|  |  |  | 		"file2.txt":           {"file2.txt"}, | 
					
						
							|  |  |  | 		"file12":              {}, | 
					
						
							|  |  |  | 		"dir":                 {"dir1/", "dir2/"}, | 
					
						
							|  |  |  | 		"dir1":                {"dir1/"}, | 
					
						
							|  |  |  | 		"dir1/":               {"dir1/file3.txt", "dir1/file4.txt"}, | 
					
						
							|  |  |  | 		"dir1/file":           {"dir1/file3.txt", "dir1/file4.txt"}, | 
					
						
							|  |  |  | 		"dir1/file3.txt":      {"dir1/file3.txt"}, | 
					
						
							|  |  |  | 		"dir1/file34":         {}, | 
					
						
							|  |  |  | 		"dir2/":               {"dir2/dir3/", "dir2/dir4/", "dir2/file5.txt"}, | 
					
						
							|  |  |  | 		"dir2/file":           {"dir2/file5.txt"}, | 
					
						
							|  |  |  | 		"dir2/dir":            {"dir2/dir3/", "dir2/dir4/"}, | 
					
						
							|  |  |  | 		"dir2/dir3/":          {"dir2/dir3/file6.txt"}, | 
					
						
							|  |  |  | 		"dir2/dir4/":          {"dir2/dir4/file7.txt", "dir2/dir4/file8.txt"}, | 
					
						
							|  |  |  | 		"dir2/dir4/file":      {"dir2/dir4/file7.txt", "dir2/dir4/file8.txt"}, | 
					
						
							|  |  |  | 		"dir2/dir4/file7.txt": {"dir2/dir4/file7.txt"}, | 
					
						
							|  |  |  | 		"dir2/dir4/file78":    {}, | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	for prefix, expected := range tests { | 
					
						
							|  |  |  | 		actual := ls(prefix) | 
					
						
							|  |  |  | 		if !reflect.DeepEqual(actual, expected) { | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 			t.Fatalf("expected prefix %q to return %v, got %v", prefix, expected, actual) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TestClientMultipartUpload tests uploading files to swarm using a multipart | 
					
						
							|  |  |  | // upload | 
					
						
							|  |  |  | func TestClientMultipartUpload(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-11-14 15:21:14 +07:00
										 |  |  | 	srv := swarmhttp.NewTestSwarmServer(t, serverFunc, nil) | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 	defer srv.Close() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// define an uploader which uploads testDirFiles with some data | 
					
						
							|  |  |  | 	data := []byte("some-data") | 
					
						
							|  |  |  | 	uploader := UploaderFunc(func(upload UploadFn) error { | 
					
						
							|  |  |  | 		for _, name := range testDirFiles { | 
					
						
							|  |  |  | 			file := &File{ | 
					
						
							|  |  |  | 				ReadCloser: ioutil.NopCloser(bytes.NewReader(data)), | 
					
						
							|  |  |  | 				ManifestEntry: api.ManifestEntry{ | 
					
						
							|  |  |  | 					Path:        name, | 
					
						
							|  |  |  | 					ContentType: "text/plain", | 
					
						
							|  |  |  | 					Size:        int64(len(data)), | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if err := upload(file); err != nil { | 
					
						
							|  |  |  | 				return err | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// upload the files as a multipart upload | 
					
						
							|  |  |  | 	client := NewClient(srv.URL) | 
					
						
							|  |  |  | 	hash, err := client.MultipartUpload("", uploader) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// check we can download the individual files | 
					
						
							|  |  |  | 	checkDownloadFile := func(path string) { | 
					
						
							|  |  |  | 		file, err := client.Download(hash, path) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			t.Fatal(err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		defer file.Close() | 
					
						
							|  |  |  | 		gotData, err := ioutil.ReadAll(file) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			t.Fatal(err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if !bytes.Equal(gotData, data) { | 
					
						
							|  |  |  | 			t.Fatalf("expected data to be %q, got %q", data, gotData) | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-06 23:22:22 +01:00
										 |  |  | 	for _, file := range testDirFiles { | 
					
						
							|  |  |  | 		checkDownloadFile(file) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-04 23:20:07 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 09:15:17 +02:00
										 |  |  | func newTestSigner() (*feed.GenericSigner, error) { | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	privKey, err := crypto.HexToECDSA("deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef") | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-10-03 09:15:17 +02:00
										 |  |  | 	return feed.NewGenericSigner(privKey), nil | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | // Test the transparent resolving of feed updates with bzz:// scheme | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | // | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | // First upload data to bzz:, and store the Swarm hash to the resulting manifest in a feed update. | 
					
						
							|  |  |  | // This effectively uses a feed to store a pointer to content rather than the content itself | 
					
						
							|  |  |  | // Retrieving the update with the Swarm hash should return the manifest pointing directly to the data | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | // and raw retrieve of that hash should return the data | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | func TestClientBzzWithFeed(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	signer, _ := newTestSigner() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | 	// Initialize a Swarm test server | 
					
						
							| 
									
										
										
										
											2018-11-14 15:21:14 +07:00
										 |  |  | 	srv := swarmhttp.NewTestSwarmServer(t, serverFunc, nil) | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | 	swarmClient := NewClient(srv.URL) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	defer srv.Close() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | 	// put together some data for our test: | 
					
						
							|  |  |  | 	dataBytes := []byte(` | 
					
						
							|  |  |  | 	// | 
					
						
							|  |  |  | 	// Create some data our manifest will point to. Data that could be very big and wouldn't fit in a feed update. | 
					
						
							|  |  |  | 	// So what we are going to do is upload it to Swarm bzz:// and obtain a **manifest hash** pointing to it: | 
					
						
							|  |  |  | 	// | 
					
						
							|  |  |  | 	// MANIFEST HASH --> DATA | 
					
						
							|  |  |  | 	// | 
					
						
							|  |  |  | 	// Then, we store that **manifest hash** into a Swarm Feed update. Once we have done this, | 
					
						
							|  |  |  | 	// we can use the **feed manifest hash** in bzz:// instead, this way: bzz://feed-manifest-hash. | 
					
						
							|  |  |  | 	// | 
					
						
							|  |  |  | 	// FEED MANIFEST HASH --> MANIFEST HASH --> DATA | 
					
						
							|  |  |  | 	// | 
					
						
							|  |  |  | 	// Given that we can update the feed at any time with a new **manifest hash** but the **feed manifest hash** | 
					
						
							|  |  |  | 	// stays constant, we have effectively created a fixed address to changing content. (Applause) | 
					
						
							|  |  |  | 	// | 
					
						
							|  |  |  | 	// FEED MANIFEST HASH (the same) --> MANIFEST HASH(2) --> DATA(2) | 
					
						
							|  |  |  | 	// | 
					
						
							|  |  |  | 	`) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Create a virtual File out of memory containing the above data | 
					
						
							|  |  |  | 	f := &File{ | 
					
						
							|  |  |  | 		ReadCloser: ioutil.NopCloser(bytes.NewReader(dataBytes)), | 
					
						
							|  |  |  | 		ManifestEntry: api.ManifestEntry{ | 
					
						
							|  |  |  | 			ContentType: "text/plain", | 
					
						
							|  |  |  | 			Mode:        0660, | 
					
						
							|  |  |  | 			Size:        int64(len(dataBytes)), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// upload data to bzz:// and retrieve the content-addressed manifest hash, hex-encoded. | 
					
						
							|  |  |  | 	manifestAddressHex, err := swarmClient.Upload(f, "", false) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | 		t.Fatalf("Error creating manifest: %s", err) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | 	// convert the hex-encoded manifest hash to a 32-byte slice | 
					
						
							|  |  |  | 	manifestAddress := common.FromHex(manifestAddressHex) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | 	if len(manifestAddress) != storage.AddressLength { | 
					
						
							|  |  |  | 		t.Fatalf("Something went wrong. Got a hash of an unexpected length. Expected %d bytes. Got %d", storage.AddressLength, len(manifestAddress)) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | 	// Now create a **feed manifest**. For that, we need a topic: | 
					
						
							|  |  |  | 	topic, _ := feed.NewTopic("interesting topic indeed", nil) | 
					
						
							| 
									
										
											  
											
												Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID. 
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru:  Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
											
										 
											2018-09-28 12:07:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | 	// Build a feed request to update data | 
					
						
							|  |  |  | 	request := feed.NewFirstRequest(topic) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Put the 32-byte address of the manifest into the feed update | 
					
						
							|  |  |  | 	request.SetData(manifestAddress) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Sign the update | 
					
						
							|  |  |  | 	if err := request.Sign(signer); err != nil { | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 		t.Fatalf("Error signing update: %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | 	// Publish the update and at the same time request a **feed manifest** to be created | 
					
						
							|  |  |  | 	feedManifestAddressHex, err := swarmClient.CreateFeedWithManifest(request) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 		t.Fatalf("Error creating feed manifest: %s", err) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | 	// Check we have received the exact **feed manifest** to be expected | 
					
						
							|  |  |  | 	// given the topic and user signing the updates: | 
					
						
							|  |  |  | 	correctFeedManifestAddrHex := "747c402e5b9dc715a25a4393147512167bab018a007fad7cdcd9adc7fce1ced2" | 
					
						
							|  |  |  | 	if feedManifestAddressHex != correctFeedManifestAddrHex { | 
					
						
							|  |  |  | 		t.Fatalf("Response feed manifest mismatch, expected '%s', got '%s'", correctFeedManifestAddrHex, feedManifestAddressHex) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 	// Check we get a not found error when trying to get feed updates with a made-up manifest | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | 	_, err = swarmClient.QueryFeed(nil, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb") | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 	if err != ErrNoFeedUpdatesFound { | 
					
						
							|  |  |  | 		t.Fatalf("Expected to receive ErrNoFeedUpdatesFound error. Got: %s", err) | 
					
						
							| 
									
										
											  
											
												Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID. 
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru:  Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
											
										 
											2018-09-28 12:07:17 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | 	// If we query the feed directly we should get **manifest hash** back: | 
					
						
							|  |  |  | 	reader, err := swarmClient.QueryFeed(nil, correctFeedManifestAddrHex) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 		t.Fatalf("Error retrieving feed updates: %s", err) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	defer reader.Close() | 
					
						
							|  |  |  | 	gotData, err := ioutil.ReadAll(reader) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//Check that indeed the **manifest hash** is retrieved | 
					
						
							|  |  |  | 	if !bytes.Equal(manifestAddress, gotData) { | 
					
						
							|  |  |  | 		t.Fatalf("Expected: %v, got %v", manifestAddress, gotData) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 16:10:22 +01:00
										 |  |  | 	// Now the final test we were looking for: Use bzz://<feed-manifest> and that should resolve all manifests | 
					
						
							|  |  |  | 	// and return the original data directly: | 
					
						
							|  |  |  | 	f, err = swarmClient.Download(feedManifestAddressHex, "") | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	gotData, err = ioutil.ReadAll(f) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Check that we get back the original data: | 
					
						
							|  |  |  | 	if !bytes.Equal(dataBytes, gotData) { | 
					
						
							|  |  |  | 		t.Fatalf("Expected: %v, got %v", manifestAddress, gotData) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | // TestClientCreateUpdateFeed will check that feeds can be created and updated via the HTTP client. | 
					
						
							|  |  |  | func TestClientCreateUpdateFeed(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	signer, _ := newTestSigner() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 15:21:14 +07:00
										 |  |  | 	srv := swarmhttp.NewTestSwarmServer(t, serverFunc, nil) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	client := NewClient(srv.URL) | 
					
						
							|  |  |  | 	defer srv.Close() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 	// set raw data for the feed update | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	databytes := []byte("En un lugar de La Mancha, de cuyo nombre no quiero acordarme...") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 	// our feed topic name | 
					
						
							| 
									
										
										
										
											2018-10-03 09:15:17 +02:00
										 |  |  | 	topic, _ := feed.NewTopic("El Quijote", nil) | 
					
						
							|  |  |  | 	createRequest := feed.NewFirstRequest(topic) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID. 
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru:  Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
											
										 
											2018-09-28 12:07:17 +02:00
										 |  |  | 	createRequest.SetData(databytes) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	if err := createRequest.Sign(signer); err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("Error signing update: %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 	feedManifestHash, err := client.CreateFeedWithManifest(createRequest) | 
					
						
							| 
									
										
										
										
											2018-11-07 20:39:08 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 	correctManifestAddrHex := "0e9b645ebc3da167b1d56399adc3276f7a08229301b72a03336be0e7d4b71882" | 
					
						
							|  |  |  | 	if feedManifestHash != correctManifestAddrHex { | 
					
						
							|  |  |  | 		t.Fatalf("Response feed manifest mismatch, expected '%s', got '%s'", correctManifestAddrHex, feedManifestHash) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 	reader, err := client.QueryFeed(nil, correctManifestAddrHex) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 		t.Fatalf("Error retrieving feed updates: %s", err) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	defer reader.Close() | 
					
						
							|  |  |  | 	gotData, err := ioutil.ReadAll(reader) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if !bytes.Equal(databytes, gotData) { | 
					
						
							|  |  |  | 		t.Fatalf("Expected: %v, got %v", databytes, gotData) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// define different data | 
					
						
							|  |  |  | 	databytes = []byte("... no ha mucho tiempo que vivía un hidalgo de los de lanza en astillero ...") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 09:51:11 +02:00
										 |  |  | 	updateRequest, err := client.GetFeedRequest(nil, correctManifestAddrHex) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("Error retrieving update request template: %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID. 
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru:  Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
											
										 
											2018-09-28 12:07:17 +02:00
										 |  |  | 	updateRequest.SetData(databytes) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	if err := updateRequest.Sign(signer); err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("Error signing update: %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 	if err = client.UpdateFeed(updateRequest); err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("Error updating feed: %s", err) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 	reader, err = client.QueryFeed(nil, correctManifestAddrHex) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 		t.Fatalf("Error retrieving feed updates: %s", err) | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	defer reader.Close() | 
					
						
							|  |  |  | 	gotData, err = ioutil.ReadAll(reader) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if !bytes.Equal(databytes, gotData) { | 
					
						
							|  |  |  | 		t.Fatalf("Expected: %v, got %v", databytes, gotData) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 	// now try retrieving feed updates without a manifest | 
					
						
							| 
									
										
											  
											
												Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID. 
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru:  Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
											
										 
											2018-09-28 12:07:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 09:15:17 +02:00
										 |  |  | 	fd := &feed.Feed{ | 
					
						
							| 
									
										
											  
											
												Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID. 
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru:  Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
											
										 
											2018-09-28 12:07:17 +02:00
										 |  |  | 		Topic: topic, | 
					
						
							|  |  |  | 		User:  signer.Address(), | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 09:15:17 +02:00
										 |  |  | 	lookupParams := feed.NewQueryLatest(fd, lookup.NoClue) | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 	reader, err = client.QueryFeed(lookupParams, "") | 
					
						
							| 
									
										
											  
											
												Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID. 
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru:  Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
											
										 
											2018-09-28 12:07:17 +02:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2018-09-30 09:43:10 +02:00
										 |  |  | 		t.Fatalf("Error retrieving feed updates: %s", err) | 
					
						
							| 
									
										
											  
											
												Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID. 
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru:  Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
											
										 
											2018-09-28 12:07:17 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	defer reader.Close() | 
					
						
							|  |  |  | 	gotData, err = ioutil.ReadAll(reader) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if !bytes.Equal(databytes, gotData) { | 
					
						
							|  |  |  | 		t.Fatalf("Expected: %v, got %v", databytes, gotData) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-21 21:49:36 +02:00
										 |  |  | } |