Skip to content

Commit

Permalink
fix: discover bootnode, try quic addr first
Browse files Browse the repository at this point in the history
  • Loading branch information
istae authored and mrekucci committed Nov 6, 2023
1 parent c45df4a commit d8a2476
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/p2p/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"context"
"errors"
"fmt"
"math/rand"
"sort"
"strings"

ma "github.com/multiformats/go-multiaddr"
madns "github.com/multiformats/go-multiaddr-dns"
Expand All @@ -35,9 +36,11 @@ func Discover(ctx context.Context, addr ma.Multiaddr, f func(ma.Multiaddr) (bool
return false, errors.New("non-resolvable API endpoint")
}

rand.Shuffle(len(addrs), func(i, j int) {
addrs[i], addrs[j] = addrs[j], addrs[i]
// sort addrs so that quic is tried first
sort.Slice(addrs, func(i, j int) bool {
return strings.Contains(addrs[i].String(), "/quic")
})

for _, addr := range addrs {
stopped, err := Discover(ctx, addr, f)
if err != nil {
Expand Down

0 comments on commit d8a2476

Please sign in to comment.