aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/swarm/swarm-smoke/feed_upload_and_sync.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/swarm/swarm-smoke/feed_upload_and_sync.go')
-rw-r--r--cmd/swarm/swarm-smoke/feed_upload_and_sync.go98
1 files changed, 5 insertions, 93 deletions
diff --git a/cmd/swarm/swarm-smoke/feed_upload_and_sync.go b/cmd/swarm/swarm-smoke/feed_upload_and_sync.go
index 2c5e3fd23..a322ba89c 100644
--- a/cmd/swarm/swarm-smoke/feed_upload_and_sync.go
+++ b/cmd/swarm/swarm-smoke/feed_upload_and_sync.go
@@ -2,13 +2,11 @@ package main
import (
"bytes"
- "context"
"crypto/md5"
+ crand "crypto/rand"
"fmt"
"io"
"io/ioutil"
- "net/http"
- "net/http/httptrace"
"os"
"os/exec"
"strings"
@@ -18,13 +16,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
- "github.com/ethereum/go-ethereum/metrics"
- "github.com/ethereum/go-ethereum/swarm/api/client"
- "github.com/ethereum/go-ethereum/swarm/spancontext"
"github.com/ethereum/go-ethereum/swarm/storage/feed"
- "github.com/ethereum/go-ethereum/swarm/testutil"
- colorable "github.com/mattn/go-colorable"
- opentracing "github.com/opentracing/opentracing-go"
"github.com/pborman/uuid"
cli "gopkg.in/urfave/cli.v1"
)
@@ -33,27 +25,6 @@ const (
feedRandomDataLength = 8
)
-func cliFeedUploadAndSync(c *cli.Context) error {
- metrics.GetOrRegisterCounter("feed-and-sync", nil).Inc(1)
- log.Root().SetHandler(log.CallerFileHandler(log.LvlFilterHandler(log.Lvl(verbosity), log.StreamHandler(colorable.NewColorableStderr(), log.TerminalFormat(true)))))
-
- errc := make(chan error)
- go func() {
- errc <- feedUploadAndSync(c)
- }()
-
- select {
- case err := <-errc:
- if err != nil {
- metrics.GetOrRegisterCounter("feed-and-sync.fail", nil).Inc(1)
- }
- return err
- case <-time.After(time.Duration(timeout) * time.Second):
- metrics.GetOrRegisterCounter("feed-and-sync.timeout", nil).Inc(1)
- return fmt.Errorf("timeout after %v sec", timeout)
- }
-}
-
// TODO: retrieve with manifest + extract repeating code
func feedUploadAndSync(c *cli.Context) error {
defer func(now time.Time) { log.Info("total time", "time", time.Since(now), "size (kb)", filesize) }(time.Now())
@@ -232,9 +203,10 @@ func feedUploadAndSync(c *cli.Context) error {
seed := int(time.Now().UnixNano() / 1e6)
log.Info("feed uploading to "+endpoints[0]+" and syncing", "seed", seed)
- randomBytes := testutil.RandomBytes(seed, filesize*1000)
+ h = md5.New()
+ r := io.TeeReader(io.LimitReader(crand.Reader, int64(filesize*1000)), h)
- hash, err := upload(&randomBytes, endpoints[0])
+ hash, err := upload(r, filesize*1000, endpoints[0])
if err != nil {
return err
}
@@ -243,10 +215,7 @@ func feedUploadAndSync(c *cli.Context) error {
return err
}
multihashHex := hexutil.Encode(hashBytes)
- fileHash, err := digest(bytes.NewReader(randomBytes))
- if err != nil {
- return err
- }
+ fileHash := h.Sum(nil)
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fileHash))
@@ -307,60 +276,3 @@ func feedUploadAndSync(c *cli.Context) error {
return nil
}
-
-func fetchFeed(topic string, user string, endpoint string, original []byte, ruid string) error {
- ctx, sp := spancontext.StartSpan(context.Background(), "feed-and-sync.fetch")
- defer sp.Finish()
-
- log.Trace("sleeping", "ruid", ruid)
- time.Sleep(3 * time.Second)
-
- log.Trace("http get request (feed)", "ruid", ruid, "api", endpoint, "topic", topic, "user", user)
-
- var tn time.Time
- reqUri := endpoint + "/bzz-feed:/?topic=" + topic + "&user=" + user
- req, _ := http.NewRequest("GET", reqUri, nil)
-
- opentracing.GlobalTracer().Inject(
- sp.Context(),
- opentracing.HTTPHeaders,
- opentracing.HTTPHeadersCarrier(req.Header))
-
- trace := client.GetClientTrace("feed-and-sync - http get", "feed-and-sync", ruid, &tn)
-
- req = req.WithContext(httptrace.WithClientTrace(ctx, trace))
- transport := http.DefaultTransport
-
- //transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
-
- tn = time.Now()
- res, err := transport.RoundTrip(req)
- if err != nil {
- log.Error(err.Error(), "ruid", ruid)
- return err
- }
-
- log.Trace("http get response (feed)", "ruid", ruid, "api", endpoint, "topic", topic, "user", user, "code", res.StatusCode, "len", res.ContentLength)
-
- if res.StatusCode != 200 {
- return fmt.Errorf("expected status code %d, got %v (ruid %v)", 200, res.StatusCode, ruid)
- }
-
- defer res.Body.Close()
-
- rdigest, err := digest(res.Body)
- if err != nil {
- log.Warn(err.Error(), "ruid", ruid)
- return err
- }
-
- if !bytes.Equal(rdigest, original) {
- err := fmt.Errorf("downloaded imported file md5=%x is not the same as the generated one=%x", rdigest, original)
- log.Warn(err.Error(), "ruid", ruid)
- return err
- }
-
- log.Trace("downloaded file matches random file", "ruid", ruid, "len", res.ContentLength)
-
- return nil
-}