aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/api/api.go
diff options
context:
space:
mode:
Diffstat (limited to 'swarm/api/api.go')
-rw-r--r--swarm/api/api.go124
1 files changed, 62 insertions, 62 deletions
diff --git a/swarm/api/api.go b/swarm/api/api.go
index 7b8f04c13..7bb631967 100644
--- a/swarm/api/api.go
+++ b/swarm/api/api.go
@@ -45,9 +45,10 @@ import (
"github.com/ethereum/go-ethereum/swarm/multihash"
"github.com/ethereum/go-ethereum/swarm/spancontext"
"github.com/ethereum/go-ethereum/swarm/storage"
- "github.com/ethereum/go-ethereum/swarm/storage/mru"
- "github.com/ethereum/go-ethereum/swarm/storage/mru/lookup"
- "github.com/opentracing/opentracing-go"
+ "github.com/ethereum/go-ethereum/swarm/storage/feed"
+ "github.com/ethereum/go-ethereum/swarm/storage/feed/lookup"
+
+ opentracing "github.com/opentracing/opentracing-go"
)
var (
@@ -235,18 +236,18 @@ on top of the FileStore
it is the public interface of the FileStore which is included in the ethereum stack
*/
type API struct {
- resource *mru.Handler
+ feed *feed.Handler
fileStore *storage.FileStore
dns Resolver
Decryptor func(context.Context, string) DecryptFunc
}
// NewAPI the api constructor initialises a new API instance.
-func NewAPI(fileStore *storage.FileStore, dns Resolver, resourceHandler *mru.Handler, pk *ecdsa.PrivateKey) (self *API) {
+func NewAPI(fileStore *storage.FileStore, dns Resolver, feedHandler *feed.Handler, pk *ecdsa.PrivateKey) (self *API) {
self = &API{
fileStore: fileStore,
dns: dns,
- resource: resourceHandler,
+ feed: feedHandler,
Decryptor: func(ctx context.Context, credentials string) DecryptFunc {
return self.doDecrypt(ctx, credentials, pk)
},
@@ -403,24 +404,24 @@ func (a *API) Get(ctx context.Context, decrypt DecryptFunc, manifestAddr storage
return a.Get(ctx, decrypt, adr, entry.Path)
}
- // we need to do some extra work if this is a mutable resource manifest
- if entry.ContentType == ResourceContentType {
- if entry.ResourceView == nil {
- return reader, mimeType, status, nil, fmt.Errorf("Cannot decode ResourceView in manifest")
+ // we need to do some extra work if this is a Swarm feed manifest
+ if entry.ContentType == FeedContentType {
+ if entry.Feed == nil {
+ return reader, mimeType, status, nil, fmt.Errorf("Cannot decode Feed in manifest")
}
- _, err := a.resource.Lookup(ctx, mru.NewQueryLatest(entry.ResourceView, lookup.NoClue))
+ _, err := a.feed.Lookup(ctx, feed.NewQueryLatest(entry.Feed, lookup.NoClue))
if err != nil {
apiGetNotFound.Inc(1)
status = http.StatusNotFound
- log.Debug(fmt.Sprintf("get resource content error: %v", err))
+ log.Debug(fmt.Sprintf("get feed update content error: %v", err))
return reader, mimeType, status, nil, err
}
// get the data of the update
- _, rsrcData, err := a.resource.GetContent(entry.ResourceView)
+ _, rsrcData, err := a.feed.GetContent(entry.Feed)
if err != nil {
apiGetNotFound.Inc(1)
status = http.StatusNotFound
- log.Warn(fmt.Sprintf("get resource content error: %v", err))
+ log.Warn(fmt.Sprintf("get feed update content error: %v", err))
return reader, mimeType, status, nil, err
}
@@ -429,18 +430,18 @@ func (a *API) Get(ctx context.Context, decrypt DecryptFunc, manifestAddr storage
if err != nil {
apiGetInvalid.Inc(1)
status = http.StatusUnprocessableEntity
- log.Warn("invalid resource multihash", "err", err)
+ log.Warn("invalid multihash in feed update", "err", err)
return reader, mimeType, status, nil, err
}
manifestAddr = storage.Address(decodedMultihash)
- log.Trace("resource is multihash", "key", manifestAddr)
+ log.Trace("feed update contains multihash", "key", manifestAddr)
// get the manifest the multihash digest points to
trie, err := loadManifest(ctx, a.fileStore, manifestAddr, nil, NOOPDecrypt)
if err != nil {
apiGetNotFound.Inc(1)
status = http.StatusNotFound
- log.Warn(fmt.Sprintf("loadManifestTrie (resource multihash) error: %v", err))
+ log.Warn(fmt.Sprintf("loadManifestTrie (feed update multihash) error: %v", err))
return reader, mimeType, status, nil, err
}
@@ -450,13 +451,13 @@ func (a *API) Get(ctx context.Context, decrypt DecryptFunc, manifestAddr storage
if entry == nil {
status = http.StatusNotFound
apiGetNotFound.Inc(1)
- err = fmt.Errorf("manifest (resource multihash) entry for '%s' not found", path)
- log.Trace("manifest (resource multihash) entry not found", "key", manifestAddr, "path", path)
+ err = fmt.Errorf("manifest (feed update multihash) entry for '%s' not found", path)
+ log.Trace("manifest (feed update multihash) entry not found", "key", manifestAddr, "path", path)
return reader, mimeType, status, nil, err
}
}
- // regardless of resource update manifests or normal manifests we will converge at this point
+ // regardless of feed update manifests or normal manifests we will converge at this point
// get the key the manifest entry points to and serve it if it's unambiguous
contentAddr = common.Hex2Bytes(entry.Hash)
status = entry.Status
@@ -956,68 +957,67 @@ func (a *API) BuildDirectoryTree(ctx context.Context, mhash string, nameresolver
return addr, manifestEntryMap, nil
}
-// ResourceLookup finds mutable resource updates at specific periods and versions
-func (a *API) ResourceLookup(ctx context.Context, query *mru.Query) ([]byte, error) {
- _, err := a.resource.Lookup(ctx, query)
+// FeedsLookup finds Swarm feeds updates at specific points in time, or the latest update
+func (a *API) FeedsLookup(ctx context.Context, query *feed.Query) ([]byte, error) {
+ _, err := a.feed.Lookup(ctx, query)
if err != nil {
return nil, err
}
var data []byte
- _, data, err = a.resource.GetContent(&query.View)
+ _, data, err = a.feed.GetContent(&query.Feed)
if err != nil {
return nil, err
}
return data, nil
}
-// ResourceNewRequest creates a Request object to update a specific mutable resource
-func (a *API) ResourceNewRequest(ctx context.Context, view *mru.View) (*mru.Request, error) {
- return a.resource.NewRequest(ctx, view)
+// FeedsNewRequest creates a Request object to update a specific feed
+func (a *API) FeedsNewRequest(ctx context.Context, feed *feed.Feed) (*feed.Request, error) {
+ return a.feed.NewRequest(ctx, feed)
}
-// ResourceUpdate updates a Mutable Resource with arbitrary data.
-// Upon retrieval the update will be retrieved verbatim as bytes.
-func (a *API) ResourceUpdate(ctx context.Context, request *mru.Request) (storage.Address, error) {
- return a.resource.Update(ctx, request)
+// FeedsUpdate publishes a new update on the given feed
+func (a *API) FeedsUpdate(ctx context.Context, request *feed.Request) (storage.Address, error) {
+ return a.feed.Update(ctx, request)
}
-// ResourceHashSize returned the size of the digest produced by the Mutable Resource hashing function
-func (a *API) ResourceHashSize() int {
- return a.resource.HashSize
+// FeedsHashSize returned the size of the digest produced by Swarm feeds' hashing function
+func (a *API) FeedsHashSize() int {
+ return a.feed.HashSize
}
-// ErrCannotLoadResourceManifest is returned when looking up a resource manifest fails
-var ErrCannotLoadResourceManifest = errors.New("Cannot load resource manifest")
+// ErrCannotLoadFeedManifest is returned when looking up a feeds manifest fails
+var ErrCannotLoadFeedManifest = errors.New("Cannot load feed manifest")
-// ErrNotAResourceManifest is returned when the address provided returned something other than a valid manifest
-var ErrNotAResourceManifest = errors.New("Not a resource manifest")
+// ErrNotAFeedManifest is returned when the address provided returned something other than a valid manifest
+var ErrNotAFeedManifest = errors.New("Not a feed manifest")
-// ResolveResourceManifest retrieves the Mutable Resource manifest for the given address, and returns the Resource's view ID.
-func (a *API) ResolveResourceManifest(ctx context.Context, addr storage.Address) (*mru.View, error) {
+// ResolveFeedManifest retrieves the Swarm feed manifest for the given address, and returns the referenced Feed.
+func (a *API) ResolveFeedManifest(ctx context.Context, addr storage.Address) (*feed.Feed, error) {
trie, err := loadManifest(ctx, a.fileStore, addr, nil, NOOPDecrypt)
if err != nil {
- return nil, ErrCannotLoadResourceManifest
+ return nil, ErrCannotLoadFeedManifest
}
entry, _ := trie.getEntry("")
- if entry.ContentType != ResourceContentType {
- return nil, ErrNotAResourceManifest
+ if entry.ContentType != FeedContentType {
+ return nil, ErrNotAFeedManifest
}
- return entry.ResourceView, nil
+ return entry.Feed, nil
}
-// ErrCannotResolveResourceURI is returned when the ENS resolver is not able to translate a name to a resource
-var ErrCannotResolveResourceURI = errors.New("Cannot resolve Resource URI")
+// ErrCannotResolveFeedURI is returned when the ENS resolver is not able to translate a name to a Swarm feed
+var ErrCannotResolveFeedURI = errors.New("Cannot resolve Feed URI")
-// ErrCannotResolveResourceView is returned when values provided are not enough or invalid to recreate a
-// resource view out of them.
-var ErrCannotResolveResourceView = errors.New("Cannot resolve resource view")
+// ErrCannotResolveFeed is returned when values provided are not enough or invalid to recreate a
+// feed out of them.
+var ErrCannotResolveFeed = errors.New("Cannot resolve Feed")
-// ResolveResourceView attempts to extract View information out of the manifest, if provided
-// If not, it attempts to extract the View out of a set of key-value pairs
-func (a *API) ResolveResourceView(ctx context.Context, uri *URI, values mru.Values) (*mru.View, error) {
- var view *mru.View
+// ResolveFeed attempts to extract feed information out of the manifest, if provided
+// If not, it attempts to extract the feed out of a set of key-value pairs
+func (a *API) ResolveFeed(ctx context.Context, uri *URI, values feed.Values) (*feed.Feed, error) {
+ var fd *feed.Feed
var err error
if uri.Addr != "" {
// resolve the content key.
@@ -1025,25 +1025,25 @@ func (a *API) ResolveResourceView(ctx context.Context, uri *URI, values mru.Valu
if manifestAddr == nil {
manifestAddr, err = a.Resolve(ctx, uri.Addr)
if err != nil {
- return nil, ErrCannotResolveResourceURI
+ return nil, ErrCannotResolveFeedURI
}
}
- // get the resource view from the manifest
- view, err = a.ResolveResourceManifest(ctx, manifestAddr)
+ // get the Swarm feed from the manifest
+ fd, err = a.ResolveFeedManifest(ctx, manifestAddr)
if err != nil {
return nil, err
}
- log.Debug("handle.get.resource: resolved", "manifestkey", manifestAddr, "view", view.Hex())
+ log.Debug("handle.get.feed: resolved", "manifestkey", manifestAddr, "feed", fd.Hex())
} else {
- var v mru.View
- if err := v.FromValues(values); err != nil {
- return nil, ErrCannotResolveResourceView
+ var f feed.Feed
+ if err := f.FromValues(values); err != nil {
+ return nil, ErrCannotResolveFeed
}
- view = &v
+ fd = &f
}
- return view, nil
+ return fd, nil
}
// MimeOctetStream default value of http Content-Type header