|
|
@ -3,7 +3,6 @@ package main |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
"bytes" |
|
|
|
"crypto/md5" |
|
|
|
"crypto/md5" |
|
|
|
crand "crypto/rand" |
|
|
|
|
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"io" |
|
|
|
"io" |
|
|
|
"io/ioutil" |
|
|
|
"io/ioutil" |
|
|
@ -16,7 +15,9 @@ import ( |
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil" |
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil" |
|
|
|
"github.com/ethereum/go-ethereum/crypto" |
|
|
|
"github.com/ethereum/go-ethereum/crypto" |
|
|
|
"github.com/ethereum/go-ethereum/log" |
|
|
|
"github.com/ethereum/go-ethereum/log" |
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/metrics" |
|
|
|
"github.com/ethereum/go-ethereum/swarm/storage/feed" |
|
|
|
"github.com/ethereum/go-ethereum/swarm/storage/feed" |
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/swarm/testutil" |
|
|
|
"github.com/pborman/uuid" |
|
|
|
"github.com/pborman/uuid" |
|
|
|
cli "gopkg.in/urfave/cli.v1" |
|
|
|
cli "gopkg.in/urfave/cli.v1" |
|
|
|
) |
|
|
|
) |
|
|
@ -25,13 +26,28 @@ const ( |
|
|
|
feedRandomDataLength = 8 |
|
|
|
feedRandomDataLength = 8 |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// TODO: retrieve with manifest + extract repeating code
|
|
|
|
func feedUploadAndSyncCmd(ctx *cli.Context, tuid string) error { |
|
|
|
func feedUploadAndSync(c *cli.Context) error { |
|
|
|
errc := make(chan error) |
|
|
|
defer func(now time.Time) { log.Info("total time", "time", time.Since(now), "size (kb)", filesize) }(time.Now()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
generateEndpoints(scheme, cluster, appName, from, to) |
|
|
|
go func() { |
|
|
|
|
|
|
|
errc <- feedUploadAndSync(ctx, tuid) |
|
|
|
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
log.Info("generating and uploading feeds to " + endpoints[0] + " and syncing") |
|
|
|
select { |
|
|
|
|
|
|
|
case err := <-errc: |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
metrics.GetOrRegisterCounter(fmt.Sprintf("%s.fail", commandName), nil).Inc(1) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
case <-time.After(time.Duration(timeout) * time.Second): |
|
|
|
|
|
|
|
metrics.GetOrRegisterCounter(fmt.Sprintf("%s.timeout", commandName), nil).Inc(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return fmt.Errorf("timeout after %v sec", timeout) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func feedUploadAndSync(c *cli.Context, tuid string) error { |
|
|
|
|
|
|
|
log.Info("generating and uploading feeds to " + httpEndpoint(hosts[0]) + " and syncing") |
|
|
|
|
|
|
|
|
|
|
|
// create a random private key to sign updates with and derive the address
|
|
|
|
// create a random private key to sign updates with and derive the address
|
|
|
|
pkFile, err := ioutil.TempFile("", "swarm-feed-smoke-test") |
|
|
|
pkFile, err := ioutil.TempFile("", "swarm-feed-smoke-test") |
|
|
@ -85,7 +101,7 @@ func feedUploadAndSync(c *cli.Context) error { |
|
|
|
|
|
|
|
|
|
|
|
// create feed manifest, topic only
|
|
|
|
// create feed manifest, topic only
|
|
|
|
var out bytes.Buffer |
|
|
|
var out bytes.Buffer |
|
|
|
cmd := exec.Command("swarm", "--bzzapi", endpoints[0], "feed", "create", "--topic", topicHex, "--user", userHex) |
|
|
|
cmd := exec.Command("swarm", "--bzzapi", httpEndpoint(hosts[0]), "feed", "create", "--topic", topicHex, "--user", userHex) |
|
|
|
cmd.Stdout = &out |
|
|
|
cmd.Stdout = &out |
|
|
|
log.Debug("create feed manifest topic cmd", "cmd", cmd) |
|
|
|
log.Debug("create feed manifest topic cmd", "cmd", cmd) |
|
|
|
err = cmd.Run() |
|
|
|
err = cmd.Run() |
|
|
@ -100,7 +116,7 @@ func feedUploadAndSync(c *cli.Context) error { |
|
|
|
out.Reset() |
|
|
|
out.Reset() |
|
|
|
|
|
|
|
|
|
|
|
// create feed manifest, subtopic only
|
|
|
|
// create feed manifest, subtopic only
|
|
|
|
cmd = exec.Command("swarm", "--bzzapi", endpoints[0], "feed", "create", "--name", subTopicHex, "--user", userHex) |
|
|
|
cmd = exec.Command("swarm", "--bzzapi", httpEndpoint(hosts[0]), "feed", "create", "--name", subTopicHex, "--user", userHex) |
|
|
|
cmd.Stdout = &out |
|
|
|
cmd.Stdout = &out |
|
|
|
log.Debug("create feed manifest subtopic cmd", "cmd", cmd) |
|
|
|
log.Debug("create feed manifest subtopic cmd", "cmd", cmd) |
|
|
|
err = cmd.Run() |
|
|
|
err = cmd.Run() |
|
|
@ -115,7 +131,7 @@ func feedUploadAndSync(c *cli.Context) error { |
|
|
|
out.Reset() |
|
|
|
out.Reset() |
|
|
|
|
|
|
|
|
|
|
|
// create feed manifest, merged topic
|
|
|
|
// create feed manifest, merged topic
|
|
|
|
cmd = exec.Command("swarm", "--bzzapi", endpoints[0], "feed", "create", "--topic", topicHex, "--name", subTopicHex, "--user", userHex) |
|
|
|
cmd = exec.Command("swarm", "--bzzapi", httpEndpoint(hosts[0]), "feed", "create", "--topic", topicHex, "--name", subTopicHex, "--user", userHex) |
|
|
|
cmd.Stdout = &out |
|
|
|
cmd.Stdout = &out |
|
|
|
log.Debug("create feed manifest mergetopic cmd", "cmd", cmd) |
|
|
|
log.Debug("create feed manifest mergetopic cmd", "cmd", cmd) |
|
|
|
err = cmd.Run() |
|
|
|
err = cmd.Run() |
|
|
@ -141,7 +157,7 @@ func feedUploadAndSync(c *cli.Context) error { |
|
|
|
dataHex := hexutil.Encode(data) |
|
|
|
dataHex := hexutil.Encode(data) |
|
|
|
|
|
|
|
|
|
|
|
// update with topic
|
|
|
|
// update with topic
|
|
|
|
cmd = exec.Command("swarm", "--bzzaccount", pkFile.Name(), "--bzzapi", endpoints[0], "feed", "update", "--topic", topicHex, dataHex) |
|
|
|
cmd = exec.Command("swarm", "--bzzaccount", pkFile.Name(), "--bzzapi", httpEndpoint(hosts[0]), "feed", "update", "--topic", topicHex, dataHex) |
|
|
|
cmd.Stdout = &out |
|
|
|
cmd.Stdout = &out |
|
|
|
log.Debug("update feed manifest topic cmd", "cmd", cmd) |
|
|
|
log.Debug("update feed manifest topic cmd", "cmd", cmd) |
|
|
|
err = cmd.Run() |
|
|
|
err = cmd.Run() |
|
|
@ -152,7 +168,7 @@ func feedUploadAndSync(c *cli.Context) error { |
|
|
|
out.Reset() |
|
|
|
out.Reset() |
|
|
|
|
|
|
|
|
|
|
|
// update with subtopic
|
|
|
|
// update with subtopic
|
|
|
|
cmd = exec.Command("swarm", "--bzzaccount", pkFile.Name(), "--bzzapi", endpoints[0], "feed", "update", "--name", subTopicHex, dataHex) |
|
|
|
cmd = exec.Command("swarm", "--bzzaccount", pkFile.Name(), "--bzzapi", httpEndpoint(hosts[0]), "feed", "update", "--name", subTopicHex, dataHex) |
|
|
|
cmd.Stdout = &out |
|
|
|
cmd.Stdout = &out |
|
|
|
log.Debug("update feed manifest subtopic cmd", "cmd", cmd) |
|
|
|
log.Debug("update feed manifest subtopic cmd", "cmd", cmd) |
|
|
|
err = cmd.Run() |
|
|
|
err = cmd.Run() |
|
|
@ -163,7 +179,7 @@ func feedUploadAndSync(c *cli.Context) error { |
|
|
|
out.Reset() |
|
|
|
out.Reset() |
|
|
|
|
|
|
|
|
|
|
|
// update with merged topic
|
|
|
|
// update with merged topic
|
|
|
|
cmd = exec.Command("swarm", "--bzzaccount", pkFile.Name(), "--bzzapi", endpoints[0], "feed", "update", "--topic", topicHex, "--name", subTopicHex, dataHex) |
|
|
|
cmd = exec.Command("swarm", "--bzzaccount", pkFile.Name(), "--bzzapi", httpEndpoint(hosts[0]), "feed", "update", "--topic", topicHex, "--name", subTopicHex, dataHex) |
|
|
|
cmd.Stdout = &out |
|
|
|
cmd.Stdout = &out |
|
|
|
log.Debug("update feed manifest merged topic cmd", "cmd", cmd) |
|
|
|
log.Debug("update feed manifest merged topic cmd", "cmd", cmd) |
|
|
|
err = cmd.Run() |
|
|
|
err = cmd.Run() |
|
|
@ -177,14 +193,14 @@ func feedUploadAndSync(c *cli.Context) error { |
|
|
|
|
|
|
|
|
|
|
|
// retrieve the data
|
|
|
|
// retrieve the data
|
|
|
|
wg := sync.WaitGroup{} |
|
|
|
wg := sync.WaitGroup{} |
|
|
|
for _, endpoint := range endpoints { |
|
|
|
for _, host := range hosts { |
|
|
|
// raw retrieve, topic only
|
|
|
|
// raw retrieve, topic only
|
|
|
|
for _, hex := range []string{topicHex, subTopicOnlyHex, mergedSubTopicHex} { |
|
|
|
for _, hex := range []string{topicHex, subTopicOnlyHex, mergedSubTopicHex} { |
|
|
|
wg.Add(1) |
|
|
|
wg.Add(1) |
|
|
|
ruid := uuid.New()[:8] |
|
|
|
ruid := uuid.New()[:8] |
|
|
|
go func(hex string, endpoint string, ruid string) { |
|
|
|
go func(hex string, endpoint string, ruid string) { |
|
|
|
for { |
|
|
|
for { |
|
|
|
err := fetchFeed(hex, userHex, endpoint, dataHash, ruid) |
|
|
|
err := fetchFeed(hex, userHex, httpEndpoint(host), dataHash, ruid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
@ -192,21 +208,18 @@ func feedUploadAndSync(c *cli.Context) error { |
|
|
|
wg.Done() |
|
|
|
wg.Done() |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
}(hex, endpoint, ruid) |
|
|
|
}(hex, httpEndpoint(host), ruid) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
wg.Wait() |
|
|
|
wg.Wait() |
|
|
|
log.Info("all endpoints synced random data successfully") |
|
|
|
log.Info("all endpoints synced random data successfully") |
|
|
|
|
|
|
|
|
|
|
|
// upload test file
|
|
|
|
// upload test file
|
|
|
|
seed := int(time.Now().UnixNano() / 1e6) |
|
|
|
log.Info("feed uploading to "+httpEndpoint(hosts[0])+" and syncing", "seed", seed) |
|
|
|
log.Info("feed uploading to "+endpoints[0]+" and syncing", "seed", seed) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h = md5.New() |
|
|
|
randomBytes := testutil.RandomBytes(seed, filesize*1000) |
|
|
|
r := io.TeeReader(io.LimitReader(crand.Reader, int64(filesize*1000)), h) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hash, err := upload(r, filesize*1000, endpoints[0]) |
|
|
|
hash, err := upload(randomBytes, httpEndpoint(hosts[0])) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
@ -220,7 +233,7 @@ func feedUploadAndSync(c *cli.Context) error { |
|
|
|
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fileHash)) |
|
|
|
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fileHash)) |
|
|
|
|
|
|
|
|
|
|
|
// update file with topic
|
|
|
|
// update file with topic
|
|
|
|
cmd = exec.Command("swarm", "--bzzaccount", pkFile.Name(), "--bzzapi", endpoints[0], "feed", "update", "--topic", topicHex, multihashHex) |
|
|
|
cmd = exec.Command("swarm", "--bzzaccount", pkFile.Name(), "--bzzapi", httpEndpoint(hosts[0]), "feed", "update", "--topic", topicHex, multihashHex) |
|
|
|
cmd.Stdout = &out |
|
|
|
cmd.Stdout = &out |
|
|
|
err = cmd.Run() |
|
|
|
err = cmd.Run() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -230,7 +243,7 @@ func feedUploadAndSync(c *cli.Context) error { |
|
|
|
out.Reset() |
|
|
|
out.Reset() |
|
|
|
|
|
|
|
|
|
|
|
// update file with subtopic
|
|
|
|
// update file with subtopic
|
|
|
|
cmd = exec.Command("swarm", "--bzzaccount", pkFile.Name(), "--bzzapi", endpoints[0], "feed", "update", "--name", subTopicHex, multihashHex) |
|
|
|
cmd = exec.Command("swarm", "--bzzaccount", pkFile.Name(), "--bzzapi", httpEndpoint(hosts[0]), "feed", "update", "--name", subTopicHex, multihashHex) |
|
|
|
cmd.Stdout = &out |
|
|
|
cmd.Stdout = &out |
|
|
|
err = cmd.Run() |
|
|
|
err = cmd.Run() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -240,7 +253,7 @@ func feedUploadAndSync(c *cli.Context) error { |
|
|
|
out.Reset() |
|
|
|
out.Reset() |
|
|
|
|
|
|
|
|
|
|
|
// update file with merged topic
|
|
|
|
// update file with merged topic
|
|
|
|
cmd = exec.Command("swarm", "--bzzaccount", pkFile.Name(), "--bzzapi", endpoints[0], "feed", "update", "--topic", topicHex, "--name", subTopicHex, multihashHex) |
|
|
|
cmd = exec.Command("swarm", "--bzzaccount", pkFile.Name(), "--bzzapi", httpEndpoint(hosts[0]), "feed", "update", "--topic", topicHex, "--name", subTopicHex, multihashHex) |
|
|
|
cmd.Stdout = &out |
|
|
|
cmd.Stdout = &out |
|
|
|
err = cmd.Run() |
|
|
|
err = cmd.Run() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -251,7 +264,7 @@ func feedUploadAndSync(c *cli.Context) error { |
|
|
|
|
|
|
|
|
|
|
|
time.Sleep(3 * time.Second) |
|
|
|
time.Sleep(3 * time.Second) |
|
|
|
|
|
|
|
|
|
|
|
for _, endpoint := range endpoints { |
|
|
|
for _, host := range hosts { |
|
|
|
|
|
|
|
|
|
|
|
// manifest retrieve, topic only
|
|
|
|
// manifest retrieve, topic only
|
|
|
|
for _, url := range []string{manifestWithTopic, manifestWithSubTopic, manifestWithMergedTopic} { |
|
|
|
for _, url := range []string{manifestWithTopic, manifestWithSubTopic, manifestWithMergedTopic} { |
|
|
@ -259,7 +272,7 @@ func feedUploadAndSync(c *cli.Context) error { |
|
|
|
ruid := uuid.New()[:8] |
|
|
|
ruid := uuid.New()[:8] |
|
|
|
go func(url string, endpoint string, ruid string) { |
|
|
|
go func(url string, endpoint string, ruid string) { |
|
|
|
for { |
|
|
|
for { |
|
|
|
err := fetch(url, endpoint, fileHash, ruid) |
|
|
|
err := fetch(url, endpoint, fileHash, ruid, "") |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
@ -267,7 +280,7 @@ func feedUploadAndSync(c *cli.Context) error { |
|
|
|
wg.Done() |
|
|
|
wg.Done() |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
}(url, endpoint, ruid) |
|
|
|
}(url, httpEndpoint(host), ruid) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|