aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/api/uri.go
diff options
context:
space:
mode:
Diffstat (limited to 'swarm/api/uri.go')
-rw-r--r--swarm/api/uri.go46
1 files changed, 28 insertions, 18 deletions
diff --git a/swarm/api/uri.go b/swarm/api/uri.go
index d8aafedf4..14965e0d9 100644
--- a/swarm/api/uri.go
+++ b/swarm/api/uri.go
@@ -19,9 +19,17 @@ package api
import (
"fmt"
"net/url"
+ "regexp"
"strings"
+
+ "github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/swarm/storage"
)
+//matches hex swarm hashes
+// TODO: this is bad, it should not be hardcoded how long is a hash
+var hashMatcher = regexp.MustCompile("^([0-9A-Fa-f]{64})([0-9A-Fa-f]{64})?$")
+
// URI is a reference to content stored in swarm.
type URI struct {
// Scheme has one of the following values:
@@ -32,18 +40,15 @@ type URI struct {
// (address is not resolved)
// * bzz-list - list of all files contained in a swarm manifest
//
- // Deprecated Schemes:
- // * bzzr - raw swarm content
- // * bzzi - immutable URI of an entry in a swarm manifest
- // (address is not resolved)
- // * bzz-hash - hash of swarm content
- //
Scheme string
- // Addr is either a hexadecimal storage key or it an address which
- // resolves to a storage key
+ // Addr is either a hexadecimal storage address or it an address which
+ // resolves to a storage address
Addr string
+ // addr stores the parsed storage address
+ addr storage.Address
+
// Path is the path to the content within a swarm manifest
Path string
}
@@ -59,7 +64,6 @@ type URI struct {
// * <scheme>://<addr>/<path>
//
// with scheme one of bzz, bzz-raw, bzz-immutable, bzz-list or bzz-hash
-// or deprecated ones bzzr and bzzi
func Parse(rawuri string) (*URI, error) {
u, err := url.Parse(rawuri)
if err != nil {
@@ -69,7 +73,7 @@ func Parse(rawuri string) (*URI, error) {
// check the scheme is valid
switch uri.Scheme {
- case "bzz", "bzz-raw", "bzz-immutable", "bzz-list", "bzz-hash", "bzzr", "bzzi":
+ case "bzz", "bzz-raw", "bzz-immutable", "bzz-list", "bzz-hash", "bzz-resource":
default:
return nil, fmt.Errorf("unknown scheme %q", u.Scheme)
}
@@ -91,6 +95,9 @@ func Parse(rawuri string) (*URI, error) {
}
return uri, nil
}
+func (u *URI) Resource() bool {
+ return u.Scheme == "bzz-resource"
+}
func (u *URI) Raw() bool {
return u.Scheme == "bzz-raw"
@@ -104,14 +111,6 @@ func (u *URI) List() bool {
return u.Scheme == "bzz-list"
}
-func (u *URI) DeprecatedRaw() bool {
- return u.Scheme == "bzzr"
-}
-
-func (u *URI) DeprecatedImmutable() bool {
- return u.Scheme == "bzzi"
-}
-
func (u *URI) Hash() bool {
return u.Scheme == "bzz-hash"
}
@@ -119,3 +118,14 @@ func (u *URI) Hash() bool {
func (u *URI) String() string {
return u.Scheme + ":/" + u.Addr + "/" + u.Path
}
+
+func (u *URI) Address() storage.Address {
+ if u.addr != nil {
+ return u.addr
+ }
+ if hashMatcher.MatchString(u.Addr) {
+ u.addr = common.Hex2Bytes(u.Addr)
+ return u.addr
+ }
+ return nil
+}