2017-01-30 13:21:46 +00:00
|
|
|
// Copyright 2017 The go-ethereum Authors
|
|
|
|
// 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/>.
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
package http
|
2017-01-26 19:33:39 +00:00
|
|
|
|
|
|
|
import (
|
2018-07-12 13:42:45 +00:00
|
|
|
"archive/tar"
|
2017-01-26 19:33:39 +00:00
|
|
|
"bytes"
|
2018-07-09 12:11:49 +00:00
|
|
|
"context"
|
2018-06-20 12:06:27 +00:00
|
|
|
"encoding/json"
|
2017-07-25 09:51:26 +00:00
|
|
|
"errors"
|
2018-06-20 12:06:27 +00:00
|
|
|
"flag"
|
2017-07-25 09:51:26 +00:00
|
|
|
"fmt"
|
2018-07-12 13:42:45 +00:00
|
|
|
"io"
|
2017-01-26 19:33:39 +00:00
|
|
|
"io/ioutil"
|
2018-09-06 10:08:39 +00:00
|
|
|
"math/big"
|
2018-08-07 10:00:12 +00:00
|
|
|
"mime/multipart"
|
2017-01-26 19:33:39 +00:00
|
|
|
"net/http"
|
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 10:07:17 +00:00
|
|
|
"net/url"
|
2018-06-20 12:06:27 +00:00
|
|
|
"os"
|
2018-10-01 11:39:39 +00:00
|
|
|
"path"
|
2018-08-07 10:00:12 +00:00
|
|
|
"strconv"
|
2017-09-08 18:29:09 +00:00
|
|
|
"strings"
|
2017-01-26 19:33:39 +00:00
|
|
|
"testing"
|
2018-07-12 13:42:45 +00:00
|
|
|
"time"
|
2017-01-26 19:33:39 +00:00
|
|
|
|
2018-10-03 07:15:17 +00: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 10:07:17 +00:00
|
|
|
|
2017-01-26 19:33:39 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2018-09-06 10:08:39 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2018-07-21 19:49:36 +00:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2018-06-20 12:06:27 +00:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2017-07-25 09:51:26 +00:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/api"
|
2017-01-26 19:33:39 +00:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/storage"
|
2018-10-03 07:15:17 +00:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/storage/feed"
|
2017-04-04 22:20:07 +00:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/testutil"
|
2017-01-26 19:33:39 +00:00
|
|
|
)
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
func init() {
|
|
|
|
loglevel := flag.Int("loglevel", 2, "loglevel")
|
|
|
|
flag.Parse()
|
|
|
|
log.Root().SetHandler(log.CallerFileHandler(log.LvlFilterHandler(log.Lvl(*loglevel), log.StreamHandler(os.Stderr, log.TerminalFormat(true)))))
|
|
|
|
}
|
|
|
|
|
2018-11-14 08:21:14 +00:00
|
|
|
func serverFunc(api *api.API) TestServer {
|
2018-07-12 13:42:45 +00:00
|
|
|
return NewServer(api, "")
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 07:15:17 +00:00
|
|
|
func newTestSigner() (*feed.GenericSigner, error) {
|
2018-07-21 19:49:36 +00:00
|
|
|
privKey, err := crypto.HexToECDSA("deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-10-03 07:15:17 +00:00
|
|
|
return feed.NewGenericSigner(privKey), nil
|
2018-07-21 19:49:36 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 15:10:22 +00:00
|
|
|
// Test the transparent resolving of feed updates with bzz:// scheme
|
2018-06-20 12:06:27 +00:00
|
|
|
//
|
2018-11-26 15:10:22 +00: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-06-20 12:06:27 +00:00
|
|
|
// and raw retrieve of that hash should return the data
|
2018-11-26 15:10:22 +00:00
|
|
|
func TestBzzWithFeed(t *testing.T) {
|
2018-06-20 12:06:27 +00:00
|
|
|
|
2018-07-21 19:49:36 +00:00
|
|
|
signer, _ := newTestSigner()
|
|
|
|
|
2018-11-26 15:10:22 +00:00
|
|
|
// Initialize Swarm test server
|
2018-11-14 08:21:14 +00:00
|
|
|
srv := NewTestSwarmServer(t, serverFunc, nil)
|
2018-06-20 12:06:27 +00:00
|
|
|
defer srv.Close()
|
|
|
|
|
2018-11-26 15:10:22 +00: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) ...
|
|
|
|
//
|
|
|
|
`)
|
|
|
|
|
|
|
|
// POST data to bzz and get back a content-addressed **manifest hash** pointing to it.
|
|
|
|
resp, err := http.Post(fmt.Sprintf("%s/bzz:/", srv.URL), "text/plain", bytes.NewReader([]byte(dataBytes)))
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-11-26 15:10:22 +00:00
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
t.Fatalf("err %s", resp.Status)
|
|
|
|
}
|
2018-11-26 15:10:22 +00:00
|
|
|
manifestAddressHex, err := ioutil.ReadAll(resp.Body)
|
2018-06-20 12:06:27 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-11-26 15:10:22 +00:00
|
|
|
manifestAddress := common.FromHex(string(manifestAddressHex))
|
2018-06-20 12:06:27 +00:00
|
|
|
|
2018-11-26 15:10:22 +00:00
|
|
|
log.Info("added data", "manifest", string(manifestAddressHex))
|
|
|
|
|
|
|
|
// At this point we have uploaded the data and have a manifest pointing to it
|
|
|
|
// Now store that manifest address in a feed update.
|
|
|
|
// We also want a feed manifest, so we can use it to refer to the feed.
|
|
|
|
|
|
|
|
// First, create a topic for our feed:
|
|
|
|
topic, _ := feed.NewTopic("interesting topic indeed", nil)
|
|
|
|
|
|
|
|
// Create a feed update request:
|
2018-10-03 07:15:17 +00:00
|
|
|
updateRequest := feed.NewFirstRequest(topic)
|
2018-06-20 12:06:27 +00:00
|
|
|
|
2018-11-26 15:10:22 +00:00
|
|
|
// Store the **manifest address** as data into the feed update.
|
|
|
|
updateRequest.SetData(manifestAddress)
|
2018-07-21 19:49:36 +00:00
|
|
|
|
2018-11-26 15:10:22 +00:00
|
|
|
// Sign the update
|
2018-07-21 19:49:36 +00:00
|
|
|
if err := updateRequest.Sign(signer); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-11-26 15:10:22 +00:00
|
|
|
log.Info("added data", "data", common.ToHex(manifestAddress))
|
2018-07-21 19:49:36 +00:00
|
|
|
|
2018-11-26 15:10:22 +00:00
|
|
|
// Build the feed update http request:
|
|
|
|
feedUpdateURL, err := url.Parse(fmt.Sprintf("%s/bzz-feed:/", srv.URL))
|
2018-07-21 19:49:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-11-26 15:10:22 +00:00
|
|
|
query := feedUpdateURL.Query()
|
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 10:07:17 +00:00
|
|
|
body := updateRequest.AppendValues(query) // this adds all query parameters and returns the data to be posted
|
2018-11-26 15:10:22 +00:00
|
|
|
query.Set("manifest", "1") // indicate we want a feed manifest back
|
|
|
|
feedUpdateURL.RawQuery = query.Encode()
|
2018-07-21 19:49:36 +00:00
|
|
|
|
2018-11-26 15:10:22 +00:00
|
|
|
// submit the feed update request to Swarm
|
|
|
|
resp, err = http.Post(feedUpdateURL.String(), "application/octet-stream", bytes.NewReader(body))
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
t.Fatalf("err %s", resp.Status)
|
|
|
|
}
|
2018-11-26 15:10:22 +00:00
|
|
|
|
|
|
|
feedManifestAddressHex, err := ioutil.ReadAll(resp.Body)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-11-26 15:10:22 +00:00
|
|
|
feedManifestAddress := &storage.Address{}
|
|
|
|
err = json.Unmarshal(feedManifestAddressHex, feedManifestAddress)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
2018-11-26 15:10:22 +00:00
|
|
|
t.Fatalf("data %s could not be unmarshaled: %v", feedManifestAddressHex, err)
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 15:10:22 +00:00
|
|
|
correctManifestAddrHex := "747c402e5b9dc715a25a4393147512167bab018a007fad7cdcd9adc7fce1ced2"
|
|
|
|
if feedManifestAddress.Hex() != correctManifestAddrHex {
|
|
|
|
t.Fatalf("Response feed manifest address mismatch, expected '%s', got '%s'", correctManifestAddrHex, feedManifestAddress.Hex())
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-30 07:43:10 +00:00
|
|
|
// get bzz manifest transparent feed update resolve
|
2018-11-26 15:10:22 +00:00
|
|
|
getBzzURL := fmt.Sprintf("%s/bzz:/%s", srv.URL, feedManifestAddress)
|
|
|
|
resp, err = http.Get(getBzzURL)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
t.Fatalf("err %s", resp.Status)
|
|
|
|
}
|
2018-11-26 15:10:22 +00:00
|
|
|
retrievedData, err := ioutil.ReadAll(resp.Body)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-11-26 15:10:22 +00:00
|
|
|
if !bytes.Equal(retrievedData, []byte(dataBytes)) {
|
|
|
|
t.Fatalf("retrieved data mismatch, expected %x, got %x", dataBytes, retrievedData)
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 07:32:46 +00:00
|
|
|
// Test Swarm feeds using the raw update methods
|
2018-09-30 07:43:10 +00:00
|
|
|
func TestBzzFeed(t *testing.T) {
|
2018-11-14 08:21:14 +00:00
|
|
|
srv := NewTestSwarmServer(t, serverFunc, nil)
|
2018-07-21 19:49:36 +00:00
|
|
|
signer, _ := newTestSigner()
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
// data of update 1
|
2018-11-14 08:21:14 +00:00
|
|
|
update1Data := testutil.RandomBytes(1, 666)
|
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 10:07:17 +00:00
|
|
|
update1Timestamp := srv.CurrentTime
|
|
|
|
//data for update 2
|
|
|
|
update2Data := []byte("foo")
|
2018-06-20 12:06:27 +00:00
|
|
|
|
2018-10-03 07:15:17 +00:00
|
|
|
topic, _ := feed.NewTopic("foo.eth", nil)
|
|
|
|
updateRequest := feed.NewFirstRequest(topic)
|
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 10:07:17 +00:00
|
|
|
updateRequest.SetData(update1Data)
|
2018-07-21 19:49:36 +00:00
|
|
|
|
|
|
|
if err := updateRequest.Sign(signer); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-09-30 07:43:10 +00:00
|
|
|
// creates feed and sets update 1
|
|
|
|
testUrl, err := url.Parse(fmt.Sprintf("%s/bzz-feed:/", srv.URL))
|
2018-07-21 19:49:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(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 10:07:17 +00:00
|
|
|
urlQuery := testUrl.Query()
|
|
|
|
body := updateRequest.AppendValues(urlQuery) // this adds all query parameters
|
|
|
|
urlQuery.Set("manifest", "1") // indicate we want a manifest back
|
|
|
|
testUrl.RawQuery = urlQuery.Encode()
|
2018-07-21 19:49:36 +00: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 10:07:17 +00:00
|
|
|
resp, err := http.Post(testUrl.String(), "application/octet-stream", bytes.NewReader(body))
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
t.Fatalf("err %s", resp.Status)
|
|
|
|
}
|
|
|
|
b, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
rsrcResp := &storage.Address{}
|
|
|
|
err = json.Unmarshal(b, rsrcResp)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("data %s could not be unmarshaled: %v", b, err)
|
|
|
|
}
|
|
|
|
|
2018-09-30 07:43:10 +00:00
|
|
|
correctManifestAddrHex := "bb056a5264c295c2b0f613c8409b9c87ce9d71576ace02458160df4cc894210b"
|
2018-06-20 12:06:27 +00:00
|
|
|
if rsrcResp.Hex() != correctManifestAddrHex {
|
2018-09-30 07:43:10 +00:00
|
|
|
t.Fatalf("Response feed manifest mismatch, expected '%s', got '%s'", correctManifestAddrHex, rsrcResp.Hex())
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// get the 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 10:07:17 +00:00
|
|
|
testRawUrl := fmt.Sprintf("%s/bzz-raw:/%s", srv.URL, rsrcResp)
|
|
|
|
resp, err = http.Get(testRawUrl)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
t.Fatalf("err %s", resp.Status)
|
|
|
|
}
|
|
|
|
b, err = ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
manifest := &api.Manifest{}
|
|
|
|
err = json.Unmarshal(b, manifest)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(manifest.Entries) != 1 {
|
|
|
|
t.Fatalf("Manifest has %d entries", len(manifest.Entries))
|
|
|
|
}
|
2018-09-30 07:43:10 +00:00
|
|
|
correctFeedHex := "0x666f6f2e65746800000000000000000000000000000000000000000000000000c96aaa54e2d44c299564da76e1cd3184a2386b8d"
|
|
|
|
if manifest.Entries[0].Feed.Hex() != correctFeedHex {
|
|
|
|
t.Fatalf("Expected manifest Feed '%s', got '%s'", correctFeedHex, manifest.Entries[0].Feed.Hex())
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 15:10:22 +00:00
|
|
|
// take the chance to have bzz: crash on resolving a feed update that does not contain
|
|
|
|
// a swarm hash:
|
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 10:07:17 +00:00
|
|
|
testBzzUrl := fmt.Sprintf("%s/bzz:/%s", srv.URL, rsrcResp)
|
|
|
|
resp, err = http.Get(testBzzUrl)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
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 10:07:17 +00:00
|
|
|
if resp.StatusCode == http.StatusOK {
|
2018-11-26 15:10:22 +00:00
|
|
|
t.Fatal("Expected error status since feed update does not contain a Swarm hash. Received 200 OK")
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
2018-11-07 19:39:08 +00:00
|
|
|
_, err = ioutil.ReadAll(resp.Body)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// get non-existent name, should fail
|
2018-09-30 07:43:10 +00:00
|
|
|
testBzzResUrl := fmt.Sprintf("%s/bzz-feed:/bar", srv.URL)
|
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 10:07:17 +00:00
|
|
|
resp, err = http.Get(testBzzResUrl)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-07-21 19:49:36 +00:00
|
|
|
|
|
|
|
if resp.StatusCode != http.StatusNotFound {
|
2018-09-30 07:43:10 +00:00
|
|
|
t.Fatalf("Expected get non-existent feed manifest to fail with StatusNotFound (404), got %d", resp.StatusCode)
|
2018-07-21 19:49:36 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
resp.Body.Close()
|
|
|
|
|
2018-09-30 07:43:10 +00:00
|
|
|
// get latest update through bzz-feed directly
|
2018-06-20 12:06:27 +00:00
|
|
|
log.Info("get update latest = 1.1", "addr", correctManifestAddrHex)
|
2018-09-30 07:43:10 +00:00
|
|
|
testBzzResUrl = fmt.Sprintf("%s/bzz-feed:/%s", srv.URL, correctManifestAddrHex)
|
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 10:07:17 +00:00
|
|
|
resp, err = http.Get(testBzzResUrl)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
t.Fatalf("err %s", resp.Status)
|
|
|
|
}
|
|
|
|
b, err = ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(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 10:07:17 +00:00
|
|
|
if !bytes.Equal(update1Data, b) {
|
|
|
|
t.Fatalf("Expected body '%x', got '%x'", update1Data, b)
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// update 2
|
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 10:07:17 +00:00
|
|
|
// Move the clock ahead 1 second
|
|
|
|
srv.CurrentTime++
|
2018-06-20 12:06:27 +00:00
|
|
|
log.Info("update 2")
|
2018-07-21 19:49:36 +00:00
|
|
|
|
2018-10-02 07:32:46 +00:00
|
|
|
// 1.- get metadata about this feed
|
2018-09-30 07:43:10 +00:00
|
|
|
testBzzResUrl = fmt.Sprintf("%s/bzz-feed:/%s/", srv.URL, correctManifestAddrHex)
|
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 10:07:17 +00:00
|
|
|
resp, err = http.Get(testBzzResUrl + "?meta=1")
|
2018-07-21 19:49:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
2018-09-30 07:43:10 +00:00
|
|
|
t.Fatalf("Get feed metadata returned %s", resp.Status)
|
2018-07-21 19:49:36 +00:00
|
|
|
}
|
|
|
|
b, err = ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-10-03 07:15:17 +00:00
|
|
|
updateRequest = &feed.Request{}
|
2018-07-21 19:49:36 +00:00
|
|
|
if err = updateRequest.UnmarshalJSON(b); err != nil {
|
2018-09-30 07:43:10 +00:00
|
|
|
t.Fatalf("Error decoding feed metadata: %s", err)
|
2018-07-21 19:49:36 +00: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 10:07:17 +00:00
|
|
|
updateRequest.SetData(update2Data)
|
2018-07-21 19:49:36 +00:00
|
|
|
if err = updateRequest.Sign(signer); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-09-30 07:43:10 +00:00
|
|
|
testUrl, err = url.Parse(fmt.Sprintf("%s/bzz-feed:/", srv.URL))
|
2018-07-21 19:49:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(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 10:07:17 +00:00
|
|
|
urlQuery = testUrl.Query()
|
|
|
|
body = updateRequest.AppendValues(urlQuery) // this adds all query parameters
|
2018-11-07 13:49:42 +00:00
|
|
|
goodQueryParameters := urlQuery.Encode() // save the query parameters for a second attempt
|
|
|
|
|
|
|
|
// create bad query parameters in which the signature is missing
|
|
|
|
urlQuery.Del("signature")
|
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 10:07:17 +00:00
|
|
|
testUrl.RawQuery = urlQuery.Encode()
|
2018-07-21 19:49:36 +00:00
|
|
|
|
2018-11-07 13:49:42 +00:00
|
|
|
// 1st attempt with bad query parameters in which the signature is missing
|
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 10:07:17 +00:00
|
|
|
resp, err = http.Post(testUrl.String(), "application/octet-stream", bytes.NewReader(body))
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
2018-11-07 13:49:42 +00:00
|
|
|
expectedCode := http.StatusBadRequest
|
|
|
|
if resp.StatusCode != expectedCode {
|
|
|
|
t.Fatalf("Update returned %s. Expected %d", resp.Status, expectedCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2nd attempt with bad query parameters in which the signature is of incorrect length
|
|
|
|
urlQuery.Set("signature", "0xabcd") // should be 130 hex chars
|
|
|
|
resp, err = http.Post(testUrl.String(), "application/octet-stream", bytes.NewReader(body))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
expectedCode = http.StatusBadRequest
|
|
|
|
if resp.StatusCode != expectedCode {
|
|
|
|
t.Fatalf("Update returned %s. Expected %d", resp.Status, expectedCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3rd attempt, with good query parameters:
|
|
|
|
testUrl.RawQuery = goodQueryParameters
|
|
|
|
resp, err = http.Post(testUrl.String(), "application/octet-stream", bytes.NewReader(body))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
expectedCode = http.StatusOK
|
|
|
|
if resp.StatusCode != expectedCode {
|
|
|
|
t.Fatalf("Update returned %s. Expected %d", resp.Status, expectedCode)
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-30 07:43:10 +00:00
|
|
|
// get latest update through bzz-feed directly
|
2018-06-20 12:06:27 +00:00
|
|
|
log.Info("get update 1.2")
|
2018-09-30 07:43:10 +00:00
|
|
|
testBzzResUrl = fmt.Sprintf("%s/bzz-feed:/%s", srv.URL, correctManifestAddrHex)
|
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 10:07:17 +00:00
|
|
|
resp, err = http.Get(testBzzResUrl)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
t.Fatalf("err %s", resp.Status)
|
|
|
|
}
|
|
|
|
b, err = ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(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 10:07:17 +00:00
|
|
|
if !bytes.Equal(update2Data, b) {
|
|
|
|
t.Fatalf("Expected body '%x', got '%x'", update2Data, b)
|
2018-06-20 12:06:27 +00: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 10:07:17 +00:00
|
|
|
// test manifest-less queries
|
|
|
|
log.Info("get first update in update1Timestamp via direct query")
|
2018-10-03 07:15:17 +00:00
|
|
|
query := feed.NewQuery(&updateRequest.Feed, update1Timestamp, lookup.NoClue)
|
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 10:07:17 +00:00
|
|
|
|
2018-09-30 07:43:10 +00:00
|
|
|
urlq, err := url.Parse(fmt.Sprintf("%s/bzz-feed:/", srv.URL))
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(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 10:07:17 +00:00
|
|
|
values := urlq.Query()
|
2018-09-30 07:43:10 +00:00
|
|
|
query.AppendValues(values) // this adds feed query parameters
|
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 10:07:17 +00:00
|
|
|
urlq.RawQuery = values.Encode()
|
|
|
|
resp, err = http.Get(urlq.String())
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
t.Fatalf("err %s", resp.Status)
|
|
|
|
}
|
|
|
|
b, err = ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(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 10:07:17 +00:00
|
|
|
if !bytes.Equal(update1Data, b) {
|
|
|
|
t.Fatalf("Expected body '%x', got '%x'", update1Data, b)
|
2018-06-20 12:06:27 +00: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 10:07:17 +00:00
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 12:47:10 +00:00
|
|
|
func TestBzzGetPath(t *testing.T) {
|
2018-06-20 12:06:27 +00:00
|
|
|
testBzzGetPath(false, t)
|
|
|
|
testBzzGetPath(true, t)
|
|
|
|
}
|
2017-01-26 19:33:39 +00:00
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
func testBzzGetPath(encrypted bool, t *testing.T) {
|
2017-01-26 19:33:39 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
testmanifest := []string{
|
|
|
|
`{"entries":[{"path":"b","hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","contentType":"","status":0},{"path":"c","hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","contentType":"","status":0}]}`,
|
2018-06-20 12:06:27 +00:00
|
|
|
`{"entries":[{"path":"a","hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","contentType":"","status":0},{"path":"b/","hash":"<key0>","contentType":"application/bzz-manifest+json","status":0}]}`,
|
|
|
|
`{"entries":[{"path":"a/","hash":"<key1>","contentType":"application/bzz-manifest+json","status":0}]}`,
|
2017-01-26 19:33:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
testrequests := make(map[string]int)
|
2018-06-20 12:06:27 +00:00
|
|
|
testrequests["/"] = 2
|
2017-04-06 22:22:22 +00:00
|
|
|
testrequests["/a/"] = 1
|
2018-06-20 12:06:27 +00:00
|
|
|
testrequests["/a/b/"] = 0
|
2017-01-26 19:33:39 +00:00
|
|
|
testrequests["/x"] = 0
|
|
|
|
testrequests[""] = 0
|
|
|
|
|
|
|
|
expectedfailrequests := []string{"", "/x"}
|
|
|
|
|
|
|
|
reader := [3]*bytes.Reader{}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
addr := [3]storage.Address{}
|
2017-01-26 19:33:39 +00:00
|
|
|
|
2018-11-14 08:21:14 +00:00
|
|
|
srv := NewTestSwarmServer(t, serverFunc, nil)
|
2017-04-04 22:20:07 +00:00
|
|
|
defer srv.Close()
|
2017-01-26 19:33:39 +00:00
|
|
|
|
|
|
|
for i, mf := range testmanifest {
|
|
|
|
reader[i] = bytes.NewReader([]byte(mf))
|
2018-07-09 12:11:49 +00:00
|
|
|
var wait func(context.Context) error
|
|
|
|
ctx := context.TODO()
|
|
|
|
addr[i], wait, err = srv.FileStore.Store(ctx, reader[i], int64(len(mf)), encrypted)
|
2017-01-26 19:33:39 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-09-13 09:42:19 +00:00
|
|
|
for j := i + 1; j < len(testmanifest); j++ {
|
|
|
|
testmanifest[j] = strings.Replace(testmanifest[j], fmt.Sprintf("<key%v>", i), addr[i].Hex(), -1)
|
|
|
|
}
|
2018-07-09 12:11:49 +00:00
|
|
|
err = wait(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-01-26 19:33:39 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
rootRef := addr[2].Hex()
|
|
|
|
|
|
|
|
_, err = http.Get(srv.URL + "/bzz-raw:/" + rootRef + "/a")
|
2017-04-04 22:20:07 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to connect to proxy: %v", err)
|
2017-01-26 19:33:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for k, v := range testrequests {
|
|
|
|
var resp *http.Response
|
|
|
|
var respbody []byte
|
|
|
|
|
2017-12-19 08:49:30 +00:00
|
|
|
url := srv.URL + "/bzz-raw:/"
|
2018-09-14 20:07:13 +00:00
|
|
|
if k != "" {
|
2018-06-20 12:06:27 +00:00
|
|
|
url += rootRef + "/" + k[1:] + "?content_type=text/plain"
|
2017-01-26 19:33:39 +00:00
|
|
|
}
|
|
|
|
resp, err = http.Get(url)
|
2017-02-17 09:48:26 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Request failed: %v", err)
|
|
|
|
}
|
2017-01-26 19:33:39 +00:00
|
|
|
defer resp.Body.Close()
|
|
|
|
respbody, err = ioutil.ReadAll(resp.Body)
|
2018-11-07 19:39:08 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error while reading response body: %v", err)
|
|
|
|
}
|
2017-01-26 19:33:39 +00:00
|
|
|
|
|
|
|
if string(respbody) != testmanifest[v] {
|
|
|
|
isexpectedfailrequest := false
|
|
|
|
|
|
|
|
for _, r := range expectedfailrequests {
|
2018-09-14 20:07:13 +00:00
|
|
|
if k == r {
|
2017-01-26 19:33:39 +00:00
|
|
|
isexpectedfailrequest = true
|
|
|
|
}
|
|
|
|
}
|
2017-08-08 17:34:35 +00:00
|
|
|
if !isexpectedfailrequest {
|
2017-01-26 19:33:39 +00:00
|
|
|
t.Fatalf("Response body does not match, expected: %v, got %v", testmanifest[v], string(respbody))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-21 12:47:10 +00:00
|
|
|
for k, v := range testrequests {
|
|
|
|
var resp *http.Response
|
|
|
|
var respbody []byte
|
|
|
|
|
|
|
|
url := srv.URL + "/bzz-hash:/"
|
2018-09-14 20:07:13 +00:00
|
|
|
if k != "" {
|
2018-06-20 12:06:27 +00:00
|
|
|
url += rootRef + "/" + k[1:]
|
2017-12-21 12:47:10 +00:00
|
|
|
}
|
|
|
|
resp, err = http.Get(url)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Request failed: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
respbody, err = ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Read request body: %v", err)
|
|
|
|
}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
if string(respbody) != addr[v].Hex() {
|
2017-12-21 12:47:10 +00:00
|
|
|
isexpectedfailrequest := false
|
|
|
|
|
|
|
|
for _, r := range expectedfailrequests {
|
2018-09-14 20:07:13 +00:00
|
|
|
if k == r {
|
2017-12-21 12:47:10 +00:00
|
|
|
isexpectedfailrequest = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !isexpectedfailrequest {
|
2018-06-20 12:06:27 +00:00
|
|
|
t.Fatalf("Response body does not match, expected: %v, got %v", addr[v], string(respbody))
|
2017-12-21 12:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
ref := addr[2].Hex()
|
|
|
|
|
2017-12-19 08:49:30 +00:00
|
|
|
for _, c := range []struct {
|
2018-08-07 09:56:55 +00:00
|
|
|
path string
|
|
|
|
json string
|
|
|
|
pageFragments []string
|
2017-12-19 08:49:30 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
path: "/",
|
|
|
|
json: `{"common_prefixes":["a/"]}`,
|
2018-08-07 09:56:55 +00:00
|
|
|
pageFragments: []string{
|
|
|
|
fmt.Sprintf("Swarm index of bzz:/%s/", ref),
|
|
|
|
`<a class="normal-link" href="a/">a/</a>`,
|
|
|
|
},
|
2017-12-19 08:49:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/a/",
|
|
|
|
json: `{"common_prefixes":["a/b/"],"entries":[{"hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","path":"a/a","mod_time":"0001-01-01T00:00:00Z"}]}`,
|
2018-08-07 09:56:55 +00:00
|
|
|
pageFragments: []string{
|
|
|
|
fmt.Sprintf("Swarm index of bzz:/%s/a/", ref),
|
|
|
|
`<a class="normal-link" href="b/">b/</a>`,
|
2018-08-08 07:33:06 +00:00
|
|
|
fmt.Sprintf(`<a class="normal-link" href="/bzz:/%s/a/a">a</a>`, ref),
|
2018-08-07 09:56:55 +00:00
|
|
|
},
|
2017-12-19 08:49:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/a/b/",
|
|
|
|
json: `{"entries":[{"hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","path":"a/b/b","mod_time":"0001-01-01T00:00:00Z"},{"hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","path":"a/b/c","mod_time":"0001-01-01T00:00:00Z"}]}`,
|
2018-08-07 09:56:55 +00:00
|
|
|
pageFragments: []string{
|
|
|
|
fmt.Sprintf("Swarm index of bzz:/%s/a/b/", ref),
|
2018-08-08 07:33:06 +00:00
|
|
|
fmt.Sprintf(`<a class="normal-link" href="/bzz:/%s/a/b/b">b</a>`, ref),
|
|
|
|
fmt.Sprintf(`<a class="normal-link" href="/bzz:/%s/a/b/c">c</a>`, ref),
|
2018-08-07 09:56:55 +00:00
|
|
|
},
|
2017-12-19 08:49:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/x",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "",
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
k := c.path
|
|
|
|
url := srv.URL + "/bzz-list:/"
|
2018-09-14 20:07:13 +00:00
|
|
|
if k != "" {
|
2018-06-20 12:06:27 +00:00
|
|
|
url += rootRef + "/" + k[1:]
|
2017-12-19 08:49:30 +00:00
|
|
|
}
|
|
|
|
t.Run("json list "+c.path, func(t *testing.T) {
|
|
|
|
resp, err := http.Get(url)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("HTTP request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
respbody, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Read response body: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
body := strings.TrimSpace(string(respbody))
|
|
|
|
if body != c.json {
|
|
|
|
isexpectedfailrequest := false
|
|
|
|
|
|
|
|
for _, r := range expectedfailrequests {
|
2018-09-14 20:07:13 +00:00
|
|
|
if k == r {
|
2017-12-19 08:49:30 +00:00
|
|
|
isexpectedfailrequest = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !isexpectedfailrequest {
|
|
|
|
t.Errorf("Response list body %q does not match, expected: %v, got %v", k, c.json, body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("html list "+c.path, func(t *testing.T) {
|
|
|
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("New request: %v", err)
|
|
|
|
}
|
|
|
|
req.Header.Set("Accept", "text/html")
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("HTTP request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
2018-08-07 09:56:55 +00:00
|
|
|
b, err := ioutil.ReadAll(resp.Body)
|
2017-12-19 08:49:30 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Read response body: %v", err)
|
|
|
|
}
|
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
body := string(b)
|
2017-12-19 08:49:30 +00:00
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
for _, f := range c.pageFragments {
|
|
|
|
if !strings.Contains(body, f) {
|
|
|
|
isexpectedfailrequest := false
|
|
|
|
|
|
|
|
for _, r := range expectedfailrequests {
|
2018-09-14 20:07:13 +00:00
|
|
|
if k == r {
|
2018-08-07 09:56:55 +00:00
|
|
|
isexpectedfailrequest = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !isexpectedfailrequest {
|
|
|
|
t.Errorf("Response list body %q does not contain %q: body %q", k, f, body)
|
2017-12-19 08:49:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-13 09:06:19 +00:00
|
|
|
nonhashtests := []string{
|
|
|
|
srv.URL + "/bzz:/name",
|
2017-12-19 08:49:30 +00:00
|
|
|
srv.URL + "/bzz-immutable:/nonhash",
|
|
|
|
srv.URL + "/bzz-raw:/nonhash",
|
|
|
|
srv.URL + "/bzz-list:/nonhash",
|
2017-12-21 12:47:10 +00:00
|
|
|
srv.URL + "/bzz-hash:/nonhash",
|
2017-04-13 09:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nonhashresponses := []string{
|
2018-08-07 09:56:55 +00:00
|
|
|
`cannot resolve name: no DNS to resolve name: "name"`,
|
2018-09-07 13:23:29 +00:00
|
|
|
`cannot resolve nonhash: no DNS to resolve name: "nonhash"`,
|
2018-08-07 09:56:55 +00:00
|
|
|
`cannot resolve nonhash: no DNS to resolve name: "nonhash"`,
|
|
|
|
`cannot resolve nonhash: no DNS to resolve name: "nonhash"`,
|
|
|
|
`cannot resolve nonhash: no DNS to resolve name: "nonhash"`,
|
2017-04-13 09:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, url := range nonhashtests {
|
|
|
|
var resp *http.Response
|
|
|
|
var respbody []byte
|
|
|
|
|
|
|
|
resp, err = http.Get(url)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Request failed: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
respbody, err = ioutil.ReadAll(resp.Body)
|
2017-08-08 17:34:35 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("ReadAll failed: %v", err)
|
|
|
|
}
|
2017-09-08 18:29:09 +00:00
|
|
|
if !strings.Contains(string(respbody), nonhashresponses[i]) {
|
2017-04-13 09:06:19 +00:00
|
|
|
t.Fatalf("Non-Hash response body does not match, expected: %v, got: %v", nonhashresponses[i], string(respbody))
|
|
|
|
}
|
|
|
|
}
|
2017-01-26 19:33:39 +00:00
|
|
|
}
|
2017-07-25 09:51:26 +00:00
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
func TestBzzTar(t *testing.T) {
|
|
|
|
testBzzTar(false, t)
|
|
|
|
testBzzTar(true, t)
|
|
|
|
}
|
|
|
|
|
2018-07-12 13:42:45 +00:00
|
|
|
func testBzzTar(encrypted bool, t *testing.T) {
|
2018-11-14 08:21:14 +00:00
|
|
|
srv := NewTestSwarmServer(t, serverFunc, nil)
|
2018-07-12 13:42:45 +00:00
|
|
|
defer srv.Close()
|
|
|
|
fileNames := []string{"tmp1.txt", "tmp2.lock", "tmp3.rtf"}
|
|
|
|
fileContents := []string{"tmp1textfilevalue", "tmp2lockfilelocked", "tmp3isjustaplaintextfile"}
|
|
|
|
|
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
tw := tar.NewWriter(buf)
|
|
|
|
defer tw.Close()
|
|
|
|
|
|
|
|
for i, v := range fileNames {
|
|
|
|
size := int64(len(fileContents[i]))
|
|
|
|
hdr := &tar.Header{
|
|
|
|
Name: v,
|
|
|
|
Mode: 0644,
|
|
|
|
Size: size,
|
|
|
|
ModTime: time.Now(),
|
|
|
|
Xattrs: map[string]string{
|
|
|
|
"user.swarm.content-type": "text/plain",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if err := tw.WriteHeader(hdr); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy the file into the tar stream
|
|
|
|
n, err := io.Copy(tw, bytes.NewBufferString(fileContents[i]))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != size {
|
|
|
|
t.Fatal("size mismatch")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//post tar stream
|
|
|
|
url := srv.URL + "/bzz:/"
|
|
|
|
if encrypted {
|
|
|
|
url = url + "encrypt"
|
|
|
|
}
|
|
|
|
req, err := http.NewRequest("POST", url, buf)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
req.Header.Add("Content-Type", "application/x-tar")
|
2019-05-05 18:34:22 +00:00
|
|
|
req.Header.Add(SwarmTagHeaderName, "test-upload")
|
2018-07-12 13:42:45 +00:00
|
|
|
client := &http.Client{}
|
|
|
|
resp2, err := client.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp2.StatusCode != http.StatusOK {
|
|
|
|
t.Fatalf("err %s", resp2.Status)
|
|
|
|
}
|
2019-05-05 18:34:22 +00:00
|
|
|
|
|
|
|
// check that the tag was written correctly
|
|
|
|
tag := srv.Tags.All()[0]
|
|
|
|
testutil.CheckTag(t, tag, 4, 4, 0, 4)
|
|
|
|
|
2018-07-12 13:42:45 +00:00
|
|
|
swarmHash, err := ioutil.ReadAll(resp2.Body)
|
|
|
|
resp2.Body.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// now do a GET to get a tarball back
|
|
|
|
req, err = http.NewRequest("GET", fmt.Sprintf(srv.URL+"/bzz:/%s", string(swarmHash)), nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
req.Header.Add("Accept", "application/x-tar")
|
|
|
|
resp2, err = client.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp2.Body.Close()
|
|
|
|
|
2018-10-01 11:39:39 +00:00
|
|
|
if h := resp2.Header.Get("Content-Type"); h != "application/x-tar" {
|
|
|
|
t.Fatalf("Content-Type header expected: application/x-tar, got: %s", h)
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedFileName := string(swarmHash) + ".tar"
|
|
|
|
expectedContentDisposition := fmt.Sprintf("inline; filename=\"%s\"", expectedFileName)
|
|
|
|
if h := resp2.Header.Get("Content-Disposition"); h != expectedContentDisposition {
|
|
|
|
t.Fatalf("Content-Disposition header expected: %s, got: %s", expectedContentDisposition, h)
|
|
|
|
}
|
|
|
|
|
2018-07-12 13:42:45 +00:00
|
|
|
file, err := ioutil.TempFile("", "swarm-downloaded-tarball")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer os.Remove(file.Name())
|
|
|
|
_, err = io.Copy(file, resp2.Body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error getting tarball: %v", err)
|
|
|
|
}
|
|
|
|
file.Sync()
|
|
|
|
file.Close()
|
|
|
|
|
|
|
|
tarFileHandle, err := os.Open(file.Name())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
tr := tar.NewReader(tarFileHandle)
|
|
|
|
|
|
|
|
for {
|
|
|
|
hdr, err := tr.Next()
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
} else if err != nil {
|
|
|
|
t.Fatalf("error reading tar stream: %s", err)
|
|
|
|
}
|
|
|
|
bb := make([]byte, hdr.Size)
|
|
|
|
_, err = tr.Read(bb)
|
|
|
|
if err != nil && err != io.EOF {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
passed := false
|
|
|
|
for i, v := range fileNames {
|
|
|
|
if v == hdr.Name {
|
|
|
|
if string(bb) == fileContents[i] {
|
|
|
|
passed = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !passed {
|
|
|
|
t.Fatalf("file %s did not pass content assertion", hdr.Name)
|
|
|
|
}
|
|
|
|
}
|
2019-05-05 18:34:22 +00:00
|
|
|
|
|
|
|
// now check the tags endpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestBzzCorrectTagEstimate checks that the HTTP middleware sets the total number of chunks
|
|
|
|
// in the tag according to an estimate from the HTTP request Content-Length header divided
|
|
|
|
// by chunk size (4096). It is needed to be checked BEFORE chunking is done, therefore
|
|
|
|
// concurrency was introduced to slow down the HTTP request
|
|
|
|
func TestBzzCorrectTagEstimate(t *testing.T) {
|
|
|
|
srv := NewTestSwarmServer(t, serverFunc, nil)
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
for _, v := range []struct {
|
|
|
|
toEncrypt bool
|
|
|
|
expChunks int64
|
|
|
|
}{
|
|
|
|
{toEncrypt: false, expChunks: 248},
|
|
|
|
{toEncrypt: true, expChunks: 250},
|
|
|
|
} {
|
|
|
|
pr, pw := io.Pipe()
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
addr := ""
|
|
|
|
if v.toEncrypt {
|
|
|
|
addr = "encrypt"
|
|
|
|
}
|
|
|
|
req, err := http.NewRequest("POST", srv.URL+"/bzz:/"+addr, pr)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
req = req.WithContext(ctx)
|
|
|
|
req.ContentLength = 1000000
|
|
|
|
req.Header.Add(SwarmTagHeaderName, "1000000")
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
case <-time.After(1 * time.Millisecond):
|
|
|
|
_, err := pw.Write([]byte{0})
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
transport := http.DefaultTransport
|
|
|
|
_, err := transport.RoundTrip(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
done := false
|
|
|
|
for !done {
|
|
|
|
switch len(srv.Tags.All()) {
|
|
|
|
case 0:
|
|
|
|
<-time.After(10 * time.Millisecond)
|
|
|
|
case 1:
|
|
|
|
tag := srv.Tags.All()[0]
|
|
|
|
testutil.CheckTag(t, tag, 0, 0, 0, v.expChunks)
|
|
|
|
srv.Tags.Delete(tag.Uid)
|
|
|
|
done = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-12 13:42:45 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 09:51:26 +00:00
|
|
|
// TestBzzRootRedirect tests that getting the root path of a manifest without
|
|
|
|
// a trailing slash gets redirected to include the trailing slash so that
|
|
|
|
// relative URLs work as expected.
|
|
|
|
func TestBzzRootRedirect(t *testing.T) {
|
2018-06-20 12:06:27 +00:00
|
|
|
testBzzRootRedirect(false, t)
|
|
|
|
}
|
|
|
|
func TestBzzRootRedirectEncrypted(t *testing.T) {
|
|
|
|
testBzzRootRedirect(true, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testBzzRootRedirect(toEncrypt bool, t *testing.T) {
|
2018-11-14 08:21:14 +00:00
|
|
|
srv := NewTestSwarmServer(t, serverFunc, nil)
|
2017-07-25 09:51:26 +00:00
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
// create a manifest with some data at the root path
|
|
|
|
data := []byte("data")
|
2019-05-05 18:34:22 +00:00
|
|
|
headers := map[string]string{"Content-Type": "text/plain"}
|
|
|
|
res, hash := httpDo("POST", srv.URL+"/bzz:/", bytes.NewReader(data), headers, false, t)
|
|
|
|
if res.StatusCode != http.StatusOK {
|
|
|
|
t.Fatalf("unexpected status code from server %d want %d", res.StatusCode, http.StatusOK)
|
2017-07-25 09:51:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// define a CheckRedirect hook which ensures there is only a single
|
|
|
|
// redirect to the correct URL
|
|
|
|
redirected := false
|
|
|
|
httpClient := http.Client{
|
|
|
|
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
|
|
|
if redirected {
|
|
|
|
return errors.New("too many redirects")
|
|
|
|
}
|
|
|
|
redirected = true
|
|
|
|
expectedPath := "/bzz:/" + hash + "/"
|
|
|
|
if req.URL.Path != expectedPath {
|
|
|
|
return fmt.Errorf("expected redirect to %q, got %q", expectedPath, req.URL.Path)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// perform the GET request and assert the response
|
|
|
|
res, err := httpClient.Get(srv.URL + "/bzz:/" + hash)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer res.Body.Close()
|
|
|
|
if !redirected {
|
|
|
|
t.Fatal("expected GET /bzz:/<hash> to redirect to /bzz:/<hash>/ but it didn't")
|
|
|
|
}
|
|
|
|
gotData, err := ioutil.ReadAll(res.Body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !bytes.Equal(gotData, data) {
|
|
|
|
t.Fatalf("expected response to equal %q, got %q", data, gotData)
|
|
|
|
}
|
|
|
|
}
|
2018-06-20 12:06:27 +00:00
|
|
|
|
|
|
|
func TestMethodsNotAllowed(t *testing.T) {
|
2018-11-14 08:21:14 +00:00
|
|
|
srv := NewTestSwarmServer(t, serverFunc, nil)
|
2018-06-20 12:06:27 +00:00
|
|
|
defer srv.Close()
|
|
|
|
databytes := "bar"
|
|
|
|
for _, c := range []struct {
|
|
|
|
url string
|
|
|
|
code int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
url: fmt.Sprintf("%s/bzz-list:/", srv.URL),
|
2018-09-06 10:11:38 +00:00
|
|
|
code: http.StatusMethodNotAllowed,
|
2018-06-20 12:06:27 +00:00
|
|
|
}, {
|
|
|
|
url: fmt.Sprintf("%s/bzz-hash:/", srv.URL),
|
2018-09-06 10:11:38 +00:00
|
|
|
code: http.StatusMethodNotAllowed,
|
2018-06-20 12:06:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
url: fmt.Sprintf("%s/bzz-immutable:/", srv.URL),
|
2018-09-06 10:11:38 +00:00
|
|
|
code: http.StatusMethodNotAllowed,
|
2018-06-20 12:06:27 +00:00
|
|
|
},
|
|
|
|
} {
|
|
|
|
res, _ := http.Post(c.url, "text/plain", bytes.NewReader([]byte(databytes)))
|
|
|
|
if res.StatusCode != c.code {
|
2018-08-07 09:56:55 +00:00
|
|
|
t.Fatalf("should have failed. requested url: %s, expected code %d, got %d", c.url, c.code, res.StatusCode)
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-08-07 10:00:12 +00:00
|
|
|
|
|
|
|
func httpDo(httpMethod string, url string, reqBody io.Reader, headers map[string]string, verbose bool, t *testing.T) (*http.Response, string) {
|
|
|
|
// Build the Request
|
|
|
|
req, err := http.NewRequest(httpMethod, url, reqBody)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
for key, value := range headers {
|
|
|
|
req.Header.Set(key, value)
|
|
|
|
}
|
|
|
|
if verbose {
|
|
|
|
t.Log(req.Method, req.URL, req.Header, req.Body)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send Request out
|
|
|
|
httpClient := &http.Client{}
|
|
|
|
res, err := httpClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the HTTP Body
|
|
|
|
buffer, err := ioutil.ReadAll(res.Body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer res.Body.Close()
|
|
|
|
body := string(buffer)
|
|
|
|
|
|
|
|
return res, body
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGet(t *testing.T) {
|
2018-11-14 08:21:14 +00:00
|
|
|
srv := NewTestSwarmServer(t, serverFunc, nil)
|
2018-08-07 10:00:12 +00:00
|
|
|
defer srv.Close()
|
|
|
|
|
2018-08-07 11:40:38 +00:00
|
|
|
for _, testCase := range []struct {
|
2018-08-07 10:00:12 +00:00
|
|
|
uri string
|
|
|
|
method string
|
|
|
|
headers map[string]string
|
|
|
|
expectedStatusCode int
|
|
|
|
assertResponseBody string
|
|
|
|
verbose bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
uri: fmt.Sprintf("%s/", srv.URL),
|
|
|
|
method: "GET",
|
|
|
|
headers: map[string]string{"Accept": "text/html"},
|
2018-09-06 10:11:38 +00:00
|
|
|
expectedStatusCode: http.StatusOK,
|
2018-08-07 11:40:38 +00:00
|
|
|
assertResponseBody: "Swarm: Serverless Hosting Incentivised Peer-To-Peer Storage And Content Distribution",
|
2018-08-07 10:00:12 +00:00
|
|
|
verbose: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: fmt.Sprintf("%s/", srv.URL),
|
|
|
|
method: "GET",
|
|
|
|
headers: map[string]string{"Accept": "application/json"},
|
2018-09-06 10:11:38 +00:00
|
|
|
expectedStatusCode: http.StatusOK,
|
2018-08-07 11:40:38 +00:00
|
|
|
assertResponseBody: "Swarm: Please request a valid ENS or swarm hash with the appropriate bzz scheme",
|
2018-08-07 10:00:12 +00:00
|
|
|
verbose: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: fmt.Sprintf("%s/robots.txt", srv.URL),
|
|
|
|
method: "GET",
|
|
|
|
headers: map[string]string{"Accept": "text/html"},
|
2018-09-06 10:11:38 +00:00
|
|
|
expectedStatusCode: http.StatusOK,
|
2018-08-07 10:00:12 +00:00
|
|
|
assertResponseBody: "User-agent: *\nDisallow: /",
|
|
|
|
verbose: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: fmt.Sprintf("%s/nonexistent_path", srv.URL),
|
|
|
|
method: "GET",
|
|
|
|
headers: map[string]string{},
|
2018-09-06 10:11:38 +00:00
|
|
|
expectedStatusCode: http.StatusNotFound,
|
2018-08-07 10:00:12 +00:00
|
|
|
verbose: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: fmt.Sprintf("%s/bzz:asdf/", srv.URL),
|
|
|
|
method: "GET",
|
|
|
|
headers: map[string]string{},
|
2018-09-06 10:11:38 +00:00
|
|
|
expectedStatusCode: http.StatusNotFound,
|
2018-08-07 10:00:12 +00:00
|
|
|
verbose: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: fmt.Sprintf("%s/tbz2/", srv.URL),
|
|
|
|
method: "GET",
|
|
|
|
headers: map[string]string{},
|
2018-09-06 10:11:38 +00:00
|
|
|
expectedStatusCode: http.StatusNotFound,
|
2018-08-07 10:00:12 +00:00
|
|
|
verbose: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: fmt.Sprintf("%s/bzz-rack:/", srv.URL),
|
|
|
|
method: "GET",
|
|
|
|
headers: map[string]string{},
|
2018-09-06 10:11:38 +00:00
|
|
|
expectedStatusCode: http.StatusNotFound,
|
2018-08-07 10:00:12 +00:00
|
|
|
verbose: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: fmt.Sprintf("%s/bzz-ls", srv.URL),
|
|
|
|
method: "GET",
|
|
|
|
headers: map[string]string{},
|
2018-09-06 10:11:38 +00:00
|
|
|
expectedStatusCode: http.StatusNotFound,
|
2018-08-07 10:00:12 +00:00
|
|
|
verbose: false,
|
2018-09-06 10:11:38 +00:00
|
|
|
}} {
|
2018-08-07 10:00:12 +00:00
|
|
|
t.Run("GET "+testCase.uri, func(t *testing.T) {
|
|
|
|
res, body := httpDo(testCase.method, testCase.uri, nil, testCase.headers, testCase.verbose, t)
|
|
|
|
if res.StatusCode != testCase.expectedStatusCode {
|
2018-08-07 11:40:38 +00:00
|
|
|
t.Fatalf("expected status code %d but got %d", testCase.expectedStatusCode, res.StatusCode)
|
2018-08-07 10:00:12 +00:00
|
|
|
}
|
|
|
|
if testCase.assertResponseBody != "" && !strings.Contains(body, testCase.assertResponseBody) {
|
2018-08-07 11:40:38 +00:00
|
|
|
t.Fatalf("expected response to be: %s but got: %s", testCase.assertResponseBody, body)
|
2018-08-07 10:00:12 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestModify(t *testing.T) {
|
2018-11-14 08:21:14 +00:00
|
|
|
srv := NewTestSwarmServer(t, serverFunc, nil)
|
2018-08-07 10:00:12 +00:00
|
|
|
defer srv.Close()
|
2019-05-05 18:34:22 +00:00
|
|
|
headers := map[string]string{"Content-Type": "text/plain"}
|
|
|
|
res, hash := httpDo("POST", srv.URL+"/bzz:/", bytes.NewReader([]byte("data")), headers, false, t)
|
|
|
|
if res.StatusCode != http.StatusOK {
|
|
|
|
t.Fatalf("unexpected status code from server %d want %d", res.StatusCode, http.StatusOK)
|
2018-08-07 10:00:12 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 11:40:38 +00:00
|
|
|
for _, testCase := range []struct {
|
2018-08-07 10:00:12 +00:00
|
|
|
uri string
|
|
|
|
method string
|
|
|
|
headers map[string]string
|
|
|
|
requestBody []byte
|
|
|
|
expectedStatusCode int
|
|
|
|
assertResponseBody string
|
|
|
|
assertResponseHeaders map[string]string
|
|
|
|
verbose bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
uri: fmt.Sprintf("%s/bzz:/%s", srv.URL, hash),
|
|
|
|
method: "DELETE",
|
|
|
|
headers: map[string]string{},
|
2018-09-06 10:11:38 +00:00
|
|
|
expectedStatusCode: http.StatusOK,
|
2018-08-07 10:00:12 +00:00
|
|
|
assertResponseBody: "8b634aea26eec353ac0ecbec20c94f44d6f8d11f38d4578a4c207a84c74ef731",
|
|
|
|
verbose: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: fmt.Sprintf("%s/bzz:/%s", srv.URL, hash),
|
|
|
|
method: "PUT",
|
|
|
|
headers: map[string]string{},
|
2018-09-06 10:11:38 +00:00
|
|
|
expectedStatusCode: http.StatusMethodNotAllowed,
|
2018-08-07 10:00:12 +00:00
|
|
|
verbose: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: fmt.Sprintf("%s/bzz-raw:/%s", srv.URL, hash),
|
|
|
|
method: "PUT",
|
|
|
|
headers: map[string]string{},
|
2018-09-06 10:11:38 +00:00
|
|
|
expectedStatusCode: http.StatusMethodNotAllowed,
|
2018-08-07 10:00:12 +00:00
|
|
|
verbose: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: fmt.Sprintf("%s/bzz:/%s", srv.URL, hash),
|
|
|
|
method: "PATCH",
|
|
|
|
headers: map[string]string{},
|
2018-09-06 10:11:38 +00:00
|
|
|
expectedStatusCode: http.StatusMethodNotAllowed,
|
2018-08-07 10:00:12 +00:00
|
|
|
verbose: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: fmt.Sprintf("%s/bzz-raw:/", srv.URL),
|
|
|
|
method: "POST",
|
|
|
|
headers: map[string]string{},
|
|
|
|
requestBody: []byte("POSTdata"),
|
2018-09-06 10:11:38 +00:00
|
|
|
expectedStatusCode: http.StatusOK,
|
2018-08-07 10:00:12 +00:00
|
|
|
assertResponseHeaders: map[string]string{"Content-Length": "64"},
|
|
|
|
verbose: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: fmt.Sprintf("%s/bzz-raw:/encrypt", srv.URL),
|
|
|
|
method: "POST",
|
|
|
|
headers: map[string]string{},
|
|
|
|
requestBody: []byte("POSTdata"),
|
2018-09-06 10:11:38 +00:00
|
|
|
expectedStatusCode: http.StatusOK,
|
2018-08-07 10:00:12 +00:00
|
|
|
assertResponseHeaders: map[string]string{"Content-Length": "128"},
|
|
|
|
verbose: false,
|
|
|
|
},
|
2018-08-07 11:40:38 +00:00
|
|
|
} {
|
2018-08-07 10:00:12 +00:00
|
|
|
t.Run(testCase.method+" "+testCase.uri, func(t *testing.T) {
|
|
|
|
reqBody := bytes.NewReader(testCase.requestBody)
|
|
|
|
res, body := httpDo(testCase.method, testCase.uri, reqBody, testCase.headers, testCase.verbose, t)
|
|
|
|
|
|
|
|
if res.StatusCode != testCase.expectedStatusCode {
|
2018-10-01 11:39:39 +00:00
|
|
|
t.Fatalf("expected status code %d but got %d, %s", testCase.expectedStatusCode, res.StatusCode, body)
|
2018-08-07 10:00:12 +00:00
|
|
|
}
|
|
|
|
if testCase.assertResponseBody != "" && !strings.Contains(body, testCase.assertResponseBody) {
|
|
|
|
t.Log(body)
|
2018-08-07 11:40:38 +00:00
|
|
|
t.Fatalf("expected response %s but got %s", testCase.assertResponseBody, body)
|
2018-08-07 10:00:12 +00:00
|
|
|
}
|
|
|
|
for key, value := range testCase.assertResponseHeaders {
|
|
|
|
if res.Header.Get(key) != value {
|
|
|
|
t.Logf("expected %s=%s in HTTP response header but got %s", key, value, res.Header.Get(key))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMultiPartUpload(t *testing.T) {
|
|
|
|
// POST /bzz:/ Content-Type: multipart/form-data
|
|
|
|
verbose := false
|
|
|
|
// Setup Swarm
|
2018-11-14 08:21:14 +00:00
|
|
|
srv := NewTestSwarmServer(t, serverFunc, nil)
|
2018-08-07 10:00:12 +00:00
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
url := fmt.Sprintf("%s/bzz:/", srv.URL)
|
|
|
|
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
form := multipart.NewWriter(buf)
|
|
|
|
form.WriteField("name", "John Doe")
|
|
|
|
file1, _ := form.CreateFormFile("cv", "cv.txt")
|
|
|
|
file1.Write([]byte("John Doe's Credentials"))
|
|
|
|
file2, _ := form.CreateFormFile("profile_picture", "profile.jpg")
|
|
|
|
file2.Write([]byte("imaginethisisjpegdata"))
|
|
|
|
form.Close()
|
|
|
|
|
|
|
|
headers := map[string]string{
|
|
|
|
"Content-Type": form.FormDataContentType(),
|
|
|
|
"Content-Length": strconv.Itoa(buf.Len()),
|
|
|
|
}
|
|
|
|
res, body := httpDo("POST", url, buf, headers, verbose, t)
|
|
|
|
|
2018-09-06 10:11:38 +00:00
|
|
|
if res.StatusCode != http.StatusOK {
|
2018-08-07 10:00:12 +00:00
|
|
|
t.Fatalf("expected POST multipart/form-data to return 200, but it returned %d", res.StatusCode)
|
|
|
|
}
|
|
|
|
if len(body) != 64 {
|
|
|
|
t.Fatalf("expected POST multipart/form-data to return a 64 char manifest but the answer was %d chars long", len(body))
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 10:08:39 +00:00
|
|
|
|
|
|
|
// TestBzzGetFileWithResolver tests fetching a file using a mocked ENS resolver
|
|
|
|
func TestBzzGetFileWithResolver(t *testing.T) {
|
|
|
|
resolver := newTestResolveValidator("")
|
2018-11-14 08:21:14 +00:00
|
|
|
srv := NewTestSwarmServer(t, serverFunc, resolver)
|
2018-09-06 10:08:39 +00:00
|
|
|
defer srv.Close()
|
|
|
|
fileNames := []string{"dir1/tmp1.txt", "dir2/tmp2.lock", "dir3/tmp3.rtf"}
|
|
|
|
fileContents := []string{"tmp1textfilevalue", "tmp2lockfilelocked", "tmp3isjustaplaintextfile"}
|
|
|
|
|
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
tw := tar.NewWriter(buf)
|
|
|
|
|
|
|
|
for i, v := range fileNames {
|
|
|
|
size := len(fileContents[i])
|
|
|
|
hdr := &tar.Header{
|
|
|
|
Name: v,
|
|
|
|
Mode: 0644,
|
|
|
|
Size: int64(size),
|
|
|
|
ModTime: time.Now(),
|
|
|
|
Xattrs: map[string]string{
|
|
|
|
"user.swarm.content-type": "text/plain",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if err := tw.WriteHeader(hdr); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy the file into the tar stream
|
|
|
|
n, err := io.WriteString(tw, fileContents[i])
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != size {
|
|
|
|
t.Fatal("size mismatch")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := tw.Close(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
//post tar stream
|
|
|
|
url := srv.URL + "/bzz:/"
|
|
|
|
|
|
|
|
req, err := http.NewRequest("POST", url, buf)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
req.Header.Add("Content-Type", "application/x-tar")
|
|
|
|
client := &http.Client{}
|
|
|
|
serverResponse, err := client.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if serverResponse.StatusCode != http.StatusOK {
|
|
|
|
t.Fatalf("err %s", serverResponse.Status)
|
|
|
|
}
|
|
|
|
swarmHash, err := ioutil.ReadAll(serverResponse.Body)
|
|
|
|
serverResponse.Body.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
// set the resolved hash to be the swarm hash of what we've just uploaded
|
|
|
|
hash := common.HexToHash(string(swarmHash))
|
|
|
|
resolver.hash = &hash
|
|
|
|
for _, v := range []struct {
|
2018-10-01 11:39:39 +00:00
|
|
|
addr string
|
|
|
|
path string
|
|
|
|
expectedStatusCode int
|
|
|
|
expectedContentType string
|
|
|
|
expectedFileName string
|
2018-09-06 10:08:39 +00:00
|
|
|
}{
|
|
|
|
{
|
2018-10-01 11:39:39 +00:00
|
|
|
addr: string(swarmHash),
|
|
|
|
path: fileNames[0],
|
|
|
|
expectedStatusCode: http.StatusOK,
|
|
|
|
expectedContentType: "text/plain",
|
|
|
|
expectedFileName: path.Base(fileNames[0]),
|
2018-09-06 10:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
2018-10-01 11:39:39 +00:00
|
|
|
addr: "somebogusensname",
|
|
|
|
path: fileNames[0],
|
|
|
|
expectedStatusCode: http.StatusOK,
|
|
|
|
expectedContentType: "text/plain",
|
|
|
|
expectedFileName: path.Base(fileNames[0]),
|
2018-09-06 10:08:39 +00:00
|
|
|
},
|
|
|
|
} {
|
|
|
|
req, err := http.NewRequest("GET", fmt.Sprintf(srv.URL+"/bzz:/%s/%s", v.addr, v.path), nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
serverResponse, err := client.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer serverResponse.Body.Close()
|
|
|
|
if serverResponse.StatusCode != v.expectedStatusCode {
|
|
|
|
t.Fatalf("expected %d, got %d", v.expectedStatusCode, serverResponse.StatusCode)
|
|
|
|
}
|
2018-10-01 11:39:39 +00:00
|
|
|
|
|
|
|
if h := serverResponse.Header.Get("Content-Type"); h != v.expectedContentType {
|
|
|
|
t.Fatalf("Content-Type header expected: %s, got %s", v.expectedContentType, h)
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedContentDisposition := fmt.Sprintf("inline; filename=\"%s\"", v.expectedFileName)
|
|
|
|
if h := serverResponse.Header.Get("Content-Disposition"); h != expectedContentDisposition {
|
|
|
|
t.Fatalf("Content-Disposition header expected: %s, got: %s", expectedContentDisposition, h)
|
|
|
|
}
|
|
|
|
|
2018-09-06 10:08:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-05 18:34:22 +00:00
|
|
|
// TestCalculateNumberOfChunks is a unit test for the chunk-number-according-to-content-length
|
|
|
|
// calculation
|
|
|
|
func TestCalculateNumberOfChunks(t *testing.T) {
|
|
|
|
|
|
|
|
//test cases:
|
|
|
|
for _, tc := range []struct{ len, chunks int64 }{
|
|
|
|
{len: 1000, chunks: 1},
|
|
|
|
{len: 5000, chunks: 3},
|
|
|
|
{len: 10000, chunks: 4},
|
|
|
|
{len: 100000, chunks: 26},
|
|
|
|
{len: 1000000, chunks: 248},
|
|
|
|
{len: 325839339210, chunks: 79550620 + 621490 + 4856 + 38 + 1},
|
|
|
|
} {
|
|
|
|
res := calculateNumberOfChunks(tc.len, false)
|
|
|
|
if res != tc.chunks {
|
|
|
|
t.Fatalf("expected result for %d bytes to be %d got %d", tc.len, tc.chunks, res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestCalculateNumberOfChunksEncrypted is a unit test for the chunk-number-according-to-content-length
|
|
|
|
// calculation with encryption (branching factor=64)
|
|
|
|
func TestCalculateNumberOfChunksEncrypted(t *testing.T) {
|
|
|
|
|
|
|
|
//test cases:
|
|
|
|
for _, tc := range []struct{ len, chunks int64 }{
|
|
|
|
{len: 1000, chunks: 1},
|
|
|
|
{len: 5000, chunks: 3},
|
|
|
|
{len: 10000, chunks: 4},
|
|
|
|
{len: 100000, chunks: 26},
|
|
|
|
{len: 1000000, chunks: 245 + 4 + 1},
|
|
|
|
{len: 325839339210, chunks: 79550620 + 1242979 + 19422 + 304 + 5 + 1},
|
|
|
|
} {
|
|
|
|
res := calculateNumberOfChunks(tc.len, true)
|
|
|
|
if res != tc.chunks {
|
|
|
|
t.Fatalf("expected result for %d bytes to be %d got %d", tc.len, tc.chunks, res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-06 10:08:39 +00:00
|
|
|
// testResolver implements the Resolver interface and either returns the given
|
|
|
|
// hash if it is set, or returns a "name not found" error
|
|
|
|
type testResolveValidator struct {
|
|
|
|
hash *common.Hash
|
|
|
|
}
|
|
|
|
|
|
|
|
func newTestResolveValidator(addr string) *testResolveValidator {
|
|
|
|
r := &testResolveValidator{}
|
|
|
|
if addr != "" {
|
|
|
|
hash := common.HexToHash(addr)
|
|
|
|
r.hash = &hash
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *testResolveValidator) Resolve(addr string) (common.Hash, error) {
|
|
|
|
if t.hash == nil {
|
|
|
|
return common.Hash{}, fmt.Errorf("DNS name not found: %q", addr)
|
|
|
|
}
|
|
|
|
return *t.hash, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *testResolveValidator) Owner(node [32]byte) (addr common.Address, err error) {
|
|
|
|
return
|
|
|
|
}
|
2019-05-05 18:34:22 +00:00
|
|
|
|
2018-09-06 10:08:39 +00:00
|
|
|
func (t *testResolveValidator) HeaderByNumber(context.Context, *big.Int) (header *types.Header, err error) {
|
|
|
|
return
|
|
|
|
}
|