aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/api
diff options
context:
space:
mode:
Diffstat (limited to 'swarm/api')
-rw-r--r--swarm/api/api.go23
-rw-r--r--swarm/api/api_test.go8
-rw-r--r--swarm/api/filesystem.go9
-rw-r--r--swarm/api/http/roundtripper.go5
-rw-r--r--swarm/api/http/server.go66
-rw-r--r--swarm/api/manifest.go19
6 files changed, 60 insertions, 70 deletions
diff --git a/swarm/api/api.go b/swarm/api/api.go
index f92a14653..3376fb484 100644
--- a/swarm/api/api.go
+++ b/swarm/api/api.go
@@ -25,8 +25,7 @@ import (
"sync"
"github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/swarm/storage"
)
@@ -72,9 +71,9 @@ type ErrResolve error
// DNS Resolver
func (self *Api) Resolve(hostPort string, nameresolver bool) (storage.Key, error) {
- glog.V(logger.Detail).Infof("Resolving : %v", hostPort)
+ log.Trace(fmt.Sprintf("Resolving : %v", hostPort))
if hashMatcher.MatchString(hostPort) || self.dns == nil {
- glog.V(logger.Detail).Infof("host is a contentHash: '%v'", hostPort)
+ log.Trace(fmt.Sprintf("host is a contentHash: '%v'", hostPort))
return storage.Key(common.Hex2Bytes(hostPort)), nil
}
if !nameresolver {
@@ -83,9 +82,9 @@ func (self *Api) Resolve(hostPort string, nameresolver bool) (storage.Key, error
contentHash, err := self.dns.Resolve(hostPort)
if err != nil {
err = ErrResolve(err)
- glog.V(logger.Warn).Infof("DNS error : %v", err)
+ log.Warn(fmt.Sprintf("DNS error : %v", err))
}
- glog.V(logger.Detail).Infof("host lookup: %v -> %v", err)
+ log.Trace(fmt.Sprintf("host lookup: %v -> %v", err))
return contentHash[:], err
}
func Parse(uri string) (hostPort, path string) {
@@ -110,7 +109,7 @@ func Parse(uri string) (hostPort, path string) {
path = parts[i]
}
}
- glog.V(logger.Debug).Infof("host: '%s', path '%s' requested.", hostPort, path)
+ log.Debug(fmt.Sprintf("host: '%s', path '%s' requested.", hostPort, path))
return
}
@@ -118,7 +117,7 @@ func (self *Api) parseAndResolve(uri string, nameresolver bool) (key storage.Key
hostPort, path = Parse(uri)
//resolving host and port
contentHash, err := self.Resolve(hostPort, nameresolver)
- glog.V(logger.Debug).Infof("Resolved '%s' to contentHash: '%s', path: '%s'", uri, contentHash, path)
+ log.Debug(fmt.Sprintf("Resolved '%s' to contentHash: '%s', path: '%s'", uri, contentHash, path))
return contentHash[:], hostPort, path, err
}
@@ -152,11 +151,11 @@ func (self *Api) Get(uri string, nameresolver bool) (reader storage.LazySectionR
quitC := make(chan bool)
trie, err := loadManifest(self.dpa, key, quitC)
if err != nil {
- glog.V(logger.Warn).Infof("loadManifestTrie error: %v", err)
+ log.Warn(fmt.Sprintf("loadManifestTrie error: %v", err))
return
}
- glog.V(logger.Detail).Infof("getEntry(%s)", path)
+ log.Trace(fmt.Sprintf("getEntry(%s)", path))
entry, _ := trie.getEntry(path)
@@ -164,12 +163,12 @@ func (self *Api) Get(uri string, nameresolver bool) (reader storage.LazySectionR
key = common.Hex2Bytes(entry.Hash)
status = entry.Status
mimeType = entry.ContentType
- glog.V(logger.Detail).Infof("content lookup key: '%v' (%v)", key, mimeType)
+ log.Trace(fmt.Sprintf("content lookup key: '%v' (%v)", key, mimeType))
reader = self.dpa.Retrieve(key)
} else {
status = http.StatusNotFound
err = fmt.Errorf("manifest entry for '%s' not found", path)
- glog.V(logger.Warn).Infof("%v", err)
+ log.Warn(fmt.Sprintf("%v", err))
}
return
}
diff --git a/swarm/api/api_test.go b/swarm/api/api_test.go
index b09811959..16e90dd32 100644
--- a/swarm/api/api_test.go
+++ b/swarm/api/api_test.go
@@ -17,13 +17,13 @@
package api
import (
+ "fmt"
"io"
"io/ioutil"
"os"
"testing"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/swarm/storage"
)
@@ -76,7 +76,7 @@ func checkResponse(t *testing.T, resp *testResponse, exp *Response) {
// func expResponse(content []byte, mimeType string, status int) *Response {
func expResponse(content string, mimeType string, status int) *Response {
- glog.V(logger.Detail).Infof("expected content (%v): %v ", len(content), content)
+ log.Trace(fmt.Sprintf("expected content (%v): %v ", len(content), content))
return &Response{mimeType, status, int64(len(content)), content}
}
@@ -91,7 +91,7 @@ func testGet(t *testing.T, api *Api, bzzhash string) *testResponse {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
- glog.V(logger.Detail).Infof("reader size: %v ", size)
+ log.Trace(fmt.Sprintf("reader size: %v ", size))
s := make([]byte, size)
_, err = reader.Read(s)
if err != io.EOF {
diff --git a/swarm/api/filesystem.go b/swarm/api/filesystem.go
index 96aaf36df..c2583e265 100644
--- a/swarm/api/filesystem.go
+++ b/swarm/api/filesystem.go
@@ -26,8 +26,7 @@ import (
"sync"
"github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/swarm/storage"
)
@@ -63,7 +62,7 @@ func (self *FileSystem) Upload(lpath, index string) (string, error) {
var start int
if stat.IsDir() {
start = len(localpath)
- glog.V(logger.Debug).Infof("uploading '%s'", localpath)
+ log.Debug(fmt.Sprintf("uploading '%s'", localpath))
err = filepath.Walk(localpath, func(path string, info os.FileInfo, err error) error {
if (err == nil) && !info.IsDir() {
//fmt.Printf("lp %s path %s\n", localpath, path)
@@ -198,7 +197,7 @@ func (self *FileSystem) Download(bzzpath, localpath string) error {
quitC := make(chan bool)
trie, err := loadManifest(self.api.dpa, key, quitC)
if err != nil {
- glog.V(logger.Warn).Infof("fs.Download: loadManifestTrie error: %v", err)
+ log.Warn(fmt.Sprintf("fs.Download: loadManifestTrie error: %v", err))
return err
}
@@ -212,7 +211,7 @@ func (self *FileSystem) Download(bzzpath, localpath string) error {
prevPath := lpath
err = trie.listWithPrefix(path, quitC, func(entry *manifestTrieEntry, suffix string) {
- glog.V(logger.Detail).Infof("fs.Download: %#v", entry)
+ log.Trace(fmt.Sprintf("fs.Download: %#v", entry))
key = common.Hex2Bytes(entry.Hash)
path := lpath + "/" + suffix
diff --git a/swarm/api/http/roundtripper.go b/swarm/api/http/roundtripper.go
index 7b5bbc883..328177a21 100644
--- a/swarm/api/http/roundtripper.go
+++ b/swarm/api/http/roundtripper.go
@@ -20,8 +20,7 @@ import (
"fmt"
"net/http"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
)
/*
@@ -58,7 +57,7 @@ func (self *RoundTripper) RoundTrip(req *http.Request) (resp *http.Response, err
host = "localhost"
}
url := fmt.Sprintf("http://%s:%s/%s:/%s/%s", host, self.Port, req.Proto, req.URL.Host, req.URL.Path)
- glog.V(logger.Info).Infof("roundtripper: proxying request '%s' to '%s'", req.RequestURI, url)
+ log.Info(fmt.Sprintf("roundtripper: proxying request '%s' to '%s'", req.RequestURI, url))
reqProxy, err := http.NewRequest(req.Method, url, req.Body)
if err != nil {
return nil, err
diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go
index b1cea60fc..a61696678 100644
--- a/swarm/api/http/server.go
+++ b/swarm/api/http/server.go
@@ -21,6 +21,7 @@ package http
import (
"bytes"
+ "fmt"
"io"
"net/http"
"regexp"
@@ -29,8 +30,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/swarm/api"
"github.com/ethereum/go-ethereum/swarm/storage"
"github.com/rs/cors"
@@ -86,7 +86,7 @@ func StartHttpServer(api *api.Api, server *Server) {
hdlr := c.Handler(serveMux)
go http.ListenAndServe(server.Addr, hdlr)
- glog.V(logger.Info).Infof("Swarm HTTP proxy started on localhost:%s", server.Addr)
+ log.Info(fmt.Sprintf("Swarm HTTP proxy started on localhost:%s", server.Addr))
}
func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
@@ -100,13 +100,13 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
// return
// }
// }
- glog.V(logger.Debug).Infof("HTTP %s request URL: '%s', Host: '%s', Path: '%s', Referer: '%s', Accept: '%s'", r.Method, r.RequestURI, requestURL.Host, requestURL.Path, r.Referer(), r.Header.Get("Accept"))
+ log.Debug(fmt.Sprintf("HTTP %s request URL: '%s', Host: '%s', Path: '%s', Referer: '%s', Accept: '%s'", r.Method, r.RequestURI, requestURL.Host, requestURL.Path, r.Referer(), r.Header.Get("Accept")))
uri := requestURL.Path
var raw, nameresolver bool
var proto string
// HTTP-based URL protocol handler
- glog.V(logger.Debug).Infof("BZZ request URI: '%s'", uri)
+ log.Debug(fmt.Sprintf("BZZ request URI: '%s'", uri))
path := bzzPrefix.ReplaceAllStringFunc(uri, func(p string) string {
proto = p
@@ -115,24 +115,18 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
// protocol identification (ugly)
if proto == "" {
- if glog.V(logger.Error) {
- glog.Errorf(
- "[BZZ] Swarm: Protocol error in request `%s`.",
- uri,
- )
- http.Error(w, "Invalid request URL: need access protocol (bzz:/, bzzr:/, bzzi:/) as first element in path.", http.StatusBadRequest)
- return
- }
+ log.Error(fmt.Sprintf("[BZZ] Swarm: Protocol error in request `%s`.", uri))
+ http.Error(w, "Invalid request URL: need access protocol (bzz:/, bzzr:/, bzzi:/) as first element in path.", http.StatusBadRequest)
+ return
}
if len(proto) > 4 {
raw = proto[1:5] == "bzzr"
nameresolver = proto[1:5] != "bzzi"
}
- glog.V(logger.Debug).Infof(
- "[BZZ] Swarm: %s request over protocol %s '%s' received.",
- r.Method, proto, path,
- )
+ log.Debug("", "msg", log.Lazy{Fn: func() string {
+ return fmt.Sprintf("[BZZ] Swarm: %s request over protocol %s '%s' received.", r.Method, proto, path)
+ }})
switch {
case r.Method == "POST" || r.Method == "PUT":
@@ -142,7 +136,7 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
}
key, err := a.Store(io.LimitReader(r.Body, r.ContentLength), r.ContentLength, nil)
if err == nil {
- glog.V(logger.Debug).Infof("Content for %v stored", key.Log())
+ log.Debug(fmt.Sprintf("Content for %v stored", key.Log()))
} else {
http.Error(w, err.Error(), http.StatusBadRequest)
return
@@ -164,10 +158,10 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
path = api.RegularSlashes(path)
mime := r.Header.Get("Content-Type")
// TODO proper root hash separation
- glog.V(logger.Debug).Infof("Modify '%s' to store %v as '%s'.", path, key.Log(), mime)
+ log.Debug(fmt.Sprintf("Modify '%s' to store %v as '%s'.", path, key.Log(), mime))
newKey, err := a.Modify(path, common.Bytes2Hex(key), mime, nameresolver)
if err == nil {
- glog.V(logger.Debug).Infof("Swarm replaced manifest by '%s'", newKey)
+ log.Debug(fmt.Sprintf("Swarm replaced manifest by '%s'", newKey))
w.Header().Set("Content-Type", "text/plain")
http.ServeContent(w, r, "", time.Now(), bytes.NewReader([]byte(newKey)))
} else {
@@ -182,10 +176,10 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
return
} else {
path = api.RegularSlashes(path)
- glog.V(logger.Debug).Infof("Delete '%s'.", path)
+ log.Debug(fmt.Sprintf("Delete '%s'.", path))
newKey, err := a.Modify(path, "", "", nameresolver)
if err == nil {
- glog.V(logger.Debug).Infof("Swarm replaced manifest by '%s'", newKey)
+ log.Debug(fmt.Sprintf("Swarm replaced manifest by '%s'", newKey))
w.Header().Set("Content-Type", "text/plain")
http.ServeContent(w, r, "", time.Now(), bytes.NewReader([]byte(newKey)))
} else {
@@ -206,7 +200,7 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
if parsedurl == path {
key, err := a.Resolve(parsedurl, nameresolver)
if err != nil {
- glog.V(logger.Error).Infof("%v", err)
+ log.Error(fmt.Sprintf("%v", err))
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
@@ -226,12 +220,12 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
quitC := make(chan bool)
size, err := reader.Size(quitC)
if err != nil {
- glog.V(logger.Debug).Infof("Could not determine size: %v", err.Error())
+ log.Debug(fmt.Sprintf("Could not determine size: %v", err.Error()))
//An error on call to Size means we don't have the root chunk
http.Error(w, err.Error(), http.StatusNotFound)
return
}
- glog.V(logger.Debug).Infof("Reading %d bytes.", size)
+ log.Debug(fmt.Sprintf("Reading %d bytes.", size))
// setting mime type
qv := requestURL.Query()
@@ -242,11 +236,11 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
w.Header().Set("Content-Type", mimeType)
http.ServeContent(w, r, uri, forever(), reader)
- glog.V(logger.Debug).Infof("Serve raw content '%s' (%d bytes) as '%s'", uri, size, mimeType)
+ log.Debug(fmt.Sprintf("Serve raw content '%s' (%d bytes) as '%s'", uri, size, mimeType))
// retrieve path via manifest
} else {
- glog.V(logger.Debug).Infof("Structured GET request '%s' received.", uri)
+ log.Debug(fmt.Sprintf("Structured GET request '%s' received.", uri))
// add trailing slash, if missing
if rootDocumentUri.MatchString(uri) {
http.Redirect(w, r, path+"/", http.StatusFound)
@@ -255,10 +249,10 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
reader, mimeType, status, err := a.Get(path, nameresolver)
if err != nil {
if _, ok := err.(api.ErrResolve); ok {
- glog.V(logger.Debug).Infof("%v", err)
+ log.Debug(fmt.Sprintf("%v", err))
status = http.StatusBadRequest
} else {
- glog.V(logger.Debug).Infof("error retrieving '%s': %v", uri, err)
+ log.Debug(fmt.Sprintf("error retrieving '%s': %v", uri, err))
status = http.StatusNotFound
}
http.Error(w, err.Error(), status)
@@ -274,12 +268,12 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
quitC := make(chan bool)
size, err := reader.Size(quitC)
if err != nil {
- glog.V(logger.Debug).Infof("Could not determine size: %v", err.Error())
+ log.Debug(fmt.Sprintf("Could not determine size: %v", err.Error()))
//An error on call to Size means we don't have the root chunk
http.Error(w, err.Error(), http.StatusNotFound)
return
}
- glog.V(logger.Debug).Infof("Served '%s' (%d bytes) as '%s' (status code: %v)", uri, size, mimeType, status)
+ log.Debug(fmt.Sprintf("Served '%s' (%d bytes) as '%s' (status code: %v)", uri, size, mimeType, status))
http.ServeContent(w, r, path, forever(), reader)
@@ -293,11 +287,11 @@ func (self *sequentialReader) ReadAt(target []byte, off int64) (n int, err error
self.lock.Lock()
// assert self.pos <= off
if self.pos > off {
- glog.V(logger.Error).Infof("non-sequential read attempted from sequentialReader; %d > %d", self.pos, off)
+ log.Error(fmt.Sprintf("non-sequential read attempted from sequentialReader; %d > %d", self.pos, off))
panic("Non-sequential read attempt")
}
if self.pos != off {
- glog.V(logger.Debug).Infof("deferred read in POST at position %d, offset %d.", self.pos, off)
+ log.Debug(fmt.Sprintf("deferred read in POST at position %d, offset %d.", self.pos, off))
wait := make(chan bool)
self.ahead[off] = wait
self.lock.Unlock()
@@ -313,9 +307,9 @@ func (self *sequentialReader) ReadAt(target []byte, off int64) (n int, err error
for localPos < len(target) {
n, err = self.reader.Read(target[localPos:])
localPos += n
- glog.V(logger.Debug).Infof("Read %d bytes into buffer size %d from POST, error %v.", n, len(target), err)
+ log.Debug(fmt.Sprintf("Read %d bytes into buffer size %d from POST, error %v.", n, len(target), err))
if err != nil {
- glog.V(logger.Debug).Infof("POST stream's reading terminated with %v.", err)
+ log.Debug(fmt.Sprintf("POST stream's reading terminated with %v.", err))
for i := range self.ahead {
self.ahead[i] <- true
delete(self.ahead, i)
@@ -327,7 +321,7 @@ func (self *sequentialReader) ReadAt(target []byte, off int64) (n int, err error
}
wait := self.ahead[self.pos]
if wait != nil {
- glog.V(logger.Debug).Infof("deferred read in POST at position %d triggered.", self.pos)
+ log.Debug(fmt.Sprintf("deferred read in POST at position %d triggered.", self.pos))
delete(self.ahead, self.pos)
close(wait)
}
diff --git a/swarm/api/manifest.go b/swarm/api/manifest.go
index 36c0b0436..199f259e1 100644
--- a/swarm/api/manifest.go
+++ b/swarm/api/manifest.go
@@ -23,8 +23,7 @@ import (
"sync"
"github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/swarm/storage"
)
@@ -52,7 +51,7 @@ type manifestTrieEntry struct {
func loadManifest(dpa *storage.DPA, hash storage.Key, quitC chan bool) (trie *manifestTrie, err error) { // non-recursive, subtrees are downloaded on-demand
- glog.V(logger.Detail).Infof("manifest lookup key: '%v'.", hash.Log())
+ log.Trace(fmt.Sprintf("manifest lookup key: '%v'.", hash.Log()))
// retrieve manifest via DPA
manifestReader := dpa.Retrieve(hash)
return readManifest(manifestReader, hash, dpa, quitC)
@@ -70,23 +69,23 @@ func readManifest(manifestReader storage.LazySectionReader, hash storage.Key, dp
manifestData := make([]byte, size)
read, err := manifestReader.Read(manifestData)
if int64(read) < size {
- glog.V(logger.Detail).Infof("Manifest %v not found.", hash.Log())
+ log.Trace(fmt.Sprintf("Manifest %v not found.", hash.Log()))
if err == nil {
err = fmt.Errorf("Manifest retrieval cut short: read %v, expect %v", read, size)
}
return
}
- glog.V(logger.Detail).Infof("Manifest %v retrieved", hash.Log())
+ log.Trace(fmt.Sprintf("Manifest %v retrieved", hash.Log()))
man := manifestJSON{}
err = json.Unmarshal(manifestData, &man)
if err != nil {
err = fmt.Errorf("Manifest %v is malformed: %v", hash.Log(), err)
- glog.V(logger.Detail).Infof("%v", err)
+ log.Trace(fmt.Sprintf("%v", err))
return
}
- glog.V(logger.Detail).Infof("Manifest %v has %d entries.", hash.Log(), len(man.Entries))
+ log.Trace(fmt.Sprintf("Manifest %v has %d entries.", hash.Log(), len(man.Entries)))
trie = &manifestTrie{
dpa: dpa,
@@ -286,7 +285,7 @@ func (self *manifestTrie) listWithPrefix(prefix string, quitC chan bool, cb func
func (self *manifestTrie) findPrefixOf(path string, quitC chan bool) (entry *manifestTrieEntry, pos int) {
- glog.V(logger.Detail).Infof("findPrefixOf(%s)", path)
+ log.Trace(fmt.Sprintf("findPrefixOf(%s)", path))
if len(path) == 0 {
return self.entries[256], 0
@@ -298,9 +297,9 @@ func (self *manifestTrie) findPrefixOf(path string, quitC chan bool) (entry *man
return self.entries[256], 0
}
epl := len(entry.Path)
- glog.V(logger.Detail).Infof("path = %v entry.Path = %v epl = %v", path, entry.Path, epl)
+ log.Trace(fmt.Sprintf("path = %v entry.Path = %v epl = %v", path, entry.Path, epl))
if (len(path) >= epl) && (path[:epl] == entry.Path) {
- glog.V(logger.Detail).Infof("entry.ContentType = %v", entry.ContentType)
+ log.Trace(fmt.Sprintf("entry.ContentType = %v", entry.ContentType))
if entry.ContentType == manifestType {
err := self.loadSubTrie(entry, quitC)
if err != nil {