diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index e997060ab9..69506e9b34 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "sort" "sync" "time" @@ -557,9 +556,9 @@ func readAllIDMessages(r pbio.Reader, finalMsg proto.Message) error { func (ids *idService) updateSnapshot() (updated bool) { addrs := ids.Host.Addrs() - sort.Slice(addrs, func(i, j int) bool { return bytes.Compare(addrs[i].Bytes(), addrs[j].Bytes()) == -1 }) + slices.SortFunc(addrs, func(a, b ma.Multiaddr) bool { return bytes.Compare(a.Bytes(), b.Bytes()) == -1 }) protos := ids.Host.Mux().Protocols() - sort.Slice(protos, func(i, j int) bool { return protos[i] < protos[j] }) + slices.Sort(protos) snapshot := identifySnapshot{ addrs: addrs, protocols: protos, diff --git a/p2p/protocol/identify/obsaddr.go b/p2p/protocol/identify/obsaddr.go index 451af096d9..3422a286ff 100644 --- a/p2p/protocol/identify/obsaddr.go +++ b/p2p/protocol/identify/obsaddr.go @@ -3,10 +3,11 @@ package identify import ( "context" "fmt" - "sort" "sync" "time" + "golang.org/x/exp/slices" + "github.com/libp2p/go-libp2p/core/event" "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/network" @@ -213,14 +214,10 @@ func (oas *ObservedAddrManager) filter(observedAddrs []*observedAddr) []ma.Multi // We prefer inbound connection observations over outbound. // For ties, we prefer the ones with more votes. - sort.Slice(s, func(i int, j int) bool { - first := s[i] - second := s[j] - + slices.SortFunc(s, func(first, second *observedAddr) bool { if first.numInbound > second.numInbound { return true } - return len(first.seenBy) > len(second.seenBy) })