From 8364d3fc5445f8e7b84b44dd1457e9775a973202 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Mon, 5 Oct 2020 18:07:06 -0400 Subject: [PATCH] small changes for easier testing --- cmd/getstream.go | 8 +++++++- cmd/reflector.go | 4 +++- cmd/root.go | 4 ++++ cmd/sendblob.go | 47 ++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/cmd/getstream.go b/cmd/getstream.go index a009ab2..f3f6d8f 100644 --- a/cmd/getstream.go +++ b/cmd/getstream.go @@ -3,6 +3,7 @@ package cmd import ( "encoding/hex" "os" + "time" "github.com/lbryio/reflector.go/peer" "github.com/lbryio/reflector.go/store" @@ -49,7 +50,12 @@ func getStreamCmd(cmd *cobra.Command, args []string) { log.Fatal(err) } - f, err := os.Create(wd + "/" + sd.SuggestedFileName) + filename := sd.SuggestedFileName + if filename == "" { + filename = "stream_" + time.Now().Format("20060102_150405") + } + + f, err := os.Create(wd + "/" + filename) if err != nil { log.Fatal(err) } diff --git a/cmd/reflector.go b/cmd/reflector.go index 41f6646..c940131 100644 --- a/cmd/reflector.go +++ b/cmd/reflector.go @@ -25,6 +25,7 @@ var http3PeerPort int var receiverPort int var metricsPort int var disableUploads bool +var disableBlocklist bool var proxyAddress string var proxyPort string var proxyProtocol string @@ -47,6 +48,7 @@ func init() { cmd.Flags().IntVar(&receiverPort, "receiver-port", 5566, "The port reflector will receive content from") cmd.Flags().IntVar(&metricsPort, "metrics-port", 2112, "The port reflector will use for metrics") cmd.Flags().BoolVar(&disableUploads, "disable-uploads", false, "Disable uploads to this reflector server") + cmd.Flags().BoolVar(&disableBlocklist, "disable-blocklist", false, "Disable blocklist watching/updating") cmd.Flags().BoolVar(&useDB, "use-db", true, "whether to connect to the reflector db or not") rootCmd.AddCommand(cmd) } @@ -94,7 +96,7 @@ func reflectorCmd(cmd *cobra.Command, args []string) { reflectorServer = reflector.NewServer(blobStore) reflectorServer.Timeout = 3 * time.Minute - reflectorServer.EnableBlocklist = true + reflectorServer.EnableBlocklist = !disableBlocklist err = reflectorServer.Start(":" + strconv.Itoa(receiverPort)) if err != nil { diff --git a/cmd/root.go b/cmd/root.go index a18dfb2..ce28f8f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -4,6 +4,7 @@ import ( "encoding/json" "io/ioutil" "os" + "strings" "github.com/lbryio/lbry.go/v2/dht" "github.com/lbryio/lbry.go/v2/extras/errors" @@ -68,8 +69,11 @@ func preRun(cmd *cobra.Command, args []string) { debugLogger.SetOutput(os.Stderr) if util.InSlice(verboseAll, verbose) { + logrus.Info("global verbose logging enabled") logrus.SetLevel(logrus.DebugLevel) verbose = []string{verboseDHT, verboseNodeFinder} + } else if len(verbose) > 0 { + logrus.Infof("verbose logging enabled for: %s", strings.Join(verbose, ", ")) } for _, debugType := range verbose { diff --git a/cmd/sendblob.go b/cmd/sendblob.go index eb6ccf6..3cd9f05 100644 --- a/cmd/sendblob.go +++ b/cmd/sendblob.go @@ -2,6 +2,8 @@ package cmd import ( "crypto/rand" + "io/ioutil" + "os" "github.com/lbryio/reflector.go/reflector" @@ -13,9 +15,9 @@ import ( func init() { var cmd = &cobra.Command{ - Use: "sendblob ADDRESS:PORT", + Use: "sendblob ADDRESS:PORT [PATH]", Short: "Send a random blob to a reflector server", - Args: cobra.ExactArgs(1), + Args: cobra.RangeArgs(1, 2), Run: sendBlobCmd, } rootCmd.AddCommand(cmd) @@ -23,6 +25,10 @@ func init() { func sendBlobCmd(cmd *cobra.Command, args []string) { addr := args[0] + var path string + if len(args) >= 2 { + path = args[1] + } c := reflector.Client{} err := c.Connect(addr) @@ -30,14 +36,37 @@ func sendBlobCmd(cmd *cobra.Command, args []string) { log.Fatal("error connecting client to server: ", err) } - blob := make(stream.Blob, 1024) - _, err = rand.Read(blob) - if err != nil { - log.Fatal("failed to make random blob: ", err) + if path == "" { + blob := make(stream.Blob, 1024) + _, err = rand.Read(blob) + if err != nil { + log.Fatal("failed to make random blob: ", err) + } + + err = c.SendBlob(blob) + if err != nil { + log.Error(err) + } + return } - err = c.SendBlob(blob) - if err != nil { - log.Error(err) + file, err := os.Open(path) + checkErr(err) + data, err := ioutil.ReadAll(file) + checkErr(err) + s, err := stream.New(data) + checkErr(err) + + sdBlob := &stream.SDBlob{} + err = sdBlob.FromBlob(s[0]) + checkErr(err) + + for i, b := range s { + if i == 0 { + err = c.SendSDBlob(b) + } else { + err = c.SendBlob(b) + } + checkErr(err) } }