aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/api/api.go
diff options
context:
space:
mode:
authornolash <dev@holbrook.no>2017-01-27 03:33:39 +0800
committernolash <dev@holbrook.no>2017-01-27 15:18:13 +0800
commit7669c5b5ec5b18e96a0714d667468247a3da3d68 (patch)
tree21d05653609b54e22dea26c946215726ce86a93d /swarm/api/api.go
parent82aa5b1de69331a43f5050717d593aa97eda1ef5 (diff)
downloaddexon-7669c5b5ec5b18e96a0714d667468247a3da3d68.tar.gz
dexon-7669c5b5ec5b18e96a0714d667468247a3da3d68.tar.zst
dexon-7669c5b5ec5b18e96a0714d667468247a3da3d68.zip
cmd/swarm, swarm/api: bzzr improve + networkid prio
fixes #3444 fixes #3494 networkid override Added comments to explain why test against 0 appears twice * Command line overrides saved config, saved config overrides system default --- fixes #3476 bzzr get with path Finally a hopefully clean commit for this PR Added check for empty path to avoid SIGSEGV in path parser and resolver Added requested tests for empty path and non-existing manifest. However signature for StartHTTPServer had changed. Now it's hacked as so: StartHttpServer(api.API, &Server{Addr: "127.0.0.1:8504", CorsString: ""}) * Parse url before resolve when path and ENS is supplied, example * swarm/api/http proxy server test for retrieval of subpath through get * Removed nil entry assignment on subtrie leaf in recursive key retrieval * Cleaned up path-or-no-path condition in proxy server get handler * swarm: processed with gofmt refers to lash/go-ethereum@90daa7a * swarm: Added public access method Parse alias to parse * swarm: processed with gofmt References nolash/go-ethereum@2ec3fd7 * Rename parse to Parse, removed alias
Diffstat (limited to 'swarm/api/api.go')
-rw-r--r--swarm/api/api.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/swarm/api/api.go b/swarm/api/api.go
index 3f48437a5..f92a14653 100644
--- a/swarm/api/api.go
+++ b/swarm/api/api.go
@@ -19,6 +19,7 @@ package api
import (
"fmt"
"io"
+ "net/http"
"regexp"
"strings"
"sync"
@@ -71,6 +72,7 @@ type ErrResolve error
// DNS Resolver
func (self *Api) Resolve(hostPort string, nameresolver bool) (storage.Key, error) {
+ glog.V(logger.Detail).Infof("Resolving : %v", hostPort)
if hashMatcher.MatchString(hostPort) || self.dns == nil {
glog.V(logger.Detail).Infof("host is a contentHash: '%v'", hostPort)
return storage.Key(common.Hex2Bytes(hostPort)), nil
@@ -86,8 +88,10 @@ func (self *Api) Resolve(hostPort string, nameresolver bool) (storage.Key, error
glog.V(logger.Detail).Infof("host lookup: %v -> %v", err)
return contentHash[:], err
}
-
-func parse(uri string) (hostPort, path string) {
+func Parse(uri string) (hostPort, path string) {
+ if uri == "" {
+ return
+ }
parts := slashes.Split(uri, 3)
var i int
if len(parts) == 0 {
@@ -111,7 +115,7 @@ func parse(uri string) (hostPort, path string) {
}
func (self *Api) parseAndResolve(uri string, nameresolver bool) (key storage.Key, hostPort, path string, err error) {
- hostPort, path = parse(uri)
+ 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)
@@ -153,7 +157,9 @@ func (self *Api) Get(uri string, nameresolver bool) (reader storage.LazySectionR
}
glog.V(logger.Detail).Infof("getEntry(%s)", path)
+
entry, _ := trie.getEntry(path)
+
if entry != nil {
key = common.Hex2Bytes(entry.Hash)
status = entry.Status
@@ -161,6 +167,7 @@ func (self *Api) Get(uri string, nameresolver bool) (reader storage.LazySectionR
glog.V(logger.Detail).Infof("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)
}