reflector.go/cmd/sendblob.go

44 lines
786 B
Go
Raw Normal View History

2018-08-15 20:25:15 +02:00
package cmd
import (
"crypto/rand"
"github.com/lbryio/reflector.go/reflector"
2019-01-10 14:02:43 +01:00
2019-11-14 01:11:35 +01:00
"github.com/lbryio/lbry.go/v2/stream"
2018-08-15 20:25:15 +02:00
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func init() {
var cmd = &cobra.Command{
Use: "sendblob ADDRESS:PORT",
Short: "Send a random blob to a reflector server",
Args: cobra.ExactArgs(1),
Run: sendBlobCmd,
}
rootCmd.AddCommand(cmd)
}
func sendBlobCmd(cmd *cobra.Command, args []string) {
addr := args[0]
c := reflector.Client{}
err := c.Connect(addr)
if err != nil {
2019-06-05 17:03:55 +02:00
log.Fatal("error connecting client to server: ", err)
2018-08-15 20:25:15 +02:00
}
2018-12-27 00:36:04 +01:00
blob := make(stream.Blob, 1024)
2018-08-15 20:25:15 +02:00
_, err = rand.Read(blob)
if err != nil {
2019-06-05 17:03:55 +02:00
log.Fatal("failed to make random blob: ", err)
2018-08-15 20:25:15 +02:00
}
err = c.SendBlob(blob)
if err != nil {
log.Error(err)
}
}