Skip to content

Commit

Permalink
replace old shuffles with rand.Shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Jun 13, 2024
1 parent b6ed519 commit 5b1f80e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 2 additions & 4 deletions addrmgr/addrmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,9 @@ func (a *AddrManager) AddressCache() []*NetAddress {

// Fisher-Yates shuffle the array. We only need to do the first
// numAddresses since we are throwing away the rest.
for i := 0; i < numAddresses; i++ {
// Pick a number between current index and the end.
j := rand.IntN(addrLen-i) + i
rand.Shuffle(len(allAddr), func(i, j int) {
allAddr[i], allAddr[j] = allAddr[j], allAddr[i]
}
})

// Slice off the limit we are willing to share.
return allAddr[0:numAddresses]
Expand Down
5 changes: 2 additions & 3 deletions peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,10 +844,9 @@ func (p *Peer) PushAddrMsg(addresses []*wire.NetAddress) ([]*wire.NetAddress, er
// Randomize the addresses sent if there are more than the maximum allowed.
if len(msg.AddrList) > wire.MaxAddrPerMsg {
// Shuffle the address list.
for i := range msg.AddrList {
j := rand.Int64n(int64(i) + 1)
rand.Shuffle(len(msg.AddrList), func(i, j int) {
msg.AddrList[i], msg.AddrList[j] = msg.AddrList[j], msg.AddrList[i]
}
})

// Truncate it to the maximum size.
msg.AddrList = msg.AddrList[:wire.MaxAddrPerMsg]
Expand Down

0 comments on commit 5b1f80e

Please sign in to comment.