diff --git a/go.mod b/go.mod index ce070c5b69..08af87adbb 100644 --- a/go.mod +++ b/go.mod @@ -55,7 +55,7 @@ require ( go.uber.org/fx v1.20.0 go.uber.org/goleak v1.1.12 golang.org/x/crypto v0.11.0 - golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 + golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb golang.org/x/sync v0.3.0 golang.org/x/sys v0.10.0 golang.org/x/tools v0.11.0 diff --git a/go.sum b/go.sum index 2d9e1e0b2e..a6fe8ddd01 100644 --- a/go.sum +++ b/go.sum @@ -563,6 +563,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw= golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb h1:mIKbk8weKhSeLH2GmUTrvx8CjkyJmnU1wFmg59CUjFA= +golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index 69506e9b34..dadb4d75a0 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -1,7 +1,6 @@ package identify import ( - "bytes" "context" "errors" "fmt" @@ -556,7 +555,9 @@ func readAllIDMessages(r pbio.Reader, finalMsg proto.Message) error { func (ids *idService) updateSnapshot() (updated bool) { addrs := ids.Host.Addrs() - slices.SortFunc(addrs, func(a, b ma.Multiaddr) bool { return bytes.Compare(a.Bytes(), b.Bytes()) == -1 }) + slices.SortFunc(addrs, func(a, b ma.Multiaddr) int { + return len(a.Bytes()) + len(b.Bytes()) + }) protos := ids.Host.Mux().Protocols() slices.Sort(protos) snapshot := identifySnapshot{ diff --git a/p2p/protocol/identify/obsaddr.go b/p2p/protocol/identify/obsaddr.go index 0412541f5d..415a5d1d48 100644 --- a/p2p/protocol/identify/obsaddr.go +++ b/p2p/protocol/identify/obsaddr.go @@ -3,6 +3,7 @@ package identify import ( "context" "fmt" + "math" "sync" "time" @@ -214,11 +215,11 @@ func (oas *ObservedAddrManager) filter(observedAddrs []*observedAddr) []ma.Multi // We prefer inbound connection observations over outbound. // For ties, we prefer the ones with more votes. - slices.SortFunc(s, func(first, second *observedAddr) bool { + slices.SortFunc(s, func(first, second *observedAddr) int { if first.numInbound > second.numInbound { - return true + return math.MaxInt } - return len(first.seenBy) > len(second.seenBy) + return len(first.seenBy) + len(second.seenBy) }) for i := 0; i < maxObservedAddrsPerIPAndTransport && i < len(s); i++ { diff --git a/test-plans/go.mod b/test-plans/go.mod index c752cbe887..bb1d1a6791 100644 --- a/test-plans/go.mod +++ b/test-plans/go.mod @@ -85,7 +85,7 @@ require ( go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.24.0 // indirect golang.org/x/crypto v0.11.0 // indirect - golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect + golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb // indirect golang.org/x/mod v0.12.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/sync v0.3.0 // indirect diff --git a/test-plans/go.sum b/test-plans/go.sum index f5d7bafb60..3003ee1b1e 100644 --- a/test-plans/go.sum +++ b/test-plans/go.sum @@ -325,6 +325,7 @@ golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIi golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw= golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=