diff --git a/cmd/sendblob.go b/cmd/sendblob.go index f5070e4..2a3051c 100644 --- a/cmd/sendblob.go +++ b/cmd/sendblob.go @@ -27,13 +27,13 @@ func sendBlobCmd(cmd *cobra.Command, args []string) { c := reflector.Client{} err := c.Connect(addr) if err != nil { - log.Fatal("error connecting client to server", err) + 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) + log.Fatal("failed to make random blob: ", err) } err = c.SendBlob(blob) diff --git a/main.go b/main.go index 00f66cb..f268821 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,13 @@ package main -import "github.com/lbryio/reflector.go/cmd" +import ( + "math/rand" + "time" + + "github.com/lbryio/reflector.go/cmd" +) func main() { + rand.Seed(time.Now().UnixNano()) cmd.Execute() } diff --git a/reflector/client.go b/reflector/client.go index 800b5a7..6bc888a 100644 --- a/reflector/client.go +++ b/reflector/client.go @@ -69,7 +69,7 @@ func (c *Client) SendBlob(blob stream.Blob) error { } if !sendResp.SendBlob { - return ErrBlobExists + return errors.Prefix(blobHash[:8], ErrBlobExists) } log.Println("Sending blob " + blobHash[:8]) @@ -96,7 +96,7 @@ func (c *Client) doHandshake(version int) error { return errors.Err("not connected") } - handshake, err := json.Marshal(handshakeRequestResponse{Version: version}) + handshake, err := json.Marshal(handshakeRequestResponse{Version: &version}) if err != nil { return err } @@ -110,7 +110,9 @@ func (c *Client) doHandshake(version int) error { err = json.NewDecoder(c.conn).Decode(&resp) if err != nil { return err - } else if resp.Version != version { + } else if resp.Version == nil { + return errors.Err("invalid handshake") + } else if *resp.Version != version { return errors.Err("handshake version mismatch") } diff --git a/reflector/server.go b/reflector/server.go index c54b2ad..1aaf983 100644 --- a/reflector/server.go +++ b/reflector/server.go @@ -274,7 +274,9 @@ func (s *Server) doHandshake(conn net.Conn) error { err := s.read(conn, &handshake) if err != nil { return err - } else if handshake.Version != protocolVersion1 && handshake.Version != protocolVersion2 { + } else if handshake.Version == nil { + return errors.Err("handshake is missing protocol version") + } else if *handshake.Version != protocolVersion1 && *handshake.Version != protocolVersion2 { return errors.Err("protocol version not supported") } @@ -411,7 +413,7 @@ func BlobHash(blob []byte) string { //} type handshakeRequestResponse struct { - Version int `json:"version"` + Version *int `json:"version"` } type sendBlobRequest struct { diff --git a/wallet/network.go b/wallet/network.go index c8194be..93f8932 100644 --- a/wallet/network.go +++ b/wallet/network.go @@ -67,7 +67,6 @@ func (n *Node) Connect(addrs []string, config *tls.Config) error { } // shuffle addresses for load balancing - rand.Seed(time.Now().UnixNano()) rand.Shuffle(len(addrs), func(i, j int) { addrs[i], addrs[j] = addrs[j], addrs[i] }) var err error