2016-08-29 19:18:00 +00: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/>.
|
|
|
|
|
|
|
|
/*
|
|
|
|
A simple http server interface to Swarm
|
|
|
|
*/
|
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
2018-06-20 12:06:27 +00:00
|
|
|
"bufio"
|
|
|
|
"bytes"
|
2017-04-06 22:22:22 +00:00
|
|
|
"encoding/json"
|
2017-02-22 12:10:07 +00:00
|
|
|
"fmt"
|
2016-08-29 19:18:00 +00:00
|
|
|
"io"
|
2017-04-06 22:22:22 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"mime"
|
|
|
|
"mime/multipart"
|
2016-08-29 19:18:00 +00:00
|
|
|
"net/http"
|
2017-04-06 22:22:22 +00:00
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"strconv"
|
2017-01-05 10:57:41 +00:00
|
|
|
"strings"
|
2016-08-29 19:18:00 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2018-02-23 13:19:59 +00:00
|
|
|
"github.com/ethereum/go-ethereum/metrics"
|
2016-08-29 19:18:00 +00:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/api"
|
2018-06-20 12:06:27 +00:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/log"
|
2017-01-26 19:33:39 +00:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/storage"
|
2018-10-03 07:15:17 +00:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/storage/feed"
|
2018-07-13 15:40:28 +00:00
|
|
|
|
2017-01-05 10:57:41 +00:00
|
|
|
"github.com/rs/cors"
|
2016-08-29 19:18:00 +00:00
|
|
|
)
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
type resourceResponse struct {
|
|
|
|
Manifest storage.Address `json:"manifest"`
|
|
|
|
Resource string `json:"resource"`
|
|
|
|
Update storage.Address `json:"update"`
|
|
|
|
}
|
|
|
|
|
2018-02-23 13:19:59 +00:00
|
|
|
var (
|
2018-06-20 12:06:27 +00:00
|
|
|
postRawCount = metrics.NewRegisteredCounter("api.http.post.raw.count", nil)
|
|
|
|
postRawFail = metrics.NewRegisteredCounter("api.http.post.raw.fail", nil)
|
|
|
|
postFilesCount = metrics.NewRegisteredCounter("api.http.post.files.count", nil)
|
|
|
|
postFilesFail = metrics.NewRegisteredCounter("api.http.post.files.fail", nil)
|
|
|
|
deleteCount = metrics.NewRegisteredCounter("api.http.delete.count", nil)
|
|
|
|
deleteFail = metrics.NewRegisteredCounter("api.http.delete.fail", nil)
|
|
|
|
getCount = metrics.NewRegisteredCounter("api.http.get.count", nil)
|
|
|
|
getFail = metrics.NewRegisteredCounter("api.http.get.fail", nil)
|
|
|
|
getFileCount = metrics.NewRegisteredCounter("api.http.get.file.count", nil)
|
|
|
|
getFileNotFound = metrics.NewRegisteredCounter("api.http.get.file.notfound", nil)
|
|
|
|
getFileFail = metrics.NewRegisteredCounter("api.http.get.file.fail", nil)
|
|
|
|
getListCount = metrics.NewRegisteredCounter("api.http.get.list.count", nil)
|
|
|
|
getListFail = metrics.NewRegisteredCounter("api.http.get.list.fail", nil)
|
2018-02-23 13:19:59 +00:00
|
|
|
)
|
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
type methodHandler map[string]http.Handler
|
|
|
|
|
|
|
|
func (m methodHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
v, ok := m[r.Method]
|
|
|
|
if ok {
|
|
|
|
v.ServeHTTP(rw, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
rw.WriteHeader(http.StatusMethodNotAllowed)
|
|
|
|
}
|
|
|
|
|
2018-07-12 13:42:45 +00:00
|
|
|
func NewServer(api *api.API, corsString string) *Server {
|
2017-01-05 10:57:41 +00:00
|
|
|
var allowedOrigins []string
|
2018-07-12 13:42:45 +00:00
|
|
|
for _, domain := range strings.Split(corsString, ",") {
|
2017-01-05 10:57:41 +00:00
|
|
|
allowedOrigins = append(allowedOrigins, strings.TrimSpace(domain))
|
|
|
|
}
|
|
|
|
c := cors.New(cors.Options{
|
|
|
|
AllowedOrigins: allowedOrigins,
|
2018-07-12 13:42:45 +00:00
|
|
|
AllowedMethods: []string{http.MethodPost, http.MethodGet, http.MethodDelete, http.MethodPatch, http.MethodPut},
|
2017-01-05 10:57:41 +00:00
|
|
|
MaxAge: 600,
|
2017-03-16 03:34:08 +00:00
|
|
|
AllowedHeaders: []string{"*"},
|
2017-01-05 10:57:41 +00:00
|
|
|
})
|
2017-04-04 22:20:07 +00:00
|
|
|
|
2018-07-12 13:42:45 +00:00
|
|
|
server := &Server{api: api}
|
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
defaultMiddlewares := []Adapter{
|
|
|
|
RecoverPanic,
|
|
|
|
SetRequestID,
|
2018-08-15 15:41:52 +00:00
|
|
|
SetRequestHost,
|
2018-08-07 09:56:55 +00:00
|
|
|
InitLoggingResponseWriter,
|
|
|
|
ParseURI,
|
|
|
|
InstrumentOpenTracing,
|
|
|
|
}
|
2018-07-12 13:42:45 +00:00
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
mux := http.NewServeMux()
|
|
|
|
mux.Handle("/bzz:/", methodHandler{
|
|
|
|
"GET": Adapt(
|
|
|
|
http.HandlerFunc(server.HandleBzzGet),
|
|
|
|
defaultMiddlewares...,
|
|
|
|
),
|
|
|
|
"POST": Adapt(
|
|
|
|
http.HandlerFunc(server.HandlePostFiles),
|
|
|
|
defaultMiddlewares...,
|
|
|
|
),
|
|
|
|
"DELETE": Adapt(
|
|
|
|
http.HandlerFunc(server.HandleDelete),
|
|
|
|
defaultMiddlewares...,
|
|
|
|
),
|
|
|
|
})
|
|
|
|
mux.Handle("/bzz-raw:/", methodHandler{
|
|
|
|
"GET": Adapt(
|
|
|
|
http.HandlerFunc(server.HandleGet),
|
|
|
|
defaultMiddlewares...,
|
|
|
|
),
|
|
|
|
"POST": Adapt(
|
|
|
|
http.HandlerFunc(server.HandlePostRaw),
|
|
|
|
defaultMiddlewares...,
|
|
|
|
),
|
|
|
|
})
|
|
|
|
mux.Handle("/bzz-immutable:/", methodHandler{
|
|
|
|
"GET": Adapt(
|
2018-09-07 13:23:29 +00:00
|
|
|
http.HandlerFunc(server.HandleBzzGet),
|
2018-08-07 09:56:55 +00:00
|
|
|
defaultMiddlewares...,
|
|
|
|
),
|
|
|
|
})
|
|
|
|
mux.Handle("/bzz-hash:/", methodHandler{
|
|
|
|
"GET": Adapt(
|
|
|
|
http.HandlerFunc(server.HandleGet),
|
|
|
|
defaultMiddlewares...,
|
|
|
|
),
|
|
|
|
})
|
|
|
|
mux.Handle("/bzz-list:/", methodHandler{
|
|
|
|
"GET": Adapt(
|
|
|
|
http.HandlerFunc(server.HandleGetList),
|
|
|
|
defaultMiddlewares...,
|
|
|
|
),
|
|
|
|
})
|
2018-09-30 07:43:10 +00:00
|
|
|
mux.Handle("/bzz-feed:/", methodHandler{
|
2018-08-07 09:56:55 +00:00
|
|
|
"GET": Adapt(
|
2018-09-30 07:43:10 +00:00
|
|
|
http.HandlerFunc(server.HandleGetFeed),
|
2018-08-07 09:56:55 +00:00
|
|
|
defaultMiddlewares...,
|
|
|
|
),
|
|
|
|
"POST": Adapt(
|
2018-09-30 07:43:10 +00:00
|
|
|
http.HandlerFunc(server.HandlePostFeed),
|
2018-08-07 09:56:55 +00:00
|
|
|
defaultMiddlewares...,
|
|
|
|
),
|
|
|
|
})
|
|
|
|
|
|
|
|
mux.Handle("/", methodHandler{
|
|
|
|
"GET": Adapt(
|
|
|
|
http.HandlerFunc(server.HandleRootPaths),
|
|
|
|
SetRequestID,
|
|
|
|
InitLoggingResponseWriter,
|
|
|
|
),
|
|
|
|
})
|
2018-07-12 13:42:45 +00:00
|
|
|
server.Handler = c.Handler(mux)
|
2018-08-07 09:56:55 +00:00
|
|
|
|
2018-07-12 13:42:45 +00:00
|
|
|
return server
|
|
|
|
}
|
2018-07-11 13:46:20 +00:00
|
|
|
|
2018-07-12 13:42:45 +00:00
|
|
|
func (s *Server) ListenAndServe(addr string) error {
|
2018-08-15 15:41:52 +00:00
|
|
|
s.listenAddr = addr
|
2018-07-12 13:42:45 +00:00
|
|
|
return http.ListenAndServe(addr, s)
|
|
|
|
}
|
2018-07-11 13:46:20 +00:00
|
|
|
|
2018-07-12 13:42:45 +00:00
|
|
|
// browser API for registering bzz url scheme handlers:
|
|
|
|
// https://developer.mozilla.org/en/docs/Web-based_protocol_handlers
|
|
|
|
// electron (chromium) api for registering bzz url scheme handlers:
|
|
|
|
// https://github.com/atom/electron/blob/master/docs/api/protocol.md
|
2017-04-04 22:20:07 +00:00
|
|
|
type Server struct {
|
2018-07-12 13:42:45 +00:00
|
|
|
http.Handler
|
2018-08-15 15:41:52 +00:00
|
|
|
api *api.API
|
|
|
|
listenAddr string
|
2016-08-29 19:18:00 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
func (s *Server) HandleBzzGet(w http.ResponseWriter, r *http.Request) {
|
2018-08-15 15:41:52 +00:00
|
|
|
log.Debug("handleBzzGet", "ruid", GetRUID(r.Context()), "uri", r.RequestURI)
|
2018-08-07 09:56:55 +00:00
|
|
|
if r.Header.Get("Accept") == "application/x-tar" {
|
|
|
|
uri := GetURI(r.Context())
|
2018-08-15 15:41:52 +00:00
|
|
|
_, credentials, _ := r.BasicAuth()
|
|
|
|
reader, err := s.api.GetDirectoryTar(r.Context(), s.api.Decryptor(r.Context(), credentials), uri)
|
2018-08-07 09:56:55 +00:00
|
|
|
if err != nil {
|
2018-08-15 15:41:52 +00:00
|
|
|
if isDecryptError(err) {
|
|
|
|
w.Header().Set("WWW-Authenticate", fmt.Sprintf("Basic realm=%q", uri.Address().String()))
|
|
|
|
RespondError(w, r, err.Error(), http.StatusUnauthorized)
|
|
|
|
return
|
|
|
|
}
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("Had an error building the tarball: %v", err), http.StatusInternalServerError)
|
2018-08-15 15:41:52 +00:00
|
|
|
return
|
2018-08-07 09:56:55 +00:00
|
|
|
}
|
|
|
|
defer reader.Close()
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/x-tar")
|
2018-10-01 11:39:39 +00:00
|
|
|
|
|
|
|
fileName := uri.Addr
|
|
|
|
if found := path.Base(uri.Path); found != "" && found != "." && found != "/" {
|
|
|
|
fileName = found
|
|
|
|
}
|
|
|
|
w.Header().Set("Content-Disposition", fmt.Sprintf("inline; filename=\"%s.tar\"", fileName))
|
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
io.Copy(w, reader)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
s.HandleGetFile(w, r)
|
|
|
|
}
|
2017-04-06 22:22:22 +00:00
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
func (s *Server) HandleRootPaths(w http.ResponseWriter, r *http.Request) {
|
|
|
|
switch r.RequestURI {
|
|
|
|
case "/":
|
|
|
|
RespondTemplate(w, r, "landing-page", "Swarm: Please request a valid ENS or swarm hash with the appropriate bzz scheme", 200)
|
|
|
|
return
|
|
|
|
case "/robots.txt":
|
|
|
|
w.Header().Set("Last-Modified", time.Now().Format(http.TimeFormat))
|
|
|
|
fmt.Fprintf(w, "User-agent: *\nDisallow: /")
|
|
|
|
case "/favicon.ico":
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
w.Write(faviconBytes)
|
|
|
|
default:
|
|
|
|
RespondError(w, r, "Not Found", http.StatusNotFound)
|
|
|
|
}
|
2017-04-06 22:22:22 +00:00
|
|
|
}
|
2016-08-29 19:18:00 +00:00
|
|
|
|
2017-12-19 08:49:30 +00:00
|
|
|
// HandlePostRaw handles a POST request to a raw bzz-raw:/ URI, stores the request
|
2018-06-20 12:06:27 +00:00
|
|
|
// body in swarm and returns the resulting storage address as a text/plain response
|
2018-08-07 09:56:55 +00:00
|
|
|
func (s *Server) HandlePostRaw(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ruid := GetRUID(r.Context())
|
|
|
|
log.Debug("handle.post.raw", "ruid", ruid)
|
2018-06-20 12:06:27 +00:00
|
|
|
|
2018-02-23 13:19:59 +00:00
|
|
|
postRawCount.Inc(1)
|
2018-06-20 12:06:27 +00:00
|
|
|
|
|
|
|
toEncrypt := false
|
2018-08-07 09:56:55 +00:00
|
|
|
uri := GetURI(r.Context())
|
|
|
|
if uri.Addr == "encrypt" {
|
2018-06-20 12:06:27 +00:00
|
|
|
toEncrypt = true
|
|
|
|
}
|
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
if uri.Path != "" {
|
2018-02-23 13:19:59 +00:00
|
|
|
postRawFail.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, "raw POST request cannot contain a path", http.StatusBadRequest)
|
2017-02-22 12:10:07 +00:00
|
|
|
return
|
2016-08-29 19:18:00 +00:00
|
|
|
}
|
2017-04-06 22:22:22 +00:00
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
if uri.Addr != "" && uri.Addr != "encrypt" {
|
2018-02-23 13:19:59 +00:00
|
|
|
postRawFail.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, "raw POST request addr can only be empty or \"encrypt\"", http.StatusBadRequest)
|
2017-04-06 22:22:22 +00:00
|
|
|
return
|
2016-08-29 19:18:00 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
if r.Header.Get("Content-Length") == "" {
|
|
|
|
postRawFail.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, "missing Content-Length header in request", http.StatusBadRequest)
|
2018-06-20 12:06:27 +00:00
|
|
|
return
|
|
|
|
}
|
2018-07-12 13:42:45 +00:00
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
addr, _, err := s.api.Store(r.Context(), r.Body, r.ContentLength, toEncrypt)
|
2017-04-06 22:22:22 +00:00
|
|
|
if err != nil {
|
2018-02-23 13:19:59 +00:00
|
|
|
postRawFail.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, err.Error(), http.StatusInternalServerError)
|
2017-04-06 22:22:22 +00:00
|
|
|
return
|
|
|
|
}
|
2018-06-20 12:06:27 +00:00
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
log.Debug("stored content", "ruid", ruid, "key", addr)
|
2017-04-06 22:22:22 +00:00
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "text/plain")
|
|
|
|
w.WriteHeader(http.StatusOK)
|
2018-06-20 12:06:27 +00:00
|
|
|
fmt.Fprint(w, addr)
|
2017-04-06 22:22:22 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
// HandlePostFiles handles a POST request to
|
2017-04-06 22:22:22 +00:00
|
|
|
// bzz:/<hash>/<path> which contains either a single file or multiple files
|
|
|
|
// (either a tar archive or multipart form), adds those files either to an
|
|
|
|
// existing manifest or to a new manifest under <path> and returns the
|
|
|
|
// resulting manifest hash as a text/plain response
|
2018-08-07 09:56:55 +00:00
|
|
|
func (s *Server) HandlePostFiles(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ruid := GetRUID(r.Context())
|
|
|
|
log.Debug("handle.post.files", "ruid", ruid)
|
2018-02-23 13:19:59 +00:00
|
|
|
postFilesCount.Inc(1)
|
2018-07-13 15:40:28 +00:00
|
|
|
|
2017-04-06 22:22:22 +00:00
|
|
|
contentType, params, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
|
|
|
if err != nil {
|
2018-02-23 13:19:59 +00:00
|
|
|
postFilesFail.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, err.Error(), http.StatusBadRequest)
|
2017-04-06 22:22:22 +00:00
|
|
|
return
|
|
|
|
}
|
2016-08-29 19:18:00 +00:00
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
toEncrypt := false
|
2018-08-07 09:56:55 +00:00
|
|
|
uri := GetURI(r.Context())
|
|
|
|
if uri.Addr == "encrypt" {
|
2018-06-20 12:06:27 +00:00
|
|
|
toEncrypt = true
|
|
|
|
}
|
|
|
|
|
|
|
|
var addr storage.Address
|
2018-08-07 09:56:55 +00:00
|
|
|
if uri.Addr != "" && uri.Addr != "encrypt" {
|
2018-08-15 15:41:52 +00:00
|
|
|
addr, err = s.api.Resolve(r.Context(), uri.Addr)
|
2017-04-06 22:22:22 +00:00
|
|
|
if err != nil {
|
2018-02-23 13:19:59 +00:00
|
|
|
postFilesFail.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("cannot resolve %s: %s", uri.Addr, err), http.StatusInternalServerError)
|
2016-11-10 20:14:17 +00:00
|
|
|
return
|
|
|
|
}
|
2018-08-07 09:56:55 +00:00
|
|
|
log.Debug("resolved key", "ruid", ruid, "key", addr)
|
2017-04-06 22:22:22 +00:00
|
|
|
} else {
|
2018-07-11 13:46:20 +00:00
|
|
|
addr, err = s.api.NewManifest(r.Context(), toEncrypt)
|
2017-04-06 22:22:22 +00:00
|
|
|
if err != nil {
|
2018-02-23 13:19:59 +00:00
|
|
|
postFilesFail.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, err.Error(), http.StatusInternalServerError)
|
2016-08-29 19:18:00 +00:00
|
|
|
return
|
|
|
|
}
|
2018-08-07 09:56:55 +00:00
|
|
|
log.Debug("new manifest", "ruid", ruid, "key", addr)
|
2017-04-06 22:22:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
newAddr, err := s.api.UpdateManifest(r.Context(), addr, func(mw *api.ManifestWriter) error {
|
2017-04-06 22:22:22 +00:00
|
|
|
switch contentType {
|
|
|
|
case "application/x-tar":
|
2018-07-12 13:42:45 +00:00
|
|
|
_, err := s.handleTarUpload(r, mw)
|
|
|
|
if err != nil {
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("error uploading tarball: %v", err), http.StatusInternalServerError)
|
2018-07-12 13:42:45 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
2017-04-06 22:22:22 +00:00
|
|
|
case "multipart/form-data":
|
2018-07-12 13:42:45 +00:00
|
|
|
return s.handleMultipartUpload(r, params["boundary"], mw)
|
2017-04-06 22:22:22 +00:00
|
|
|
|
|
|
|
default:
|
2018-07-12 13:42:45 +00:00
|
|
|
return s.handleDirectUpload(r, mw)
|
2017-04-06 22:22:22 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
if err != nil {
|
2018-02-23 13:19:59 +00:00
|
|
|
postFilesFail.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("cannot create manifest: %s", err), http.StatusInternalServerError)
|
2017-04-06 22:22:22 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
log.Debug("stored content", "ruid", ruid, "key", newAddr)
|
2018-06-20 12:06:27 +00:00
|
|
|
|
2017-04-06 22:22:22 +00:00
|
|
|
w.Header().Set("Content-Type", "text/plain")
|
|
|
|
w.WriteHeader(http.StatusOK)
|
2018-06-20 12:06:27 +00:00
|
|
|
fmt.Fprint(w, newAddr)
|
2017-04-06 22:22:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
func (s *Server) handleTarUpload(r *http.Request, mw *api.ManifestWriter) (storage.Address, error) {
|
|
|
|
log.Debug("handle.tar.upload", "ruid", GetRUID(r.Context()))
|
2017-04-06 22:22:22 +00:00
|
|
|
|
2018-08-10 14:12:55 +00:00
|
|
|
defaultPath := r.URL.Query().Get("defaultpath")
|
|
|
|
|
|
|
|
key, err := s.api.UploadTar(r.Context(), r.Body, GetURI(r.Context()).Path, defaultPath, mw)
|
2018-07-12 13:42:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2017-04-06 22:22:22 +00:00
|
|
|
}
|
2018-07-12 13:42:45 +00:00
|
|
|
return key, nil
|
2017-04-06 22:22:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
func (s *Server) handleMultipartUpload(r *http.Request, boundary string, mw *api.ManifestWriter) error {
|
|
|
|
ruid := GetRUID(r.Context())
|
|
|
|
log.Debug("handle.multipart.upload", "ruid", ruid)
|
|
|
|
mr := multipart.NewReader(r.Body, boundary)
|
2017-04-06 22:22:22 +00:00
|
|
|
for {
|
|
|
|
part, err := mr.NextPart()
|
|
|
|
if err == io.EOF {
|
|
|
|
return nil
|
|
|
|
} else if err != nil {
|
|
|
|
return fmt.Errorf("error reading multipart form: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var size int64
|
|
|
|
var reader io.Reader = part
|
|
|
|
if contentLength := part.Header.Get("Content-Length"); contentLength != "" {
|
|
|
|
size, err = strconv.ParseInt(contentLength, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error parsing multipart content length: %s", err)
|
2016-08-29 19:18:00 +00:00
|
|
|
}
|
2017-04-06 22:22:22 +00:00
|
|
|
reader = part
|
2016-08-29 19:18:00 +00:00
|
|
|
} else {
|
2017-04-06 22:22:22 +00:00
|
|
|
// copy the part to a tmp file to get its size
|
|
|
|
tmp, err := ioutil.TempFile("", "swarm-multipart")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2016-08-29 19:18:00 +00:00
|
|
|
}
|
2017-04-06 22:22:22 +00:00
|
|
|
defer os.Remove(tmp.Name())
|
|
|
|
defer tmp.Close()
|
|
|
|
size, err = io.Copy(tmp, part)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error copying multipart content: %s", err)
|
|
|
|
}
|
2017-08-08 17:34:35 +00:00
|
|
|
if _, err := tmp.Seek(0, io.SeekStart); err != nil {
|
2017-04-06 22:22:22 +00:00
|
|
|
return fmt.Errorf("error copying multipart content: %s", err)
|
2016-08-29 19:18:00 +00:00
|
|
|
}
|
2017-04-06 22:22:22 +00:00
|
|
|
reader = tmp
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the entry under the path from the request
|
|
|
|
name := part.FileName()
|
|
|
|
if name == "" {
|
|
|
|
name = part.FormName()
|
|
|
|
}
|
2018-08-07 09:56:55 +00:00
|
|
|
uri := GetURI(r.Context())
|
|
|
|
path := path.Join(uri.Path, name)
|
2017-04-06 22:22:22 +00:00
|
|
|
entry := &api.ManifestEntry{
|
|
|
|
Path: path,
|
|
|
|
ContentType: part.Header.Get("Content-Type"),
|
|
|
|
Size: size,
|
2016-08-29 19:18:00 +00:00
|
|
|
}
|
2018-08-07 09:56:55 +00:00
|
|
|
log.Debug("adding path to new manifest", "ruid", ruid, "bytes", entry.Size, "path", entry.Path)
|
|
|
|
contentKey, err := mw.AddEntry(r.Context(), reader, entry)
|
2017-04-06 22:22:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error adding manifest entry from multipart form: %s", err)
|
|
|
|
}
|
2018-08-07 09:56:55 +00:00
|
|
|
log.Debug("stored content", "ruid", ruid, "key", contentKey)
|
2017-04-06 22:22:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
func (s *Server) handleDirectUpload(r *http.Request, mw *api.ManifestWriter) error {
|
|
|
|
ruid := GetRUID(r.Context())
|
|
|
|
log.Debug("handle.direct.upload", "ruid", ruid)
|
|
|
|
key, err := mw.AddEntry(r.Context(), r.Body, &api.ManifestEntry{
|
|
|
|
Path: GetURI(r.Context()).Path,
|
|
|
|
ContentType: r.Header.Get("Content-Type"),
|
2017-04-06 22:22:22 +00:00
|
|
|
Mode: 0644,
|
2018-08-07 09:56:55 +00:00
|
|
|
Size: r.ContentLength,
|
2017-04-06 22:22:22 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-07 09:56:55 +00:00
|
|
|
log.Debug("stored content", "ruid", ruid, "key", key)
|
2017-04-06 22:22:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// HandleDelete handles a DELETE request to bzz:/<manifest>/<path>, removes
|
|
|
|
// <path> from <manifest> and returns the resulting manifest hash as a
|
|
|
|
// text/plain response
|
2018-08-07 09:56:55 +00:00
|
|
|
func (s *Server) HandleDelete(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ruid := GetRUID(r.Context())
|
|
|
|
uri := GetURI(r.Context())
|
|
|
|
log.Debug("handle.delete", "ruid", ruid)
|
2018-02-23 13:19:59 +00:00
|
|
|
deleteCount.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
newKey, err := s.api.Delete(r.Context(), uri.Addr, uri.Path)
|
2017-04-06 22:22:22 +00:00
|
|
|
if err != nil {
|
2018-02-23 13:19:59 +00:00
|
|
|
deleteFail.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("could not delete from manifest: %v", err), http.StatusInternalServerError)
|
2017-04-06 22:22:22 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "text/plain")
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
fmt.Fprint(w, newKey)
|
|
|
|
}
|
|
|
|
|
2018-09-30 07:43:10 +00:00
|
|
|
// Handles feed manifest creation and feed updates
|
2018-10-03 07:15:17 +00:00
|
|
|
// The POST request admits a JSON structure as defined in the feeds package: `feed.updateRequestJSON`
|
2018-09-30 07:43:10 +00:00
|
|
|
// The requests can be to a) create a feed manifest, b) update a feed or c) both a+b: create a feed manifest and publish a first update
|
|
|
|
func (s *Server) HandlePostFeed(w http.ResponseWriter, r *http.Request) {
|
2018-08-07 09:56:55 +00:00
|
|
|
ruid := GetRUID(r.Context())
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
uri := GetURI(r.Context())
|
2018-09-30 07:43:10 +00:00
|
|
|
log.Debug("handle.post.feed", "ruid", ruid)
|
2018-06-20 12:06:27 +00:00
|
|
|
var err error
|
2018-07-21 19:49:36 +00:00
|
|
|
|
2018-10-03 07:15:17 +00:00
|
|
|
// Creation and update must send feed.updateRequestJSON JSON structure
|
2018-07-21 19:49:36 +00:00
|
|
|
body, err := ioutil.ReadAll(r.Body)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, err.Error(), http.StatusInternalServerError)
|
2018-07-21 19:49:36 +00:00
|
|
|
return
|
|
|
|
}
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
|
2018-10-03 07:15:17 +00:00
|
|
|
fd, err := s.api.ResolveFeed(r.Context(), uri, r.URL.Query())
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
if err != nil { // couldn't parse query string or retrieve manifest
|
|
|
|
getFail.Inc(1)
|
|
|
|
httpStatus := http.StatusBadRequest
|
2018-09-30 07:43:10 +00:00
|
|
|
if err == api.ErrCannotLoadFeedManifest || err == api.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 10:07:17 +00:00
|
|
|
httpStatus = http.StatusNotFound
|
|
|
|
}
|
2018-09-30 07:43:10 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("cannot retrieve feed from manifest: %s", err), httpStatus)
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-03 07:15:17 +00:00
|
|
|
var updateRequest feed.Request
|
|
|
|
updateRequest.Feed = *fd
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
query := r.URL.Query()
|
|
|
|
|
|
|
|
if err := updateRequest.FromValues(query, body); err != nil { // decodes request from query parameters
|
|
|
|
RespondError(w, r, err.Error(), http.StatusBadRequest)
|
2018-06-20 12:06:27 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-21 19:49:36 +00:00
|
|
|
if updateRequest.IsUpdate() {
|
|
|
|
// Verify that the signature is intact and that the signer is authorized
|
2018-09-30 07:43:10 +00:00
|
|
|
// to update this feed
|
|
|
|
// Check this early, to avoid creating a feed and then not being able to set its first update.
|
2018-07-21 19:49:36 +00:00
|
|
|
if err = updateRequest.Verify(); err != nil {
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, err.Error(), http.StatusForbidden)
|
2018-07-21 19:49:36 +00:00
|
|
|
return
|
|
|
|
}
|
2018-09-30 07:43:10 +00:00
|
|
|
_, err = s.api.FeedsUpdate(r.Context(), &updateRequest)
|
2018-07-21 19:49:36 +00:00
|
|
|
if err != nil {
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, err.Error(), http.StatusInternalServerError)
|
2018-07-21 19:49:36 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
if query.Get("manifest") == "1" {
|
2018-09-30 07:43:10 +00:00
|
|
|
// we create a manifest so we can retrieve feed updates with bzz:// later
|
|
|
|
// this manifest has a special "feed type" manifest, and saves the
|
|
|
|
// feed identification used to retrieve feed updates later
|
|
|
|
m, err := s.api.NewFeedManifest(r.Context(), &updateRequest.Feed)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
2018-09-30 07:43:10 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("failed to create feed manifest: %v", err), http.StatusInternalServerError)
|
2018-06-20 12:06:27 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
// the key to the manifest will be passed back to the client
|
2018-10-02 07:32:46 +00:00
|
|
|
// the client can access the feed directly through its Feed member
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
// the manifest key can be set as content in the resolver of the ENS name
|
2018-07-21 19:49:36 +00:00
|
|
|
outdata, err := json.Marshal(m)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("failed to create json response: %s", err), http.StatusInternalServerError)
|
2018-06-20 12:06:27 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Fprint(w, string(outdata))
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
|
|
|
|
w.Header().Add("Content-type", "application/json")
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 07:32:46 +00:00
|
|
|
// HandleGetFeed retrieves Swarm feeds updates:
|
2018-09-30 07:43:10 +00:00
|
|
|
// bzz-feed://<manifest address or ENS name> - get latest feed update, given a manifest address
|
|
|
|
// - or -
|
|
|
|
// specify user + topic (optional), subtopic name (optional) directly, without manifest:
|
|
|
|
// bzz-feed://?user=0x...&topic=0x...&name=subtopic name
|
|
|
|
// topic defaults to 0x000... if not specified.
|
|
|
|
// name defaults to empty string if not specified.
|
|
|
|
// thus, empty name and topic refers to the user's default feed.
|
|
|
|
//
|
|
|
|
// Optional parameters:
|
|
|
|
// time=xx - get the latest update before time (in epoch seconds)
|
|
|
|
// hint.time=xx - hint the lookup algorithm looking for updates at around that time
|
|
|
|
// hint.level=xx - hint the lookup algorithm looking for updates at around this frequency level
|
|
|
|
// meta=1 - get feed metadata and status information instead of performing a feed query
|
|
|
|
// NOTE: meta=1 will be deprecated in the near future
|
|
|
|
func (s *Server) HandleGetFeed(w http.ResponseWriter, r *http.Request) {
|
2018-08-07 09:56:55 +00:00
|
|
|
ruid := GetRUID(r.Context())
|
|
|
|
uri := GetURI(r.Context())
|
2018-09-30 07:43:10 +00:00
|
|
|
log.Debug("handle.get.feed", "ruid", ruid)
|
2018-06-20 12:06:27 +00:00
|
|
|
var err error
|
|
|
|
|
2018-10-03 07:15:17 +00:00
|
|
|
fd, err := s.api.ResolveFeed(r.Context(), uri, r.URL.Query())
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
if err != nil { // couldn't parse query string or retrieve manifest
|
2018-06-20 12:06:27 +00:00
|
|
|
getFail.Inc(1)
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
httpStatus := http.StatusBadRequest
|
2018-09-30 07:43:10 +00:00
|
|
|
if err == api.ErrCannotLoadFeedManifest || err == api.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 10:07:17 +00:00
|
|
|
httpStatus = http.StatusNotFound
|
|
|
|
}
|
2018-09-30 07:43:10 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("cannot retrieve feed information from manifest: %s", err), httpStatus)
|
2018-06-20 12:06:27 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-21 19:49:36 +00:00
|
|
|
// determine if the query specifies period and version or it is a metadata query
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
if r.URL.Query().Get("meta") == "1" {
|
2018-10-03 07:15:17 +00:00
|
|
|
unsignedUpdateRequest, err := s.api.FeedsNewRequest(r.Context(), fd)
|
2018-06-20 12:06:27 +00: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 10:07:17 +00:00
|
|
|
getFail.Inc(1)
|
2018-10-03 07:15:17 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("cannot retrieve feed metadata for feed=%s: %s", fd.Hex(), err), http.StatusNotFound)
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
return
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
rawResponse, err := unsignedUpdateRequest.MarshalJSON()
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
2018-09-30 07:43:10 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("cannot encode unsigned feed update request: %v", err), http.StatusInternalServerError)
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
return
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
w.Header().Add("Content-type", "application/json")
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
fmt.Fprint(w, string(rawResponse))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-03 07:15:17 +00:00
|
|
|
lookupParams := &feed.Query{Feed: *fd}
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
if err = lookupParams.FromValues(r.URL.Query()); err != nil { // parse period, version
|
2018-09-30 07:43:10 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("invalid feed update request:%s", err), http.StatusBadRequest)
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
return
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-30 07:43:10 +00:00
|
|
|
data, err := s.api.FeedsLookup(r.Context(), lookupParams)
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
// any error from the switch statement will end up here
|
|
|
|
if err != nil {
|
2018-09-30 07:43:10 +00:00
|
|
|
code, err2 := s.translateFeedError(w, r, "feed lookup fail", err)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, err2.Error(), code)
|
2018-06-20 12:06:27 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// All ok, serve the retrieved update
|
2018-10-03 07:15:17 +00:00
|
|
|
log.Debug("Found update", "feed", fd.Hex(), "ruid", ruid)
|
2018-10-01 11:39:39 +00:00
|
|
|
w.Header().Set("Content-Type", api.MimeOctetStream)
|
Swarm MRUs: Adaptive frequency / Predictable lookups / API simplification (#17559)
* swarm/storage/mru: Adaptive Frequency
swarm/storage/mru/lookup: fixed getBaseTime
Added NewEpoch constructor
swarm/api/client: better error handling in GetResource()
swarm/storage/mru: Renamed structures.
Renamed ResourceMetadata to ResourceID.
Renamed ResourceID.Name to ResourceID.Topic
swarm/storage/mru: Added binarySerializer interface and test tools
swarm/storage/mru/lookup: Changed base time to time and + marshallers
swarm/storage/mru: Added ResourceID (former resourceMetadata)
swarm/storage/mru: Added ResourceViewId and serialization tests
swarm/storage/mru/lookup: fixed epoch unmarshaller. Added Epoch Equals
swarm/storage/mru: Fixes as per review comments
cmd/swarm: reworded resource create/update help text regarding topic
swarm/storage/mru: Added UpdateLookup and serializer tests
swarm/storage/mru: Added UpdateHeader, serializers and tests
swarm/storage/mru: changed UpdateAddr / epoch to Base()
swarm/storage/mru: Added resourceUpdate serializer and tests
swarm/storage/mru: Added SignedResourceUpdate tests and serializers
swarm/storage/mru/lookup: fixed GetFirstEpoch bug
swarm/storage/mru: refactor, comments, cleanup
Also added tests for Topic
swarm/storage/mru: handler tests pass
swarm/storage/mru: all resource package tests pass
swarm/storage/mru: resource test pass after adding
timestamp checking support
swarm/storage/mru: Added JSON serializers to ResourceIDView structures
swarm/storage/mru: Sever, client, API test pass
swarm/storage/mru: server test pass
swarm/storage/mru: Added topic length check
swarm/storage/mru: removed some literals,
improved "previous lookup" test case
swarm/storage/mru: some fixes and comments as per review
swarm/storage/mru: first working version without metadata chunk
swarm/storage/mru: Various fixes as per review
swarm/storage/mru: client test pass
swarm/storage/mru: resource query strings and manifest-less queries
swarm/storage/mru: simplify naming
swarm/storage/mru: first autofreq working version
swarm/storage/mru: renamed ToValues to AppendValues
swarm/resource/mru: Added ToValues / FromValues for URL query strings
swarm/storage/mru: Changed POST resource to work with query strings.
No more JSON.
swarm/storage/mru: removed resourceid
swarm/storage/mru: Opened up structures
swarm/storage/mru: Merged Request and SignedResourceUpdate
swarm/storage/mru: removed initial data from CLI resource create
swarm/storage/mru: Refactor Topic as a direct fixed-length array
swarm/storage/mru/lookup: Comprehensive GetNextLevel tests
swarm/storage/mru: Added comments
Added length checks in Topic
swarm/storage/mru: fixes in tests and some code comments
swarm/storage/mru/lookup: new optimized lookup algorithm
swarm/api: moved getResourceView to api out of server
swarm/storage/mru: Lookup algorithm working
swarm/storage/mru: comments and renamed NewLookupParams
Deleted commented code
swarm/storage/mru/lookup: renamed Epoch.LaterThan to After
swarm/storage/mru/lookup: Comments and tidying naming
swarm/storage/mru: fix lookup algorithm
swarm/storage/mru: exposed lookup hint
removed updateheader
swarm/storage/mru/lookup: changed GetNextEpoch for initial values
swarm/storage/mru: resource tests pass
swarm/storage/mru: valueSerializer interface and tests
swarm/storage/mru/lookup: Comments, improvements, fixes, more tests
swarm/storage/mru: renamed UpdateLookup to ID, LookupParams to Query
swarm/storage/mru: renamed query receiver var
swarm/cmd: MRU CLI tests
* cmd/swarm: remove rogue fmt
* swarm/storage/mru: Add version / header for future use
* swarm/storage/mru: Fixes/comments as per review
cmd/swarm: remove rogue fmt
swarm/storage/mru: Add version / header for future use-
* swarm/storage/mru: fix linter errors
* cmd/swarm: Speeded up TestCLIResourceUpdate
2018-09-28 10:07:17 +00:00
|
|
|
http.ServeContent(w, r, "", time.Now(), bytes.NewReader(data))
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-30 07:43:10 +00:00
|
|
|
func (s *Server) translateFeedError(w http.ResponseWriter, r *http.Request, supErr string, err error) (int, error) {
|
2018-06-20 12:06:27 +00:00
|
|
|
code := 0
|
|
|
|
defaultErr := fmt.Errorf("%s: %v", supErr, err)
|
2018-10-03 07:15:17 +00:00
|
|
|
rsrcErr, ok := err.(*feed.Error)
|
2018-06-20 12:06:27 +00:00
|
|
|
if !ok && rsrcErr != nil {
|
|
|
|
code = rsrcErr.Code()
|
|
|
|
}
|
|
|
|
switch code {
|
|
|
|
case storage.ErrInvalidValue:
|
|
|
|
return http.StatusBadRequest, defaultErr
|
|
|
|
case storage.ErrNotFound, storage.ErrNotSynced, storage.ErrNothingToReturn, storage.ErrInit:
|
|
|
|
return http.StatusNotFound, defaultErr
|
|
|
|
case storage.ErrUnauthorized, storage.ErrInvalidSignature:
|
|
|
|
return http.StatusUnauthorized, defaultErr
|
|
|
|
case storage.ErrDataOverflow:
|
|
|
|
return http.StatusRequestEntityTooLarge, defaultErr
|
|
|
|
}
|
|
|
|
|
|
|
|
return http.StatusInternalServerError, defaultErr
|
|
|
|
}
|
|
|
|
|
2017-12-21 12:47:10 +00:00
|
|
|
// HandleGet handles a GET request to
|
|
|
|
// - bzz-raw://<key> and responds with the raw content stored at the
|
|
|
|
// given storage key
|
|
|
|
// - bzz-hash://<key> and responds with the hash of the content stored
|
|
|
|
// at the given storage key as a text/plain response
|
2018-08-07 09:56:55 +00:00
|
|
|
func (s *Server) HandleGet(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ruid := GetRUID(r.Context())
|
|
|
|
uri := GetURI(r.Context())
|
|
|
|
log.Debug("handle.get", "ruid", ruid, "uri", uri)
|
2018-02-23 13:19:59 +00:00
|
|
|
getCount.Inc(1)
|
2018-08-15 15:41:52 +00:00
|
|
|
_, pass, _ := r.BasicAuth()
|
2018-07-13 15:40:28 +00:00
|
|
|
|
2018-08-15 15:41:52 +00:00
|
|
|
addr, err := s.api.ResolveURI(r.Context(), uri, pass)
|
|
|
|
if err != nil {
|
|
|
|
getFail.Inc(1)
|
|
|
|
RespondError(w, r, fmt.Sprintf("cannot resolve %s: %s", uri.Addr, err), http.StatusNotFound)
|
|
|
|
return
|
2017-04-06 22:22:22 +00:00
|
|
|
}
|
2018-08-15 15:41:52 +00:00
|
|
|
w.Header().Set("Cache-Control", "max-age=2147483648, immutable") // url was of type bzz://<hex key>/path, so we are sure it is immutable.
|
2017-04-06 22:22:22 +00:00
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
log.Debug("handle.get: resolved", "ruid", ruid, "key", addr)
|
2018-06-20 12:06:27 +00:00
|
|
|
|
2017-04-06 22:22:22 +00:00
|
|
|
// if path is set, interpret <key> as a manifest and return the
|
|
|
|
// raw entry at the given path
|
2016-08-29 19:18:00 +00:00
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
etag := common.Bytes2Hex(addr)
|
|
|
|
noneMatchEtag := r.Header.Get("If-None-Match")
|
|
|
|
w.Header().Set("ETag", fmt.Sprintf("%q", etag)) // set etag to manifest key or raw entry key.
|
|
|
|
if noneMatchEtag != "" {
|
|
|
|
if bytes.Equal(storage.Address(common.Hex2Bytes(noneMatchEtag)), addr) {
|
2018-08-07 09:56:55 +00:00
|
|
|
w.WriteHeader(http.StatusNotModified)
|
2017-04-06 22:22:22 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2016-08-29 19:18:00 +00:00
|
|
|
|
2017-04-06 22:22:22 +00:00
|
|
|
// check the root chunk exists by retrieving the file's size
|
2018-08-07 09:56:55 +00:00
|
|
|
reader, isEncrypted := s.api.Retrieve(r.Context(), addr)
|
|
|
|
if _, err := reader.Size(r.Context(), nil); err != nil {
|
2018-02-23 13:19:59 +00:00
|
|
|
getFail.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("root chunk not found %s: %s", addr, err), http.StatusNotFound)
|
2017-04-06 22:22:22 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
w.Header().Set("X-Decrypted", fmt.Sprintf("%v", isEncrypted))
|
|
|
|
|
2017-12-21 12:47:10 +00:00
|
|
|
switch {
|
2018-08-07 09:56:55 +00:00
|
|
|
case uri.Raw():
|
2017-12-21 12:47:10 +00:00
|
|
|
// allow the request to overwrite the content type using a query
|
|
|
|
// parameter
|
|
|
|
if typ := r.URL.Query().Get("content_type"); typ != "" {
|
2018-10-01 11:39:39 +00:00
|
|
|
w.Header().Set("Content-Type", typ)
|
2017-12-21 12:47:10 +00:00
|
|
|
}
|
2018-08-07 09:56:55 +00:00
|
|
|
http.ServeContent(w, r, "", time.Now(), reader)
|
|
|
|
case uri.Hash():
|
2017-12-21 12:47:10 +00:00
|
|
|
w.Header().Set("Content-Type", "text/plain")
|
|
|
|
w.WriteHeader(http.StatusOK)
|
2018-06-20 12:06:27 +00:00
|
|
|
fmt.Fprint(w, addr)
|
2017-12-21 12:47:10 +00:00
|
|
|
}
|
2017-04-06 22:22:22 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 08:49:30 +00:00
|
|
|
// HandleGetList handles a GET request to bzz-list:/<manifest>/<path> and returns
|
|
|
|
// a list of all files contained in <manifest> under <path> grouped into
|
|
|
|
// common prefixes using "/" as a delimiter
|
2018-08-07 09:56:55 +00:00
|
|
|
func (s *Server) HandleGetList(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ruid := GetRUID(r.Context())
|
|
|
|
uri := GetURI(r.Context())
|
2018-08-15 15:41:52 +00:00
|
|
|
_, credentials, _ := r.BasicAuth()
|
2018-08-07 09:56:55 +00:00
|
|
|
log.Debug("handle.get.list", "ruid", ruid, "uri", uri)
|
2018-02-23 13:19:59 +00:00
|
|
|
getListCount.Inc(1)
|
2018-07-13 15:40:28 +00:00
|
|
|
|
2017-04-06 22:22:22 +00:00
|
|
|
// ensure the root path has a trailing slash so that relative URLs work
|
2018-08-07 09:56:55 +00:00
|
|
|
if uri.Path == "" && !strings.HasSuffix(r.URL.Path, "/") {
|
|
|
|
http.Redirect(w, r, r.URL.Path+"/", http.StatusMovedPermanently)
|
2017-04-06 22:22:22 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-15 15:41:52 +00:00
|
|
|
addr, err := s.api.Resolve(r.Context(), uri.Addr)
|
2017-04-06 22:22:22 +00:00
|
|
|
if err != nil {
|
2018-02-23 13:19:59 +00:00
|
|
|
getListFail.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("cannot resolve %s: %s", uri.Addr, err), http.StatusNotFound)
|
2017-04-06 22:22:22 +00:00
|
|
|
return
|
|
|
|
}
|
2018-08-07 09:56:55 +00:00
|
|
|
log.Debug("handle.get.list: resolved", "ruid", ruid, "key", addr)
|
2017-04-06 22:22:22 +00:00
|
|
|
|
2018-08-15 15:41:52 +00:00
|
|
|
list, err := s.api.GetManifestList(r.Context(), s.api.Decryptor(r.Context(), credentials), addr, uri.Path)
|
2017-04-06 22:22:22 +00:00
|
|
|
if err != nil {
|
2018-02-23 13:19:59 +00:00
|
|
|
getListFail.Inc(1)
|
2018-08-15 15:41:52 +00:00
|
|
|
if isDecryptError(err) {
|
|
|
|
w.Header().Set("WWW-Authenticate", fmt.Sprintf("Basic realm=%q", addr.String()))
|
|
|
|
RespondError(w, r, err.Error(), http.StatusUnauthorized)
|
|
|
|
return
|
|
|
|
}
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, err.Error(), http.StatusInternalServerError)
|
2017-04-06 22:22:22 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-10-06 13:45:54 +00:00
|
|
|
// if the client wants HTML (e.g. a browser) then render the list as a
|
|
|
|
// HTML index with relative URLs
|
|
|
|
if strings.Contains(r.Header.Get("Accept"), "text/html") {
|
|
|
|
w.Header().Set("Content-Type", "text/html")
|
2018-08-07 09:56:55 +00:00
|
|
|
err := TemplatesMap["bzz-list"].Execute(w, &htmlListData{
|
2017-12-19 08:49:30 +00:00
|
|
|
URI: &api.URI{
|
|
|
|
Scheme: "bzz",
|
2018-08-07 09:56:55 +00:00
|
|
|
Addr: uri.Addr,
|
|
|
|
Path: uri.Path,
|
2017-12-19 08:49:30 +00:00
|
|
|
},
|
2017-10-06 13:45:54 +00:00
|
|
|
List: &list,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2018-02-23 13:19:59 +00:00
|
|
|
getListFail.Inc(1)
|
2018-06-20 12:06:27 +00:00
|
|
|
log.Error(fmt.Sprintf("error rendering list HTML: %s", err))
|
2017-10-06 13:45:54 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
json.NewEncoder(w).Encode(&list)
|
|
|
|
}
|
|
|
|
|
2017-04-06 22:22:22 +00:00
|
|
|
// HandleGetFile handles a GET request to bzz://<manifest>/<path> and responds
|
|
|
|
// with the content of the file at <path> from the given <manifest>
|
2018-08-07 09:56:55 +00:00
|
|
|
func (s *Server) HandleGetFile(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ruid := GetRUID(r.Context())
|
|
|
|
uri := GetURI(r.Context())
|
2018-08-15 15:41:52 +00:00
|
|
|
_, credentials, _ := r.BasicAuth()
|
|
|
|
log.Debug("handle.get.file", "ruid", ruid, "uri", r.RequestURI)
|
2018-02-23 13:19:59 +00:00
|
|
|
getFileCount.Inc(1)
|
2018-07-13 15:40:28 +00:00
|
|
|
|
2017-07-25 09:51:26 +00:00
|
|
|
// ensure the root path has a trailing slash so that relative URLs work
|
2018-08-07 09:56:55 +00:00
|
|
|
if uri.Path == "" && !strings.HasSuffix(r.URL.Path, "/") {
|
|
|
|
http.Redirect(w, r, r.URL.Path+"/", http.StatusMovedPermanently)
|
2017-07-25 09:51:26 +00:00
|
|
|
return
|
|
|
|
}
|
2018-06-20 12:06:27 +00:00
|
|
|
var err error
|
2018-08-07 09:56:55 +00:00
|
|
|
manifestAddr := uri.Address()
|
2017-07-25 09:51:26 +00:00
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
if manifestAddr == nil {
|
2018-08-22 14:53:33 +00:00
|
|
|
manifestAddr, err = s.api.Resolve(r.Context(), uri.Addr)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
getFileFail.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("cannot resolve %s: %s", uri.Addr, err), http.StatusNotFound)
|
2018-06-20 12:06:27 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
w.Header().Set("Cache-Control", "max-age=2147483648, immutable") // url was of type bzz://<hex key>/path, so we are sure it is immutable.
|
|
|
|
}
|
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
log.Debug("handle.get.file: resolved", "ruid", ruid, "key", manifestAddr)
|
2018-08-15 15:41:52 +00:00
|
|
|
|
|
|
|
reader, contentType, status, contentKey, err := s.api.Get(r.Context(), s.api.Decryptor(r.Context(), credentials), manifestAddr, uri.Path)
|
2018-06-20 12:06:27 +00:00
|
|
|
|
|
|
|
etag := common.Bytes2Hex(contentKey)
|
|
|
|
noneMatchEtag := r.Header.Get("If-None-Match")
|
|
|
|
w.Header().Set("ETag", fmt.Sprintf("%q", etag)) // set etag to actual content key.
|
|
|
|
if noneMatchEtag != "" {
|
|
|
|
if bytes.Equal(storage.Address(common.Hex2Bytes(noneMatchEtag)), contentKey) {
|
2018-08-07 09:56:55 +00:00
|
|
|
w.WriteHeader(http.StatusNotModified)
|
2018-06-20 12:06:27 +00:00
|
|
|
return
|
|
|
|
}
|
2017-04-06 22:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
2018-08-15 15:41:52 +00:00
|
|
|
if isDecryptError(err) {
|
|
|
|
w.Header().Set("WWW-Authenticate", fmt.Sprintf("Basic realm=%q", manifestAddr))
|
|
|
|
RespondError(w, r, err.Error(), http.StatusUnauthorized)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-09-08 18:29:09 +00:00
|
|
|
switch status {
|
|
|
|
case http.StatusNotFound:
|
2018-02-23 13:19:59 +00:00
|
|
|
getFileNotFound.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, err.Error(), http.StatusNotFound)
|
2017-09-08 18:29:09 +00:00
|
|
|
default:
|
2018-02-23 13:19:59 +00:00
|
|
|
getFileFail.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, err.Error(), http.StatusInternalServerError)
|
2017-09-08 18:29:09 +00:00
|
|
|
}
|
2017-04-06 22:22:22 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-10-06 13:45:54 +00:00
|
|
|
//the request results in ambiguous files
|
|
|
|
//e.g. /read with readme.md and readinglist.txt available in manifest
|
|
|
|
if status == http.StatusMultipleChoices {
|
2018-08-15 15:41:52 +00:00
|
|
|
list, err := s.api.GetManifestList(r.Context(), s.api.Decryptor(r.Context(), credentials), manifestAddr, uri.Path)
|
2017-10-06 13:45:54 +00:00
|
|
|
if err != nil {
|
2018-02-23 13:19:59 +00:00
|
|
|
getFileFail.Inc(1)
|
2018-08-15 15:41:52 +00:00
|
|
|
if isDecryptError(err) {
|
|
|
|
w.Header().Set("WWW-Authenticate", fmt.Sprintf("Basic realm=%q", manifestAddr))
|
|
|
|
RespondError(w, r, err.Error(), http.StatusUnauthorized)
|
|
|
|
return
|
|
|
|
}
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, err.Error(), http.StatusInternalServerError)
|
2017-10-06 13:45:54 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-07 09:56:55 +00:00
|
|
|
log.Debug(fmt.Sprintf("Multiple choices! --> %v", list), "ruid", ruid)
|
2017-10-06 13:45:54 +00:00
|
|
|
//show a nice page links to available entries
|
2018-02-27 13:32:38 +00:00
|
|
|
ShowMultipleChoices(w, r, list)
|
2017-10-06 13:45:54 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-04-06 22:22:22 +00:00
|
|
|
// check the root chunk exists by retrieving the file's size
|
2018-08-07 09:56:55 +00:00
|
|
|
if _, err := reader.Size(r.Context(), nil); err != nil {
|
2018-02-23 13:19:59 +00:00
|
|
|
getFileNotFound.Inc(1)
|
2018-08-07 09:56:55 +00:00
|
|
|
RespondError(w, r, fmt.Sprintf("file not found %s: %s", uri, err), http.StatusNotFound)
|
2018-07-13 15:40:28 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-01 11:39:39 +00:00
|
|
|
if contentType != "" {
|
|
|
|
w.Header().Set("Content-Type", contentType)
|
|
|
|
}
|
|
|
|
|
|
|
|
fileName := uri.Addr
|
|
|
|
if found := path.Base(uri.Path); found != "" && found != "." && found != "/" {
|
|
|
|
fileName = found
|
|
|
|
}
|
|
|
|
w.Header().Set("Content-Disposition", fmt.Sprintf("inline; filename=\"%s\"", fileName))
|
|
|
|
|
|
|
|
http.ServeContent(w, r, fileName, time.Now(), newBufferedReadSeeker(reader, getFileBufferSize))
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
2017-04-06 22:22:22 +00:00
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
// The size of buffer used for bufio.Reader on LazyChunkReader passed to
|
|
|
|
// http.ServeContent in HandleGetFile.
|
|
|
|
// Warning: This value influences the number of chunk requests and chunker join goroutines
|
|
|
|
// per file request.
|
|
|
|
// Recommended value is 4 times the io.Copy default buffer value which is 32kB.
|
|
|
|
const getFileBufferSize = 4 * 32 * 1024
|
|
|
|
|
|
|
|
// bufferedReadSeeker wraps bufio.Reader to expose Seek method
|
|
|
|
// from the provied io.ReadSeeker in newBufferedReadSeeker.
|
|
|
|
type bufferedReadSeeker struct {
|
|
|
|
r io.Reader
|
|
|
|
s io.Seeker
|
2017-04-06 22:22:22 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
// newBufferedReadSeeker creates a new instance of bufferedReadSeeker,
|
|
|
|
// out of io.ReadSeeker. Argument `size` is the size of the read buffer.
|
|
|
|
func newBufferedReadSeeker(readSeeker io.ReadSeeker, size int) bufferedReadSeeker {
|
|
|
|
return bufferedReadSeeker{
|
|
|
|
r: bufio.NewReaderSize(readSeeker, size),
|
|
|
|
s: readSeeker,
|
2018-02-23 13:19:59 +00:00
|
|
|
}
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b bufferedReadSeeker) Read(p []byte) (n int, err error) {
|
|
|
|
return b.r.Read(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b bufferedReadSeeker) Seek(offset int64, whence int) (int64, error) {
|
|
|
|
return b.s.Seek(offset, whence)
|
|
|
|
}
|
|
|
|
|
|
|
|
type loggingResponseWriter struct {
|
|
|
|
http.ResponseWriter
|
|
|
|
statusCode int
|
2017-04-06 22:22:22 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
func newLoggingResponseWriter(w http.ResponseWriter) *loggingResponseWriter {
|
|
|
|
return &loggingResponseWriter{w, http.StatusOK}
|
2017-09-08 18:29:09 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
func (lrw *loggingResponseWriter) WriteHeader(code int) {
|
|
|
|
lrw.statusCode = code
|
|
|
|
lrw.ResponseWriter.WriteHeader(code)
|
2016-08-29 19:18:00 +00:00
|
|
|
}
|
2018-08-15 15:41:52 +00:00
|
|
|
|
|
|
|
func isDecryptError(err error) bool {
|
|
|
|
return strings.Contains(err.Error(), api.ErrDecrypt.Error())
|
|
|
|
}
|