small changes for easier testing

This commit is contained in:
Alex Grintsvayg 2020-10-05 18:07:06 -04:00
parent de0ccd4da7
commit 8364d3fc54
No known key found for this signature in database
GPG key ID: AEB3F089F86A22B5
4 changed files with 52 additions and 11 deletions

View file

@ -3,6 +3,7 @@ package cmd
import ( import (
"encoding/hex" "encoding/hex"
"os" "os"
"time"
"github.com/lbryio/reflector.go/peer" "github.com/lbryio/reflector.go/peer"
"github.com/lbryio/reflector.go/store" "github.com/lbryio/reflector.go/store"
@ -49,7 +50,12 @@ func getStreamCmd(cmd *cobra.Command, args []string) {
log.Fatal(err) 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 { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View file

@ -25,6 +25,7 @@ var http3PeerPort int
var receiverPort int var receiverPort int
var metricsPort int var metricsPort int
var disableUploads bool var disableUploads bool
var disableBlocklist bool
var proxyAddress string var proxyAddress string
var proxyPort string var proxyPort string
var proxyProtocol 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(&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().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(&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") cmd.Flags().BoolVar(&useDB, "use-db", true, "whether to connect to the reflector db or not")
rootCmd.AddCommand(cmd) rootCmd.AddCommand(cmd)
} }
@ -94,7 +96,7 @@ func reflectorCmd(cmd *cobra.Command, args []string) {
reflectorServer = reflector.NewServer(blobStore) reflectorServer = reflector.NewServer(blobStore)
reflectorServer.Timeout = 3 * time.Minute reflectorServer.Timeout = 3 * time.Minute
reflectorServer.EnableBlocklist = true reflectorServer.EnableBlocklist = !disableBlocklist
err = reflectorServer.Start(":" + strconv.Itoa(receiverPort)) err = reflectorServer.Start(":" + strconv.Itoa(receiverPort))
if err != nil { if err != nil {

View file

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"os" "os"
"strings"
"github.com/lbryio/lbry.go/v2/dht" "github.com/lbryio/lbry.go/v2/dht"
"github.com/lbryio/lbry.go/v2/extras/errors" "github.com/lbryio/lbry.go/v2/extras/errors"
@ -68,8 +69,11 @@ func preRun(cmd *cobra.Command, args []string) {
debugLogger.SetOutput(os.Stderr) debugLogger.SetOutput(os.Stderr)
if util.InSlice(verboseAll, verbose) { if util.InSlice(verboseAll, verbose) {
logrus.Info("global verbose logging enabled")
logrus.SetLevel(logrus.DebugLevel) logrus.SetLevel(logrus.DebugLevel)
verbose = []string{verboseDHT, verboseNodeFinder} verbose = []string{verboseDHT, verboseNodeFinder}
} else if len(verbose) > 0 {
logrus.Infof("verbose logging enabled for: %s", strings.Join(verbose, ", "))
} }
for _, debugType := range verbose { for _, debugType := range verbose {

View file

@ -2,6 +2,8 @@ package cmd
import ( import (
"crypto/rand" "crypto/rand"
"io/ioutil"
"os"
"github.com/lbryio/reflector.go/reflector" "github.com/lbryio/reflector.go/reflector"
@ -13,9 +15,9 @@ import (
func init() { func init() {
var cmd = &cobra.Command{ var cmd = &cobra.Command{
Use: "sendblob ADDRESS:PORT", Use: "sendblob ADDRESS:PORT [PATH]",
Short: "Send a random blob to a reflector server", Short: "Send a random blob to a reflector server",
Args: cobra.ExactArgs(1), Args: cobra.RangeArgs(1, 2),
Run: sendBlobCmd, Run: sendBlobCmd,
} }
rootCmd.AddCommand(cmd) rootCmd.AddCommand(cmd)
@ -23,6 +25,10 @@ func init() {
func sendBlobCmd(cmd *cobra.Command, args []string) { func sendBlobCmd(cmd *cobra.Command, args []string) {
addr := args[0] addr := args[0]
var path string
if len(args) >= 2 {
path = args[1]
}
c := reflector.Client{} c := reflector.Client{}
err := c.Connect(addr) err := c.Connect(addr)
@ -30,6 +36,7 @@ func sendBlobCmd(cmd *cobra.Command, args []string) {
log.Fatal("error connecting client to server: ", err) log.Fatal("error connecting client to server: ", err)
} }
if path == "" {
blob := make(stream.Blob, 1024) blob := make(stream.Blob, 1024)
_, err = rand.Read(blob) _, err = rand.Read(blob)
if err != nil { if err != nil {
@ -40,4 +47,26 @@ func sendBlobCmd(cmd *cobra.Command, args []string) {
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
return
}
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)
}
} }