mirror of
https://github.com/logos-messaging/go-libp2p-rendezvous.git
synced 2026-01-02 12:53:13 +00:00
update for response error changes in the protocol
This commit is contained in:
parent
b7c304ddf3
commit
aeac2e2a0f
@ -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 {
|
||||
|
||||
11
proto.go
11
proto.go
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user