Skip to content

Commit

Permalink
swarm/storage/mru: Renamed rest of MRU references
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeletier committed Oct 3, 2018
1 parent b35622c commit 83705ef
Show file tree
Hide file tree
Showing 19 changed files with 315 additions and 382 deletions.
66 changes: 33 additions & 33 deletions cmd/swarm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,25 +207,25 @@ var (
Name: "compressed",
Usage: "Prints encryption keys in compressed form",
}
SwarmResourceNameFlag = cli.StringFlag{
SwarmFeedNameFlag = cli.StringFlag{
Name: "name",
Usage: "User-defined name for the new resource, limited to 32 characters. If combined with topic, the resource will be a subtopic with this name",
Usage: "User-defined name for the new feed, limited to 32 characters. If combined with topic, it will refer to a subtopic with this name",
}
SwarmResourceTopicFlag = cli.StringFlag{
SwarmFeedTopicFlag = cli.StringFlag{
Name: "topic",
Usage: "User-defined topic this resource is tracking, hex encoded. Limited to 64 hexadecimal characters",
Usage: "User-defined topic this feed is tracking, hex encoded. Limited to 64 hexadecimal characters",
}
SwarmResourceDataOnCreateFlag = cli.StringFlag{
SwarmFeedDataOnCreateFlag = cli.StringFlag{
Name: "data",
Usage: "Initializes the resource with the given hex-encoded data. Data must be prefixed by 0x",
Usage: "Initializes the feed with the given hex-encoded data. Data must be prefixed by 0x",
}
SwarmResourceManifestFlag = cli.StringFlag{
SwarmFeedManifestFlag = cli.StringFlag{
Name: "manifest",
Usage: "Refers to the resource through a manifest",
Usage: "Refers to the feed through a manifest",
}
SwarmResourceUserFlag = cli.StringFlag{
SwarmFeedUserFlag = cli.StringFlag{
Name: "user",
Usage: "Indicates the user who updates the resource",
Usage: "Indicates the user who updates the feed",
}
)

Expand Down Expand Up @@ -346,62 +346,62 @@ func init() {
},
{
CustomHelpTemplate: helpTemplate,
Name: "resource",
Usage: "(Advanced) Create and update Mutable Resources",
Name: "feed",
Usage: "(Advanced) Create and update Swarm Feeds",
ArgsUsage: "<create|update|info>",
Description: "Works with Mutable Resource Updates",
Description: "Works with Swarm Feeds",
Subcommands: []cli.Command{
{
Action: resourceCreate,
Action: feedCreateManifest,
CustomHelpTemplate: helpTemplate,
Name: "create",
Usage: "creates and publishes a new Mutable Resource manifest",
Description: `creates and publishes a new Mutable Resource manifest pointing to a specified user's updates about a particular topic.
The resource topic can be built in the following ways:
Usage: "creates and publishes a new Feed manifest",
Description: `creates and publishes a new Feed manifest pointing to a specified user's updates about a particular topic.
The feed topic can be built in the following ways:
* use --topic to set the topic to an arbitrary binary hex string.
* use --name to set the topic to a human-readable name.
For example --name could be set to "profile-picture", meaning this Mutable Resource allows to get this user's current profile picture.
For example --name could be set to "profile-picture", meaning this feed allows to get this user's current profile picture.
* use both --topic and --name to create named subtopics.
For example, --topic could be set to an Ethereum contract address and --name could be set to "comments", meaning
the Mutable Resource tracks a discussion about that contract.
this feed tracks a discussion about that contract.
The --user flag allows to have this manifest refer to a user other than yourself. If not specified,
it will then default to your local account (--bzzaccount)`,
Flags: []cli.Flag{SwarmResourceNameFlag, SwarmResourceTopicFlag, SwarmResourceUserFlag},
Flags: []cli.Flag{SwarmFeedNameFlag, SwarmFeedTopicFlag, SwarmFeedUserFlag},
},
{
Action: resourceUpdate,
Action: feedUpdate,
CustomHelpTemplate: helpTemplate,
Name: "update",
Usage: "updates the content of an existing Mutable Resource",
Usage: "updates the content of an existing Swarm Feed",
ArgsUsage: "<0x Hex data>",
Description: `publishes a new update on the specified topic
The resource topic can be built in the following ways:
The feed topic can be built in the following ways:
* use --topic to set the topic to an arbitrary binary hex string.
* use --name to set the topic to a human-readable name.
For example --name could be set to "profile-picture", meaning this Mutable Resource allows to get this user's current profile picture.
For example --name could be set to "profile-picture", meaning this feed allows to get this user's current profile picture.
* use both --topic and --name to create named subtopics.
For example, --topic could be set to an Ethereum contract address and --name could be set to "comments", meaning
the Mutable Resource tracks a discussion about that contract.
this feed tracks a discussion about that contract.
If you have a manifest, you can specify it with --manifest to refer to the resource,
If you have a manifest, you can specify it with --manifest to refer to the feed,
instead of using --topic / --name
`,
Flags: []cli.Flag{SwarmResourceManifestFlag, SwarmResourceNameFlag, SwarmResourceTopicFlag},
Flags: []cli.Flag{SwarmFeedManifestFlag, SwarmFeedNameFlag, SwarmFeedTopicFlag},
},
{
Action: resourceInfo,
Action: feedInfo,
CustomHelpTemplate: helpTemplate,
Name: "info",
Usage: "obtains information about an existing Mutable Resource",
Description: `obtains information about an existing Mutable Resource
Usage: "obtains information about an existing Swarm Feed",
Description: `obtains information about an existing Swarm Feed
The topic can be specified directly with the --topic flag as an hex string
If no topic is specified, the default topic (zero) will be used
The --name flag can be used to specify subtopics with a specific name.
The --user flag allows to refer to a user other than yourself. If not specified,
it will then default to your local account (--bzzaccount)
If you have a manifest, you can specify it with --manifest instead of --topic / --name / ---user
to refer to the resource`,
Flags: []cli.Flag{SwarmResourceManifestFlag, SwarmResourceNameFlag, SwarmResourceTopicFlag, SwarmResourceUserFlag},
to refer to the feed`,
Flags: []cli.Flag{SwarmFeedManifestFlag, SwarmFeedNameFlag, SwarmFeedTopicFlag, SwarmFeedUserFlag},
},
},
},
Expand Down Expand Up @@ -738,7 +738,7 @@ func getAccount(bzzaccount string, ctx *cli.Context, stack *node.Node) *ecdsa.Pr
}

// getPrivKey returns the private key of the specified bzzaccount
// Used only by client commands, such as `resource`
// Used only by client commands, such as `feed`
func getPrivKey(ctx *cli.Context) *ecdsa.PrivateKey {
// booting up the swarm node just as we do in bzzd action
bzzconfig, err := buildConfig(ctx)
Expand Down
52 changes: 26 additions & 26 deletions cmd/swarm/mru.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.

// Command resource allows the user to create and update signed Swarm Feeds
// Command feed allows the user to create and update signed Swarm Feeds
package main

import (
Expand All @@ -36,8 +36,8 @@ func NewGenericSigner(ctx *cli.Context) mru.Signer {
}

func getTopic(ctx *cli.Context) (topic mru.Topic) {
var name = ctx.String(SwarmResourceNameFlag.Name)
var relatedTopic = ctx.String(SwarmResourceTopicFlag.Name)
var name = ctx.String(SwarmFeedNameFlag.Name)
var relatedTopic = ctx.String(SwarmFeedTopicFlag.Name)
var relatedTopicBytes []byte
var err error

Expand All @@ -55,35 +55,35 @@ func getTopic(ctx *cli.Context) (topic mru.Topic) {
return topic
}

// swarm resource create <frequency> [--name <name>] [--data <0x Hexdata> [--multihash=false]]
// swarm resource update <Manifest Address or ENS domain> <0x Hexdata> [--multihash=false]
// swarm resource info <Manifest Address or ENS domain>
// swarm feed create <frequency> [--name <name>] [--data <0x Hexdata> [--multihash=false]]
// swarm feed update <Manifest Address or ENS domain> <0x Hexdata> [--multihash=false]
// swarm feed info <Manifest Address or ENS domain>

func resourceCreate(ctx *cli.Context) {
func feedCreateManifest(ctx *cli.Context) {
var (
bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
client = swarm.NewClient(bzzapi)
)

newResourceRequest := mru.NewFirstRequest(getTopic(ctx))
newResourceRequest.Feed.User = resourceGetUser(ctx)
newFeedUpdateRequest := mru.NewFirstRequest(getTopic(ctx))
newFeedUpdateRequest.Feed.User = feedGetUser(ctx)

manifestAddress, err := client.CreateResource(newResourceRequest)
manifestAddress, err := client.CreateFeedWithManifest(newFeedUpdateRequest)
if err != nil {
utils.Fatalf("Error creating resource: %s", err.Error())
utils.Fatalf("Error creating feed manifest: %s", err.Error())
return
}
fmt.Println(manifestAddress) // output manifest address to the user in a single line (useful for other commands to pick up)

}

func resourceUpdate(ctx *cli.Context) {
func feedUpdate(ctx *cli.Context) {
args := ctx.Args()

var (
bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
client = swarm.NewClient(bzzapi)
manifestAddressOrDomain = ctx.String(SwarmResourceManifestFlag.Name)
manifestAddressOrDomain = ctx.String(SwarmFeedManifestFlag.Name)
)

if len(args) < 1 {
Expand All @@ -110,45 +110,45 @@ func resourceUpdate(ctx *cli.Context) {

}

// Retrieve resource status and metadata out of the manifest
updateRequest, err = client.GetResourceMetadata(query, manifestAddressOrDomain)
// Retrieve feed status and metadata out of the manifest
updateRequest, err = client.GetFeedMetadata(query, manifestAddressOrDomain)
if err != nil {
utils.Fatalf("Error retrieving resource status: %s", err.Error())
utils.Fatalf("Error retrieving feed status: %s", err.Error())
}

// set the new data
updateRequest.SetData(data)

// sign update
if err = updateRequest.Sign(signer); err != nil {
utils.Fatalf("Error signing resource update: %s", err.Error())
utils.Fatalf("Error signing feed update: %s", err.Error())
}

// post update
err = client.UpdateResource(updateRequest)
err = client.UpdateFeed(updateRequest)
if err != nil {
utils.Fatalf("Error updating resource: %s", err.Error())
utils.Fatalf("Error updating feed: %s", err.Error())
return
}
}

func resourceInfo(ctx *cli.Context) {
func feedInfo(ctx *cli.Context) {
var (
bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
client = swarm.NewClient(bzzapi)
manifestAddressOrDomain = ctx.String(SwarmResourceManifestFlag.Name)
manifestAddressOrDomain = ctx.String(SwarmFeedManifestFlag.Name)
)

var query *mru.Query
if manifestAddressOrDomain == "" {
query = new(mru.Query)
query.Topic = getTopic(ctx)
query.User = resourceGetUser(ctx)
query.User = feedGetUser(ctx)
}

metadata, err := client.GetResourceMetadata(query, manifestAddressOrDomain)
metadata, err := client.GetFeedMetadata(query, manifestAddressOrDomain)
if err != nil {
utils.Fatalf("Error retrieving resource metadata: %s", err.Error())
utils.Fatalf("Error retrieving feed metadata: %s", err.Error())
return
}
encodedMetadata, err := metadata.MarshalJSON()
Expand All @@ -158,8 +158,8 @@ func resourceInfo(ctx *cli.Context) {
fmt.Println(string(encodedMetadata))
}

func resourceGetUser(ctx *cli.Context) common.Address {
var user = ctx.String(SwarmResourceUserFlag.Name)
func feedGetUser(ctx *cli.Context) common.Address {
var user = ctx.String(SwarmFeedUserFlag.Name)
if user != "" {
return common.HexToAddress(user)
}
Expand Down
34 changes: 17 additions & 17 deletions cmd/swarm/mru_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ import (
swarmhttp "github.com/ethereum/go-ethereum/swarm/api/http"
)

func TestCLIResourceUpdate(t *testing.T) {
func TestCLIFeedUpdate(t *testing.T) {

srv := testutil.NewTestSwarmServer(t, func(api *api.API) testutil.TestServer {
return swarmhttp.NewServer(api, "")
}, nil)
log.Info("starting 1 node cluster")
log.Info("starting a test swarm server")
defer srv.Close()

// create a private key file for signing
Expand Down Expand Up @@ -77,13 +77,13 @@ func TestCLIResourceUpdate(t *testing.T) {
flags := []string{
"--bzzapi", srv.URL,
"--bzzaccount", pkfile.Name(),
"resource", "update",
"feed", "update",
"--topic", topic.Hex(),
"--name", name,
hexData}

// create an update and expect an exit without errors
log.Info(fmt.Sprintf("updating a resource with 'swarm resource update'"))
log.Info(fmt.Sprintf("updating a feed with 'swarm feed update'"))
cmd := runSwarm(t, flags...)
cmd.ExpectExit()

Expand All @@ -100,17 +100,17 @@ func TestCLIResourceUpdate(t *testing.T) {
t.Fatal(err)
}

// View configures whose updates we will be looking up.
view := mru.Feed{
// Feed configures whose updates we will be looking up.
feed := mru.Feed{
Topic: topic,
User: address,
}

// Build a query to get the latest update
query := mru.NewQueryLatest(&view, lookup.NoClue)
query := mru.NewQueryLatest(&feed, lookup.NoClue)

// retrieve content!
reader, err := client.GetResource(query, "")
reader, err := client.QueryFeed(query, "")
if err != nil {
t.Fatal(err)
}
Expand All @@ -128,12 +128,12 @@ func TestCLIResourceUpdate(t *testing.T) {
// Now retrieve info for the next update
flags = []string{
"--bzzapi", srv.URL,
"resource", "info",
"feed", "info",
"--topic", topic.Hex(),
"--user", address.Hex(),
}

log.Info(fmt.Sprintf("getting resource info with 'swarm resource info'"))
log.Info(fmt.Sprintf("getting feed info with 'swarm feed info'"))
cmd = runSwarm(t, flags...)
_, matches := cmd.ExpectRegexp(`.*`) // regex hack to extract stdout
cmd.ExpectExit()
Expand All @@ -145,28 +145,28 @@ func TestCLIResourceUpdate(t *testing.T) {
t.Fatal(err)
}

// make sure the retrieved view is the same
if request.Feed != view {
t.Fatalf("Expected view to be: %s, got %s", view, request.Feed)
// make sure the retrieved Feed is the same
if request.Feed != feed {
t.Fatalf("Expected feed to be: %s, got %s", feed, request.Feed)
}

// test publishing a manifest
flags = []string{
"--bzzapi", srv.URL,
"--bzzaccount", pkfile.Name(),
"resource", "create",
"feed", "create",
"--topic", topic.Hex(),
}

log.Info(fmt.Sprintf("Publishing manifest with 'swarm resource create'"))
log.Info(fmt.Sprintf("Publishing manifest with 'swarm feed create'"))
cmd = runSwarm(t, flags...)
_, matches = cmd.ExpectRegexp(`[a-f\d]{64}`) // regex hack to extract stdout
cmd.ExpectExit()

manifestAddress := matches[0] // read the received resource manifest
manifestAddress := matches[0] // read the received feed manifest

// now attempt to lookup the latest update using a manifest instead
reader, err = client.GetResource(nil, manifestAddress)
reader, err = client.QueryFeed(nil, manifestAddress)
if err != nil {
t.Fatal(err)
}
Expand Down
Loading

0 comments on commit 83705ef

Please sign in to comment.