2016-08-29 22:18:00 +03:00
|
|
|
// Copyright 2016 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/>.
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
2018-10-01 14:39:39 +03:00
|
|
|
//go:generate mimegen --types=./../../cmd/swarm/mimegen/mime.types --package=api --out=gen_mime.go
|
|
|
|
//go:generate gofmt -s -w gen_mime.go
|
|
|
|
|
2016-08-29 22:18:00 +03:00
|
|
|
import (
|
2018-07-12 16:42:45 +03:00
|
|
|
"archive/tar"
|
2018-06-20 15:06:27 +03:00
|
|
|
"context"
|
2018-08-15 18:41:52 +03:00
|
|
|
"crypto/ecdsa"
|
|
|
|
"encoding/hex"
|
|
|
|
"errors"
|
2016-08-29 22:18:00 +03:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2018-06-20 15:06:27 +03:00
|
|
|
"math/big"
|
2017-01-26 22:33:39 +03:00
|
|
|
"net/http"
|
2017-12-05 00:56:52 +03:00
|
|
|
"path"
|
2016-08-29 22:18:00 +03:00
|
|
|
"strings"
|
|
|
|
|
2017-04-12 03:06:02 +03:00
|
|
|
"bytes"
|
|
|
|
"mime"
|
|
|
|
"path/filepath"
|
|
|
|
"time"
|
2017-05-13 03:02:25 +03:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2018-06-20 15:06:27 +03:00
|
|
|
"github.com/ethereum/go-ethereum/contracts/ens"
|
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2018-02-23 16:19:59 +03:00
|
|
|
"github.com/ethereum/go-ethereum/metrics"
|
2018-06-20 15:06:27 +03:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/log"
|
|
|
|
"github.com/ethereum/go-ethereum/swarm/multihash"
|
2018-07-13 18:40:28 +03:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/spancontext"
|
2017-05-13 03:02:25 +03:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/storage"
|
2018-10-03 10:15:17 +03:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/storage/feed"
|
|
|
|
"github.com/ethereum/go-ethereum/swarm/storage/feed/lookup"
|
2018-09-30 10:51:11 +03:00
|
|
|
|
|
|
|
opentracing "github.com/opentracing/opentracing-go"
|
2016-08-29 22:18:00 +03:00
|
|
|
)
|
|
|
|
|
2018-08-15 18:41:52 +03:00
|
|
|
var (
|
|
|
|
ErrNotFound = errors.New("not found")
|
|
|
|
)
|
|
|
|
|
2018-02-23 16:19:59 +03:00
|
|
|
var (
|
2018-07-12 16:42:45 +03:00
|
|
|
apiResolveCount = metrics.NewRegisteredCounter("api.resolve.count", nil)
|
|
|
|
apiResolveFail = metrics.NewRegisteredCounter("api.resolve.fail", nil)
|
|
|
|
apiPutCount = metrics.NewRegisteredCounter("api.put.count", nil)
|
|
|
|
apiPutFail = metrics.NewRegisteredCounter("api.put.fail", nil)
|
|
|
|
apiGetCount = metrics.NewRegisteredCounter("api.get.count", nil)
|
|
|
|
apiGetNotFound = metrics.NewRegisteredCounter("api.get.notfound", nil)
|
|
|
|
apiGetHTTP300 = metrics.NewRegisteredCounter("api.get.http.300", nil)
|
|
|
|
apiManifestUpdateCount = metrics.NewRegisteredCounter("api.manifestupdate.count", nil)
|
|
|
|
apiManifestUpdateFail = metrics.NewRegisteredCounter("api.manifestupdate.fail", nil)
|
|
|
|
apiManifestListCount = metrics.NewRegisteredCounter("api.manifestlist.count", nil)
|
|
|
|
apiManifestListFail = metrics.NewRegisteredCounter("api.manifestlist.fail", nil)
|
|
|
|
apiDeleteCount = metrics.NewRegisteredCounter("api.delete.count", nil)
|
|
|
|
apiDeleteFail = metrics.NewRegisteredCounter("api.delete.fail", nil)
|
|
|
|
apiGetTarCount = metrics.NewRegisteredCounter("api.gettar.count", nil)
|
|
|
|
apiGetTarFail = metrics.NewRegisteredCounter("api.gettar.fail", nil)
|
|
|
|
apiUploadTarCount = metrics.NewRegisteredCounter("api.uploadtar.count", nil)
|
|
|
|
apiUploadTarFail = metrics.NewRegisteredCounter("api.uploadtar.fail", nil)
|
|
|
|
apiModifyCount = metrics.NewRegisteredCounter("api.modify.count", nil)
|
|
|
|
apiModifyFail = metrics.NewRegisteredCounter("api.modify.fail", nil)
|
|
|
|
apiAddFileCount = metrics.NewRegisteredCounter("api.addfile.count", nil)
|
|
|
|
apiAddFileFail = metrics.NewRegisteredCounter("api.addfile.fail", nil)
|
|
|
|
apiRmFileCount = metrics.NewRegisteredCounter("api.removefile.count", nil)
|
|
|
|
apiRmFileFail = metrics.NewRegisteredCounter("api.removefile.fail", nil)
|
|
|
|
apiAppendFileCount = metrics.NewRegisteredCounter("api.appendfile.count", nil)
|
|
|
|
apiAppendFileFail = metrics.NewRegisteredCounter("api.appendfile.fail", nil)
|
|
|
|
apiGetInvalid = metrics.NewRegisteredCounter("api.get.invalid", nil)
|
2018-02-23 16:19:59 +03:00
|
|
|
)
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// Resolver interface resolve a domain name to a hash using ENS
|
2016-08-29 22:18:00 +03:00
|
|
|
type Resolver interface {
|
|
|
|
Resolve(string) (common.Hash, error)
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// ResolveValidator is used to validate the contained Resolver
|
|
|
|
type ResolveValidator interface {
|
|
|
|
Resolver
|
|
|
|
Owner(node [32]byte) (common.Address, error)
|
|
|
|
HeaderByNumber(context.Context, *big.Int) (*types.Header, error)
|
|
|
|
}
|
|
|
|
|
2017-12-19 01:07:48 +03:00
|
|
|
// NoResolverError is returned by MultiResolver.Resolve if no resolver
|
2017-12-01 12:32:14 +03:00
|
|
|
// can be found for the address.
|
2017-12-19 01:07:48 +03:00
|
|
|
type NoResolverError struct {
|
|
|
|
TLD string
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// NewNoResolverError creates a NoResolverError for the given top level domain
|
2017-12-19 01:07:48 +03:00
|
|
|
func NewNoResolverError(tld string) *NoResolverError {
|
|
|
|
return &NoResolverError{TLD: tld}
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// Error NoResolverError implements error
|
2017-12-19 01:07:48 +03:00
|
|
|
func (e *NoResolverError) Error() string {
|
|
|
|
if e.TLD == "" {
|
|
|
|
return "no ENS resolver"
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("no ENS endpoint configured to resolve .%s TLD names", e.TLD)
|
|
|
|
}
|
2017-12-01 12:32:14 +03:00
|
|
|
|
|
|
|
// MultiResolver is used to resolve URL addresses based on their TLDs.
|
2018-08-27 11:51:58 +03:00
|
|
|
// Each TLD can have multiple resolvers, and the resolution from the
|
2017-12-01 12:32:14 +03:00
|
|
|
// first one in the sequence will be returned.
|
|
|
|
type MultiResolver struct {
|
2018-06-20 15:06:27 +03:00
|
|
|
resolvers map[string][]ResolveValidator
|
|
|
|
nameHash func(string) common.Hash
|
2017-12-01 12:32:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// MultiResolverOption sets options for MultiResolver and is used as
|
|
|
|
// arguments for its constructor.
|
|
|
|
type MultiResolverOption func(*MultiResolver)
|
|
|
|
|
|
|
|
// MultiResolverOptionWithResolver adds a Resolver to a list of resolvers
|
|
|
|
// for a specific TLD. If TLD is an empty string, the resolver will be added
|
|
|
|
// to the list of default resolver, the ones that will be used for resolution
|
|
|
|
// of addresses which do not have their TLD resolver specified.
|
2018-06-20 15:06:27 +03:00
|
|
|
func MultiResolverOptionWithResolver(r ResolveValidator, tld string) MultiResolverOption {
|
2017-12-01 12:32:14 +03:00
|
|
|
return func(m *MultiResolver) {
|
|
|
|
m.resolvers[tld] = append(m.resolvers[tld], r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// MultiResolverOptionWithNameHash is unused at the time of this writing
|
|
|
|
func MultiResolverOptionWithNameHash(nameHash func(string) common.Hash) MultiResolverOption {
|
|
|
|
return func(m *MultiResolver) {
|
|
|
|
m.nameHash = nameHash
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 12:32:14 +03:00
|
|
|
// NewMultiResolver creates a new instance of MultiResolver.
|
|
|
|
func NewMultiResolver(opts ...MultiResolverOption) (m *MultiResolver) {
|
|
|
|
m = &MultiResolver{
|
2018-06-20 15:06:27 +03:00
|
|
|
resolvers: make(map[string][]ResolveValidator),
|
|
|
|
nameHash: ens.EnsNode,
|
2017-12-01 12:32:14 +03:00
|
|
|
}
|
|
|
|
for _, o := range opts {
|
|
|
|
o(m)
|
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resolve resolves address by choosing a Resolver by TLD.
|
|
|
|
// If there are more default Resolvers, or for a specific TLD,
|
2018-08-27 11:49:29 +03:00
|
|
|
// the Hash from the first one which does not return error
|
2017-12-01 12:32:14 +03:00
|
|
|
// will be returned.
|
2018-06-20 15:06:27 +03:00
|
|
|
func (m *MultiResolver) Resolve(addr string) (h common.Hash, err error) {
|
|
|
|
rs, err := m.getResolveValidator(addr)
|
|
|
|
if err != nil {
|
|
|
|
return h, err
|
2017-12-01 12:32:14 +03:00
|
|
|
}
|
|
|
|
for _, r := range rs {
|
|
|
|
h, err = r.Resolve(addr)
|
|
|
|
if err == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// ValidateOwner checks the ENS to validate that the owner of the given domain is the given eth address
|
|
|
|
func (m *MultiResolver) ValidateOwner(name string, address common.Address) (bool, error) {
|
|
|
|
rs, err := m.getResolveValidator(name)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
var addr common.Address
|
|
|
|
for _, r := range rs {
|
|
|
|
addr, err = r.Owner(m.nameHash(name))
|
|
|
|
// we hide the error if it is not for the last resolver we check
|
|
|
|
if err == nil {
|
|
|
|
return addr == address, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// HeaderByNumber uses the validator of the given domainname and retrieves the header for the given block number
|
|
|
|
func (m *MultiResolver) HeaderByNumber(ctx context.Context, name string, blockNr *big.Int) (*types.Header, error) {
|
|
|
|
rs, err := m.getResolveValidator(name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
for _, r := range rs {
|
|
|
|
var header *types.Header
|
|
|
|
header, err = r.HeaderByNumber(ctx, blockNr)
|
|
|
|
// we hide the error if it is not for the last resolver we check
|
|
|
|
if err == nil {
|
|
|
|
return header, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// getResolveValidator uses the hostname to retrieve the resolver associated with the top level domain
|
|
|
|
func (m *MultiResolver) getResolveValidator(name string) ([]ResolveValidator, error) {
|
|
|
|
rs := m.resolvers[""]
|
|
|
|
tld := path.Ext(name)
|
|
|
|
if tld != "" {
|
|
|
|
tld = tld[1:]
|
|
|
|
rstld, ok := m.resolvers[tld]
|
|
|
|
if ok {
|
|
|
|
return rstld, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(rs) == 0 {
|
|
|
|
return rs, NewNoResolverError(tld)
|
|
|
|
}
|
|
|
|
return rs, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNameHash sets the hasher function that hashes the domain into a name hash that ENS uses
|
|
|
|
func (m *MultiResolver) SetNameHash(nameHash func(string) common.Hash) {
|
|
|
|
m.nameHash = nameHash
|
|
|
|
}
|
|
|
|
|
2016-08-29 22:18:00 +03:00
|
|
|
/*
|
2018-06-20 15:06:27 +03:00
|
|
|
API implements webserver/file system related content storage and retrieval
|
|
|
|
on top of the FileStore
|
|
|
|
it is the public interface of the FileStore which is included in the ethereum stack
|
2016-08-29 22:18:00 +03:00
|
|
|
*/
|
2018-06-20 15:06:27 +03:00
|
|
|
type API struct {
|
2018-10-03 10:15:17 +03:00
|
|
|
feed *feed.Handler
|
2018-06-20 15:06:27 +03:00
|
|
|
fileStore *storage.FileStore
|
|
|
|
dns Resolver
|
2018-08-15 18:41:52 +03:00
|
|
|
Decryptor func(context.Context, string) DecryptFunc
|
2016-08-29 22:18:00 +03:00
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// NewAPI the api constructor initialises a new API instance.
|
2018-10-03 10:15:17 +03:00
|
|
|
func NewAPI(fileStore *storage.FileStore, dns Resolver, feedHandler *feed.Handler, pk *ecdsa.PrivateKey) (self *API) {
|
2018-06-20 15:06:27 +03:00
|
|
|
self = &API{
|
|
|
|
fileStore: fileStore,
|
|
|
|
dns: dns,
|
2018-10-03 10:15:17 +03:00
|
|
|
feed: feedHandler,
|
2018-08-15 18:41:52 +03:00
|
|
|
Decryptor: func(ctx context.Context, credentials string) DecryptFunc {
|
|
|
|
return self.doDecrypt(ctx, credentials, pk)
|
|
|
|
},
|
2016-08-29 22:18:00 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// Retrieve FileStore reader API
|
2018-07-09 15:11:49 +03:00
|
|
|
func (a *API) Retrieve(ctx context.Context, addr storage.Address) (reader storage.LazySectionReader, isEncrypted bool) {
|
|
|
|
return a.fileStore.Retrieve(ctx, addr)
|
2016-08-29 22:18:00 +03:00
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// Store wraps the Store API call of the embedded FileStore
|
2018-07-09 15:11:49 +03:00
|
|
|
func (a *API) Store(ctx context.Context, data io.Reader, size int64, toEncrypt bool) (addr storage.Address, wait func(ctx context.Context) error, err error) {
|
2018-06-20 15:06:27 +03:00
|
|
|
log.Debug("api.store", "size", size)
|
2018-07-09 15:11:49 +03:00
|
|
|
return a.fileStore.Store(ctx, data, size, toEncrypt)
|
2016-08-29 22:18:00 +03:00
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// ErrResolve is returned when an URI cannot be resolved from ENS.
|
2016-08-29 22:18:00 +03:00
|
|
|
type ErrResolve error
|
|
|
|
|
2018-08-15 18:41:52 +03:00
|
|
|
// Resolve a name into a content-addressed hash
|
|
|
|
// where address could be an ENS name, or a content addressed hash
|
|
|
|
func (a *API) Resolve(ctx context.Context, address string) (storage.Address, error) {
|
|
|
|
// if DNS is not configured, return an error
|
|
|
|
if a.dns == nil {
|
|
|
|
if hashMatcher.MatchString(address) {
|
|
|
|
return common.Hex2Bytes(address), nil
|
|
|
|
}
|
|
|
|
apiResolveFail.Inc(1)
|
|
|
|
return nil, fmt.Errorf("no DNS to resolve name: %q", address)
|
|
|
|
}
|
|
|
|
// try and resolve the address
|
|
|
|
resolved, err := a.dns.Resolve(address)
|
|
|
|
if err != nil {
|
|
|
|
if hashMatcher.MatchString(address) {
|
|
|
|
return common.Hex2Bytes(address), nil
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resolved[:], nil
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// Resolve resolves a URI to an Address using the MultiResolver.
|
2018-08-15 18:41:52 +03:00
|
|
|
func (a *API) ResolveURI(ctx context.Context, uri *URI, credentials string) (storage.Address, error) {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiResolveCount.Inc(1)
|
2018-06-20 15:06:27 +03:00
|
|
|
log.Trace("resolving", "uri", uri.Addr)
|
2017-04-13 12:06:19 +03:00
|
|
|
|
2018-07-13 18:40:28 +03:00
|
|
|
var sp opentracing.Span
|
|
|
|
ctx, sp = spancontext.StartSpan(
|
|
|
|
ctx,
|
|
|
|
"api.resolve")
|
|
|
|
defer sp.Finish()
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// if the URI is immutable, check if the address looks like a hash
|
|
|
|
if uri.Immutable() {
|
|
|
|
key := uri.Address()
|
|
|
|
if key == nil {
|
2017-05-13 03:02:25 +03:00
|
|
|
return nil, fmt.Errorf("immutable address not a content hash: %q", uri.Addr)
|
2017-04-13 12:06:19 +03:00
|
|
|
}
|
2018-06-20 15:06:27 +03:00
|
|
|
return key, nil
|
2017-04-13 12:06:19 +03:00
|
|
|
}
|
2017-05-13 03:02:25 +03:00
|
|
|
|
2018-08-15 18:41:52 +03:00
|
|
|
addr, err := a.Resolve(ctx, uri.Addr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-08-29 22:18:00 +03:00
|
|
|
}
|
2017-05-13 03:02:25 +03:00
|
|
|
|
2018-08-15 18:41:52 +03:00
|
|
|
if uri.Path == "" {
|
|
|
|
return addr, nil
|
2018-06-20 15:06:27 +03:00
|
|
|
}
|
2018-08-15 18:41:52 +03:00
|
|
|
walker, err := a.NewManifestWalker(ctx, addr, a.Decryptor(ctx, credentials), nil)
|
|
|
|
if err != nil {
|
2017-05-13 03:02:25 +03:00
|
|
|
return nil, err
|
2016-08-29 22:18:00 +03:00
|
|
|
}
|
2018-08-15 18:41:52 +03:00
|
|
|
var entry *ManifestEntry
|
|
|
|
walker.Walk(func(e *ManifestEntry) error {
|
|
|
|
// if the entry matches the path, set entry and stop
|
|
|
|
// the walk
|
|
|
|
if e.Path == uri.Path {
|
|
|
|
entry = e
|
|
|
|
// return an error to cancel the walk
|
|
|
|
return errors.New("found")
|
|
|
|
}
|
|
|
|
// ignore non-manifest files
|
|
|
|
if e.ContentType != ManifestType {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
// if the manifest's path is a prefix of the
|
|
|
|
// requested path, recurse into it by returning
|
|
|
|
// nil and continuing the walk
|
|
|
|
if strings.HasPrefix(uri.Path, e.Path) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return ErrSkipManifest
|
|
|
|
})
|
|
|
|
if entry == nil {
|
|
|
|
return nil, errors.New("not found")
|
|
|
|
}
|
|
|
|
addr = storage.Address(common.Hex2Bytes(entry.Hash))
|
|
|
|
return addr, nil
|
2016-08-29 22:18:00 +03:00
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// Put provides singleton manifest creation on top of FileStore store
|
2018-07-09 15:11:49 +03:00
|
|
|
func (a *API) Put(ctx context.Context, content string, contentType string, toEncrypt bool) (k storage.Address, wait func(context.Context) error, err error) {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiPutCount.Inc(1)
|
2016-08-29 22:18:00 +03:00
|
|
|
r := strings.NewReader(content)
|
2018-07-09 15:11:49 +03:00
|
|
|
key, waitContent, err := a.fileStore.Store(ctx, r, int64(len(content)), toEncrypt)
|
2016-08-29 22:18:00 +03:00
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiPutFail.Inc(1)
|
2018-06-20 15:06:27 +03:00
|
|
|
return nil, nil, err
|
2016-08-29 22:18:00 +03:00
|
|
|
}
|
|
|
|
manifest := fmt.Sprintf(`{"entries":[{"hash":"%v","contentType":"%s"}]}`, key, contentType)
|
|
|
|
r = strings.NewReader(manifest)
|
2018-07-09 15:11:49 +03:00
|
|
|
key, waitManifest, err := a.fileStore.Store(ctx, r, int64(len(manifest)), toEncrypt)
|
2016-08-29 22:18:00 +03:00
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiPutFail.Inc(1)
|
2018-06-20 15:06:27 +03:00
|
|
|
return nil, nil, err
|
2016-08-29 22:18:00 +03:00
|
|
|
}
|
2018-07-09 15:11:49 +03:00
|
|
|
return key, func(ctx context.Context) error {
|
|
|
|
err := waitContent(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return waitManifest(ctx)
|
2018-06-20 15:06:27 +03:00
|
|
|
}, nil
|
2016-08-29 22:18:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get uses iterative manifest retrieval and prefix matching
|
2018-06-20 15:06:27 +03:00
|
|
|
// to resolve basePath to content using FileStore retrieve
|
|
|
|
// it returns a section reader, mimeType, status, the key of the actual content and an error
|
2018-08-15 18:41:52 +03:00
|
|
|
func (a *API) Get(ctx context.Context, decrypt DecryptFunc, manifestAddr storage.Address, path string) (reader storage.LazySectionReader, mimeType string, status int, contentAddr storage.Address, err error) {
|
2018-06-20 15:06:27 +03:00
|
|
|
log.Debug("api.get", "key", manifestAddr, "path", path)
|
2018-02-23 16:19:59 +03:00
|
|
|
apiGetCount.Inc(1)
|
2018-08-15 18:41:52 +03:00
|
|
|
trie, err := loadManifest(ctx, a.fileStore, manifestAddr, nil, decrypt)
|
2016-08-29 22:18:00 +03:00
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiGetNotFound.Inc(1)
|
2017-09-08 21:29:09 +03:00
|
|
|
status = http.StatusNotFound
|
2018-08-07 12:56:55 +03:00
|
|
|
return nil, "", http.StatusNotFound, nil, err
|
2016-08-29 22:18:00 +03:00
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
log.Debug("trie getting entry", "key", manifestAddr, "path", path)
|
2016-08-29 22:18:00 +03:00
|
|
|
entry, _ := trie.getEntry(path)
|
2017-01-26 22:33:39 +03:00
|
|
|
|
2016-08-29 22:18:00 +03:00
|
|
|
if entry != nil {
|
2018-06-20 15:06:27 +03:00
|
|
|
log.Debug("trie got entry", "key", manifestAddr, "path", path, "entry.Hash", entry.Hash)
|
2018-08-15 18:41:52 +03:00
|
|
|
|
|
|
|
if entry.ContentType == ManifestType {
|
|
|
|
log.Debug("entry is manifest", "key", manifestAddr, "new key", entry.Hash)
|
|
|
|
adr, err := hex.DecodeString(entry.Hash)
|
|
|
|
if err != nil {
|
|
|
|
return nil, "", 0, nil, err
|
|
|
|
}
|
|
|
|
return a.Get(ctx, decrypt, adr, entry.Path)
|
|
|
|
}
|
|
|
|
|
2018-10-02 10:32:46 +03:00
|
|
|
// we need to do some extra work if this is a Swarm feed manifest
|
2018-09-30 10:43:10 +03:00
|
|
|
if entry.ContentType == FeedContentType {
|
|
|
|
if entry.Feed == nil {
|
|
|
|
return reader, mimeType, status, nil, fmt.Errorf("Cannot decode Feed in 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 13:07:17 +03:00
|
|
|
}
|
2018-10-03 10:15:17 +03:00
|
|
|
_, err := a.feed.Lookup(ctx, feed.NewQueryLatest(entry.Feed, lookup.NoClue))
|
2018-06-20 15:06:27 +03:00
|
|
|
if err != nil {
|
|
|
|
apiGetNotFound.Inc(1)
|
|
|
|
status = http.StatusNotFound
|
2018-09-30 10:43:10 +03:00
|
|
|
log.Debug(fmt.Sprintf("get feed update content error: %v", err))
|
2018-06-20 15:06:27 +03:00
|
|
|
return reader, mimeType, status, nil, 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 13:07:17 +03:00
|
|
|
// get the data of the update
|
2018-10-03 10:15:17 +03:00
|
|
|
_, rsrcData, err := a.feed.GetContent(entry.Feed)
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 13:07:17 +03:00
|
|
|
if err != nil {
|
|
|
|
apiGetNotFound.Inc(1)
|
|
|
|
status = http.StatusNotFound
|
2018-09-30 10:43:10 +03:00
|
|
|
log.Warn(fmt.Sprintf("get feed update content error: %v", 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 13:07:17 +03:00
|
|
|
return reader, mimeType, status, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// extract multihash
|
|
|
|
decodedMultihash, err := multihash.FromMultihash(rsrcData)
|
|
|
|
if err != nil {
|
|
|
|
apiGetInvalid.Inc(1)
|
|
|
|
status = http.StatusUnprocessableEntity
|
2018-09-30 10:43:10 +03:00
|
|
|
log.Warn("invalid multihash in feed update", "err", 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 13:07:17 +03:00
|
|
|
return reader, mimeType, status, nil, err
|
|
|
|
}
|
|
|
|
manifestAddr = storage.Address(decodedMultihash)
|
2018-09-30 10:43:10 +03:00
|
|
|
log.Trace("feed update contains multihash", "key", manifestAddr)
|
2018-06-20 15:06:27 +03: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 13:07:17 +03:00
|
|
|
// get the manifest the multihash digest points to
|
|
|
|
trie, err := loadManifest(ctx, a.fileStore, manifestAddr, nil, NOOPDecrypt)
|
2018-06-20 15:06:27 +03:00
|
|
|
if err != nil {
|
|
|
|
apiGetNotFound.Inc(1)
|
|
|
|
status = http.StatusNotFound
|
2018-09-30 10:43:10 +03:00
|
|
|
log.Warn(fmt.Sprintf("loadManifestTrie (feed update multihash) error: %v", err))
|
2018-06-20 15:06:27 +03:00
|
|
|
return reader, mimeType, status, nil, 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 13:07:17 +03:00
|
|
|
// finally, get the manifest entry
|
|
|
|
// it will always be the entry on path ""
|
|
|
|
entry, _ = trie.getEntry(path)
|
|
|
|
if entry == nil {
|
|
|
|
status = http.StatusNotFound
|
|
|
|
apiGetNotFound.Inc(1)
|
2018-09-30 10:43:10 +03:00
|
|
|
err = fmt.Errorf("manifest (feed update multihash) entry for '%s' not found", path)
|
|
|
|
log.Trace("manifest (feed update multihash) entry not found", "key", manifestAddr, "path", path)
|
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 13:07:17 +03:00
|
|
|
return reader, mimeType, status, nil, err
|
2018-06-20 15:06:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-30 10:43:10 +03:00
|
|
|
// regardless of feed update manifests or normal manifests we will converge at this point
|
2018-06-20 15:06:27 +03:00
|
|
|
// get the key the manifest entry points to and serve it if it's unambiguous
|
|
|
|
contentAddr = common.Hex2Bytes(entry.Hash)
|
2016-08-29 22:18:00 +03:00
|
|
|
status = entry.Status
|
2017-10-06 16:45:54 +03:00
|
|
|
if status == http.StatusMultipleChoices {
|
2018-06-20 15:06:27 +03:00
|
|
|
apiGetHTTP300.Inc(1)
|
|
|
|
return nil, entry.ContentType, status, contentAddr, err
|
2017-10-06 16:45:54 +03:00
|
|
|
}
|
2018-06-20 15:06:27 +03:00
|
|
|
mimeType = entry.ContentType
|
|
|
|
log.Debug("content lookup key", "key", contentAddr, "mimetype", mimeType)
|
2018-07-09 15:11:49 +03:00
|
|
|
reader, _ = a.fileStore.Retrieve(ctx, contentAddr)
|
2016-08-29 22:18:00 +03:00
|
|
|
} else {
|
2018-06-20 15:06:27 +03:00
|
|
|
// no entry found
|
2017-01-26 22:33:39 +03:00
|
|
|
status = http.StatusNotFound
|
2018-02-23 16:19:59 +03:00
|
|
|
apiGetNotFound.Inc(1)
|
2018-11-26 14:53:15 +03:00
|
|
|
err = fmt.Errorf("Not found: could not find resource '%s'", path)
|
2018-06-20 15:06:27 +03:00
|
|
|
log.Trace("manifest entry not found", "key", contentAddr, "path", path)
|
2016-08-29 22:18:00 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:42:45 +03:00
|
|
|
func (a *API) Delete(ctx context.Context, addr string, path string) (storage.Address, error) {
|
|
|
|
apiDeleteCount.Inc(1)
|
|
|
|
uri, err := Parse("bzz:/" + addr)
|
|
|
|
if err != nil {
|
|
|
|
apiDeleteFail.Inc(1)
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-08-15 18:41:52 +03:00
|
|
|
key, err := a.ResolveURI(ctx, uri, EMPTY_CREDENTIALS)
|
2018-07-12 16:42:45 +03:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
newKey, err := a.UpdateManifest(ctx, key, func(mw *ManifestWriter) error {
|
|
|
|
log.Debug(fmt.Sprintf("removing %s from manifest %s", path, key.Log()))
|
|
|
|
return mw.RemoveEntry(path)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
apiDeleteFail.Inc(1)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return newKey, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetDirectoryTar fetches a requested directory as a tarstream
|
|
|
|
// it returns an io.Reader and an error. Do not forget to Close() the returned ReadCloser
|
2018-08-15 18:41:52 +03:00
|
|
|
func (a *API) GetDirectoryTar(ctx context.Context, decrypt DecryptFunc, uri *URI) (io.ReadCloser, error) {
|
2018-07-12 16:42:45 +03:00
|
|
|
apiGetTarCount.Inc(1)
|
2018-08-15 18:41:52 +03:00
|
|
|
addr, err := a.Resolve(ctx, uri.Addr)
|
2018-07-12 16:42:45 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-08-15 18:41:52 +03:00
|
|
|
walker, err := a.NewManifestWalker(ctx, addr, decrypt, nil)
|
2018-07-12 16:42:45 +03:00
|
|
|
if err != nil {
|
|
|
|
apiGetTarFail.Inc(1)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
piper, pipew := io.Pipe()
|
|
|
|
|
|
|
|
tw := tar.NewWriter(pipew)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
err := walker.Walk(func(entry *ManifestEntry) error {
|
|
|
|
// ignore manifests (walk will recurse into them)
|
|
|
|
if entry.ContentType == ManifestType {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// retrieve the entry's key and size
|
|
|
|
reader, _ := a.Retrieve(ctx, storage.Address(common.Hex2Bytes(entry.Hash)))
|
2018-07-13 18:40:28 +03:00
|
|
|
size, err := reader.Size(ctx, nil)
|
2018-07-12 16:42:45 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// write a tar header for the entry
|
|
|
|
hdr := &tar.Header{
|
|
|
|
Name: entry.Path,
|
|
|
|
Mode: entry.Mode,
|
|
|
|
Size: size,
|
|
|
|
ModTime: entry.ModTime,
|
|
|
|
Xattrs: map[string]string{
|
|
|
|
"user.swarm.content-type": entry.ContentType,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := tw.WriteHeader(hdr); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy the file into the tar stream
|
|
|
|
n, err := io.Copy(tw, io.LimitReader(reader, hdr.Size))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if n != size {
|
|
|
|
return fmt.Errorf("error writing %s: expected %d bytes but sent %d", entry.Path, size, n)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
2018-08-09 17:15:07 +03:00
|
|
|
// close tar writer before closing pipew
|
|
|
|
// to flush remaining data to pipew
|
|
|
|
// regardless of error value
|
|
|
|
tw.Close()
|
2018-07-12 16:42:45 +03:00
|
|
|
if err != nil {
|
|
|
|
apiGetTarFail.Inc(1)
|
|
|
|
pipew.CloseWithError(err)
|
|
|
|
} else {
|
|
|
|
pipew.Close()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return piper, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetManifestList lists the manifest entries for the specified address and prefix
|
|
|
|
// and returns it as a ManifestList
|
2018-08-15 18:41:52 +03:00
|
|
|
func (a *API) GetManifestList(ctx context.Context, decryptor DecryptFunc, addr storage.Address, prefix string) (list ManifestList, err error) {
|
2018-07-12 16:42:45 +03:00
|
|
|
apiManifestListCount.Inc(1)
|
2018-08-15 18:41:52 +03:00
|
|
|
walker, err := a.NewManifestWalker(ctx, addr, decryptor, nil)
|
2018-07-12 16:42:45 +03:00
|
|
|
if err != nil {
|
|
|
|
apiManifestListFail.Inc(1)
|
|
|
|
return ManifestList{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = walker.Walk(func(entry *ManifestEntry) error {
|
|
|
|
// handle non-manifest files
|
|
|
|
if entry.ContentType != ManifestType {
|
|
|
|
// ignore the file if it doesn't have the specified prefix
|
|
|
|
if !strings.HasPrefix(entry.Path, prefix) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the path after the prefix contains a slash, add a
|
|
|
|
// common prefix to the list, otherwise add the entry
|
|
|
|
suffix := strings.TrimPrefix(entry.Path, prefix)
|
|
|
|
if index := strings.Index(suffix, "/"); index > -1 {
|
|
|
|
list.CommonPrefixes = append(list.CommonPrefixes, prefix+suffix[:index+1])
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if entry.Path == "" {
|
|
|
|
entry.Path = "/"
|
|
|
|
}
|
|
|
|
list.Entries = append(list.Entries, entry)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the manifest's path is a prefix of the specified prefix
|
|
|
|
// then just recurse into the manifest by returning nil and
|
|
|
|
// continuing the walk
|
|
|
|
if strings.HasPrefix(prefix, entry.Path) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the manifest's path has the specified prefix, then if the
|
|
|
|
// path after the prefix contains a slash, add a common prefix
|
|
|
|
// to the list and skip the manifest, otherwise recurse into
|
|
|
|
// the manifest by returning nil and continuing the walk
|
|
|
|
if strings.HasPrefix(entry.Path, prefix) {
|
|
|
|
suffix := strings.TrimPrefix(entry.Path, prefix)
|
|
|
|
if index := strings.Index(suffix, "/"); index > -1 {
|
|
|
|
list.CommonPrefixes = append(list.CommonPrefixes, prefix+suffix[:index+1])
|
|
|
|
return ErrSkipManifest
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// the manifest neither has the prefix or needs recursing in to
|
|
|
|
// so just skip it
|
|
|
|
return ErrSkipManifest
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
apiManifestListFail.Inc(1)
|
|
|
|
return ManifestList{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return list, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *API) UpdateManifest(ctx context.Context, addr storage.Address, update func(mw *ManifestWriter) error) (storage.Address, error) {
|
|
|
|
apiManifestUpdateCount.Inc(1)
|
|
|
|
mw, err := a.NewManifestWriter(ctx, addr, nil)
|
|
|
|
if err != nil {
|
|
|
|
apiManifestUpdateFail.Inc(1)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := update(mw); err != nil {
|
|
|
|
apiManifestUpdateFail.Inc(1)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
addr, err = mw.Store()
|
|
|
|
if err != nil {
|
|
|
|
apiManifestUpdateFail.Inc(1)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
log.Debug(fmt.Sprintf("generated manifest %s", addr))
|
|
|
|
return addr, nil
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// Modify loads manifest and checks the content hash before recalculating and storing the manifest.
|
2018-07-09 15:11:49 +03:00
|
|
|
func (a *API) Modify(ctx context.Context, addr storage.Address, path, contentHash, contentType string) (storage.Address, error) {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiModifyCount.Inc(1)
|
2016-08-29 22:18:00 +03:00
|
|
|
quitC := make(chan bool)
|
2018-08-15 18:41:52 +03:00
|
|
|
trie, err := loadManifest(ctx, a.fileStore, addr, quitC, NOOPDecrypt)
|
2016-08-29 22:18:00 +03:00
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiModifyFail.Inc(1)
|
2017-04-07 01:22:22 +03:00
|
|
|
return nil, err
|
2016-08-29 22:18:00 +03:00
|
|
|
}
|
|
|
|
if contentHash != "" {
|
2017-04-07 01:22:22 +03:00
|
|
|
entry := newManifestTrieEntry(&ManifestEntry{
|
2016-08-29 22:18:00 +03:00
|
|
|
Path: path,
|
|
|
|
ContentType: contentType,
|
2017-04-07 01:22:22 +03:00
|
|
|
}, nil)
|
|
|
|
entry.Hash = contentHash
|
2016-08-29 22:18:00 +03:00
|
|
|
trie.addEntry(entry, quitC)
|
|
|
|
} else {
|
|
|
|
trie.deleteEntry(path, quitC)
|
|
|
|
}
|
|
|
|
|
2017-04-07 01:22:22 +03:00
|
|
|
if err := trie.recalcAndStore(); err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiModifyFail.Inc(1)
|
2017-04-07 01:22:22 +03:00
|
|
|
return nil, err
|
2016-08-29 22:18:00 +03:00
|
|
|
}
|
2018-06-20 15:06:27 +03:00
|
|
|
return trie.ref, nil
|
2016-08-29 22:18:00 +03:00
|
|
|
}
|
2017-04-12 03:06:02 +03:00
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// AddFile creates a new manifest entry, adds it to swarm, then adds a file to swarm.
|
2018-07-09 15:11:49 +03:00
|
|
|
func (a *API) AddFile(ctx context.Context, mhash, path, fname string, content []byte, nameresolver bool) (storage.Address, string, error) {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiAddFileCount.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
|
|
|
|
uri, err := Parse("bzz:/" + mhash)
|
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiAddFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return nil, "", err
|
|
|
|
}
|
2018-08-15 18:41:52 +03:00
|
|
|
mkey, err := a.ResolveURI(ctx, uri, EMPTY_CREDENTIALS)
|
2017-04-12 03:06:02 +03:00
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiAddFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return nil, "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
// trim the root dir we added
|
|
|
|
if path[:1] == "/" {
|
|
|
|
path = path[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
entry := &ManifestEntry{
|
|
|
|
Path: filepath.Join(path, fname),
|
|
|
|
ContentType: mime.TypeByExtension(filepath.Ext(fname)),
|
|
|
|
Mode: 0700,
|
|
|
|
Size: int64(len(content)),
|
|
|
|
ModTime: time.Now(),
|
|
|
|
}
|
|
|
|
|
2018-07-09 15:11:49 +03:00
|
|
|
mw, err := a.NewManifestWriter(ctx, mkey, nil)
|
2017-04-12 03:06:02 +03:00
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiAddFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return nil, "", err
|
|
|
|
}
|
|
|
|
|
2018-07-09 15:11:49 +03:00
|
|
|
fkey, err := mw.AddEntry(ctx, bytes.NewReader(content), entry)
|
2017-04-12 03:06:02 +03:00
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiAddFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return nil, "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
newMkey, err := mw.Store()
|
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiAddFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return nil, "", err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return fkey, newMkey.String(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:12:55 +03:00
|
|
|
func (a *API) UploadTar(ctx context.Context, bodyReader io.ReadCloser, manifestPath, defaultPath string, mw *ManifestWriter) (storage.Address, error) {
|
2018-07-12 16:42:45 +03:00
|
|
|
apiUploadTarCount.Inc(1)
|
|
|
|
var contentKey storage.Address
|
|
|
|
tr := tar.NewReader(bodyReader)
|
|
|
|
defer bodyReader.Close()
|
2018-08-10 17:12:55 +03:00
|
|
|
var defaultPathFound bool
|
2018-07-12 16:42:45 +03:00
|
|
|
for {
|
|
|
|
hdr, err := tr.Next()
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
} else if err != nil {
|
|
|
|
apiUploadTarFail.Inc(1)
|
|
|
|
return nil, fmt.Errorf("error reading tar stream: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// only store regular files
|
|
|
|
if !hdr.FileInfo().Mode().IsRegular() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the entry under the path from the request
|
|
|
|
manifestPath := path.Join(manifestPath, hdr.Name)
|
2018-10-01 14:39:39 +03:00
|
|
|
contentType := hdr.Xattrs["user.swarm.content-type"]
|
|
|
|
if contentType == "" {
|
|
|
|
contentType = mime.TypeByExtension(filepath.Ext(hdr.Name))
|
|
|
|
}
|
|
|
|
//DetectContentType("")
|
2018-07-12 16:42:45 +03:00
|
|
|
entry := &ManifestEntry{
|
|
|
|
Path: manifestPath,
|
2018-10-01 14:39:39 +03:00
|
|
|
ContentType: contentType,
|
2018-07-12 16:42:45 +03:00
|
|
|
Mode: hdr.Mode,
|
|
|
|
Size: hdr.Size,
|
|
|
|
ModTime: hdr.ModTime,
|
|
|
|
}
|
|
|
|
contentKey, err = mw.AddEntry(ctx, tr, entry)
|
|
|
|
if err != nil {
|
|
|
|
apiUploadTarFail.Inc(1)
|
|
|
|
return nil, fmt.Errorf("error adding manifest entry from tar stream: %s", err)
|
|
|
|
}
|
2018-08-10 17:12:55 +03:00
|
|
|
if hdr.Name == defaultPath {
|
2018-10-01 14:39:39 +03:00
|
|
|
contentType := hdr.Xattrs["user.swarm.content-type"]
|
|
|
|
if contentType == "" {
|
|
|
|
contentType = mime.TypeByExtension(filepath.Ext(hdr.Name))
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:12:55 +03:00
|
|
|
entry := &ManifestEntry{
|
|
|
|
Hash: contentKey.Hex(),
|
|
|
|
Path: "", // default entry
|
2018-10-01 14:39:39 +03:00
|
|
|
ContentType: contentType,
|
2018-08-10 17:12:55 +03:00
|
|
|
Mode: hdr.Mode,
|
|
|
|
Size: hdr.Size,
|
|
|
|
ModTime: hdr.ModTime,
|
|
|
|
}
|
|
|
|
contentKey, err = mw.AddEntry(ctx, nil, entry)
|
|
|
|
if err != nil {
|
|
|
|
apiUploadTarFail.Inc(1)
|
|
|
|
return nil, fmt.Errorf("error adding default manifest entry from tar stream: %s", err)
|
|
|
|
}
|
|
|
|
defaultPathFound = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if defaultPath != "" && !defaultPathFound {
|
|
|
|
return contentKey, fmt.Errorf("default path %q not found", defaultPath)
|
2018-07-12 16:42:45 +03:00
|
|
|
}
|
|
|
|
return contentKey, nil
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// RemoveFile removes a file entry in a manifest.
|
2018-07-09 15:11:49 +03:00
|
|
|
func (a *API) RemoveFile(ctx context.Context, mhash string, path string, fname string, nameresolver bool) (string, error) {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiRmFileCount.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
|
|
|
|
uri, err := Parse("bzz:/" + mhash)
|
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiRmFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return "", err
|
|
|
|
}
|
2018-08-15 18:41:52 +03:00
|
|
|
mkey, err := a.ResolveURI(ctx, uri, EMPTY_CREDENTIALS)
|
2017-04-12 03:06:02 +03:00
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiRmFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
// trim the root dir we added
|
|
|
|
if path[:1] == "/" {
|
|
|
|
path = path[1:]
|
|
|
|
}
|
|
|
|
|
2018-07-09 15:11:49 +03:00
|
|
|
mw, err := a.NewManifestWriter(ctx, mkey, nil)
|
2017-04-12 03:06:02 +03:00
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiRmFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = mw.RemoveEntry(filepath.Join(path, fname))
|
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiRmFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
newMkey, err := mw.Store()
|
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiRmFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return "", err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return newMkey.String(), nil
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// AppendFile removes old manifest, appends file entry to new manifest and adds it to Swarm.
|
2018-07-09 15:11:49 +03:00
|
|
|
func (a *API) AppendFile(ctx context.Context, mhash, path, fname string, existingSize int64, content []byte, oldAddr storage.Address, offset int64, addSize int64, nameresolver bool) (storage.Address, string, error) {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiAppendFileCount.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
|
|
|
|
buffSize := offset + addSize
|
|
|
|
if buffSize < existingSize {
|
|
|
|
buffSize = existingSize
|
|
|
|
}
|
|
|
|
|
|
|
|
buf := make([]byte, buffSize)
|
|
|
|
|
2018-07-09 15:11:49 +03:00
|
|
|
oldReader, _ := a.Retrieve(ctx, oldAddr)
|
2017-04-12 03:06:02 +03:00
|
|
|
io.ReadAtLeast(oldReader, buf, int(offset))
|
|
|
|
|
|
|
|
newReader := bytes.NewReader(content)
|
|
|
|
io.ReadAtLeast(newReader, buf[offset:], int(addSize))
|
|
|
|
|
|
|
|
if buffSize < existingSize {
|
|
|
|
io.ReadAtLeast(oldReader, buf[addSize:], int(buffSize))
|
|
|
|
}
|
|
|
|
|
|
|
|
combinedReader := bytes.NewReader(buf)
|
|
|
|
totalSize := int64(len(buf))
|
|
|
|
|
|
|
|
// TODO(jmozah): to append using pyramid chunker when it is ready
|
2018-06-20 15:06:27 +03:00
|
|
|
//oldReader := a.Retrieve(oldKey)
|
2017-04-12 03:06:02 +03:00
|
|
|
//newReader := bytes.NewReader(content)
|
|
|
|
//combinedReader := io.MultiReader(oldReader, newReader)
|
|
|
|
|
|
|
|
uri, err := Parse("bzz:/" + mhash)
|
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiAppendFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return nil, "", err
|
|
|
|
}
|
2018-08-15 18:41:52 +03:00
|
|
|
mkey, err := a.ResolveURI(ctx, uri, EMPTY_CREDENTIALS)
|
2017-04-12 03:06:02 +03:00
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiAppendFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return nil, "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
// trim the root dir we added
|
|
|
|
if path[:1] == "/" {
|
|
|
|
path = path[1:]
|
|
|
|
}
|
|
|
|
|
2018-07-09 15:11:49 +03:00
|
|
|
mw, err := a.NewManifestWriter(ctx, mkey, nil)
|
2017-04-12 03:06:02 +03:00
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiAppendFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return nil, "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = mw.RemoveEntry(filepath.Join(path, fname))
|
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiAppendFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return nil, "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
entry := &ManifestEntry{
|
|
|
|
Path: filepath.Join(path, fname),
|
|
|
|
ContentType: mime.TypeByExtension(filepath.Ext(fname)),
|
|
|
|
Mode: 0700,
|
|
|
|
Size: totalSize,
|
|
|
|
ModTime: time.Now(),
|
|
|
|
}
|
|
|
|
|
2018-07-09 15:11:49 +03:00
|
|
|
fkey, err := mw.AddEntry(ctx, io.Reader(combinedReader), entry)
|
2017-04-12 03:06:02 +03:00
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiAppendFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return nil, "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
newMkey, err := mw.Store()
|
|
|
|
if err != nil {
|
2018-02-23 16:19:59 +03:00
|
|
|
apiAppendFileFail.Inc(1)
|
2017-04-12 03:06:02 +03:00
|
|
|
return nil, "", err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return fkey, newMkey.String(), nil
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
// BuildDirectoryTree used by swarmfs_unix
|
2018-07-09 15:11:49 +03:00
|
|
|
func (a *API) BuildDirectoryTree(ctx context.Context, mhash string, nameresolver bool) (addr storage.Address, manifestEntryMap map[string]*manifestTrieEntry, err error) {
|
2018-02-23 16:19:59 +03:00
|
|
|
|
2017-04-12 03:06:02 +03:00
|
|
|
uri, err := Parse("bzz:/" + mhash)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2018-08-15 18:41:52 +03:00
|
|
|
addr, err = a.Resolve(ctx, uri.Addr)
|
2017-04-12 03:06:02 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
quitC := make(chan bool)
|
2018-08-15 18:41:52 +03:00
|
|
|
rootTrie, err := loadManifest(ctx, a.fileStore, addr, quitC, NOOPDecrypt)
|
2017-04-12 03:06:02 +03:00
|
|
|
if err != nil {
|
2018-06-20 15:06:27 +03:00
|
|
|
return nil, nil, fmt.Errorf("can't load manifest %v: %v", addr.String(), err)
|
2017-04-12 03:06:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
manifestEntryMap = map[string]*manifestTrieEntry{}
|
|
|
|
err = rootTrie.listWithPrefix(uri.Path, quitC, func(entry *manifestTrieEntry, suffix string) {
|
|
|
|
manifestEntryMap[suffix] = entry
|
|
|
|
})
|
|
|
|
|
2017-08-08 20:34:35 +03:00
|
|
|
if err != nil {
|
2018-06-20 15:06:27 +03:00
|
|
|
return nil, nil, fmt.Errorf("list with prefix failed %v: %v", addr.String(), err)
|
|
|
|
}
|
|
|
|
return addr, manifestEntryMap, nil
|
|
|
|
}
|
|
|
|
|
2018-10-02 10:32:46 +03:00
|
|
|
// FeedsLookup finds Swarm feeds updates at specific points in time, or the latest update
|
2018-10-03 10:15:17 +03:00
|
|
|
func (a *API) FeedsLookup(ctx context.Context, query *feed.Query) ([]byte, error) {
|
|
|
|
_, err := a.feed.Lookup(ctx, query)
|
2018-06-20 15:06:27 +03:00
|
|
|
if err != nil {
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 13:07:17 +03:00
|
|
|
return nil, err
|
2018-06-20 15:06:27 +03:00
|
|
|
}
|
|
|
|
var data []byte
|
2018-10-03 10:15:17 +03:00
|
|
|
_, data, err = a.feed.GetContent(&query.Feed)
|
2018-06-20 15:06:27 +03:00
|
|
|
if err != nil {
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 13:07:17 +03:00
|
|
|
return nil, err
|
2018-06-20 15:06:27 +03: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 13:07:17 +03:00
|
|
|
return data, nil
|
2018-06-20 15:06:27 +03:00
|
|
|
}
|
|
|
|
|
2018-10-02 10:32:46 +03:00
|
|
|
// FeedsNewRequest creates a Request object to update a specific feed
|
2018-10-03 10:15:17 +03:00
|
|
|
func (a *API) FeedsNewRequest(ctx context.Context, feed *feed.Feed) (*feed.Request, error) {
|
|
|
|
return a.feed.NewRequest(ctx, feed)
|
2018-06-20 15:06:27 +03:00
|
|
|
}
|
|
|
|
|
2018-10-02 10:32:46 +03:00
|
|
|
// FeedsUpdate publishes a new update on the given feed
|
2018-10-03 10:15:17 +03:00
|
|
|
func (a *API) FeedsUpdate(ctx context.Context, request *feed.Request) (storage.Address, error) {
|
|
|
|
return a.feed.Update(ctx, request)
|
2018-06-20 15:06:27 +03:00
|
|
|
}
|
|
|
|
|
2018-10-02 10:32:46 +03:00
|
|
|
// FeedsHashSize returned the size of the digest produced by Swarm feeds' hashing function
|
2018-09-30 10:43:10 +03:00
|
|
|
func (a *API) FeedsHashSize() int {
|
2018-10-03 10:15:17 +03:00
|
|
|
return a.feed.HashSize
|
2018-06-20 15:06:27 +03:00
|
|
|
}
|
|
|
|
|
2018-09-30 10:43:10 +03:00
|
|
|
// ErrCannotLoadFeedManifest is returned when looking up a feeds manifest fails
|
|
|
|
var ErrCannotLoadFeedManifest = errors.New("Cannot load feed 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 13:07:17 +03:00
|
|
|
|
2018-09-30 10:43:10 +03:00
|
|
|
// ErrNotAFeedManifest is returned when the address provided returned something other than a valid manifest
|
|
|
|
var ErrNotAFeedManifest = errors.New("Not a feed 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 13:07:17 +03:00
|
|
|
|
2018-10-02 10:32:46 +03:00
|
|
|
// ResolveFeedManifest retrieves the Swarm feed manifest for the given address, and returns the referenced Feed.
|
2018-10-03 10:15:17 +03:00
|
|
|
func (a *API) ResolveFeedManifest(ctx context.Context, addr storage.Address) (*feed.Feed, error) {
|
2018-08-15 18:41:52 +03:00
|
|
|
trie, err := loadManifest(ctx, a.fileStore, addr, nil, NOOPDecrypt)
|
2018-06-20 15:06:27 +03:00
|
|
|
if err != nil {
|
2018-09-30 10:43:10 +03:00
|
|
|
return nil, ErrCannotLoadFeedManifest
|
2018-06-20 15:06:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
entry, _ := trie.getEntry("")
|
2018-09-30 10:43:10 +03:00
|
|
|
if entry.ContentType != FeedContentType {
|
|
|
|
return nil, ErrNotAFeedManifest
|
2018-06-20 15:06:27 +03:00
|
|
|
}
|
|
|
|
|
2018-09-30 10:43:10 +03:00
|
|
|
return entry.Feed, nil
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 13:07:17 +03:00
|
|
|
}
|
|
|
|
|
2018-10-02 10:32:46 +03:00
|
|
|
// ErrCannotResolveFeedURI is returned when the ENS resolver is not able to translate a name to a Swarm feed
|
2018-09-30 10:43:10 +03:00
|
|
|
var ErrCannotResolveFeedURI = errors.New("Cannot resolve Feed URI")
|
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 13:07:17 +03:00
|
|
|
|
2018-09-30 10:43:10 +03:00
|
|
|
// ErrCannotResolveFeed is returned when values provided are not enough or invalid to recreate a
|
2018-10-02 10:32:46 +03:00
|
|
|
// feed out of them.
|
2018-09-30 10:43:10 +03:00
|
|
|
var ErrCannotResolveFeed = errors.New("Cannot resolve Feed")
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 13:07:17 +03:00
|
|
|
|
2018-10-02 10:32:46 +03:00
|
|
|
// ResolveFeed attempts to extract feed information out of the manifest, if provided
|
|
|
|
// If not, it attempts to extract the feed out of a set of key-value pairs
|
2018-10-03 10:15:17 +03:00
|
|
|
func (a *API) ResolveFeed(ctx context.Context, uri *URI, values feed.Values) (*feed.Feed, error) {
|
|
|
|
var fd *feed.Feed
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 13:07:17 +03:00
|
|
|
var err error
|
|
|
|
if uri.Addr != "" {
|
|
|
|
// resolve the content key.
|
|
|
|
manifestAddr := uri.Address()
|
|
|
|
if manifestAddr == nil {
|
|
|
|
manifestAddr, err = a.Resolve(ctx, uri.Addr)
|
|
|
|
if err != nil {
|
2018-09-30 10:43:10 +03:00
|
|
|
return nil, ErrCannotResolveFeedURI
|
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 13:07:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 10:32:46 +03:00
|
|
|
// get the Swarm feed from the manifest
|
2018-10-03 10:15:17 +03:00
|
|
|
fd, err = a.ResolveFeedManifest(ctx, manifestAddr)
|
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 13:07:17 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-10-03 10:15:17 +03:00
|
|
|
log.Debug("handle.get.feed: resolved", "manifestkey", manifestAddr, "feed", fd.Hex())
|
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 13:07:17 +03:00
|
|
|
} else {
|
2018-10-03 10:15:17 +03:00
|
|
|
var f feed.Feed
|
|
|
|
if err := f.FromValues(values); err != nil {
|
2018-09-30 10:43:10 +03:00
|
|
|
return nil, ErrCannotResolveFeed
|
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 13:07:17 +03:00
|
|
|
|
|
|
|
}
|
2018-10-03 10:15:17 +03:00
|
|
|
fd = &f
|
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 13:07:17 +03:00
|
|
|
}
|
2018-10-03 10:15:17 +03:00
|
|
|
return fd, nil
|
2017-04-12 03:06:02 +03:00
|
|
|
}
|
2018-10-01 14:39:39 +03:00
|
|
|
|
|
|
|
// MimeOctetStream default value of http Content-Type header
|
|
|
|
const MimeOctetStream = "application/octet-stream"
|
|
|
|
|
|
|
|
// DetectContentType by file file extension, or fallback to content sniff
|
|
|
|
func DetectContentType(fileName string, f io.ReadSeeker) (string, error) {
|
|
|
|
ctype := mime.TypeByExtension(filepath.Ext(fileName))
|
|
|
|
if ctype != "" {
|
|
|
|
return ctype, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// save/rollback to get content probe from begin of file
|
|
|
|
currentPosition, err := f.Seek(0, io.SeekCurrent)
|
|
|
|
if err != nil {
|
|
|
|
return MimeOctetStream, fmt.Errorf("seeker can't seek, %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// read a chunk to decide between utf-8 text and binary
|
|
|
|
var buf [512]byte
|
|
|
|
n, _ := f.Read(buf[:])
|
|
|
|
ctype = http.DetectContentType(buf[:n])
|
|
|
|
|
|
|
|
_, err = f.Seek(currentPosition, io.SeekStart) // rewind to output whole file
|
|
|
|
if err != nil {
|
|
|
|
return MimeOctetStream, fmt.Errorf("seeker can't seek, %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctype, nil
|
|
|
|
}
|