p2p: return copy of capabilities in Peer.Caps()

This commit is contained in:
GarmashAlex 2025-03-13 22:44:07 +03:00 committed by GitHub
parent f9f1172d59
commit dff049c2ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -173,8 +173,10 @@ func (p *Peer) Fullname() string {
// Caps returns the capabilities (supported subprotocols) of the remote peer.
func (p *Peer) Caps() []Cap {
// TODO: maybe return copy
return p.rw.caps
// Return a copy of the capabilities slice to prevent modification of the original
caps := make([]Cap, len(p.rw.caps))
copy(caps, p.rw.caps)
return caps
}
// RunningCap returns true if the peer is actively connected using any of the