Skip to content

Commit

Permalink
node/p2p: simplify copying and returning of announce multi addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
ynewmann committed Dec 23, 2021
1 parent 7e4c966 commit f68b864
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions node/p2p/addrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ func AddrsFactory(announce []string, noAnnounce []string) func() (_ p2pconfig.Ad
maNoAnnounce[string(maddr.Bytes())] = true
}

return func(maListen []ma.Multiaddr) (out []ma.Multiaddr) {
// combine maListen and maAnnounce addresses
out = make([]ma.Multiaddr, len(maAnnounce), len(maAnnounce)+len(maListen))
copy(out[:len(maAnnounce)], maAnnounce)
return func(maListen []ma.Multiaddr) []ma.Multiaddr {
// copy maAnnounce to out
out := make([]ma.Multiaddr, 0, len(maAnnounce)+len(maListen))
out = append(out, maAnnounce...)

// filter out unneeded
for _, maddr := range maListen {
Expand All @@ -57,7 +57,7 @@ func AddrsFactory(announce []string, noAnnounce []string) func() (_ p2pconfig.Ad
out = append(out, maddr)
}
}
return
return out
}, nil
}
}

0 comments on commit f68b864

Please sign in to comment.