update for response error changes in the protocol

This commit is contained in:
vyzo 2018-04-21 12:06:27 +03:00
parent b7c304ddf3
commit aeac2e2a0f
2 changed files with 14 additions and 4 deletions

View File

@ -66,7 +66,7 @@ func (cli *client) Register(ctx context.Context, ns string, ttl int) error {
status := res.GetRegisterResponse().GetStatus()
if status != pb.Message_OK {
return RegistrationError(status)
return RendezvousError{Status: status, Text: res.GetRegisterResponse().GetStatusText()}
}
return nil
@ -142,6 +142,11 @@ func discoverQuery(ns string, limit int, cookie []byte, r ggio.Reader, w ggio.Wr
return nil, nil, fmt.Errorf("Unexpected response: %s", res.GetType().String())
}
status := res.GetDiscoverResponse().GetStatus()
if status != pb.Message_OK {
return nil, nil, RendezvousError{Status: status, Text: res.GetDiscoverResponse().GetStatusText()}
}
regs := res.GetDiscoverResponse().GetRegistrations()
pinfos := make([]pstore.PeerInfo, 0, len(regs))
for _, reg := range regs {

View File

@ -1,6 +1,8 @@
package rendezvous
import (
"fmt"
pb "github.com/libp2p/go-libp2p-rendezvous/pb"
peer "github.com/libp2p/go-libp2p-peer"
@ -13,10 +15,13 @@ const (
RendezvousProto = protocol.ID("/rendezvous/1.0.0")
)
type RegistrationError pb.Message_RegisterStatus
type RendezvousError struct {
Status pb.Message_ResponseStatus
Text string
}
func (e RegistrationError) Error() string {
return "Registration error: " + pb.Message_RegisterStatus(e).String()
func (e RendezvousError) Error() string {
return fmt.Sprintf("Rendezvous error: %s (%s)", e.Text, pb.Message_ResponseStatus(e.Status).String())
}
func newRegisterMessage(ns string, pi pstore.PeerInfo, ttl int) *pb.Message {