mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
swarm: Added public access method Parse alias to parse
This commit is contained in:
parent
5cb586c8ac
commit
2ec3fd7d00
1 changed files with 9 additions and 0 deletions
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
|
|
@ -71,6 +72,7 @@ type ErrResolve error
|
||||||
|
|
||||||
// DNS Resolver
|
// DNS Resolver
|
||||||
func (self *Api) Resolve(hostPort string, nameresolver bool) (storage.Key, error) {
|
func (self *Api) Resolve(hostPort string, nameresolver bool) (storage.Key, error) {
|
||||||
|
glog.V(logger.Warn).Infof("Resolving : %v", hostPort)
|
||||||
if hashMatcher.MatchString(hostPort) || self.dns == nil {
|
if hashMatcher.MatchString(hostPort) || self.dns == nil {
|
||||||
glog.V(logger.Detail).Infof("host is a contentHash: '%v'", hostPort)
|
glog.V(logger.Detail).Infof("host is a contentHash: '%v'", hostPort)
|
||||||
return storage.Key(common.Hex2Bytes(hostPort)), nil
|
return storage.Key(common.Hex2Bytes(hostPort)), nil
|
||||||
|
|
@ -87,6 +89,10 @@ func (self *Api) Resolve(hostPort string, nameresolver bool) (storage.Key, error
|
||||||
return contentHash[:], err
|
return contentHash[:], err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Parse(url string) (hostPost, path string) {
|
||||||
|
return parse(url)
|
||||||
|
}
|
||||||
|
|
||||||
func parse(uri string) (hostPort, path string) {
|
func parse(uri string) (hostPort, path string) {
|
||||||
parts := slashes.Split(uri, 3)
|
parts := slashes.Split(uri, 3)
|
||||||
var i int
|
var i int
|
||||||
|
|
@ -150,7 +156,9 @@ func (self *Api) Get(uri string, nameresolver bool) (reader storage.LazySectionR
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(logger.Detail).Infof("getEntry(%s)", path)
|
glog.V(logger.Detail).Infof("getEntry(%s)", path)
|
||||||
|
|
||||||
entry, _ := trie.getEntry(path)
|
entry, _ := trie.getEntry(path)
|
||||||
|
|
||||||
if entry != nil {
|
if entry != nil {
|
||||||
key = common.Hex2Bytes(entry.Hash)
|
key = common.Hex2Bytes(entry.Hash)
|
||||||
status = entry.Status
|
status = entry.Status
|
||||||
|
|
@ -158,6 +166,7 @@ func (self *Api) Get(uri string, nameresolver bool) (reader storage.LazySectionR
|
||||||
glog.V(logger.Detail).Infof("content lookup key: '%v' (%v)", key, mimeType)
|
glog.V(logger.Detail).Infof("content lookup key: '%v' (%v)", key, mimeType)
|
||||||
reader = self.dpa.Retrieve(key)
|
reader = self.dpa.Retrieve(key)
|
||||||
} else {
|
} else {
|
||||||
|
status = http.StatusNotFound
|
||||||
err = fmt.Errorf("manifest entry for '%s' not found", path)
|
err = fmt.Errorf("manifest entry for '%s' not found", path)
|
||||||
glog.V(logger.Warn).Infof("%v", err)
|
glog.V(logger.Warn).Infof("%v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue