Skip to content

Commit 8a75690

Browse files
committed
go/p2p/rpc: Add fallback protocols to RPC client
1 parent 810f1e3 commit 8a75690

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

go/p2p/rpc/client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ type Client interface {
269269
}
270270

271271
type client struct {
272-
host core.Host
273-
protocolID protocol.ID
272+
host core.Host
273+
protocolIDs []protocol.ID
274274

275275
listeners struct {
276276
sync.RWMutex
@@ -486,7 +486,7 @@ func (c *client) call(
486486
stream, err := c.host.NewStream(
487487
ctx,
488488
peerID,
489-
c.protocolID,
489+
c.protocolIDs...,
490490
)
491491
if err != nil {
492492
return fmt.Errorf("failed to open stream: %w", err)
@@ -612,15 +612,15 @@ func retryFn(ctx context.Context, fn func() error, maxRetries uint64, retryInter
612612
}
613613

614614
// NewClient creates a new RPC client for the given protocol.
615-
func NewClient(h host.Host, p protocol.ID) Client {
615+
func NewClient(h host.Host, p protocol.ID, fallback ...protocol.ID) Client {
616616
if h == nil {
617617
// No P2P service, use the no-op client.
618618
return &nopClient{}
619619
}
620620

621621
return &client{
622-
host: h,
623-
protocolID: p,
622+
host: h,
623+
protocolIDs: append([]protocol.ID{p}, fallback...),
624624
listeners: struct {
625625
sync.RWMutex
626626
m map[ClientListener]struct{}

0 commit comments

Comments
 (0)