diff options
author | Javier Peletier <jm@epiclabs.io> | 2018-09-30 15:43:10 +0800 |
---|---|---|
committer | Javier Peletier <jm@epiclabs.io> | 2018-10-03 15:12:06 +0800 |
commit | 83705ef6aa3645a6305a400fa175e44904a929f7 (patch) | |
tree | 013c6594b7d275ab5eaa90b3969e77719787483f /swarm/api/client | |
parent | b35622cf3c758d96874f287d137725946fc6341d (diff) | |
download | dexon-83705ef6aa3645a6305a400fa175e44904a929f7.tar dexon-83705ef6aa3645a6305a400fa175e44904a929f7.tar.gz dexon-83705ef6aa3645a6305a400fa175e44904a929f7.tar.bz2 dexon-83705ef6aa3645a6305a400fa175e44904a929f7.tar.lz dexon-83705ef6aa3645a6305a400fa175e44904a929f7.tar.xz dexon-83705ef6aa3645a6305a400fa175e44904a929f7.tar.zst dexon-83705ef6aa3645a6305a400fa175e44904a929f7.zip |
swarm/storage/mru: Renamed rest of MRU references
Diffstat (limited to 'swarm/api/client')
-rw-r--r-- | swarm/api/client/client.go | 57 | ||||
-rw-r--r-- | swarm/api/client/client_test.go | 70 |
2 files changed, 63 insertions, 64 deletions
diff --git a/swarm/api/client/client.go b/swarm/api/client/client.go index 47a6980de..76ada1297 100644 --- a/swarm/api/client/client.go +++ b/swarm/api/client/client.go @@ -601,16 +601,15 @@ func (c *Client) MultipartUpload(hash string, uploader Uploader) (string, error) return string(data), nil } -// ErrNoResourceUpdatesFound is returned when Swarm cannot find updates of the given resource -var ErrNoResourceUpdatesFound = errors.New("No updates found for this resource") +// ErrNoFeedUpdatesFound is returned when Swarm cannot find updates of the given feed +var ErrNoFeedUpdatesFound = errors.New("No updates found for this feed") -// CreateResource creates a Mutable Resource with the given name and frequency, initializing it with the provided -// data. Data is interpreted as multihash or not depending on the multihash parameter. -// startTime=0 means "now" -// Returns the resulting Mutable Resource manifest address that you can use to include in an ENS Resolver (setContent) -// or reference future updates (Client.UpdateResource) -func (c *Client) CreateResource(request *mru.Request) (string, error) { - responseStream, err := c.updateResource(request, true) +// CreateFeedWithManifest creates a Feed Manifest, initializing it with the provided +// data +// Returns the resulting Feed Manifest address that you can use to include in an ENS Resolver (setContent) +// or reference future updates (Client.UpdateFeed) +func (c *Client) CreateFeedWithManifest(request *mru.Request) (string, error) { + responseStream, err := c.updateFeed(request, true) if err != nil { return "", err } @@ -628,18 +627,18 @@ func (c *Client) CreateResource(request *mru.Request) (string, error) { return manifestAddress, nil } -// UpdateResource allows you to set a new version of your content -func (c *Client) UpdateResource(request *mru.Request) error { - _, err := c.updateResource(request, false) +// UpdateFeed allows you to set a new version of your content +func (c *Client) UpdateFeed(request *mru.Request) error { + _, err := c.updateFeed(request, false) return err } -func (c *Client) updateResource(request *mru.Request, createManifest bool) (io.ReadCloser, error) { +func (c *Client) updateFeed(request *mru.Request, createManifest bool) (io.ReadCloser, error) { URL, err := url.Parse(c.Gateway) if err != nil { return nil, err } - URL.Path = "/bzz-resource:/" + URL.Path = "/bzz-feed:/" values := URL.Query() body := request.AppendValues(values) if createManifest { @@ -660,23 +659,23 @@ func (c *Client) updateResource(request *mru.Request, createManifest bool) (io.R return res.Body, nil } -// GetResource returns a byte stream with the raw content of the resource -// manifestAddressOrDomain is the address you obtained in CreateResource or an ENS domain whose Resolver +// QueryFeed returns a byte stream with the raw content of the feed update +// manifestAddressOrDomain is the address you obtained in CreateFeedWithManifest or an ENS domain whose Resolver // points to that address -func (c *Client) GetResource(query *mru.Query, manifestAddressOrDomain string) (io.ReadCloser, error) { - return c.getResource(query, manifestAddressOrDomain, false) +func (c *Client) QueryFeed(query *mru.Query, manifestAddressOrDomain string) (io.ReadCloser, error) { + return c.queryFeed(query, manifestAddressOrDomain, false) } -// getResource returns a byte stream with the raw content of the resource -// manifestAddressOrDomain is the address you obtained in CreateResource or an ENS domain whose Resolver +// queryFeed returns a byte stream with the raw content of the feed update +// manifestAddressOrDomain is the address you obtained in CreateFeedWithManifest or an ENS domain whose Resolver // points to that address -// meta set to true will instruct the node return resource metainformation instead -func (c *Client) getResource(query *mru.Query, manifestAddressOrDomain string, meta bool) (io.ReadCloser, error) { +// meta set to true will instruct the node return Feed metainformation instead +func (c *Client) queryFeed(query *mru.Query, manifestAddressOrDomain string, meta bool) (io.ReadCloser, error) { URL, err := url.Parse(c.Gateway) if err != nil { return nil, err } - URL.Path = "/bzz-resource:/" + manifestAddressOrDomain + URL.Path = "/bzz-feed:/" + manifestAddressOrDomain values := URL.Query() if query != nil { query.AppendValues(values) //adds query parameters @@ -692,7 +691,7 @@ func (c *Client) getResource(query *mru.Query, manifestAddressOrDomain string, m if res.StatusCode != http.StatusOK { if res.StatusCode == http.StatusNotFound { - return nil, ErrNoResourceUpdatesFound + return nil, ErrNoFeedUpdatesFound } errorMessageBytes, err := ioutil.ReadAll(res.Body) var errorMessage string @@ -701,18 +700,18 @@ func (c *Client) getResource(query *mru.Query, manifestAddressOrDomain string, m } else { errorMessage = string(errorMessageBytes) } - return nil, fmt.Errorf("Error retrieving resource: %s", errorMessage) + return nil, fmt.Errorf("Error retrieving feed updates: %s", errorMessage) } return res.Body, nil } -// GetResourceMetadata returns a structure that describes the Mutable Resource -// manifestAddressOrDomain is the address you obtained in CreateResource or an ENS domain whose Resolver +// GetFeedMetadata returns a structure that describes the referenced Feed status +// manifestAddressOrDomain is the address you obtained in CreateFeedWithManifest or an ENS domain whose Resolver // points to that address -func (c *Client) GetResourceMetadata(query *mru.Query, manifestAddressOrDomain string) (*mru.Request, error) { +func (c *Client) GetFeedMetadata(query *mru.Query, manifestAddressOrDomain string) (*mru.Request, error) { - responseStream, err := c.getResource(query, manifestAddressOrDomain, true) + responseStream, err := c.queryFeed(query, manifestAddressOrDomain, true) if err != nil { return nil, err } diff --git a/swarm/api/client/client_test.go b/swarm/api/client/client_test.go index c6ad0237b..fbc49a6e1 100644 --- a/swarm/api/client/client_test.go +++ b/swarm/api/client/client_test.go @@ -369,12 +369,12 @@ func newTestSigner() (*mru.GenericSigner, error) { return mru.NewGenericSigner(privKey), nil } -// test the transparent resolving of multihash resource types with bzz:// scheme +// test the transparent resolving of multihash feed updates with bzz:// scheme // -// first upload data, and store the multihash to the resulting manifest in a resource update +// first upload data, and store the multihash to the resulting manifest in a feed update // retrieving the update with the multihash should return the manifest pointing directly to the data // and raw retrieve of that hash should return the data -func TestClientCreateResourceMultihash(t *testing.T) { +func TestClientCreateFeedMultihash(t *testing.T) { signer, _ := newTestSigner() @@ -393,7 +393,7 @@ func TestClientCreateResourceMultihash(t *testing.T) { s := common.FromHex(swarmHash) mh := multihash.ToMultihash(s) - // our mutable resource topic + // our feed topic topic, _ := mru.NewTopic("foo.eth", nil) createRequest := mru.NewFirstRequest(topic) @@ -403,26 +403,26 @@ func TestClientCreateResourceMultihash(t *testing.T) { t.Fatalf("Error signing update: %s", err) } - resourceManifestHash, err := client.CreateResource(createRequest) + feedManifestHash, err := client.CreateFeedWithManifest(createRequest) if err != nil { - t.Fatalf("Error creating resource: %s", err) + t.Fatalf("Error creating feed manifest: %s", err) } - correctManifestAddrHex := "6ef40ba1492cf2a029dc9a8b5896c822cf689d3cd010842f4f1744e6db8824bd" - if resourceManifestHash != correctManifestAddrHex { - t.Fatalf("Response resource manifest mismatch, expected '%s', got '%s'", correctManifestAddrHex, resourceManifestHash) + correctManifestAddrHex := "bb056a5264c295c2b0f613c8409b9c87ce9d71576ace02458160df4cc894210b" + if feedManifestHash != correctManifestAddrHex { + t.Fatalf("Response feed manifest mismatch, expected '%s', got '%s'", correctManifestAddrHex, feedManifestHash) } - // Check we get a not found error when trying to get the resource with a made-up manifest - _, err = client.GetResource(nil, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb") - if err != ErrNoResourceUpdatesFound { - t.Fatalf("Expected to receive ErrNoResourceUpdatesFound error. Got: %s", err) + // Check we get a not found error when trying to get feed updates with a made-up manifest + _, err = client.QueryFeed(nil, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb") + if err != ErrNoFeedUpdatesFound { + t.Fatalf("Expected to receive ErrNoFeedUpdatesFound error. Got: %s", err) } - reader, err := client.GetResource(nil, correctManifestAddrHex) + reader, err := client.QueryFeed(nil, correctManifestAddrHex) if err != nil { - t.Fatalf("Error retrieving resource: %s", err) + t.Fatalf("Error retrieving feed updates: %s", err) } defer reader.Close() gotData, err := ioutil.ReadAll(reader) @@ -435,8 +435,8 @@ func TestClientCreateResourceMultihash(t *testing.T) { } -// TestClientCreateUpdateResource will check that mutable resources can be created and updated via the HTTP client. -func TestClientCreateUpdateResource(t *testing.T) { +// TestClientCreateUpdateFeed will check that feeds can be created and updated via the HTTP client. +func TestClientCreateUpdateFeed(t *testing.T) { signer, _ := newTestSigner() @@ -444,10 +444,10 @@ func TestClientCreateUpdateResource(t *testing.T) { client := NewClient(srv.URL) defer srv.Close() - // set raw data for the resource + // set raw data for the feed update databytes := []byte("En un lugar de La Mancha, de cuyo nombre no quiero acordarme...") - // our mutable resource name + // our feed topic name topic, _ := mru.NewTopic("El Quijote", nil) createRequest := mru.NewFirstRequest(topic) @@ -456,16 +456,16 @@ func TestClientCreateUpdateResource(t *testing.T) { t.Fatalf("Error signing update: %s", err) } - resourceManifestHash, err := client.CreateResource(createRequest) + feedManifestHash, err := client.CreateFeedWithManifest(createRequest) - correctManifestAddrHex := "fcb8e75f53e480e197c083ad1976d265674d0ce776f2bf359c09c413fb5230b8" - if resourceManifestHash != correctManifestAddrHex { - t.Fatalf("Response resource manifest mismatch, expected '%s', got '%s'", correctManifestAddrHex, resourceManifestHash) + correctManifestAddrHex := "0e9b645ebc3da167b1d56399adc3276f7a08229301b72a03336be0e7d4b71882" + if feedManifestHash != correctManifestAddrHex { + t.Fatalf("Response feed manifest mismatch, expected '%s', got '%s'", correctManifestAddrHex, feedManifestHash) } - reader, err := client.GetResource(nil, correctManifestAddrHex) + reader, err := client.QueryFeed(nil, correctManifestAddrHex) if err != nil { - t.Fatalf("Error retrieving resource: %s", err) + t.Fatalf("Error retrieving feed updates: %s", err) } defer reader.Close() gotData, err := ioutil.ReadAll(reader) @@ -479,7 +479,7 @@ func TestClientCreateUpdateResource(t *testing.T) { // define different data databytes = []byte("... no ha mucho tiempo que vivĂa un hidalgo de los de lanza en astillero ...") - updateRequest, err := client.GetResourceMetadata(nil, correctManifestAddrHex) + updateRequest, err := client.GetFeedMetadata(nil, correctManifestAddrHex) if err != nil { t.Fatalf("Error retrieving update request template: %s", err) } @@ -489,13 +489,13 @@ func TestClientCreateUpdateResource(t *testing.T) { t.Fatalf("Error signing update: %s", err) } - if err = client.UpdateResource(updateRequest); err != nil { - t.Fatalf("Error updating resource: %s", err) + if err = client.UpdateFeed(updateRequest); err != nil { + t.Fatalf("Error updating feed: %s", err) } - reader, err = client.GetResource(nil, correctManifestAddrHex) + reader, err = client.QueryFeed(nil, correctManifestAddrHex) if err != nil { - t.Fatalf("Error retrieving resource: %s", err) + t.Fatalf("Error retrieving feed updates: %s", err) } defer reader.Close() gotData, err = ioutil.ReadAll(reader) @@ -506,17 +506,17 @@ func TestClientCreateUpdateResource(t *testing.T) { t.Fatalf("Expected: %v, got %v", databytes, gotData) } - // now try retrieving resource without a manifest + // now try retrieving feed updates without a manifest - view := &mru.Feed{ + feed := &mru.Feed{ Topic: topic, User: signer.Address(), } - lookupParams := mru.NewQueryLatest(view, lookup.NoClue) - reader, err = client.GetResource(lookupParams, "") + lookupParams := mru.NewQueryLatest(feed, lookup.NoClue) + reader, err = client.QueryFeed(lookupParams, "") if err != nil { - t.Fatalf("Error retrieving resource: %s", err) + t.Fatalf("Error retrieving feed updates: %s", err) } defer reader.Close() gotData, err = ioutil.ReadAll(reader) |