mirror of
https://github.com/LBRYFoundation/reflector.go.git
synced 2025-08-23 09:17:24 +00:00
better error when connection fails
This commit is contained in:
parent
2e81b1ab03
commit
c649636eeb
5 changed files with 18 additions and 9 deletions
|
@ -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)
|
||||
|
|
8
main.go
8
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()
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue